fix(claw): a repo watch resumes from its durable cursor, or starts now
android / release (pull_request) Skipped
android / debug (pull_request) Successful in 2m17s
ci / checks (pull_request) Failing after 24s
ci / test (pull_request) Failing after 27s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Failing after 59s
ci / web (pull_request) Successful in 12s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (pull_request) Skipped
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (pull_request) Skipped
ci / publish-edge-chart (pull_request) Skipped

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:
kosmos committed 2026-11-14 13:25:44 +00:00
1 parent e4244f02d8
commit ba258a1f50
6 files changed
+265 -8

No files matched your search

+9 -2
View File
@@ -67,10 +67,17 @@ fn config(dir: &tempfile::TempDir) -> ClawConfig {
/// 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");
}
#[tokio::test]