Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): a run that committed nothing gets one progress window from its start before the watchdog calls it a stall

garrytan67a3bebfd384
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c5f489523a..a1d971f051 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,7 +21,7 @@ identifiers and attribution are available in the pre-removal Git revision
| `gbrain sync status --json` on a source with thousands of holds | every hold inline | `holds_summary` counts plus the first 20 holds, needs-human first; `--detail` pages them |
| Who is syncing this source right now? | not shown | `live` names the drain-lease holder (serve pass, sync job, CLI sync or cycle) with heartbeat and `stalled` |
| An old error after a later pass moved past it | still drove `state` and `next` | reads `superseded` with `by` and `age_seconds`, and no longer drives `state` or `next` |
-| A sync that reaches its deadline having committed nothing | extended as "still progressing" | stops with `sync_deadline_stalled` and a read-only status fix |
+| A sync that reaches its deadline having committed nothing | extended as "still progressing" | stops with `sync_deadline_stalled` and a read-only status fix, once at least one progress window has passed since it started |
| A drain holder that has committed nothing for 5 minutes | the commit notifier deferred silently | counted as a failed attempt (`drain_holder_stalled`), so status and doctor show the sync-now fix |
| A pass checkpoint whose pass already ended | `revision_conflict`, recorded as a failure | `sync_pass_superseded`, not a failure |
| A pooler's client cap (`EMAXCONNSESSION`, "too many clients already") during a managed write | terminal `storage_error` | released as contention and retried, like SQLSTATE 53300 |
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index bee62bd1c5..2002fa1c43 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1204,7 +1204,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.423.0', text: '`gbrain sync status --json` now prints at most 20 holds without `--detail`: `holds_summary` counts every hold by code and by state (`needs_human`, `actionable`, `held`), and `holds` lists the first 20, needs-human first, after every other field. When holds are left out, `holds_page` carries `returned`, `limit`, `complete`, `next_cursor` and `next_command`; `--detail` pages 100 holds at a time, `--limit <n>` and `--cursor <next_cursor>` page, `--all` prints every hold, and `--hold-state <state>` lists one state. A source whose holds fit on one page prints them as before. The text status lists the same 20 and says how many more there are.' },
{ since: '0.60.423.0', text: '`gbrain sync status` always reports `last_commit` (the commit the source\'s sync applied through) and `live`: the process holding the source\'s drain lease (a serve pass, a sync job, a CLI sync or the cycle) with its pid, heartbeat and progress, `job_id` for a Minions sync job and `stalled`, or null. `live_job_id` also names a sync job that drains a pass, not only a legacy cursor. `convergence` adds `converged_target`, the commit the stored converged obligation records (null when no stamp backs one); `convergence.target` stays the newest pass\'s pinned commit.' },
{ since: '0.60.423.0', text: 'A `last_error` in `gbrain sync status` now also reads `superseded` once a later attempt got past the phase it failed in (a later pass started, read the source, admitted a page or committed one), with `by` naming which and `age_seconds`, and it then sets neither `needs_human`, `state` nor `next`; before, only a later committed page superseded it. The notifier block of `sync status` and doctor adds `recorded_resident`: when its row names a resident whose notifier lease lapsed, the fix names that resident instead of saying no resident watches the source. A managed pass prints `[sync] pass round N: read ...` after each level read and `... importing N file(s) ...` before its import walk, and a resident notifier\'s background run also writes its lines to the serve log (`[serve-sync] job=<id> ...`).' },
- { since: '0.60.423.0', text: 'The `gbrain sync` hard deadline now extends only while the run commits work (a page written, deleted or renamed, or a sync cursor advanced). Screening unchanged files, held files and legacy-sweep slices no longer count, so a run that reaches its default or env deadline having committed nothing stops as a stall: it prints `code=sync_deadline_stalled` with a why and a read-only `gbrain sync status` fix (one JSON object under `--json`) instead of extending as "still progressing". A run delegated to a PGLite owner does the same, adds `deadline_stall` to its JSON and exits 1.' },
+ { since: '0.60.423.0', text: 'The `gbrain sync` hard deadline now extends only while the run commits work (a page written, deleted or renamed, or a sync cursor advanced). Screening unchanged files, held files and legacy-sweep slices no longer count, so a run that has committed nothing by its default or env deadline (it always gets one progress window from its start, for a first unit of work still running) stops as a stall: it prints `code=sync_deadline_stalled` with a why and a read-only `gbrain sync status` fix (one JSON object under `--json`) instead of extending as "still progressing". A run delegated to a PGLite owner does the same, adds `deadline_stall` to its JSON and exits 1.' },
{ since: '0.60.423.0', text: 'A managed sync drain stopped by its governor drops the abandoned pass\'s late progress events (no late `[sync] N processed` line, no count added after the stop), and a stop whose head owner reports restart_required now says so: `drain.stall.cause` is `owner_restart_required` with the owner\'s heartbeat row, and `next` tells the host admin to restart that process, then rerun (it used to read `publication_overdue` or `no_progress`).' },
{ since: '0.60.423.0', text: 'The commit notifier counts a resumable sync that committed pages as progress even while `last_commit` has not moved yet (a long managed catch-up no longer reads `notifier_stalled`), and a source whose drain-lease holder has committed nothing for 5 minutes is no longer deferred silently: it counts as a failed attempt (`drain_holder_stalled`), so the retry tiers run and sync status and doctor show the sync-now fix.' },
{ since: '0.60.423.0', text: 'A sync pass\'s checkpoint that its pass can no longer publish (the pass ended, or another pass started) is now refused `sync_pass_superseded` instead of `revision_conflict`: it records no managed-sync failure, reads `superseded` in `gbrain sources writer failures` and does not count as an unresolved terminal failure, and a pass that stops with its checkpoint still pending reports `managedWrite.disposition: superseded` instead of "Re-run the same sync options to resume this request".' },
diff --git a/src/core/process-watchdog.ts b/src/core/process-watchdog.ts
index 1d9e4287e6..5fa6c97da2 100644
--- a/src/core/process-watchdog.ts
+++ b/src/core/process-watchdog.ts
@@ -63,7 +63,8 @@ export type ProgressDeadlineAction = 'wait' | 'extend' | 'stop';
* last progress note is younger than `windowMs`, and stops the run only after
* a full window with no progress. `windowMs <= 0` keeps the plain wall-clock
* deadline. GBRA-133 PR 3a: `progressed` false (a run that must commit to
- * count, and has committed nothing) never extends: the deadline stops it.
+ * count, and has committed nothing) gets one window from its start, never an
+ * extension from a later note: past the deadline and that window, it stops.
* elapsed < deadline -> 'wait'
* deadline passed, progress within window -> 'extend'
* deadline passed, no progress for window -> 'stop' (SIGTERM, then SIGKILL after grace)
@@ -72,7 +73,7 @@ export function progressDeadlineDecision(
elapsedMs: number, deadlineMs: number, sinceProgressMs: number, windowMs: number, progressed = true,
): ProgressDeadlineAction {
if (elapsedMs < deadlineMs) return 'wait';
- if (windowMs > 0 && progressed && sinceProgressMs < windowMs) return 'extend';
+ if (windowMs > 0 && (progressed ? sinceProgressMs : elapsedMs) < windowMs) return 'extend';
return 'stop';
}
@@ -104,8 +105,8 @@ export interface ProcessWatchdogOpts {
/**
* GBRA-133 PR 3a: which notes count as progress. `committed` listens to
* `noteCommittedProgress()` only (pages written, a cursor advanced), and a
- * run that reaches its deadline having committed nothing stops at once
- * instead of getting a window; `stallNotice` is then written instead of
+ * run that has committed nothing gets one window from its start and no
+ * extension, and stops past its deadline and that window; `stallNotice` is then written instead of
* `stopNotice`. Default `forward`.
*/
progressSignal?: 'forward' | 'committed';
@@ -219,8 +220,10 @@ function check() {
const since = now - lastProgress;
// mirrors progressDeadlineDecision
if (now - t0 < deadlineMs) { setTimeout(check, deadlineMs - (now - t0)); return; }
- if (progressWindowMs > 0 && progressed && since < progressWindowMs) {
- if (!extended) w('deadline reached (' + Math.round(deadlineMs/1000) + 's) but the run is still progressing (last progress ' + Math.round(since / 1000) + 's ago) — extending; it stops after ' + Math.round(progressWindowMs / 1000) + 's without progress');
+ if (progressWindowMs > 0 && since < progressWindowMs) {
+ if (!extended) w(progressed
+ ? 'deadline reached (' + Math.round(deadlineMs/1000) + 's) but the run is still progressing (last progress ' + Math.round(since / 1000) + 's ago) — extending; it stops after ' + Math.round(progressWindowMs / 1000) + 's without progress'
+ : 'deadline reached (' + Math.round(deadlineMs/1000) + 's) before the run committed anything; it stops as a stall unless it commits within ' + Math.round(progressWindowMs / 1000) + 's of its start');
extended = true;
setTimeout(check, progressWindowMs - since);
return;
diff --git a/test/honest-stalls-gbra133.test.ts b/test/honest-stalls-gbra133.test.ts
index 8112fb3e2a..b246aebc7f 100644
--- a/test/honest-stalls-gbra133.test.ts
+++ b/test/honest-stalls-gbra133.test.ts
@@ -36,6 +36,9 @@ describe('a deadline never extends a run that committed nothing', () => {
expect(progressDeadlineDecision(5000, 1000, 0, 500, true)).toBe('extend');
expect(progressDeadlineDecision(5000, 1000, 0, 500, false)).toBe('stop');
expect(progressDeadlineDecision(999, 1000, 0, 500, false)).toBe('wait');
+ // A run that has committed nothing yet gets one window from its start (its first unit of work may still be running).
+ expect(progressDeadlineDecision(1200, 1000, 1200, 60_000, false)).toBe('extend');
+ expect(progressDeadlineDecision(61_000, 1000, 0, 60_000, false)).toBe('stop');
});
test('the delegated deadline: passes that only screen paths stop the run at the deadline as sync_deadline_stalled', async () => {