Repository navigation
Description
Goal
Audit terminal lease, exclusive writes and child-process completion in the engine, including tidy and toolchain callers. Model confirmed phase-dependent data; keep orthogonal queues, terminal capabilities and platform policy separate.
Yolo: the user delegated every decision except the merge to the agent.
Mode: plan-and-implement
Research
Baseline: parent #267 assigns cli/src except plan/ (#270), engine-native/syncConcurrency.ts (#268), and derived payload bytes. git ls-files cli/src is the inventory. The command adapters, argv scanner, agent-doc checks, skill parsers and scorers, root services and entry points have linear flows, independent counters or already tagged results; no new machine there.
The remaining engine modules have explicit handoffs: tidy passes a TidyPlan with its resolved Docker endpoint to apply/report; sync passes resolved OmpWriteFolders through locks into deployment; kitLock owns SQLite connections. bun memoizes one promise of BunRuntimeState. engineCtx holds independent capabilities and run data. OS modules, version probes, caches, merge/deploy passes, atomic writes, option scanners and report formatting do not need another lifetime model. Quoting state in exec.windowsPathEntries is independent of the accumulated path text.
engine-native/logger.ts tracks the same lease through activeLease and released. Current identity gates the lease methods; stale update/release cannot erase a successor. Already-admitted actions must still run. The queue is per lease; exclusive writes use a logger-wide buffer. AsyncLocalStorage rejects nested actions while their owner remains active. Errors bypass buffered durable output. syncDispatch.runPipeline releases in finally. No production caller enters withExclusive; the installer pipes stderr. The logger tests exercise its contract. Preserve reentrant flushing and restoration on failure.
Handoff boundary: release does not cancel an admitted action or wait for it. A stale handle passes new actions through. Starting a successor before old actions drain can overlap the two queues and affect progress; this is existing library behavior, not a sequence the sync pipeline drives. Verify stale methods during a successor and completion of admitted work across release. Do not introduce cross-lease serialization, delay acquisition, or change flush/redraw timing in this behavior-preserving child.
exec.spawnProcess races the child close event with a deadline. Today a late close still performs cleanup and tries to resolve the already-settled promise. The winning event must own settlement and the loser's cancellation. Keep errors from the child and its pipes until close, partial streams on timeout, no timeout error field, and existing ordinary results with a numeric or null exit code. captureWithin, deps, tidy, ompChild and the Bun installer consume those results. Do not change host lookup, tree termination, pipes, deadlines, or the process-exit handler.
Decision: use the current lease identity as the only lease authority and buffered output as the exclusive-write state. A separate released flag can disagree with the current holder. Do not combine the independent admission queue, nesting context and redraw capability into a single global phase. Keep externally observable transitions covered by real writes to recording sinks. This local change is reversible without a caller migration.
Decision: use the one-shot close listener and deadline as mutually exclusive completion paths and narrow the result type using the existing timeout marker. An additional state flag would duplicate registrations; a new public discriminant would change returned objects. Guard against late events by retiring the competing callback before cleanup. No new dependency or wrapper remains. See Node close, async context and TypeScript narrowing.
docks-kit agent-docs verify-skill detect: verify skill: present. Verify flow V3 already drives public sync and toolchain checks in disposable fixture homes. Select those two rows and compare exit status and output to checked-in goldens. A live sync or real install would add unrelated side effects.
Tool versions: Bun 1.4.5, Node 26.13.0, git 2.53.0, gh 2.103.3, docks-kit 0.31.0 (local version output); Vitest 5.1.2, Oxlint 1.95.0 and Effect tsgo 0.74.1 (package.json).
Engineering standards
Both steps use code-clarity, type-safety-discipline, engine-native-context, host-platform-context and commit-discipline. Tests characterize existing behavior using test-coverage. No new public behavior or policy is intended.
Steps
| # | Id | Task | Files | Depends | Effect | Status | Done when |
|---|---|---|---|---|---|---|---|
| 1 | terminal | Make lease authority and durable buffering explicit. Preserve queued and stale handles. | cli/src/engine-native/logger.ts, cli/test/unit/logger.test.ts | - | local | done | Release cannot clear a later lease. Admitted actions finish; durable output flushes in order, including on rejection. |
| 2 | completion | Give close and timeout exclusive ownership of completion and encode their result shapes. | cli/src/engine-native/exec.ts, cli/test/unit/exec.test.ts | - | local | done | Only the winner settles and owns cleanup. Ordinary and timed-out results retain their public shape and exact output. |
Acceptance
| ID | Command | Expected |
|---|---|---|
| A1 | git diff 701e104c29fb5e1a3c40fbc1d3867ea625ddf281 -- cli/src/engine-native/logger.ts cli/src/engine-native/exec.ts |
Inspect the resulting sources: lease identity replaces the release flag; buffering exists only during exclusive output; deadline and close disarm one another; a timeout cannot carry a numeric exit code or a process error. Fail the structural check if any condition is absent, even if the behavior checks pass. |
| A2 | bun run test:unit cli/test/unit/logger.test.ts cli/test/unit/exec.test.ts cli/test/unit/syncLock.test.ts cli/test/unit/bun.test.ts cli/test/unit/deps.test.ts cli/test/unit/tidy.test.ts cli/test/unit/toolchain.test.ts |
All applicable tests pass, including ordered writes, stale lease operations, release with pending work, close with both output streams, error and timeout, and bounded process cleanup. |
| A3 | GOLDEN_FILTER='^cli=public fixture=home-fresh cmd=sync --dry-run$' bun run golden:dryrun then GOLDEN_FILTER='^cli=public fixture=home-fresh cmd=toolchain check$' bun run golden:dryrun |
Each selected V3 public case matches checked-in output and exit status; neither updates goldens nor deploys. |
| A4 | bun run check:types plus bun run lint and bun fmt --no-script --check on the changed TypeScript paths |
Types and Effect diagnostics, lint and formatting pass. |
| A5 | Require the protected Full CI job from the authorized ready-for-review run on the reviewed head and current base. |
All required jobs pass, including the Linux full gate and portable jobs; GitHub accepts the reviewed candidate. |
| A6 | Run the following Linux fixture command in Bash. | The real public tidy command exits zero, keeps the dirty worktree, and reports the seeded cache. No apply, remote endpoint, or live home. |
Reuse the archived #268 A3 fixture unchanged. Its code is reproduced below. createGitSandbox is the tracked fixture. Tool versions from #268 on this workstation: Bubblewrap 0.11.1, Bash 5.3.0, and coreutils 0.10.0.
bwrap --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp --tmpfs /var/tmp --setenv TMPDIR /tmp -- \
bun -e 'import {createGitSandbox} from "./cli/test/lib/gitSandbox.ts"; import {mkdirSync,existsSync,symlinkSync} from "node:fs"; const s=createGitSandbox(); try { const cache=s.home+"/.cache/ms-playwright", bin=s.base+"/bin"; mkdirSync(cache,{recursive:true}); mkdirSync(bin); for(const name of ["bun","git","dirname","uname","du"]) { const path=Bun.which(name); if(!path) throw new Error("missing "+name); symlinkSync(path,bin+"/"+name); } const p=Bun.spawnSync(["./docks-kit","tidy","--repo",s.main,"--report"],{env:{PATH:bin,HOME:s.home,LC_ALL:"C",GIT_CONFIG_NOSYSTEM:"1",GIT_CONFIG_GLOBAL:s.base+"/gitconfig"},stdout:"pipe",stderr:"pipe"}); const out=p.stdout.toString(); if(p.exitCode!==0 || !out.includes("keep worktree "+s.worktrees.dirty+":") || !out.includes(" "+cache+"\n") || !existsSync(s.worktrees.dirty) || !existsSync(cache)) throw new Error("tidy fixture proof failed"); console.log("tidy kept the dirty worktree and measured the seeded cache"); } finally { s.dispose(); }'The required full repository gate runs once on the exact reviewed candidate in CI. Run only focused local checks. Keep the separate full local bun run check checklist item unticked; a remote result cannot prove it ran locally.
Do not touch
Leave public CLI contracts, unrelated output policy, host-specific kill behavior, generated files, and other children's scope unchanged.
Open questions
Verification Results
Candidate 92d4e95360e139fc80ea9108cba5a859ebb980e1, base 701e104c29fb5e1a3c40fbc1d3867ea625ddf281.
- A1: the current lease identity gates update/release/redraw. The optional write buffer replaces the exclusive flag. Close cancels the deadline; timeout unregisters close before cleanup. The timeout variant admits neither a numeric exit code nor a process error.
- A2: seven files, 138 tests passed on Linux. Both new terminal scenarios passed, as did child close and timeout.
- A3: each selected public CLI golden passed (one sync case, one toolchain case). Both used the current TypeScript entry.
- A4:
bun run check:types, targeted Oxlint and Bun formatting passed on all four changed files. The full local gate did not run. - A6: the sandboxed public CLI printed
tidy kept the dirty worktree and measured the seeded cache. The fixture was disposed. - A5 follows publication of the reviewed head.
After review, 197e2e8d516a05331da6e9a4b5c433ac7d51bfb2 preserves A1 and releases processed write batches during long reentrant flushes. A2: 139 of 139 passed. A3: both public goldens passed. A4: types, Oxlint and format passed. A6: the public tidy proof passed. The tests include sink failure recovery, a real missing executable, strict result shapes and both partial streams.
Candidate 458a7cf1940fa5ed307f0b558999b71e7004908f: A1 unchanged. A2 passed all 139 tests, including a synchronized real-child test for partial output. A3 passed both public goldens. A4 passed types, lint and formatting. A6 passed the isolated tidy proof.
Candidate 0a2b8b1e16eeb0e24bbbe9df86d03a306996bfe4: A1 unchanged. A2 passed all 138 tests in seven files. One synchronized tree test replaces two timing-sensitive process tests; it checks both partial streams and descendant termination. A3 passed both public goldens. A4 passed types, lint and formatting. A6 passed the public tidy proof.
Candidate ecb5047670a4ad95a01c0193df03d44e873c8226: A1 unchanged. A2 passed all 138 tests after the fixture cleanup repair. A3 passed both public goldens. A4 passed types, lint and formatting. A6 passed the public tidy proof.
A5, first request: run 46544646567 failed the skill source-range guard on Linux, macOS and Windows. The logger ended on line 192, but the project skill cited line 196. Commit d168ea0a1d6dbb254dac355aafbd69d206c7928d corrects the two affected source extents. The guard and all 138 behavior tests passed on that head. A1 stayed unchanged. A3, A4 and A6 passed again. A5 needs a fresh request.
A5, second request: Linux and Windows passed on d168ea0. GitHub cancelled the macOS job before any step ran. Its annotation reported no available hosted runner. The required gate failed closed. Requested a new first-attempt run on the same head; no code changed.
A5 passed on d168ea0a1d6dbb254dac355aafbd69d206c7928d. All 10 jobs passed in run 46547968375, including Linux, macOS, Windows and the required Full CI job. The run tested merge 4cad8e6c0d069516f8664dcf1e870ec9dd604570 against main at 701e104c29fb5e1a3c40fbc1d3867ea625ddf281. GitHub reported CLEAN for PR #275.
Activity
DocksDocks commentedon Nov 30, 2026
Delegation grant: yolo: next up is a yolo issue for "scan this codebase for any implicit state machines and make it explicit"
Parent event: 7294751276
DocksDocks commentedon Nov 30, 2026
Delegation grant: yolo: ok go ahead and do issue://269 with the yolo skill
DocksDocks commentedon Dec 1, 2026
Plan review round 1
Plan-review: repair
terminal, Acceptance A1–A2 -cli/src/engine-native/logger.ts:122–170queues work per lease but buffers writes per logger. If lease A admits work, releases, and lease B acquires before A's callback starts, A's callback erases B's progress. A and B can also overlap, so A's cleanup can flush or disable buffering while B still owns exclusive output. Replacing the release flag alone can pass A1 while preserving both failures - Define the handoff so admitted work drains without overlapping exclusive sections or erasing successor progress, and check that interleaving in A2 - class: lease handoff missing from the ownership modelcli/src/engine-native/bun.ts:47–56ignores stdin and stdout and pipes stderr.syncDispatch.ts:174–186acquires and releases the lease, but no production call enterswithExclusive. A Bun install therefore does not exercise the exclusive buffer as the audit claims - Record that exclusivity is currently exercised by logger tests, not by an installer, and base the retention decision on that boundary - class: claimed production caller does not existcompletion, Acceptance A2–A3 - Publictidy --repousesdefaultTidyHostto resolve the repository through Git and the changedspawnProcesspath (cli/src/commands/tidy.ts:126–141,cli/src/engine-native/tidy.ts:125–134,336–345). A2 callsrunTidydirectly with an injected host (cli/test/unit/tidy.test.ts:480–495), and A3 runs only sync and toolchain. Both rows can pass without driving the tidy command named in the Goal - Run publictidy --repoagainst an isolated fixture without--apply, and name the expected exit status and preview output - class: missing end-to-end check for an affected public commandAGENTS.md:69–73requires the full local unit and golden gate once at the pre-commit or release boundary. A2–A4 run focused checks, while A5 runs only after a pull request is marked ready (.github/workflows/parity.yml:1–5,190–207). The plan can therefore reach its final commit without the required local gate - Recordbun run checkonce at the pre-commit boundary and retain A5 as the separate landing gate - class: required local check deferred to post-commit CIDocksDocks commentedon Dec 1, 2026
Plan review round 2, delta
Plan-review: pass
None.
Previous findings:
terminal, Acceptance A1–A2: rejected - not repeatedwithExclusive.completion, Acceptance A2–A3: resolved - A6 runs publictidy --repo --reportagainst an isolated Git fixture and checks the exit status, worktree retention, and seeded cache output.Manager response to round 1
Repaired:
Redesigned: none.
Rejected:
DocksDocks commentedon Dec 1, 2026
Self-review
Correctness
No findings. Both callbacks disarm the competing completion path. Late events cannot change the timeout result. Sink writes appended during a flush retain call order.
Spec and tests
No findings. The focused tests cover stale lease methods, already-admitted work, reentrant buffering and partial output on timeout. The two public goldens and the tidy fixture passed.
Text and safety
No findings. The change retains process-group and Windows cleanup policy. It adds no new command or configuration value.
DocksDocks commentedon Dec 1, 2026
Code review round 1, lens correctness
Code-review: pass
Standards
withExclusive, and the documented exclusive-use cases don't describe a reentrant sink. - Drain in batches while keeping buffering active so reentrant writes still follow pending writes. - class: retained drained queue entriesSpec
None.
Code review round 1, lens spec-and-tests
Code-review: pass
Standards
undefinedbecause Vitest'stoEqualignores them. The timeout test would pass with an ownerror: undefinedproperty, even though the plan requires that field to be absent. The close test likewise acceptstimedOut: undefined. - UsetoStrictEqualfor both result objects. - class: non-strict result shape assertionerrorfromonClosewould therefore escape these tests and could make tidy misclassify an executable that disappears before spawn. - Add a real asynchronous spawn failure and assert that the close result retains the process error without reporting a timeout. - class: untested asynchronous error propagationSpec
None.
Code review round 1, lens text-and-safety
Code-review: pass
Standards
withExclusivedoc promises serialization without saying it is per lease. The handoff test shows admitted work surviving release and stale calls running directly. If the successor starts exclusive work before the old action finishes, the separate queues allow both actions to run at once (inference). - Document that serialization is per lease, release does not drain admitted work, and stale calls bypass the queue. Keep the handoff behavior unchanged. - class: overstated lease guaranteeflushDurableclears the array even though its only caller immediately drops it on both success and failure. The reset makes the buffer look reusable when the next exclusive section gets a fresh one. - Removewrites.length = 0; keep the iteration that visits writes appended by a sink and thefinallythat drops the buffer. - class: redundant state resetSpec
None.
DocksDocks commentedon Dec 1, 2026
Code review round 2, delta
Code-review: pass
Previous findings
cli/src/engine-native/logger.ts:104-116).toStrictEqual(cli/test/unit/exec.test.ts:118-122,144-149).cli/test/unit/exec.test.ts:130-149).ENOENTwithout a timeout marker (cli/test/unit/exec.test.ts:99-106).cli/test/unit/logger.test.ts:207-229).cli/src/engine-native/logger.ts:14-17).cli/src/engine-native/logger.ts:104-116,150-155).Standards
spawnProcesscorrectly returns an empty stderr and the new assertion fails. Inference: a loaded runner can hit that ordering; its frequency is unknown. - Make the partial-output assertion wait for both real stream reads before advancing a controlled deadline, and keep the real-clock child cleanup check separate. - class: unsynchronized subprocess output assertionSpec
None.
Manager response to round 1
Repaired in 197e2e8:
Rejected: none.
Redesigned: none.
DocksDocks commentedon Dec 1, 2026
Code review round 3, delta
Code-review: pass
Previous findings
cli/test/unit/exec.test.ts:156-169). The process-tree test still has an instance of the same defect, repeated under Standards.Standards
spawnProcesscorrectly returns empty stdout and the test fails atexpect(grandchild).toBeGreaterThan(0)before checking cleanup. Inference: a loaded runner can hit this ordering; its frequency is unknown. - Wait for the real grandchild PID before advancing a controlled deadline, then check that the grandchild exits. Keep the separate real-clockcaptureWithintest. - class: unsynchronized subprocess output assertionSpec
None.
Manager response to round 2
Repaired:
Rejected: none.
Redesigned: none.
DocksDocks commentedon Dec 1, 2026
Code review round 4, delta
Code-review: pass
Previous findings
captureWithintest remains (cli/test/unit/exec.test.ts:170-177,198-204).cli/test/unit/exec.test.ts:152-154,185-188).Standards
Promise.allrejects before the test saves the PID. Teardown kills only the direct child, leaving the grandchild to run until its own 30-second or 90-second timer expires. Inference: this can happen if the two pipe events are delivered on opposite sides of the watchdog deadline. - Save the validated PID as soon as the stdout line arrives, while still waiting for both lines before advancing the simulated deadline. - class: cleanup state lost on partial readinessprocess.kill, the signal can throwESRCH. That skips timer restoration and can make the following real-clockcaptureWithintest hang. Inference: the cascade requires the grandchild to exit in that teardown window. - Restore real timers before signaling the grandchild, and tolerate onlyESRCHfrom the cleanup signal. - class: throwing teardown skips clock restorationSpec
None.
Manager response to round 3
Repaired:
Redesigned:
Rejected: none.
DocksDocks commentedon Dec 1, 2026
Code review round 5, delta
Code-review: pass
Previous findings
cli/test/unit/exec.test.ts:179-188).ESRCH, and the success path clears the saved PID after observing that the grandchild has stopped (cli/test/unit/exec.test.ts:36-42,196-207).Standards
None.
Spec
None.
Manager response to round 4
Repaired:
Rejected: none.
Redesigned: none.
DocksDocks commentedon Dec 1, 2026
Code review round 6, delta
Code-review: pass
Previous findings
None.
Standards
None.
Spec
None.
Manager response to round 5
Repaired: none (no open findings). The CI range guard required a separate two-line metadata repair.
Rejected: none.
Redesigned: none.
DocksDocks commentedon Dec 1, 2026
Archived with landing pull request #275