Skip to content

fix(devkitd): stabilize durable adoption after daemon restart - #489

Open
codeaholicguy wants to merge 1 commit into
mainfrom
cursor/fix-durable-reconcile-flake-3aea
Open

codeaholicguy wants to merge 1 commit into
mainfrom
cursor/fix-durable-reconcile-flake-3aea

Conversation

@codeaholicguy

Copy link
Copy Markdown
Owner

Root cause

The flake in stop_and_restart_adoption_do_not_double_launch is a product race in devkitd, not the integration test itself.

durable.run returned to callers as soon as the provider child was spawned, while prompt bytes were still being written on a background thread. Under parallel cargo test load (the same pattern CI uses when it runs cargo test --workspace), the test could kill and replace devkitd before the stub provider received the full block prompt. The orphaned provider exited on broken stdin instead of sleeping, so startup reconciliation treated the adopted run as dead and moved the agent to degraded rather than keeping it running.

A secondary issue made this worse when identity was ambiguous: adopted-run reconciliation used a single identity() probe and immediately finalized the run on any non-match, instead of retrying transient /proc misses as the durable design calls for.

On PR #486 commit f3060f4, both Node 22 and Node 24 CI jobs failed with assertion left: "degraded" right: "running" in this test (see failed Test (Node 22) job).

Fix

In rust/crates/devkitd/src/durable.rs:

  1. Launch synchronization — join the stdin writer before durable.run / durable.send return, so the prompt is fully delivered before callers can tear down the daemon. Stdout parsing still runs concurrently on its own thread.

  2. Reconciliation — when an adopted provider is not in the local supervisor set, retry identity probes (with short backoff) before marking a run interrupted; leave the row unchanged when observation is still inconclusive.

Before / after

Repro command: cargo test -p devkitd --test durable -- --test-threads=8 in a loop.

Phase Loop count Failures
Before fix 50 3 (~6%)
After fix 100 0

Isolated runs of stop_and_restart_adoption_do_not_double_launch alone did not fail; the bug only appeared when all nine durable.rs tests ran in parallel.

Test plan

Executed locally (Node 24):

  • npm install and npm run build at repo root
  • Pre-commit hook on commit (fmt check + full unit suite)
  • cargo fmt, cargo clippy --workspace -- -D warnings
  • cargo test --workspace
  • 100× parallel durable integration loop above (0 failures)

Risks

  • durable.run now blocks until stdin write completes. Prompts are capped at 1 MiB and writes are typically small; this mainly removes the race rather than changing semantics for normal callers.
  • Reconcile may defer a destructive decision by up to ~100ms when /proc is ambiguous; inconclusive cases are left for the next reconcile pass instead of interrupting immediately.

Skills / friction

  • dev-worktree / tdd / verify / dev-commit: followed for setup, reproduce-first, validation, and commit.
  • Did not edit skills/ or docs/ai/*.
  • node packages/cli/dist/bundle/cli.js install not re-run (skills already present in repo).
Open in Web Open in Cursor 

Wait for stdin delivery before durable.run returns so providers enter their
blocking state before callers can kill the daemon, and make adopted-run
reconciliation retry provider identity probes instead of finalizing on a
single transient /proc miss under parallel test load.

This branch has not been deployed

No deployments
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.

2 participants