fix(server): enforce one owner per state directory #14694
main fromfix/6097-single-state-owner·opened View on GitHubblocked: published P1 data loss and reported ownership-continuity data loss
Local correction
f0007bfa61e3344ef87ad66341686b3c1432068a, followed by docs-only62a458a8, remains unpublished. It addresses the original cancellation-persistence case by refusing automatic trial or restoration from an uncertain pre-existing pending backup; interrupted updates with such backups require manual recovery. 90 focused tests, scoped lint/typecheck and a native Node reproduction pass. Two independent reviewers approved the exact local correction SHA for combined retest only; their approval of the publishedf4444feis withdrawn.Intermediate combined validation reported a second continuity data-loss case: another owner can accept writes between the snapshot and trial ownership, after which rollback can overwrite those writes. Final combined validation was stopped by platform review and remains blocked; no completed final combined-validation result is claimed. Local checks and reviews, and prior CI on the published SHA, do not establish readiness. Publication remains blocked.
Combined protocol integration independently reproduced the original data-loss case on the published ownership SHA
f4444fe79c036b849a46b9c00ae6a37deced3c62: if persisting ownership-refusal cancellation fails before the service-state rename, the update remains pending. After the foreign owner accepts writes and releases ownership, restarting the service can restore the stale backup over those writes. A post-rename directory-sync failure control retains the cancellation and data. The local correction and persistence-failure regressions address this original case, but no corrective code has been published. Prior successful checks and approvals below do not cover the later findings, and this PR must remain blocked.
Problem#
Desktop can move to another port while a background server owns the same T3 home, starting two backends against one database. A disposable baseline reproduction at a3abb5266080c15b2a675d7f92b517b567c427e2 produced two live servers and replaced the incumbent runtime descriptor.
Change#
Acquire an exclusive OS lock on a separate, persistent SQLite ownership file before constructing the server application/database graph. Canonical directory identity handles aliases; owner IDs protect descriptor publication and cleanup; process exit releases the lock. Refuse live legacy owners conservatively and fail closed on malformed ownership state.
Desktop and WSL display ownership refusal (exit 78) and stop retrying. Service install/restart and backup/restore respect the same boundary. An ownership interruption cancels pending rollback without restoring stale data and parks the launcher until explicit restart/stop. Offline project writes acquire ownership.
Scope and approval#
Addresses #6097, one underlying reliability defect: independent owners of one server home. Server, service and desktop changes enforce that same invariant. This submits the focused obvious-bug repair for maintainer triage; no maintainer approval of this exact adaptation is claimed.
Adapted from Theo Browne's #9652, source 4700334a2a37c0fb71366078eef151aaa122cf15, with current-main behavior preserved. Maria authorized this fresh adaptation branch; existing candidates are untouched. SSH identity/catch-up in #5749, CLI parsing/directory creation and stale command-model behavior in #14629, registered Git review-root validation in #4022, and Electron connection-catalog safety in #4750/#8341 remain separate.
Verification#
Published SHA: f4444fe79c036b849a46b9c00ae6a37deced3c62. Two independent read-only gpt-6-astra/xhigh reviewers previously approved this SHA and the narrow Linux/Node evidence after their then-confirmed findings were fixed; that approval is now withdrawn as described above.
Actual source, emitted Node bundle and Linux Node 25.7.0 single executable each refused the competing backend with exit 78, retained the incumbent descriptor and returned SQLite integrity ok after stopping task-owned processes. Four simultaneous source starts yielded one owner and three refusals; restart succeeded after SIGKILL of the captured winner, followed by clean descriptor removal and integrity ok. A protocol-3 standalone launcher stayed alive after refusal, then exited zero and wrote its stop marker on SIGTERM. Node/Bun lock interoperability and crash release passed; full-app Bun startup hits the pre-existing node:sea failure on baseline too.
| Same disposable-home workload | Baseline | Final |
|---|---|---|
| Live backend count | 2 | 1 |
| Total live RSS, KiB | 795,824 | 410,608 |
| Second startup/refusal outcome, ms | 6,564.9 | 4,454.8 |
These are single-run observations with differing background test load, not a controlled latency benchmark. The release-between-lock-attempts negative control at dbfbbd03 fails by restoring “older backup” over “live database”; the final regression passes.
Passed:
vp test run src/serverRuntimeState.test.ts src/serviceLauncher.test.ts src/cloud/bootService.test.ts src/cli/project.test.tsfrom apps/server: 68.- Scoped server/desktop/contracts typecheck and lint; repository typecheck (15 tasks, task-local Astro cache) and lint.
- Final web suite: 5,484. Normal-environment desktop suite: 1,410 tests passed, 12 skipped; native-helper suite blocked.
- Server bundle and Linux single-executable builds; final CI run passed. No unresolved review threads at snapshot.
Failed/blocked:
- Final server aggregate: 5,623 passed, 5 failed, 10 skipped plus one suite failure. The same failures reproduce on baseline because fixtures require a writable executor home.
- Repository aggregate is non-green: missing libsecret development headers; a global telemetry override changed an existing WSLENV expectation (baseline control reproduces it; normal-environment desktop rerun passes). Cancelled tasks are not reported passed.
- Actual native refusal-dialog before/after media, installed OS service-manager races, Windows/macOS/WSL/mobile flows and real-provider resume/replay are unverified. A paired cloud web-client startup capture is only smoke evidence; no provider was enabled. Media publication is blocked by unavailable shared upload helper and Library batch-helper network access.
- The existing CLI authentication layer can still open/migrate SQLite before the offline guard. Unknown word
srevecreates a disposable home and starts a server on baseline and final; the related CLI parsing/directory-creation acceptance gate in #14629 is not fixed here.
All runtime checks used disposable state and captured task-owned PIDs. Direct cloud checks/browser use followed Maria's task-specific override after Blacksmith setup failed. PR remains draft; no merge, deployment or release inclusion is claimed.
Model: unknown-model (exact runtime slug unavailable). Harness: Codex cloud. Independent reviewers: gpt-6-astra, xhigh, fork_turns none.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Note
Written by
gpt-6.1-solon behalf of MariaSuperseded by #16102. This draft has merge conflicts and its published rollback can restore a snapshot over another owner's accepted writes. The replacement is based on current main, enforces exclusive ownership before persistence opens, and refuses stale or interrupted restoration. It includes the real-client reproduction, 153 focused tests, and native update verification. #6097 stays open until the replacement lands.
maria-rcks closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
b33eda1· PR result:f4444fe· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.