fix(drive): atomically hand off detached start ownership#44
Merged
Conversation
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.
What
Prevent concurrent detached
startcommands from spawning competing daemon processes for the same named instance, covering both automatic initialization andinit-prepared artifacts.Before / After
Before: Two launchers could reuse the same initialized manifest before either daemon registered. Both spawned detached owners; the loser could remain in the 60-second startup loop while the integration test timed out after 30 seconds with exit code 130. Prepared manifests had the same unclaimed race, and overlapping artifact cleanup could then fail.
After: Exactly one launcher atomically claims the initialized manifest and may transfer that claim to its daemon. Competing launchers fail immediately with
already starting. Matching daemon adoption survives the launcher exiting first, and dead claims on prepared manifests are released without replacing their artifacts.How
src/instance/registry.tsrecords a launcher PID under the registry lock, adopts a matching daemon before stale-owner pruning, persists dead prepared-claim release, and rechecks ownership during registration.src/cli/start.tspasses the claim through a one-shot internal environment variable, removes it before runtime children are created, and relies on the registry claim rather than a redundant pre-spawn scan.test/cli/integration.test.tssynchronizes on the ready manifest and launcher exits, covers automatic and prepared starts independently, force-cleans an unready detached owner, and removes each tracked temporary root once.test/fixtures/fake-opencode.tsreplaces a 500 ms recording-test lifetime with an event-driven exit after LLM attachment.opencode-drive.sequenceDiagram participant A as Launcher A participant B as Launcher B participant R as Registry participant D as Daemon par concurrent start A->>R: claim name with launcher PID and B->>R: claim name with launcher PID end R-->>A: claim granted R--xB: already starting A->>D: spawn with initializer PID D->>R: adopt matching claim R-->>D: transfer ownership D->>R: register ready instanceScope
Limited to detached launcher/daemon ownership, dead prepared-claim recovery, and integration-harness determinism. No CLI command or simulation protocol shapes change.
Testing
bun run release:validate: 202 Effect tests, 57 CLI tests, lint, typecheck, and 95-file package dry-run passed.bun run test:cli: 57/57 passed after the persisted-release fix.bun run checkandgit diff --checkpassed.