feat(claw): answer a thread only when somebody addresses the daemon #2

Merged
vhaudiquet merged 1 commits from kosmos/rhema-claw:feat/mention-gate into main 2026-11-17 22:16:37 +00:00
Collaborator

Second half of the watch debugging, and the feature you asked for: "hey @kosmos-ai-bot, can you take a look at this?" on an issue is now the way to hand me a thread, and anything else is left alone.

The problem this closes. A repo watch saw every issue, PR, review and comment on the repository, and the handler treated every dispatch as work: snapshot, coding-agent turn, comment posted back. So a working watch was a daemon answering every comment in the repo, including its own replies — the loop is real, since a reply quotes the mention it answers. Turning the Gitea watch on without this would have been a nuisance generator, which is why it went in behind the parse fix rather than after it.

The gate. A dispatch runs when the thread delivered a triaged notification (assigned, review requested, @-mentioned — the notifications feed adjudicated those before they arrived), or when one of its plain events names the handle the daemon speaks as, written by anybody but the daemon. Everything else is drained and dropped before the snapshot: no model call, no comment. The outcome is Superseded — RSD's vocabulary has no "nothing was asked", and that is the closest: the work the event names is not this daemon's.

Matching is @{handle}, case-insensitive, anywhere in the body — you type a sentence, not a protocol. The actor check is what keeps it honest: our own replies quote the mention they answer, so "addressed by name" alone would have the daemon answer itself forever.

Recognizing our own name took plumbing. A watch's credential carries a login only when an account identity supplied the token; a token pasted into the watch row, or GITEA_TOKEN in the environment, names nobody — and that is exactly the deployment where a mention gate must not go inert. So Forge::viewer_login() is the backend's own answer to "who am I", from its /user (GitHub and Gitea spell it login, GitLab username), defaulting to None for backends that cannot say. The handler asks at most once per credential (a OnceCell beside the cached client) and falls back to it only when the credential has no login of its own. A credential the forge will not name leaves the gate open, with a warning in the log: silently muting a watch would be a worse failure mode than over-answering.

Tests. Unit tests for the gate (name in any case, own comment, no body, notification, unnamed credential), three end-to-end ones — a mention runs exactly one turn and posts exactly one reply; a thread's own chatter runs nothing and posts nothing (the snapshot is deliberately unmocked, so a dispatch that slipped past the gate fails loudly); the daemon's own reply does not reopen it — and viewer_login against all three backends.

