Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): a queued head that keeps moving is not a stall in the in-pass line

garrytanef47eb2718aa
diff --git a/src/core/persistence/sync-drain.ts b/src/core/persistence/sync-drain.ts
index ba495d4e9e..165e2574e2 100644
--- a/src/core/persistence/sync-drain.ts
+++ b/src/core/persistence/sync-drain.ts
@@ -384,6 +384,9 @@ export async function runDrain(input: DrainInput): Promise<SyncResult> {
// #6317: `extended` marks the one extra window a lapsed head gets while a consumer here can reclaim it; `ownerAt`/`owner` throttle the owner-row read to one per progress interval.
let stall: { key: string; since: number; passes: number; claim: DrainClaim | null; stallInfo: Omit<DrainStall, 'stalled_seconds'>; extended?: boolean; ownerAt?: number; owner?: DrainOwnerRow | null } | null = null;
let lastCommitAt = startedAt, lastSweptAt = startedAt, inPass = false, readingHead = false;
+ // The in-pass line's view of the head: a head that moved since the last read is the writer making progress (it commits
+ // requests queued ahead of this pass, a dead owner's in-flight writes among them), so its age counts from that read.
+ let headSeen: { id: string | null | undefined; at: number; since: number } | null = null;
// #6278 (B7): a pass refused for write capacity keeps the last pass's result for the report; `capacity` spans the refusals since the last pass that ran.
let last: SyncResult | undefined, capacity: { since: number; attempts: number } | null = null;
// #6278 (B7): a pass may finish one run and yield for the next (re-screens scheduled while it ran); the counts of finished runs carry into the report.
@@ -409,7 +412,9 @@ export async function runDrain(input: DrainInput): Promise<SyncResult> {
Promise.resolve().then(() => probe.head!()).then(head => {
if (!head || !inPass || stall || clock() - lastCommitAt < every || tickAt - lastLine < every) return;
lastLine = tickAt;
- serr(stallText(index, total, head.claim?.step_age_ms ?? clock() - lastCommitAt, head.claim, head.head_state, head));
+ const at = clock();
+ headSeen = { id: head.request_id, at, since: headSeen && headSeen.id !== head.request_id ? headSeen.at : headSeen?.since ?? lastCommitAt };
+ serr(stallText(index, total, head.claim?.step_age_ms ?? at - Math.max(lastCommitAt, headSeen.since), head.claim, head.head_state, head));
}).catch(() => undefined).finally(() => { readingHead = false; });
}, every) : null;
stallLine?.unref?.();
diff --git a/test/sync-drain-claims.test.ts b/test/sync-drain-claims.test.ts
index 676545d501..6e1d2255a5 100644
--- a/test/sync-drain-claims.test.ts
+++ b/test/sync-drain-claims.test.ts
@@ -326,6 +326,24 @@ describe('live stall line during a pass (B6)', () => {
} finally { err.restore(); }
});
+ // The convergence nightly's owner-kill stall: after a serve died, the drain's one entry queued behind the dead serve's
+ // 40-odd in-flight writes, which this process's consumer committed one group after another. The head moved every few
+ // seconds, but the line counted from the drain's own last commit and printed "stalled 140s on queued".
+ test('a queued head that keeps moving is not a stall: the age counts from when this head became the head', async () => {
+ const err = captureStderr();
+ try {
+ let now = 0, reads = 0;
+ const t0 = Date.now();
+ const head: StallProbe['head'] = async () => { reads++; now += 10_000; return { head_state: 'queued', claim: null, request_id: `r${Math.min(reads, 4)}` }; };
+ await runDrain({ announce: true, progressMs: PROGRESS, governMs: 60_000, clock: () => now + (Date.now() - t0) / 10, probe: headProbe(head), pass: async () => {
+ expect(await until(() => err.stalled().length >= 6, 20 * PROGRESS)).toBe(true);
+ return done();
+ } });
+ const ages = err.stalled().slice(0, 6).map(line => Number(/stalled (\d+)s on queued/.exec(line)?.[1]));
+ expect(ages).toEqual([10, 10, 10, 10, 20, 30]);
+ } finally { err.restore(); }
+ });
+
test('a head read that rejects or hangs never escapes the ticker or stacks; announce off never reads', async () => {
const err = captureStderr();
try {