fix: drain sqlite write inside workspace chain - #320
Merged
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
saveWorkflowSnapshot/saveWorkflowTerminalStateawaited 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, sodrainWriteChain()returned while a SQLite tmp file was still being written into.coder/.Symptom
Intermittent ENOTEMPTY failures on CI in tests that call
rmSyncon the workspace dir after the test body (workflow-launcher-completion, develop-runid). Examples:ENOTEMPTY: directory not empty, rmdir '/tmp/coder-launcher-e2e-fSt1d9/.coder'(PR chore(deps): bump xstate from 5.28.0 to 5.30.0 #295 CI run)Reproduces only on slow CI runners — not locally — because the race between the SQLite tmp file and
rmSyncis timing-dependent.Fix
Move
persistSnapshotToSqliteinto the chain, so a singledrainWriteChain()call covers both writes.Test plan