Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(serve-sync): a pass that stops short names its stop reason, blocking write and failed files on the done line (GBRA-133 PR 3a)
garrytancf2e29797b9d
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 8c271a5507..21b120b367 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1082,6 +1082,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: 'TBD', 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: 'TBD', 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".' },{ since: 'TBD', text: '`gbrain sync status` also reports `last_sync_at` (when the source last converged: every path of its target imported, deleted or held) and `last_committed_at` (when a managed sync write of the source last committed), and the human line says when the source is still importing since it last converged, so a long catch-up no longer reads as a day stale. Its `freshness` block adds `waiting_commits`, the commits on HEAD not synced yet; `unresolved_commits` still counts only synced commits that git cannot date on this host.' },+ { since: 'TBD', text: 'A serve sync pass that stops short now names why on its `[serve-sync] done` line: `stop=<reason>`, the write that stopped it (`write_error`, `write_reason`, `request`), the failed files by code, or `cause=unrecorded` when the pass recorded none, followed by a `next` line with the command to run. Before, a blocked pass printed only `status=blocked_by_failures`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/sync-drain.ts b/src/core/persistence/sync-drain.tsindex a122326ff4..d066f05fa6 100644--- a/src/core/persistence/sync-drain.ts+++ b/src/core/persistence/sync-drain.ts@@ -980,6 +980,23 @@ function passNext(stop: DrainStopReason | undefined, result: SyncResult, resumeC}/** What the agent runs next, or null when the sync is done (DX-A2). */+/**+ * GBRA-133: what stopped a drain that did not converge, as `key=value` log fields: the stop reason, the write that stopped it+ * (its error code and request), and the failed files by code. A blocked stop with none of them says `cause=unrecorded`+ * instead of looking like a clean end. Empty for a synced result.+ */+export function drainStopFields(result: Pick<SyncResult, 'status' | 'reason' | 'managedWrite' | 'drain' | 'failedFiles' | 'failureCodes'>): string {+ const outcome = syncOutcome(result);+ if (outcome === 'synced') return '';+ const write = result.managedWrite;+ const fields = [+ result.drain?.stop_reason ? `stop=${result.drain.stop_reason}` : result.reason ? `stop=${result.reason}` : '',+ write ? `write_error=${write.write_error}${write.reason && write.reason !== write.write_error ? ` write_reason=${write.reason}` : ''} request=${write.write_request.request_id}` : '',+ result.failedFiles ? `failed_files=${result.failedFiles}${result.failureCodes?.length ? ` failures=${result.failureCodes.map(c => `${c.code}:${c.count}`).join(',')}` : ''}` : '',+ ].filter(Boolean);+ return ` ${outcome === 'blocked' && !write && !result.failedFiles ? [...fields, 'cause=unrecorded'].join(' ') : fields.join(' ')}`.trimEnd();+}+export function drainNext(result: SyncResult, resumeCommand: string, sourceId: string): DrainNext | null {const outcome = syncOutcome(result);if (outcome === 'synced') return null;diff --git a/src/core/serve-sync-runner.ts b/src/core/serve-sync-runner.tsindex a73f32ce02..dc9f455e67 100644--- a/src/core/serve-sync-runner.ts+++ b/src/core/serve-sync-runner.ts@@ -420,8 +420,10 @@ async function startVerifiedDelegatedSync(});job.result = toWireSyncResult(r);job.drain = r.drain;+ let stopFields = '';if (managed) {- const { drainNext } = await import('./persistence/sync-drain.ts');+ const { drainNext, drainStopFields } = await import('./persistence/sync-drain.ts');+ stopFields = drainStopFields(r);const { managedSyncResumeArgs, syncResumeCommand } = await import('./sync-reconcile.ts');const id = sourceId ?? 'default';job.next = drainNext(r, syncResumeCommand(managedSyncResumeArgs({ sourceId: id, processingOptions: options })), id);@@ -429,8 +431,9 @@ async function startVerifiedDelegatedSync(job.state = 'done';log(`done job=${job.id} status=${r.status} added=${r.added} modified=${r.modified} ` +- `deleted=${r.deleted}${r.drain ? ` drain=${r.drain.outcome}` : ''} in=${Math.round((Date.now() - job.startedAt) / 1000)}s`,+ `deleted=${r.deleted}${r.drain ? ` drain=${r.drain.outcome}` : ''}${stopFields} in=${Math.round((Date.now() - job.startedAt) / 1000)}s`,);+ if (stopFields && job.next) log(`next job=${job.id}: ${job.next.command} (${job.next.why})`);// GBRA-133 PR 2a.3: the post-run re-check (generation-checked); whatever is still due goes to this serve's notifier.if (!options.dryRun) await settleRunMarkers(engine, sourceId ?? 'default', markers, { pulled: !managed && !options.noPull, full: options.full === true }, { queue: false });if (!managed && !options.dryRun && !options.noEmbed && r.added + r.modified > 0) {diff --git a/test/honest-stalls-gbra133.test.ts b/test/honest-stalls-gbra133.test.tsindex f546decf46..42fe9b2bf4 100644--- a/test/honest-stalls-gbra133.test.ts+++ b/test/honest-stalls-gbra133.test.ts@@ -18,7 +18,7 @@ import { DelegatedSyncDeadline } from '../src/commands/sync-persistence-delegateimport { noteCommittedProgress, noteForwardProgress, onCommittedProgress, onForwardProgress, registerRunDeadline } from '../src/core/forward-progress.ts';import { progressDeadlineDecision } from '../src/core/process-watchdog.ts';import { syncDeadlineStallNotice, syncWatchdogPlan } from '../src/core/sync-reconcile.ts';-import { drainNext, formatDrainSummary, runDrain, type DrainClaim, type DrainOwnerRow, type StallProbe } from '../src/core/persistence/sync-drain.ts';+import { drainNext, drainStopFields, formatDrainSummary, runDrain, type DrainClaim, type DrainOwnerRow, type StallProbe } from '../src/core/persistence/sync-drain.ts';import { startServeHeadWatcher, type OnCommitJobStatus, type ServeHeadWatcherOptions } from '../src/core/serve-head-watcher.ts';import { RETRY_BACKOFF_MS } from '../src/core/commit-notifier.ts';import { CODES } from '../src/core/error-registry.ts';@@ -209,3 +209,24 @@ describe('commit notifier: committed runs are progress, and a stalled lease holdexpect(h.s.starts).toEqual([]);});});++describe('GBRA-133: a drain that stops short names its cause on the serve done line', () => {+ const base = { added: 3, modified: 0, deleted: 0, renamed: 0, chunksCreated: 0, embedded: 0, pagesAffected: [], fromCommit: null, toCommit: 'a'.repeat(40) } as unknown as SyncResult;+ test('a synced result adds nothing', () => {+ expect(drainStopFields({ ...base, status: 'synced', drain: { outcome: 'synced' } as never })).toBe('');+ });+ test('a blocked stop names its stop reason, the write that stopped it, and the failed files by code', () => {+ const managedWrite = { write_error: 'storage_error', reason: 'database_contention', write_request: { request_id: '123e4567-e89b-42d3-a456-426614174000' } } as never;+ expect(drainStopFields({ ...base, status: 'blocked_by_failures', drain: { outcome: 'blocked', stop_reason: 'blocked_by_failures' } as never, managedWrite }))+ .toBe(' stop=blocked_by_failures write_error=storage_error write_reason=database_contention request=123e4567-e89b-42d3-a456-426614174000');+ expect(drainStopFields({ ...base, status: 'blocked_by_failures', failedFiles: 3, failureCodes: [{ code: 'invalid_frontmatter', count: 2 }, { code: 'file_too_large', count: 1 }] }))+ .toBe(' failed_files=3 failures=invalid_frontmatter:2,file_too_large:1');+ });+ test('a blocked stop that recorded no write and no failed file says cause=unrecorded instead of reading like a clean end', () => {+ expect(drainStopFields({ ...base, status: 'blocked_by_failures', drain: { outcome: 'blocked', stop_reason: 'blocked_by_failures' } as never }))+ .toBe(' stop=blocked_by_failures cause=unrecorded');+ });+ test('a resumable stop names its reason', () => {+ expect(drainStopFields({ ...base, status: 'partial', reason: 'deadline', drain: { outcome: 'resumable', stop_reason: 'deadline' } as never })).toBe(' stop=deadline');+ });+});