Compare commits

..
2 Commits
Author SHA1 Message Date
kosmos b6327a458f 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
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.
2026-11-14 16:58:33 +00:00
kosmos 2f6c369e02 fix(forge): a gitea comment names its thread without issue_url
`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.
2026-11-14 16:58:25 +00:00
8 changed files with 55 additions and 25 deletions

No files matched your search

+7 -10
View File
@@ -26,7 +26,8 @@ use rhema_autonomous_agent::{Source, SourceError, async_trait};
use rhema_forge_integration::forge_key_fn; use rhema_forge_integration::forge_key_fn;
use rhema_forge_integration::triage::{self, Triage}; use rhema_forge_integration::triage::{self, Triage};
use rhema_forge_integration::{ use rhema_forge_integration::{
Forge, GitHubForge, GitLabForge, GiteaForge, Notification, Timestamp, Watcher, register_forge, Forge, GitHubForge, GitLabForge, GiteaForge, Notification, RepoRef, Timestamp, Watcher,
register_forge,
}; };
use rhema_identity::{IdentityStore, SecretKind}; use rhema_identity::{IdentityStore, SecretKind};
use rhema_rsd::{Clock, Dispatcher, Event, KeyFn, SystemClock}; use rhema_rsd::{Clock, Dispatcher, Event, KeyFn, SystemClock};
@@ -390,7 +391,7 @@ impl ForgeSource {
if let Some(since) = stored.as_deref().and_then(Timestamp::parse) { if let Some(since) = stored.as_deref().and_then(Timestamp::parse) {
return Ok(since); return Ok(since);
} }
let now = Timestamp::from_epoch_millis(SystemClock.now_millis()) let now = Timestamp::from_epoch_millis(SystemClock.now_millis() as i64)
.ok_or_else(|| SourceError::Backend("cannot spell this instant".to_owned()))?; .ok_or_else(|| SourceError::Backend("cannot spell this instant".to_owned()))?;
self.store self.store
.set_cursor(SCOPE_REPO, &record.forge, &record.repo, now.raw()) .set_cursor(SCOPE_REPO, &record.forge, &record.repo, now.raw())
@@ -619,13 +620,7 @@ mod tests {
.add("gitea", "acme/barn", Some(&server.uri()), "tok") .add("gitea", "acme/barn", Some(&server.uri()), "tok")
.expect("add"); .expect("add");
let (dispatcher, accounts, notifications) = test_parts(store.clone()); let (dispatcher, accounts, notifications) = test_parts(store.clone());
let source = ForgeSource::new( let source = ForgeSource::new(&dispatcher, "gitea", store.clone(), accounts, notifications);
&dispatcher,
"gitea",
store.clone(),
accounts,
notifications,
);
assert_eq!( assert_eq!(
source.detect().await.expect("the pass runs"), source.detect().await.expect("the pass runs"),
@@ -667,7 +662,9 @@ mod tests {
Some(cursor) Some(cursor)
); );
assert_eq!( assert_eq!(
store.health(SCOPE_REPO, "gitea", "acme/barn").expect("health reads") store
.health(SCOPE_REPO, "gitea", "acme/barn")
.expect("health reads")
.map(|health| health.consecutive_failures), .map(|health| health.consecutive_failures),
Some(0), Some(0),
"the watch polled cleanly" "the watch polled cleanly"
+15 -5
View File
@@ -703,7 +703,9 @@ mod tests {
fn a_cursor_is_kept_per_watch_and_moves_forward() { fn a_cursor_is_kept_per_watch_and_moves_forward() {
let store = ClawStore::in_memory().expect("store opens"); let store = ClawStore::in_memory().expect("store opens");
assert_eq!( assert_eq!(
store.cursor(SCOPE_REPO, "gitea", "acme/barn").expect("read"), store
.cursor(SCOPE_REPO, "gitea", "acme/barn")
.expect("read"),
None, None,
"a watch that never polled has no cursor" "a watch that never polled has no cursor"
); );
@@ -712,12 +714,16 @@ mod tests {
.set_cursor(SCOPE_REPO, "gitea", "acme/barn", "2026-10-08T00:00:00Z") .set_cursor(SCOPE_REPO, "gitea", "acme/barn", "2026-10-08T00:00:00Z")
.expect("cursor lands"); .expect("cursor lands");
assert_eq!( assert_eq!(
store.cursor(SCOPE_REPO, "gitea", "acme/barn").expect("read"), store
.cursor(SCOPE_REPO, "gitea", "acme/barn")
.expect("read"),
Some("2026-10-08T00:00:00Z".to_owned()) Some("2026-10-08T00:00:00Z".to_owned())
); );
// Another watch of the same forge is another cursor. // Another watch of the same forge is another cursor.
assert_eq!( assert_eq!(
store.cursor(SCOPE_REPO, "gitea", "acme/quarry").expect("read"), store
.cursor(SCOPE_REPO, "gitea", "acme/quarry")
.expect("read"),
None None
); );
@@ -725,7 +731,9 @@ mod tests {
.set_cursor(SCOPE_REPO, "gitea", "acme/barn", "2026-10-09T00:00:00Z") .set_cursor(SCOPE_REPO, "gitea", "acme/barn", "2026-10-09T00:00:00Z")
.expect("the cursor advances"); .expect("the cursor advances");
assert_eq!( assert_eq!(
store.cursor(SCOPE_REPO, "gitea", "acme/barn").expect("read"), store
.cursor(SCOPE_REPO, "gitea", "acme/barn")
.expect("read"),
Some("2026-10-09T00:00:00Z".to_owned()) Some("2026-10-09T00:00:00Z".to_owned())
); );
@@ -736,7 +744,9 @@ mod tests {
.expect("add"); .expect("add");
store.remove("gitea", "acme/barn").expect("remove"); store.remove("gitea", "acme/barn").expect("remove");
assert_eq!( assert_eq!(
store.cursor(SCOPE_REPO, "gitea", "acme/barn").expect("read"), store
.cursor(SCOPE_REPO, "gitea", "acme/barn")
.expect("read"),
None None
); );
} }
+8 -3
View File
@@ -13,8 +13,8 @@ use rhema_claw::{ClawConfig, run_once};
/// carrying watches, and the test speaks to the daemon the way an /// carrying watches, and the test speaks to the daemon the way an
/// integration would: through the store the routes share. /// integration would: through the store the routes share.
fn seed_watch(dir: &tempfile::TempDir, host: &str) { fn seed_watch(dir: &tempfile::TempDir, host: &str) {
let store = rhema_claw::ClawStore::open(dir.path().join("dispatch.db")) let store =
.expect("the watch table opens"); rhema_claw::ClawStore::open(dir.path().join("dispatch.db")).expect("the watch table opens");
store store
.add("github", "acme/widgets", Some(host), "tok") .add("github", "acme/widgets", Some(host), "tok")
.expect("the seed row lands"); .expect("the seed row lands");
@@ -22,7 +22,12 @@ fn seed_watch(dir: &tempfile::TempDir, host: &str) {
// the feed from there instead of seeding one at *now* (which a // the feed from there instead of seeding one at *now* (which a
// never-polled watch does, and which feeds nothing). // never-polled watch does, and which feeds nothing).
store store
.set_cursor(rhema_claw::SCOPE_REPO, "github", "acme/widgets", "2026-10-01T00:00:00Z") .set_cursor(
rhema_claw::SCOPE_REPO,
"github",
"acme/widgets",
"2026-10-01T00:00:00Z",
)
.expect("the cursor seeds"); .expect("the cursor seeds");
} }
use rhema_core::{Message, MockProvider, ModelOutput, Role, Session, StopReason, Usage}; use rhema_core::{Message, MockProvider, ModelOutput, Role, Session, StopReason, Usage};
+8 -3
View File
@@ -67,8 +67,8 @@ fn config(dir: &tempfile::TempDir) -> ClawConfig {
/// carrying watches, and the test speaks to the daemon the way an /// carrying watches, and the test speaks to the daemon the way an
/// integration would: through the store the routes share. /// integration would: through the store the routes share.
fn seed_watch(dir: &tempfile::TempDir, host: &str) { fn seed_watch(dir: &tempfile::TempDir, host: &str) {
let store = rhema_claw::ClawStore::open(dir.path().join("dispatch.db")) let store =
.expect("the watch table opens"); rhema_claw::ClawStore::open(dir.path().join("dispatch.db")).expect("the watch table opens");
store store
.add("github", "acme/widgets", Some(host), "tok") .add("github", "acme/widgets", Some(host), "tok")
.expect("the seed row lands"); .expect("the seed row lands");
@@ -76,7 +76,12 @@ fn seed_watch(dir: &tempfile::TempDir, host: &str) {
// the feed from there instead of seeding one at *now* (which a // the feed from there instead of seeding one at *now* (which a
// never-polled watch does, and which feeds nothing). // never-polled watch does, and which feeds nothing).
store store
.set_cursor(rhema_claw::SCOPE_REPO, "github", "acme/widgets", "2026-10-01T00:00:00Z") .set_cursor(
rhema_claw::SCOPE_REPO,
"github",
"acme/widgets",
"2026-10-01T00:00:00Z",
)
.expect("the cursor seeds"); .expect("the cursor seeds");
} }
+6 -1
View File
@@ -1119,7 +1119,12 @@ async fn watches_added_over_http_feed_the_next_detect_pass() {
// Rewound to before the feed's rows — an established watch — the same // Rewound to before the feed's rows — an established watch — the same
// pass detects the feed's event. // pass detects the feed's event.
Arc::new(rhema_claw::ClawStore::open(dir.path().join("dispatch.db")).expect("reopens")) Arc::new(rhema_claw::ClawStore::open(dir.path().join("dispatch.db")).expect("reopens"))
.set_cursor(rhema_claw::SCOPE_REPO, "github", "acme/widgets", "2026-10-01T00:00:00Z") .set_cursor(
rhema_claw::SCOPE_REPO,
"github",
"acme/widgets",
"2026-10-01T00:00:00Z",
)
.expect("the cursor rewinds"); .expect("the cursor rewinds");
let report = daemon.tick().await.expect("the pass runs"); let report = daemon.tick().await.expect("the pass runs");
assert_eq!(report.detected, 1, "the new watch's feed event was fed"); assert_eq!(report.detected, 1, "the new watch's feed event was fed");
@@ -397,7 +397,9 @@ impl Timestamp {
let raw = if sub_millis == 0 { let raw = if sub_millis == 0 {
format!("{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}Z") format!("{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}Z")
} else { } else {
format!("{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}.{sub_millis:03}Z") format!(
"{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}.{sub_millis:03}Z"
)
}; };
Self::parse(&raw) Self::parse(&raw)
} }
@@ -520,7 +520,10 @@ fn comment_urls(row: &WireComment) -> [Option<&str>; 3] {
/// number is therefore read from the first URL that carries one, in /// number is therefore read from the first URL that carries one, in
/// order of directness. /// order of directness.
fn comment_parent(row: &WireComment) -> Option<u64> { fn comment_parent(row: &WireComment) -> Option<u64> {
comment_urls(row).into_iter().flatten().find_map(parent_number) comment_urls(row)
.into_iter()
.flatten()
.find_map(parent_number)
} }
/// [`comment_parent`]'s "is it a pull request" half: `pull_request_url` /// [`comment_parent`]'s "is it a pull request" half: `pull_request_url`
@@ -606,6 +606,9 @@ async fn poll_survives_a_comments_feed_with_blank_issue_urls() {
.collect(); .collect();
assert_eq!( assert_eq!(
summary, summary,
vec![(EventKind::Comment, 1, true), (EventKind::Comment, 2, false)] vec![
(EventKind::Comment, 1, true),
(EventKind::Comment, 2, false)
]
); );
} }