Skip to content

fix: drain sqlite write inside workspace chain - #320

Merged
canesin merged 1 commit into
devfrom
fix/workflow-state-drain-sqlite
Apr 10, 2026
Merged

fix: drain sqlite write inside workspace chain#320
canesin merged 1 commit into
devfrom
fix/workflow-state-drain-sqlite

Conversation

@canesin

@canesin canesin commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

saveWorkflowSnapshot / saveWorkflowTerminalState awaited the JSON write through the workspace chain, then awaited the SQLite write outside the chain. Fire-and-forget callers (actor.subscribe) discarded the returned promise, so drainWriteChain() returned while a SQLite tmp file was still being written into .coder/.

Symptom

Intermittent ENOTEMPTY failures on CI in tests that call rmSync on the workspace dir after the test body (workflow-launcher-completion, develop-runid). Examples:

Reproduces only on slow CI runners — not locally — because the race between the SQLite tmp file and rmSync is timing-dependent.

Fix

Move persistSnapshotToSqlite into the chain, so a single drainWriteChain() call covers both writes.

Test plan

  • All 806 local tests pass
  • CI green

saveWorkflowSnapshot and saveWorkflowTerminalState awaited the JSON
write through the workspace chain, then awaited the SQLite write
afterward outside the chain. Fire-and-forget callers (actor.subscribe)
discarded the returned promise, so drainWriteChain() returned while a
SQLite tmp file was still being written into .coder/.

This caused intermittent ENOTEMPTY failures in workflow-launcher-completion
and develop-runid tests on slow CI runners — the test's finally rmSync
raced the in-flight SQLite tmp file.

Move persistSnapshotToSqlite into the chain so a single drainWriteChain()
call covers both writes.
@canesin
canesin merged commit 5e5059e into dev Apr 10, 2026
5 checks passed
@canesin
canesin deleted the fix/workflow-state-drain-sqlite branch April 10, 2026 06:13
canesin added a commit that referenced this pull request Apr 11, 2026
saveWorkflowSnapshot and saveWorkflowTerminalState awaited the JSON
write through the workspace chain, then awaited the SQLite write
afterward outside the chain. Fire-and-forget callers (actor.subscribe)
discarded the returned promise, so drainWriteChain() returned while a
SQLite tmp file was still being written into .coder/.

This caused intermittent ENOTEMPTY failures in workflow-launcher-completion
and develop-runid tests on slow CI runners — the test's finally rmSync
raced the in-flight SQLite tmp file.

Move persistSnapshotToSqlite into the chain so a single drainWriteChain()
call covers both writes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant