feat(claw): answer a thread only when somebody addresses the daemon
android / release (pull_request) Skipped
ci / checks (pull_request) Failing after 23s
ci / test (pull_request) Failing after 29s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Successful in 1m20s
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 (pull_request) Successful in 2m19s
android / release (pull_request) Skipped
ci / checks (pull_request) Failing after 23s
ci / test (pull_request) Failing after 29s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Successful in 1m20s
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 (pull_request) Successful in 2m19s
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.
This commit is contained in:
1 parent
00037993af
commit
bb9b68e361
10 files changed
+521
-5
No files matched your search
@@ -99,6 +99,19 @@ pub trait Forge: Send + Sync {
|
||||
&self,
|
||||
since: Option<&Timestamp>,
|
||||
) -> Result<NotificationPage, ForgeError>;
|
||||
|
||||
/// The login this client authenticates as — the backend's own answer
|
||||
/// to "who am I".
|
||||
///
|
||||
/// A consumer that must recognize its own handle (to see an @-mention
|
||||
/// in a body, and to ignore its own replies) cannot always read it off
|
||||
/// its credential: a token pasted into a watch row, or an environment
|
||||
/// variable, names nobody. `None` is the honest default — a backend
|
||||
/// with no such route simply cannot say who it is — and a backend that
|
||||
/// can say answers with its `/user` row.
|
||||
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -690,6 +690,11 @@ impl Forge for GiteaForge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||
let user: WireUser = decode(self.send(self.get("/user")).await?).await?;
|
||||
Ok(user.login.filter(|login| !login.trim().is_empty()))
|
||||
}
|
||||
|
||||
async fn snapshot(
|
||||
&self,
|
||||
repo: &RepoRef,
|
||||
|
||||
@@ -646,6 +646,16 @@ impl Forge for GitHubForge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||
let response = self
|
||||
.get("/user")
|
||||
.send()
|
||||
.await
|
||||
.map_err(ForgeError::network)?;
|
||||
let user: WireUser = decode(response).await?;
|
||||
Ok(user.login.filter(|login| !login.trim().is_empty()))
|
||||
}
|
||||
|
||||
async fn snapshot(
|
||||
&self,
|
||||
repo: &RepoRef,
|
||||
|
||||
@@ -523,6 +523,18 @@ impl Forge for GitLabForge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||
// GitLab spells the login `username`, like every author object it
|
||||
// sends.
|
||||
let response = self
|
||||
.get("/user")
|
||||
.send()
|
||||
.await
|
||||
.map_err(ForgeError::network)?;
|
||||
let user: WireAuthor = decode(response).await?;
|
||||
Ok(user.username.filter(|login| !login.trim().is_empty()))
|
||||
}
|
||||
|
||||
async fn snapshot(
|
||||
&self,
|
||||
repo: &RepoRef,
|
||||
|
||||
@@ -557,3 +557,19 @@ async fn notifications_poll_maps_the_subject_feed() {
|
||||
assert_eq!(note.repo, RepoRef::new("acme", "widgets"));
|
||||
assert_eq!(note.title.as_deref(), Some("Fix the gate"));
|
||||
}
|
||||
|
||||
/// The mention gate asks the forge who the credential is, because a token
|
||||
/// read from a watch row names nobody.
|
||||
#[tokio::test]
|
||||
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/api/v1/user"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "login": "kosmos" })))
|
||||
.mount(&server)
|
||||
.await;
|
||||
assert_eq!(
|
||||
forge(&server).viewer_login().await.expect("the call lands"),
|
||||
Some("kosmos".to_owned())
|
||||
);
|
||||
}
|
||||
@@ -532,3 +532,19 @@ async fn notifications_without_a_cursor_still_return_the_newest_seen() {
|
||||
Some(Timestamp::parse("2026-10-02T00:00:00Z").expect("parses"))
|
||||
);
|
||||
}
|
||||
|
||||
/// The mention gate asks the forge who the credential is, because a token
|
||||
/// read from a watch row names nobody.
|
||||
#[tokio::test]
|
||||
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/user"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "login": "kosmos-ai-bot" })))
|
||||
.mount(&server)
|
||||
.await;
|
||||
assert_eq!(
|
||||
forge(&server).viewer_login().await.expect("the call lands"),
|
||||
Some("kosmos-ai-bot".to_owned())
|
||||
);
|
||||
}
|
||||
@@ -572,3 +572,20 @@ async fn todos_poll_maps_actions_targets_and_projects() {
|
||||
Some("https://gitlab.com/acme/widgets/-/merge_requests/12")
|
||||
);
|
||||
}
|
||||
|
||||
/// The mention gate asks the forge who the credential is, because a token
|
||||
/// read from a watch row names nobody. GitLab spells the login
|
||||
/// `username`.
|
||||
#[tokio::test]
|
||||
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/api/v4/user"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "username": "kosmos" })))
|
||||
.mount(&server)
|
||||
.await;
|
||||
assert_eq!(
|
||||
forge(&server).viewer_login().await.expect("the call lands"),
|
||||
Some("kosmos".to_owned())
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user