Skip to content

docs(adr): 0059 a worker with real drivers holds a per-user lock (#1189) - #1190

Merged
V3RON merged 6 commits into
mainfrom
feature/1189-adr
Nov 2, 2026
Merged

V3RON merged 6 commits into
mainfrom
feature/1189-adr

Conversation

@V3RON

@V3RON V3RON commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

ADR 0059 for #1189, Accepted — not yet implemented. A worker that runs real drivers takes a per-user lock (/tmp/simlock-<uid>/worker.lock/, holding pid, folder and start time) before it discovers drivers. A second real-driver worker of the same user with another folder refuses to start and names the first. Workers with substituted drivers (the fast e2e lane, the gateway-fleet tests) and gateways never take it. It narrows ADR 0034 §1's "No new lock is needed" and ends bug #264 for one user.

This PR is the bottom of #1189's stack and merges with the feature's last task.

Status

Review: round 1 3 blocking, round 2 1 blocking, fix-check passed (R1–R3 fixed) Gate: waiting for the stack
Next: stack with #1193

Review

Spec review: 4 blocking, 4 fixed, 1 notes. Code review: skipped. Claims review: skipped.
Rounds: 2. Tokens: 6.6M.
Runs: 7. Cost USD: 2.3004. Agent seconds: 759.
Assessment: complete

Written by an agent.

@V3RON

V3RON commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Decision taken

Question: two starts of the same folder race. Start A takes the worker lock, start B (same folder, lock held by a live A) goes on, and B wins the socket claim. A then fails and removes its lock, so B runs real drivers with no lock. What should happen?

Options:

  • The socket claim's winner rewrites the lock (taken). After a worker wins the socket claim while the lock names its folder and another pid, it rewrites owner.json with its own pid. A failed start removes the lock only when owner.json is still the one that start wrote, so the loser leaves it. A user sees nothing: one worker runs, and it holds the lock.
  • The same folder counts as held. B is refused with the "another worker" message. A user doing two simlock commands at once could see a confusing start error even though a worker runs.
  • A failed start never removes the lock. The loser's lock goes stale after it exits, and a worker in another folder could take it over while B runs.

Why: the first keeps today's "already running" behaviour, and changes only who is named in owner.json.

Reverting: one rewrite step after the socket claim in startDaemon, and its test line in #1191.

Written by an agent.

@V3RON
V3RON added this pull request to stack #1195 November 2, 2026 10:12
@V3RON

V3RON commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Review ledger

Round 1: 9aaaecb
Round 2: 15b43ff
Round fix-check: d5cd4be

Runs: 7. Cost USD: 2.3004. Agent seconds: 759.
Tokens input 146, output 37208, cache read 3308458, cache write 286723.
- review 1 reviewer: claude-sonnet-5-5 270 s $0.158
- review 1 reviewer spec: claude-opus-5-5 186 s $1.3619
- fix 1 implementer: claude-sonnet-5-5 29 s $0.0836
- review 2 reviewer: claude-sonnet-5-5 148 s $0.1617
- review 2 spec: claude-opus-5-5 69 s $0.399
- fix 2 implementer: claude-sonnet-5-5 28 s $0.065
- review fix-check reviewer: claude-sonnet-5-5 29 s $0.0712
Finding outcomes: {"fixed":3}. Classes: {"adr-index status lines stale":1,"false statement in ADR consequence":1,"same-folder race undecided":1}.
{"findings":[{"id":"R1","role":"spec","class":"false statement in ADR consequence","outcome":"fixed","path":"docs/internal/adr/0059-a-worker-with-real-drivers-holds-a-per-user-lock.md","round":"1","fix":"15b43ff13e4cb3fabae085dec77e1503bf8119ec"},{"id":"R2","role":"spec","class":"same-folder race undecided","outcome":"fixed","path":"docs/internal/adr/0059-a-worker-with-real-drivers-holds-a-per-user-lock.md","round":"1","fix":"d5cd4be973890d68a22b59b9c783ced67afa88f9"},{"id":"R3","role":"spec","class":"adr-index status lines stale","outcome":"fixed","path":"docs/internal/adr/README.md","round":"1","fix":"15b43ff13e4cb3fabae085dec77e1503bf8119ec"}]}

Written by an agent.

@V3RON

V3RON commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Review notes

Not blocking, not verified. Each is one reviewer's claim.

  • spec: docs/internal/adr/0059-a-worker-with-real-drivers-holds-a-per-user-lock.md §2–§3 a tiny window remains where a stopping holder removes the lock between the claim winner's check and its rewrite; judged unrealistic.

Written by an agent.

@V3RON
V3RON marked this pull request as ready for review November 2, 2026 10:14
@V3RON
V3RON merged commit dc5a04d into main Nov 2, 2026
51 checks passed
@V3RON
V3RON deleted the feature/1189-adr branch November 2, 2026 11:25
V3RON added a commit that referenced this pull request Nov 2, 2026
Closes #1191

### Status

Implement: done Review: passed (R1–R4 fixed, R5 dup) Hardware: pass ADR
0059: Accepted (adr-flip-check ok) Gate: not run — merge needs the
maintainer's permission
Next: .agents/scripts/merge-pr.sh 1193 (gates and merges #1190 and
#1193)

## Assumptions
- Assumption: a failed check after the socket claim — the start fails
for any error from that check, not only a foreign live holder; the
conservative reading of ADR 0059's "makes sure it holds the lock".

## Review

Spec review: 0 blocking, 0 fixed, 0 notes. Code review: 4 blocking, 4
fixed, 0 notes. Claims review: 0 blocking, 0 fixed, 0 notes.
Rounds: 2. Tokens: 11.9M.
Runs: 20. Cost USD: 8.9458. Agent seconds: 4414.
Assessment: complete

## Done when

- [x] `pnpm exec vitest run --project unit src/daemon/main.test.ts
src/ports/worker-lock.test.ts src/slow-e2e.test.ts` passes, with the
lines above. — run by the build, audit and fix runs; CI Unit tests on
the head
- [x] Slow lane, real hardware: `e2e/slow-android-smoke.test.ts` checks
that `/tmp/simlock-<uid>/worker.lock/owner.json` names its worker's pid
and folder while it runs, and is gone after `simlock daemon stop`. —
hardware verifier pass at f3dced3 (log
simlock-slow-e2e-20261102-120326.log)
- [x] `pnpm test:e2e` passes with its files in parallel (F11). — CI E2E
jobs on the head
- [x] `running-the-daemon.mdx` no longer offers a second worker through
`SIMLOCK_HOME`, and says a second worker refuses to start and names the
first. — spec and claims review, round 1
- [x] ADR 0059 is set to Accepted on PR #1190 when this merges. — `adr:
0059 to Accepted` fix run on this branch, adr-flip-check
- [x] A second real-driver worker of the same user with another folder
refuses to start with the message above, exit 1, and starts no driver. —
main.test.ts worker-lock block (refusal before discovery, R1 probe)
- [x] The first worker's stop frees the lock; a crashed worker's lock is
taken over at the next start. — main.test.ts stop table,
worker-lock.test.ts stale case, slow-android-smoke
- [x] `pnpm test:e2e` still runs its files in parallel and passes. — CI
E2E jobs on the head
- [x] `scripts/slow-e2e.sh` exits 69 naming the holder while a worker
outside the lane holds the lock. — src/slow-e2e.test.ts
- [x] `worker/running-the-daemon.mdx` no longer offers a separate
install with `SIMLOCK_HOME`. — claims review, round 1

*Written by an agent.*
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