fix(forge): poll gitea comments on instances that send an empty issue_url #1

Merged
vhaudiquet merged 3 commits from kosmos/rhema-claw:fix/gitea-comment-thread-number into main 2026-11-17 21:59:44 +00:00
Collaborator

The Gitea watch on vhaudiquet/rhema has never polled once: 5296 consecutive failures since it was created, all with

malformed forge response: comment issue_url without a thread number:

That is this bug. comment_event reads a comment's thread number from issue_url and nothing else, and the instance behind git.vhaudiquet.fr sends issue_url: "" on every row of the repo-wide /issues/comments feed (checked against the live API: all rows blank, pull_request_url and html_url populated). One blank row fails the whole pass with ForgeError::Parse, so no issue event, no PR comment and no review from that repo has ever reached the dispatcher. Nothing else in the adapter is at fault.

Commit 1 — the parse fix. The number comes from the first URL that carries one: issue_url, then pull_request_url, then html_url. Any fragment is stripped first, because a comment's html_url points at the comment (…/pulls/1#issuecomment-164) and its trailing segment is not a thread. is_pr reads the same three URLs, so a PR comment with a blank issue_url still lands on the pull request's sequence rather than the issue one. A row with no number anywhere stays a loud parse error — the fallbacks must not turn into a silently skipped event. Covered by three unit tests and one wiremock poll test that was red before the fix.

Commit 2 — the rest of the story, and the reason this could not ship alone. Fixing the parse is not enough, because the watcher's cursor lives in a Mutex<HashMap>: it is per-process. Every daemon restart polled from scratch, and Watcher::poll reads "no cursor" as "feed everything the forge returns". The dispatcher does not dedup that away — it dedups against the pending inbox, so an event that was already drained re-ingests clean. Fixing commit 1 in isolation would therefore have fired the repository's entire history as dispatches, each one a comment posted on an old thread.

So the cursor is a row now (watch_cursors, beside watch_health, same scope/forge/subject key): written after every successful poll, read before every one. A watch with no cursor yet — including one that has never polled, which is this watch — starts at now: a watch reports news, and a repository's 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. Removing a watch forgets its cursor, so a re-add seeds afresh instead of resuming into a backlog.

Watcher::poll_since is the seam that lets the daemon pass a cursor it keeps itself; Watcher::poll keeps its in-memory behaviour for other embedders. Timestamp::from_epoch_millis spells an instant the way the forges spell theirs, which is what a seed needs.

Review notes

  • Three existing tests (e2e, continuity, http) now seed a cursor before the pass, since their subject is the dispatch, not the bootstrap. In http the "watch added over HTTP detects on the next pass" assertion is split in two: the first pass seeds (0 events, asserted), and a rewound cursor then detects the feed (1 event, asserted) — the behaviour change is pinned instead of quietly accommodated.
  • Account watches keep their in-memory cursor; they are unused today and their replay is bounded by the notifications feed, but the same argument applies if one is ever enabled. Left out to keep this reviewable.
  • I could not build here (no Rust toolchain in this box), so CI is the first real compile — apologies if it needs a follow-up push for a fmt/clippy nit.

Not in this PR: the mention gate. Right now a repo watch dispatches every comment on the watched repo and posts the reply back as a comment, so once this watch starts working it will answer every comment in vhaudiquet/rhema, including its own replies. That is the next PR; until then this watch should stay quiet (it has no cursor to replay, and a new comment will trigger a reply).

