Skip to content

fix(sandbox): preserve routes across create and cleanup races - #4277

Merged
yannickmonney merged 1 commit into
mainfrom
fix/sandbox-hub-create-cleanup
Oct 4, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/sandbox-hub-create-cleanup

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

A deleting sweep could remove or mark a newly created device session’s route as deleting while its placement write was in progress. Candidate selection could also outlive a device connection, and a create rejected locally before transmission kept a route that no remote session could use.

Destroy finalization now checks the captured placement identity as well as the existing create generation under the per-session ordering. Create admission rechecks the registered connection and eligibility, then checks that connection again after durable publication. A private forwarding outcome permits fallback only for a fresh create proved unsent; remote errors, lost answers, abandoned calls and retries of existing placements retain their conservative routing behavior.

Addresses N1–N3 in the independent #4189 follow-up review. Updates the existing device-routing contract and automated manual-test references.

Validation on Bun 1.4.2, macOS:

  • Seven causal regressions failed on unchanged production source; all nine new cases pass, including two remote 503 lookalike controls. Barriers exercise the real hub, in-memory tunnels and durable placement files, with restart readback.
  • Hub/placement/tunnel suites: 90 passed; full sandbox suite: 967 passed, 0 failed (3884 assertions).
  • Sandbox strict type check, type-aware changed-file lint, format, manual references (1448 boxes), links, scoped SAST and normal commit hooks passed. SAST reports 0 findings across 2 files with configured exclusions.

These are local protocol/filesystem checks. Fresh hosted CI and independent review remain the merge gate; no deployment or real remote-device acceptance is claimed.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent source review — #4277

Verdict: no blocking finding in the four-file N1–N3 repair at 0651bdabd5d894a0bde701e698af6a44b3aeb4ae, tree 1355ab041f414c11d5c5fbd1088114cf0c3835f3, based on ffa15e019c3b6453bfb82dc44231abef2b8be0de. This is source acceptance, pending fresh hosted checks and the root's live merge/composition gate.

Identity: independently verified all four frozen source SHA256 values and all fifteen retained receipt SHA256 values in review-source-v1/manifest.json (SHA256 8113682ef44f8c631f18954b6b7dc8e7367d775cba29cebca120a325c031320d). All four published Git blobs equal that manifest. The patch is SHA256 77d6dc4764b2f8eed141272d234ed3ffcc9ee03546779bc03c30457a660a01b4.

Mechanism review

  • N1: maybeForward captures the actual published Placement object and current unique create symbol before dispatch. afterDestroy compares both inside the existing per-session ordering. This closes the case where a sweep starts after the new symbol is installed but before its placement is durably published. PlacementStore publishes only after atomic rename, preserves unchanged object identities across unrelated writes, and replaces an entry for set/markDeleting; therefore reference comparison identifies the route that the old response actually described. Existing create/destroy serialization remains intact. Stale done and pending responses cannot delete or mark the new placement.
  • N2: eligibility is checked again immediately before reservation/durable write, including registered object identity, tenant, compatible version, cooldown and free slots. The exact expected connection and compatibility are checked after the awaited write, immediately before calling the tunnel. The expected connection's organization and HELLO identity are fixed for its lifetime. An incompatible replacement cannot inherit an old candidate's eligibility. Device-reported capacity remains an advisory admission hint; the remote admission remains authoritative.
  • N3: notSent is a private hub result, never inferred from an error body or a device-provided status/header. Missing/changed expected connection and TunnelBusyError permit fallback only for the just-created placement. In the exact base tunnel, TunnelBusyError is produced before stream allocation/OPEN. Actual remote 503 responses, lost answers and cancellations remain conservative/sticky; retries of existing placements use the response-only wrapper and cannot authorize fallback. No external API or persistence format changes.
  • The manual automation register and developer device contract track these behaviors. No other production path changed. N4/P1 and N5/P2 remain separately routed; this review does not claim to repair them.

Regression and retained execution evidence

Read the new tests, existing race/lost-answer/cancellation/tenant tests, placement publication implementation and tunnel pre-send boundary. New regressions use the real filesystem publication seam and real paired in-memory tunnel endpoints. The publication barrier is restored in finally; each new fixture stops its hub and teardown removes only its own temporary directory.

The retained old-source run contains seven causal failures: two old done/pending sweep answers corrupting the new route; removed/replaced candidates during a previous refusal; removed/replaced connections during durable publication; and fresh unsent tunnel-saturation stickiness. Both adversarial remote-503 lookalike controls already pass on the old source. The repaired run is 9/9 with 48 assertions. Its established-placement saturation assertion verifies that the new fallback does not relocate an existing workspace.

Retained actual local execution, not cached status: hub/placements/tunnel 90/90, 412 assertions; full sandbox 967/967, 3,884 assertions across 49 files (64.62 seconds). Inspected the successful scoped TypeScript/lint, four-file format, manual register, links, SAST and diff-check receipts. An initial missing dependency binding attempt is separately preserved as setup failure and is not counted as a product regression.

Limits

This reviewer made no source changes and ran no tests, containers, browser sessions, devices or CI. The tests are the author's retained Darwin/Bun execution with real temporary filesystem and in-memory tunnel transport, not a physical-device or Linux deployment proof. Fresh hosted CI, exact-head review/protection state and current-main composition remain the merge gate. Deliberately conservative errors other than the explicitly proven pre-send cases can still retain a route; no blanket offline/error fallback is accepted.

@yannickmonney
yannickmonney merged commit dcfca98 into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/sandbox-hub-create-cleanup branch October 4, 2026 15:15
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