Review notes

  • GET /user is one extra request per credential per process, only for watches whose credential has no login. Cached, so not per dispatch.
  • The account-watch path is untouched: its notifications were already gated by triage.
  • Behaviour change worth naming: a repo watch no longer reacts to an opened/closed issue, a merge, or a label change at all — those have no body to be addressed in. That is the intent ("a feed, not an invitation"), and it is documented in the crate README beside the account-token paragraph.
  • Independent of the poll fix (#1): different files, and it applies to every forge. Both are worth landing; the order does not matter.

I could not compile here (no toolchain in this box), so CI is the first build — if it flags a fmt/clippy nit I will push the fix.

Second half of the watch debugging, and the feature you asked for: *"hey @kosmos-ai-bot, can you take a look at this?"* on an issue is now the way to hand me a thread, and anything else is left alone. **The problem this closes.** A repo watch saw every issue, PR, review and comment on the repository, and the handler treated every dispatch as work: snapshot, coding-agent turn, comment posted back. So a working watch was a daemon answering every comment in the repo, including its own replies — the loop is real, since a reply quotes the mention it answers. Turning the Gitea watch on without this would have been a nuisance generator, which is why it went in behind the parse fix rather than after it. **The gate.** A dispatch runs when the thread delivered a triaged notification (assigned, review requested, @-mentioned — the notifications feed adjudicated those before they arrived), or when one of its plain events names the handle the daemon speaks as, written by anybody **but** the daemon. Everything else is drained and dropped before the snapshot: no model call, no comment. The outcome is `Superseded` — RSD's vocabulary has no "nothing was asked", and that is the closest: the work the event names is not this daemon's. Matching is `@{handle}`, case-insensitive, anywhere in the body — you type a sentence, not a protocol. The actor check is what keeps it honest: our own replies quote the mention they answer, so "addressed by name" alone would have the daemon answer itself forever. **Recognizing our own name took plumbing.** A watch's credential carries a login only when an account identity supplied the token; a token pasted into the watch row, or `GITEA_TOKEN` in the environment, names nobody — and that is exactly the deployment where a mention gate must not go inert. So `Forge::viewer_login()` is the backend's own answer to "who am I", from its `/user` (GitHub and Gitea spell it `login`, GitLab `username`), defaulting to `None` for backends that cannot say. The handler asks at most once per credential (a `OnceCell` beside the cached client) and falls back to it only when the credential has no login of its own. A credential the forge will not name leaves the gate **open**, with a warning in the log: silently muting a watch would be a worse failure mode than over-answering. **Tests.** Unit tests for the gate (name in any case, own comment, no body, notification, unnamed credential), three end-to-end ones — a mention runs exactly one turn and posts exactly one reply; a thread's own chatter runs nothing and posts nothing (the snapshot is deliberately unmocked, so a dispatch that slipped past the gate fails loudly); the daemon's own reply does not reopen it — and `viewer_login` against all three backends. **Review notes** - `GET /user` is one extra request per credential per process, only for watches whose credential has no login. Cached, so not per dispatch. - The account-watch path is untouched: its notifications were already gated by `triage`. - Behaviour change worth naming: a repo watch no longer reacts to an opened/closed issue, a merge, or a label change at all — those have no body to be addressed in. That is the intent ("a feed, not an invitation"), and it is documented in the crate README beside the account-token paragraph. - Independent of the poll fix (#1): different files, and it applies to every forge. Both are worth landing; the order does not matter. I could not compile here (no toolchain in this box), so CI is the first build — if it flags a `fmt`/`clippy` nit I will push the fix.
kosmos force-pushed feat/mention-gate from bb9b68e361 to 139a887c24 2026-11-14 13:32:52 +00:00 Compare
vhaudiquet added 1 commit 2026-11-17 22:00:18 +00:00
feat(claw): answer a thread only when somebody addresses the daemon
android / release (pull_request) Skipped
android / debug (pull_request) Successful in 4m7s
ci / checks (pull_request) Successful in 1m12s
ci / test (pull_request) Successful in 39s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Successful in 1m22s
ci / web (pull_request) Successful in 13s
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
android / debug (push) Successful in 3m51s
android / release (push) Successful in 2m2s
ci / checks (push) Successful in 59s
ci / test (push) Successful in 37s
ci / chart (push) Successful in 6s
ci / docker (push) Successful in 1m22s
ci / web (push) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m29s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 4s
d74b1c40df
A repo watch saw *every* issue, pull request, review and comment on the
repository, and the handler treated each dispatch as work to do: a
snapshot fetch, a coding-agent turn, and a comment posted back. On a
repository with any traffic at all that is the wrong end of the
question — watching a repo is not volunteering to answer it — and it is
also how a daemon ends up talking to itself, since its own replies are
news too.

The dispatch now starts with a mention gate. A thread runs when:

- it delivered a triaged notification — assigned, review requested,
  @-mentioned: the notifications feed already adjudicated that one; or
- one of its plain events names the handle the daemon speaks as
  (`@kosmos`), written by anybody *but* the daemon.

Everything else is drained and dropped: no snapshot, no model call, no
comment. The outcome is `Superseded` — RSD's vocabulary has no "nothing
was asked", and the closest is that the work the event names is not
this daemon's.

Recognizing its own name took a little plumbing. The credential a watch
resolves carries a login only when an account identity supplied the
token; a token pasted into a watch row, or a forge environment variable,
names nobody — and that is the deployment the gate must not go inert on.
So `Forge::viewer_login` is the backend's own answer to "who am I", from
its `/user` (Gitea and GitHub spell it `login`, GitLab `username`), with
a `None` default for backends that cannot say; the handler asks at most
once per credential and keeps the answer beside the cached client. A
forge that will not name the credential leaves the gate *open*, with a
warning in the log: a filter that silently mutes a watch is worse than
one that occasionally over-answers.

The actor check is load-bearing for the same reason the gate exists: a
reply quotes the mention it answers, so "addressed by name" alone would
have the daemon answer itself, forever.

Tests: unit tests for the gate (name in any case, own comment, no body,
notification, unnamed credential), one end-to-end test per behaviour —
a mention runs one turn and posts one reply; a thread's own chatter runs
nothing and posts nothing; the daemon's own reply does not reopen the
gate — plus `viewer_login` against all three backends.
vhaudiquet force-pushed feat/mention-gate from 139a887c24 to d74b1c40df 2026-11-17 22:00:18 +00:00 Compare
vhaudiquet merged commit d74b1c40df into main 2026-11-17 22:16:37 +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#2