forked from vhaudiquet/rhema-claw
fix(claw): a repo watch resumes from its durable cursor, or starts now
The watcher kept one cursor per repo in a `Mutex<HashMap>`, so every daemon restart began with no cursor — and `Watcher::poll` reads "no cursor" as "feed everything the forge returns". A restart therefore replayed the repository's whole history: every old thread a dispatch, and every dispatch a comment posted on a thread nobody had just touched. The dispatcher's dedup lane does not save this: it dedups against the pending inbox, and a drained event re-ingests clean. The cursor is a row now (`watch_cursors`, beside `watch_health`, same scope/forge/subject key), written after every successful poll and read before every poll, so a restart resumes where the last pass stopped. A watch with no cursor yet — newly added, or added to a repository full of history — starts at *now* rather than at the beginning: a watch reports news, and history is not news. The seed is written before the poll, so a forge that is down cannot walk the start line forward on every pass and lose the news arriving in between. Removing a watch forgets its cursor too, so a re-add seeds afresh instead of resuming into a backlog. `Watcher::poll_since` is the seam the daemon needs to pass a cursor it keeps itself; `Watcher::poll` keeps its in-memory behaviour unchanged. `Timestamp::from_epoch_millis` spells an instant the way the forges spell theirs, which is what a seed is. Tests: the first pass feeds nothing and asks from the seeded instant; a second pass resumes from it; the cursor moves only forward per watch and dies with the watch. `e2e`/`continuity`/`http` seed an established watch, since their subject is the dispatch, not the bootstrap.
This commit is contained in:
1 parent
2f6c369e02
commit
b6327a458f
6 files changed
+287
-8
No files matched your search
@@ -13,10 +13,22 @@ use rhema_claw::{ClawConfig, run_once};
|
||||
/// carrying watches, and the test speaks to the daemon the way an
|
||||
/// integration would: through the store the routes share.
|
||||
fn seed_watch(dir: &tempfile::TempDir, host: &str) {
|
||||
rhema_claw::ClawStore::open(dir.path().join("dispatch.db"))
|
||||
.expect("the watch table opens")
|
||||
let store =
|
||||
rhema_claw::ClawStore::open(dir.path().join("dispatch.db")).expect("the watch table opens");
|
||||
store
|
||||
.add("github", "acme/widgets", Some(host), "tok")
|
||||
.expect("the seed row lands");
|
||||
// An established watch: it already has a cursor, so the pass reads
|
||||
// the feed from there instead of seeding one at *now* (which a
|
||||
// never-polled watch does, and which feeds nothing).
|
||||
store
|
||||
.set_cursor(
|
||||
rhema_claw::SCOPE_REPO,
|
||||
"github",
|
||||
"acme/widgets",
|
||||
"2026-10-01T00:00:00Z",
|
||||
)
|
||||
.expect("the cursor seeds");
|
||||
}
|
||||
use rhema_core::{Message, MockProvider, ModelOutput, Role, Session, StopReason, Usage};
|
||||
use rhema_rsd::{KeyState, Outcome, ResourceKey, SqliteStore, Store};
|
||||
|
||||
Reference in new issue
Block a user