Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (an abort after the run returned its result no longer marks the job aborting)

garrytanb44de895dcc8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4088ac02b6..8856a5b89a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,12 +12,12 @@ identifiers and attribution are available in the pre-removal Git revision
## [Unreleased]
-**A delegated sync no longer reports `done` while it is still finishing.** The serve's sync runner published `done` before it re-checked the wanted markers and scheduled the deferred embeds. A client polling in that window saw a finished job with no embed backlog queued yet, and a second `sync_start` could begin while the first run was still settling its markers. Since #7941 the marker re-check also reads the checkout HEAD through git, which widened the window enough to fail `test/serve-sync-runner.serial.test.ts` intermittently on master (#8354). Both lanes (the shared-secret lane and the verified lane) now set `done` only after those steps.
+**A delegated sync no longer reports `done` while it is still finishing.** The serve's sync runner published `done` before it re-checked the wanted markers and scheduled the deferred embeds. A client polling in that window saw a finished job with no embed backlog queued yet, and a second `sync_start` could begin while the first run was still settling its markers. Since #7941 the marker re-check also reads the checkout HEAD through git, which widened the window enough to fail `test/serve-sync-runner.serial.test.ts` intermittently on master (#8354). Both lanes (the shared-secret lane and the verified lane) now set `done` only after those steps, and a deadline or client abort that arrives after the run has finished no longer marks it `aborting`.
### Itemized changes
-- `src/core/serve-sync-runner.ts`: `job.state = 'done'` moves after `settleRunMarkers` and `scheduleDeferredSyncEmbeds` in both lanes (#8354).
-- `test/serve-sync-runner.serial.test.ts`: a probe slows the post-run marker read and checks that `done` is only visible once the markers have settled and the deferred embeds are pending. It fails on master and passes with the fix.
+- `src/core/serve-sync-runner.ts`: `job.state = 'done'` moves after `settleRunMarkers` and `scheduleDeferredSyncEmbeds` in both lanes (#8354); the deadline and `sync_abort` skip a job whose run already returned its result.
+- `test/serve-sync-runner.serial.test.ts`: a probe slows the post-run marker read and checks that `done` is only visible once the markers have settled and the deferred embeds are pending; a second probe aborts during that settle and checks the job still ends `done`. Both fail without the fix.
## [0.60.532.0] - 2026-11-01
diff --git a/src/core/serve-sync-runner.ts b/src/core/serve-sync-runner.ts
index 81da6e0fee..0c52d4dc5e 100644
--- a/src/core/serve-sync-runner.ts
+++ b/src/core/serve-sync-runner.ts
@@ -275,7 +275,7 @@ function startDelegatedSyncScoped(
let deadlineTimer: ReturnType<typeof setTimeout> | null = null;
if (options.timeoutSeconds > 0) {
deadlineTimer = setTimeout(() => {
- if (!isTerminal(job.state)) {
+ if (!isTerminal(job.state) && !job.result) {
log(`abort job=${job.id} reason=deadline after ${options.timeoutSeconds}s`);
job.state = 'aborting';
controller.abort();
@@ -484,7 +484,7 @@ export function abortDelegatedSync(jobId: string): SyncAbortResponse {
if (!job || job.id !== jobId) {
return { ok: false, protocol: 2, error: 'unknown_job' };
}
- if (!isTerminal(job.state)) {
+ if (!isTerminal(job.state) && !job.result) {
log(`abort job=${job.id} reason=client`);
job.state = 'aborting';
job.controller.abort();
diff --git a/test/serve-sync-runner.serial.test.ts b/test/serve-sync-runner.serial.test.ts
index bc9ab57693..696c35bf47 100644
--- a/test/serve-sync-runner.serial.test.ts
+++ b/test/serve-sync-runner.serial.test.ts
@@ -187,6 +187,31 @@ describe('serve-sync-runner delegated jobs', () => {
}
}, 60_000);
+ test('#8354: a client abort while the finished run settles its markers leaves it done, never aborting', async () => {
+ let markerReads = 0;
+ let release!: () => void;
+ const settling = new Promise<void>((r) => { release = r; });
+ let inSettle!: () => void;
+ const entered = new Promise<void>((r) => { inSettle = r; });
+ const slowSettle = new Proxy(engine, { get(target, key) {
+ const value = Reflect.get(target, key, target);
+ if (key === 'executeRaw') return async (sql: string, params?: unknown[]) => {
+ if (sql.includes('FROM sync_wanted_markers m JOIN sources') && ++markerReads > 1) { inSettle(); await settling; }
+ return target.executeRaw(sql, params);
+ };
+ return typeof value === 'function' ? value.bind(target) : value;
+ } });
+ const start = startDelegatedSync(slowSettle, { sourceId: 'default', noPull: true, timeoutSeconds: 120 }, 'token-8354-abort');
+ await entered;
+ const ab = abortDelegatedSync(start.jobId!);
+ expect(ab.ok).toBe(true);
+ expect(ab.state).toBe('running');
+ release();
+ const s = await waitForTerminal(start.jobId!);
+ expect(s.state).toBe('done');
+ expect(s.result!.added).toBe(2);
+ }, 60_000);
+
test('single-flight: a different token while running answers busy with the jobId', async () => {
const first = startDelegatedSync(engine, { noPull: true, timeoutSeconds: 60, sourceId: 'default' }, 'token-a');
expect(first.ok).toBe(true);