The Gitea watch on `vhaudiquet/rhema` has never polled once: 5296 consecutive failures since it was created, all with ``` malformed forge response: comment issue_url without a thread number: ``` That is this bug. `comment_event` reads a comment's thread number from `issue_url` and nothing else, and the instance behind `git.vhaudiquet.fr` sends `issue_url: ""` on **every** row of the repo-wide `/issues/comments` feed (checked against the live API: all rows blank, `pull_request_url` and `html_url` populated). One blank row fails the whole pass with `ForgeError::Parse`, so no issue event, no PR comment and no review from that repo has ever reached the dispatcher. Nothing else in the adapter is at fault. **Commit 1 — the parse fix.** The number comes from the first URL that carries one: `issue_url`, then `pull_request_url`, then `html_url`. Any fragment is stripped first, because a comment's `html_url` points at the *comment* (`…/pulls/1#issuecomment-164`) and its trailing segment is not a thread. `is_pr` reads the same three URLs, so a PR comment with a blank `issue_url` still lands on the pull request's sequence rather than the issue one. A row with no number anywhere stays a loud parse error — the fallbacks must not turn into a silently skipped event. Covered by three unit tests and one wiremock poll test that was red before the fix. **Commit 2 — the rest of the story, and the reason this could not ship alone.** Fixing the parse is not enough, because the watcher's cursor lives in a `Mutex<HashMap>`: it is per-process. Every daemon restart polled from scratch, and `Watcher::poll` reads "no cursor" as "feed everything the forge returns". The dispatcher does not dedup that away — it dedups against the pending inbox, so an event that was already drained re-ingests clean. Fixing commit 1 in isolation would therefore have fired the repository's entire history as dispatches, each one a comment posted on an old thread. So the cursor is a row now (`watch_cursors`, beside `watch_health`, same `scope/forge/subject` key): written after every successful poll, read before every one. A watch with no cursor yet — including one that has never polled, which is this watch — starts at *now*: a watch reports news, and a repository's 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. Removing a watch forgets its cursor, so a re-add seeds afresh instead of resuming into a backlog. `Watcher::poll_since` is the seam that lets the daemon pass a cursor it keeps itself; `Watcher::poll` keeps its in-memory behaviour for other embedders. `Timestamp::from_epoch_millis` spells an instant the way the forges spell theirs, which is what a seed needs. **Review notes** - Three existing tests (`e2e`, `continuity`, `http`) now seed a cursor before the pass, since their subject is the dispatch, not the bootstrap. In `http` the "watch added over HTTP detects on the next pass" assertion is split in two: the first pass seeds (0 events, asserted), and a rewound cursor then detects the feed (1 event, asserted) — the behaviour change is pinned instead of quietly accommodated. - Account watches keep their in-memory cursor; they are unused today and their replay is bounded by the notifications feed, but the same argument applies if one is ever enabled. Left out to keep this reviewable. - I could not build here (no Rust toolchain in this box), so CI is the first real compile — apologies if it needs a follow-up push for a `fmt`/`clippy` nit. **Not in this PR:** the mention gate. Right now a repo watch dispatches *every* comment on the watched repo and posts the reply back as a comment, so once this watch starts working it will answer every comment in `vhaudiquet/rhema`, including its own replies. That is the next PR; until then this watch should stay quiet (it has no cursor to replay, and a new comment will trigger a reply).
kosmos added 2 commits 2026-11-14 17:11:25 +00:00
`comment_event` read the thread number from `issue_url` alone and failed
the whole poll when it could not. The instance behind git.vhaudiquet.fr
sends `issue_url: ""` on every row of the repo-wide `/issues/comments`
feed, so the first comment row failed the pass with

    malformed forge response: comment issue_url without a thread number:

and kept failing on every poll since the watch was created — 5296
consecutive failures, no event ever reported, no comment, no pull
request, nothing. The feed being broken was invisible: a watch that has
never polled once looks exactly like a quiet repository.

The number now comes from the first URL that carries one
(`issue_url`, then `pull_request_url`, then `html_url`), and a fragment is
dropped first: a comment's `html_url` points at the comment
(`…/pulls/1#issuecomment-164`), not at its thread. `is_pr` reads the same
three URLs, so a PR comment whose `issue_url` is blank still lands on the
pull request's sequence.

A row with no number anywhere is still a loud parse error — the
fallbacks must not degrade into a silently skipped event.
fix(claw): a repo watch resumes from its durable cursor, or starts now
android / release (pull_request) Skipped
android / debug (pull_request) Successful in 2m16s
ci / checks (pull_request) Successful in 1m0s
ci / test (pull_request) Failing after 36s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Successful in 1m23s
ci / web (pull_request) Successful in 14s
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
b6327a458f
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.
kosmos force-pushed fix/gitea-comment-thread-number from ba258a1f50 to b6327a458f 2026-11-14 17:11:25 +00:00 Compare
vhaudiquet added 1 commit 2026-11-17 21:39:22 +00:00
test(claw): the github mock answers since, as the forge does
android / debug (push) Successful in 2m24s
android / release (push) Successful in 3m5s
ci / checks (push) Successful in 1m6s
ci / test (push) Successful in 42s
ci / chart (push) Successful in 6s
ci / docker (push) Successful in 1m23s
ci / web (push) Successful in 14s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m28s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 3s
android / debug (pull_request) Canceled after 0s
android / release (pull_request) Canceled after 0s
ci / checks (pull_request) Canceled after 0s
ci / test (pull_request) Canceled after 0s
ci / chart (pull_request) Canceled after 0s
ci / docker (pull_request) Canceled after 0s
ci / web (pull_request) Canceled after 0s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (pull_request) Canceled after 0s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (pull_request) Canceled after 0s
ci / publish-edge-chart (pull_request) Canceled after 0s
504330b1b5
The fresh-watch pass now seeds its cursor at *now*, and the issues feed
is where GitHub applies `since` server-side. The mock always answered
the whole history, so the seeding pass fed an issue the real forge would
have filtered out and the new "a fresh watch seeds its cursor" assertion
saw one event.

The mock now returns the issue row only for the rewound cursor the test
sets, and nothing for any other `since`.
vhaudiquet merged commit 504330b1b5 into main 2026-11-17 21:59:44 +00:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vhaudiquet/rhema-claw#1