Relationships
#4434 Cancel / shutdown can drop an in-flight model write — abort severs the write RPC and saveVersion is not abort-aware, so a committed side effect ends up with no persisted record
Opened by kneel · 11/5/2026· Shipped 11/5/2026
Severity: data-integrity (silent record loss on cancel)
Component: workflow execution / data persistence / process shutdown
Summary
When a workflow step is cancelled (Ctrl+C) while a model method is between an
external side effect and its writeResource call, the record can be lost even
though the side effect already happened. The abort signal is threaded into the
write RPC, so an in-flight write is actively cancelled rather than allowed to
finish; the local saveVersion takes no abort signal and cannot deliberately
finish-or-cleanly-fail; the run only waits a ~4s grace before abandoning the
method; and a second Ctrl+C force-exits the process with Deno.exit(130)
mid-write. Under a parallel fan-out, per-model .lock contention serializes the
writes and widens the window.
Observed concretely with the @kneel/koji submit_build method during a
Fedora fan-out build run: a geopm build task fired on the koji hub, Ctrl+C was
pressed mid-submit, and no build-write record persisted — a silent orphan (hub
task exists, swamp has no record of it). The extension is being changed to write
a pending record before the hub call so the orphan is at least recoverable, but
the engine behavior below means even a correctly-ordered write can still be
severed on cancel.
Repro
- Run a workflow whose step calls a model method that performs an external
side effect and then persists a record via
writeResource(any such method;@kneel/koji submit_buildis the real-world case). - Fan the step out in parallel over many inputs so the per-model datastore lock is contended (widens the gap between side effect and persisted write).
- Press Ctrl+C while a submit is between its side effect and its write.
- Press Ctrl+C a second time.
- Observe: the external side effect is present (task on the remote), but no local data record was written for it.
Root-cause pointers (file:line, swamp source)
Paths relative to the swamp source tree (read at ~/.swamp/source/src):
Grace too short / abandons in-flight method:
src/domain/workflows/execution_service.ts:938—STEP_STOP_GRACE_MS = 4_000.src/domain/workflows/execution_service.ts:976-997—InFlightMethodRuns.settle()races the pending method set against that grace (counted from the abort) and returns when it elapses.src/domain/workflows/execution_service.ts:1004-1013—awaitInFlightWork()is bounded by that grace.src/domain/workflows/execution_service.ts:1019-1039— the aborted step is markedstoppedByAbortand abandoned.Write RPC is abort-aware → in-flight write gets cancelled:
src/worker/remote_method_context.ts:447-460—writeResourceforwards the cancellationsignalinto theclient.writeResourcecall (within that line range). So on abort the in-flight write is actively severed, not completed.Local save is NOT abort-aware (cannot finish-or-cleanly-fail):
src/infrastructure/persistence/unified_data_repository.ts:1194-1200—saveVersion(type, modelId, data, content, stageAs)takes noAbortSignal. The write runs insidestaged()/ the per-model lock at :1207-1210, so once started it has no notion of a deadline or of "finish this one, then stop."Second signal force-exits mid-write:
src/infrastructure/process/shutdown_handlers.ts:74-83— withforceExitOnRepeat, a second signal callsDeno.exit(130)immediately, regardless of an in-flight write.Per-model lock contention widens the window (fan-out):
src/infrastructure/persistence/file_lock.ts:48-51—.datastore.lock,DEFAULT_LOCK_TTL_MS = 30_000.src/infrastructure/persistence/datastore_sync_coordinator.ts:60-61—SLOW_LOCK_MODEL_CONTENTION_ADVICE: "concurrent runs against one behavior instance take turns on its lock."
Why this is a correctness bug, not just a UX rough edge
The write RPC carrying the abort signal means cancel does not merely "fail to
wait" for the write — it can cancel a write that was about to make a committed
external side effect durable. The combination of (a) abort-severable write,
(b) non-abort-aware saveVersion, and (c) a 4s-then-abandon grace with a hard
force-exit escape hatch makes silent record loss reachable in normal operation.
Suggested fix direction (for discussion — not prescriptive)
- Let an already-started write complete before abandoning. Distinguish
"don't start new work" from "cancel the write that is already mid-flight." The
grace at
InFlightMethodRuns.settle()should prefer to let an in-progress durable write finish rather than race it against a 4s timeout and sever it. - Make
saveVersionabort-aware deliberately (unified_data_repository.ts:1194): honor the signal at safe points (e.g. beforeatomicAllocateVersionDir) so an abort either completes the version durably or fails cleanly with nothing half-written — never a torn/partial write. "Abort-aware" should mean finish-or-clean-fail, not sever-anywhere. - Don't force-exit over an in-flight durable write. The second-signal
Deno.exit(130)(shutdown_handlers.ts:78) could gate on a "critical write in progress" flag, or give the write a short bounded completion window before exiting. - Reduce fan-out lock contention (or document it): the per-model
.datastore.lockserialization (file_lock.ts:48) widens the vulnerable window; namespacing / per-run scoping would shrink it.
Workaround in use (extension side)
@kneel/koji submit_build is being changed to write a status: "submitting"
pending record before the hub call and finalize it with the task_id
afterward, so an interruption leaves a recoverable record instead of a silent
orphan. This mitigates the silence but not the underlying engine behavior —
the pending write itself is still subject to all of the above.
Shipped
Click a lifecycle step above to view its details.
zack commented 11/5/2026, 7:11:31 PM
Thanks @kneel for reporting this! We shipped: On Ctrl+C a committed side effect can lose its record because steps queued on a sibling's model lock still start after the abort, the coordinator's first-SIGINT handler releases every model lock even when the command owns shutdown, the run abandons in-flight work after the 4 s step stop grace and exits mid-write, and a second Ctrl+C exits at once. Fix: no method starts and no lock wait continues once the step's signal fired; locks stay held while the command owns shutdown; data writes already started are tracked per run and waited for (bounded, inside the run so they commit with it); the second signal waits for started writes and a third exits; docs tell extension authors to write a pending record before a side effect and honour context.signal.. The fix has been merged and a release is on its way. We appreciate your contribution to swamp.
Sign in to post a ripple.