Skip to content

Model the bounded worker pool’s failure drain #268

Done

Description

@DocksDocks

Goal

In runBounded, make accepting work and draining after a failure mutually exclusive. Preserve input-order results, bounded overlap, the first failing input by index, and the exact rejection value.

Yolo: the user delegated every decision except the merge to the agent.

Mode: plan-and-implement

Research

cli/src/engine-native/syncConcurrency.ts:19–41 stores stopped, nextIndex and every rejection independently. The first rejection stops admission. Already running workers may still reject. Only the reason from the smallest failing input index is observable. Failure can be undefined; its presence cannot be tested by truthiness. No worker needs a failure map or a final scan over every task.

runBounded has three production call sites in tidy.ts and tidyReport.ts. None needs a signature change. cli/test/unit/engine-di.test.ts already controls overlap and completion order with promises and checks two failures arriving in reverse input order. Add an independent case where one worker rejects with undefined, another remains active, and a queued task must never start.

Engineering standards

The pool step uses type-safety-discipline, code-clarity, test-coverage, and engine-native-context. commit-discipline and code-review apply to landing. Keep the next input index in the accepting state. Only the draining state can carry a failure; its reason stays unknown. Use the TypeScript narrowing handbook. The change adds no dependency, public type or new behavior.

Decision: use a local two-state model. Keeping the map permits contradictions and a post-drain search; a state-machine library adds a dependency for two transitions. Revert the local change without migrating a caller. The lowest-index rule and the undefined regression guard against future conflation of completion order and input order.

docks-kit agent-docs verify-skill detect reported verify skill: present. None of its six flows drives tidy. Use the read-only public tidy command directly; do not add a verify flow for this internal refactor. Never pass --apply. Release, configuration and generated data do not change.

Tools: Linux x64, Node.js 26.13.0, Bun 1.4.5, git 2.53.0 and GitHub CLI 2.103.3 (local version output); Vitest 5.1.2 and effect-tsgo 0.74.1 (root package pins). A2 and A4 need the supported Node runtime on PATH. Commands use the repository root and installed dependencies. A5 is a landing check after the draft pull request opens.

Verification-only prerequisites (local version output): Bubblewrap 0.11.1, Bash 5.3.0, uutils coreutils 0.10.0 (dirname, uname, du, tail), and standalone jq 1.8.1. Run A3 and the A5 gate procedure in Bash. A3 uses private temporary mounts and a private tool directory. Only Bun, git, dirname, uname and du reach the CLI through PATH; it cannot invoke Docker or npm. The checkout contains installed dependencies, so the launcher does not install any. None of these requirements changes the product dependencies.

Decision after review stall: use an allowlist rather than guessing which host utilities to exclude. An outer read-only mount alone still exposes programs and service sockets. Reject a new container image and registry dependency for this small proof. Test the actual fixture in the restricted environment, with the launcher and its two output assertions. Keep the command reproducible in this issue. The setup is temporary and disposable. If a later launcher requires another tool, the proof must fail until the prerequisite is verified and named.

Experiment: A3 on the original implementation with the final allowlist exited 0 and printed tidy kept the dirty worktree and measured the seeded cache. Repeat it on the candidate; the baseline alone is not proof of the change.

Steps

# Id Task Files Depends Effect Status Done when
1 pool Replace independent stop and failure tracking with one state and prove drain behavior cli/src/engine-native/syncConcurrency.ts, cli/test/unit/engine-di.test.ts - local done Workers can claim inputs only in the accepting state. After all active work ends, a draining pool throws the lowest-index reason unchanged, even when undefined.

Acceptance

ID Command Expected
A1 git diff origin/main -- cli/src/engine-native/syncConcurrency.ts Inspect the candidate diff, before or after the commit: one state owns admission and phase-specific data. No stop flag or failure collection remains. A partial conversion or no implementation diff fails.
A2 bun run test:unit cli/test/unit/engine-di.test.ts cli/test/unit/tidy.test.ts cli/test/unit/tidyReport.test.ts Pass. Verify overlap, ordered results and failures in reverse order. With the other worker held, the pool stays pending; after release it rejects with exactly undefined. The queued task never starts.
A3 Run the isolated public CLI command below on Linux. It exits 0, names the dirty fixture worktree in a keep line, reports the seeded cache path, and leaves both in place. This exercises nonempty worker input.
A4 bun run check:types Project types and Effect diagnostics pass locally. For the repository-wide bun run check gate, use the matching jobs on the reviewed candidate, not a duplicate local full-suite run.
A5 gh pr checks --required and the commands in SoT/.omp/plugin/skills/ci-speed/references/github-actions.md, “Verify a gate result” GitHub accepts Full CI from the GitHub Actions app. The maintainer ready event, attempt 1, workflow, actors, all jobs, reviewed head, current base and tested merge parents match. A previous green run cannot pass.
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(); }'

Do not touch

Do not change the public runner API, tidy policy, concurrency limits, paths, fixtures or dependency versions. Do not clean user resources.

Open questions

Verification Results

Reviewed candidate b6569346053ff2ef633e9158dfd2d8c4f585aa2d against 26c90afd43cba7e385f4c52de97855c953630ff2.

  • A1 passed: only the accepting state owns the next index; only the draining state owns the minimum failing index and its original rejection reason. No stop flag, failure map or post-drain search remains.
  • A2 passed on Linux: 3 files, 61 passed, 1 skipped (Windows-only report). The tests cover reverse failure order, pending work, exact undefined rejection and a queued task that never starts.
  • A3 passed on the candidate: tidy kept the dirty worktree and measured the seeded cache. The disposable fixture was removed.
  • A4 passed: bun run check:types. Targeted Oxlint and bun fmt --check also passed on both changed files.
  • A5 runs after review and publication. The complete local bun run check was not run; do not tick that local command based on a remote result.

Final candidate 37dfb4a0fe07a25b0f5a0251f1a74c700794dc69, same base. The repair changes only the test. A1 still holds. A2 again passed: 61 passed, the one Windows-only case skipped. The two cases now assert the exact lowest-index reason in both rejection orders. A3 again kept the dirty worktree and measured the cache. A4, targeted Oxlint and formatting passed on the final files.

Candidate bb9b23bdffba12ff42f186ebf36420074a0b077d supersedes the previous test-only repair. A1 is unchanged. A2: 61 passed, one Windows-only case skipped. A3: the isolated public CLI kept the dirty worktree and measured the seeded cache. A4, targeted Oxlint and formatting passed. Both failure-order tests now create rejections only when the pool starts a task.

A5 passed on bb9b23bdffba12ff42f186ebf36420074a0b077d. CI run 46540091201 passed all 10 jobs on attempt 1. The ready actor had push access. The tested merge cb6d96bf3bbce8ee3d75172dd351f64fa8965d5c has the reviewed base and head as its parents. GitHub accepted Full CI for #274.

Activity

  1. self-assigned this
    on Nov 30, 2026
  2. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    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

  3. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 1

    Plan-review: repair

    • goal_fit - Acceptance A2, Research line 15, and Steps pool - The Goal requires the pool to reject with exactly undefined after the other worker drains. The existing test only checks an Error rejection (cli/test/unit/engine-di.test.ts:74–94), and A2 names the wait but not the pool's final outcome. A refactor that stops admission, waits, then fulfills because it treats undefined as no failure could pass those checks. The current runner distinguishes failure presence from its value (cli/src/engine-native/syncConcurrency.ts:37–41). - Make A2 require that the pool is still pending while the other worker is held, then rejects with exactly undefined after release, with the queued task never started. - class: missing terminal outcome assertion
    • goal_fit - Acceptance A3 - On a checkout with no linked worktrees, tidy --repo . can exit 0 and print Nothing to tidy. without starting a worker: listWorktreeCandidates drops the main worktree, and runBounded starts zero workers for an empty list (cli/src/engine-native/tidy.ts:620–629,905–911; cli/src/engine-native/syncConcurrency.ts:24). The command also bypasses both report callers because --report defaults off (cli/src/commands/tidy.ts:32–35,113–118; cli/src/engine-native/tidyReport.ts:115,201). - Make A3 drive the real CLI against a known linked worktree and a known report entry, and require their observable output without --apply. - class: end-to-end check can bypass the changed behavior
    • research_gap - Research Tools; Acceptance A2 and A4 - The tool record omits Node.js. package.json:31,38 launches Vitest and effect-tsgo through Node shebangs, which Bun respects by default. The installed Vitest 5.1.2 declares supported Node versions in node_modules/vitest/package.json:114–115. A checkout with Bun and installed dependencies but only Node 18 on PATH meets the stated prerequisites yet runs A2 on an unsupported runtime. - Record the supported Node version used by both commands and make it a local prerequisite. - class: missing acceptance runtime prerequisite
    • goal_fit - Acceptance A5, also used by A4 - gh pr checks --required reports required check status but does not establish which ready event, attempt, or base SHA produced it. AGENTS.md:81 requires that proof, and .github/workflows/parity.yml:3–5,10–31,191–208 records it. If the base advances while the PR head stays unchanged, a green head check alone does not show that the new base was tested. - Keep the remote gate and make A5 match the successful GitHub Actions Full CI check to the maintainer's ready event, attempt 1, and the recorded head, base, and test-merge SHAs. - class: landing status without tested-candidate provenance
  4. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 2, delta

    Plan-review: repair

    • goal_fit - Acceptance A3, fixture command - The command isolates the Git repo and home, but --report still measures directories under the host's /tmp and /var/tmp and includes the absolute /tmp/.pnpm-store in the cache check (cli/src/engine-native/tidyReport.ts:47,71,95–119,178–209,497–502). Inference: a large unrelated temp tree can make this small fixture check wait on a full directory walk, and if the host pnpm store disappears during measurement, the cache section can omit the seeded Playwright path even when the pool is correct. - Keep the real CLI and both output assertions, but run the fixture in a disposable Linux environment with private temp roots. - class: fixture verification reads unscoped host data
    • research_gap - Research Tools; Acceptance A3 and A5 - The Node prerequisite is fixed, but the new commands have two unrecorded requirements. Without du on PATH, A3 emits an unavailable cache section instead of the seeded path (cli/src/engine-native/tidyReport.ts:95–119,475–481,501). Without standalone jq, A5 skips the per-commit check lookups (SoT/.omp/plugin/skills/ci-speed/references/github-actions.md:75–83); SoT/toolchain.json:4 explicitly makes jq optional, and GitHub CLI's built-in --jq does not provide that executable. - Record the du version in A3's environment and either record standalone jq as an A5 prerequisite or extract the SHAs with gh pr view --jq. - class: missing acceptance runtime prerequisite

    Previous findings:

    • Round-1 finding on Acceptance A2, Research line 15, and Steps pool: resolved - A2 now requires a pending pool before release, rejection with exactly undefined after release, and no queued work started.
    • Round-1 finding on Acceptance A3: resolved - A3 now runs the real CLI against a linked worktree and a seeded cache, and requires output for both.
    • Round-1 finding on Research Tools; Acceptance A2 and A4: open - repeated above for A3 and A5. The Node.js version and PATH requirement are now explicit.
    • Round-1 finding on Acceptance A5, also used by A4: resolved - A5 now requires the ready event, attempt 1, actors, workflow, jobs, reviewed head, current base, and tested merge parents to match the required check.

    Manager response to round 1

    Repaired:

    • Round 1 A2: require pending before drain, exact undefined rejection after drain, and no queued work started.
    • Round 1 A3: the checked-in sandbox helper supplies real linked worktrees. The CLI reports a seeded cache and keeps the dirty worktree. The sandbox is disposed in finally.
    • Round 1 Research: record the actual supported Node version for the local verification tools.
    • Round 1 A5: bind the successful protected check to the latest ready event, actors, first attempt, tested merge parents and current base/head.

    Rejected: none.
    Redesigned: none.

  5. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 3, delta

    Plan-review: repair

    • goal_fit - Acceptance A3, fixture command - The private mounts fix the /tmp and /var/tmp walks, but the read-only root still exposes host sockets. With a reachable local Docker daemon, tidy waits for docker ps and docker system df before emitting the report. It also scans the host's global npm directory if npm root -g returns one (cli/src/engine-native/tidy.ts:125–132,931–942; cli/src/engine-native/tidyReport.ts:269–279,451–455,496–506; Bubblewrap socket limitations). Inference: a slow daemon can stall A3 even when both fixture assertions would pass. - Keep the real CLI, private mounts, and both assertions, but run with a fixture-only tool PATH that excludes Docker and npm. - class: fixture verification reads unscoped host data
    • research_gap - Research Tools; Acceptance A3 and A5 - Research now records Bubblewrap, du, and standalone jq, but A3 still needs /bin/bash, dirname, and uname inside the sandbox (docks-kit:1–6,18). A5's Bash procedure needs tail -n 1 and a shell that accepts the <<< here-string (SoT/.omp/plugin/skills/ci-speed/references/github-actions.md:57–66,75–83). With only the listed tools, A3 can stop before running tidy, and A5 can fail to identify the latest ready event or run the per-commit lookups. - Specify Bash for the gate procedure and record the Bash and coreutils versions actually used by A3 and A5. - class: missing acceptance runtime prerequisite

    Previous findings:

    • Round-2 finding on Acceptance A3, fixture command: open - repeated above
    • Round-2 finding on Research Tools; Acceptance A3 and A5: open - repeated above

    Manager response to round 2

    Repaired:

    • Round 2 A3: Bubblewrap provides private temporary mounts and a read-only root. The CLI still runs on real Git worktrees and reports a real seeded cache.
    • Round 2 Tools/A3/A5: record and check the verification-only binaries, including Bubblewrap, du and standalone jq, as well as the runtimes already identified.

    Redesigned:

    • The prerequisite check now follows each acceptance action to its external commands, including the disk measurement and the GitHub evidence procedure. Recording only the runtime of package scripts missed both.

    Rejected: none.

  6. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 4, delta

    Plan-review: pass

    None.

    Previous findings:

    • Round-3 finding on Acceptance A3, fixture command: resolved - A3 retains the private temporary mounts and gives the real tidy launcher a fixture-only PATH that excludes Docker and npm. The recorded baseline run passed both output assertions; A3 still requires rerunning the command on the candidate.
    • Round-3 finding on Research Tools; Acceptance A3 and A5: resolved - Research now specifies Bash for both procedures and records the versions of Bash, dirname, uname, du, tail, and standalone jq.

    Manager response to round 3

    Repaired:

    • Round 3 A3: a private allowlist makes Docker and npm unreachable to tidy; private temp mounts contain host-independent test data. Running that exact command produced both required observations.
    • Round 3 Tools/A3/A5: the plan identifies the shell and coreutils version for fixture and landing checks, plus every executable in the fixture CLI's PATH.

    Redesigned:

    • First stall, extend the plan ceiling by ten. Choose executable allowlisting and direct experiment. An inherited PATH reached unrelated tools after the earlier filesystem isolation. Adding exclusions one by one risks missing another probe. A container image adds a registry dependency. A fixed disposable PATH plus the real dry run requires no product dependency and can be reverted in the plan alone. A future required executable must be present before either assertion can pass; rerun the known witness whenever the launcher changes.

    Rejected: none.

  7. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Self-review

    Candidate b6569346053ff2ef633e9158dfd2d8c4f585aa2d.

    Correctness

    No findings. Admission increments the index before awaiting the task. On rejection the worker reads the current pool state, so an earlier input that rejects later replaces the selected reason. All workers drain before the pool throws.

    Spec and tests

    No findings. The existing cases cover bounded overlap and reversed failures. The new case yields one event-loop turn with an active task held; the pool must still be pending. It then checks the exact rejection and that queued work never starts.

    Text and safety

    No findings. The index and reason exist only in the phase that uses them. The public signature and caller behavior do not change. The refactor removes the map and final search without a new dependency.

  8. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 1, lens correctness

    Code-review: pass

    Standards

    None.

    Spec

    None.

    Code review round 1, lens spec-and-tests

    Code-review: pass

    Standards

    • [MEDIUM] Maintainability - cli/src/engine-native/syncConcurrency.ts:14-17, cli/test/unit/engine-di.test.ts:75-124 - If the lower-index worker fails first and a higher-index worker fails during drain, the tests do not check that the pool retains the lower-index reason. The two-failure test rejects in reverse index order, and the new test has only one rejection. Inference: a regression that always keeps the last rejection would pass both tests. - Test both rejection orders and assert that the exact lower-index reason wins in each. - class: missing failure-order coverage
    • [LOW] Bug - cli/test/unit/engine-di.test.ts:112-124 - If the pool regresses and rejects early with a non-undefined reason, the assertion inside run.then rejects settled before the test awaits it. Inference: Vitest can report an unhandled rejection instead of a clean failure at the pending-state assertion. - Record settlement and its reason without asserting inside the handler. Release the held worker in finally and assert the reason in the test body. - class: delayed handling of assertion rejection

    Spec

    None.

    Code review round 1, lens text-and-safety

    Code-review: pass

    Standards

    • [LOW] Maintainability - cli/src/engine-native/syncConcurrency.ts:14-17, cli/test/unit/engine-di.test.ts:75-124 - When the lower-index task rejects first and the higher-index task rejects during drain, the pool must keep the first reason. The two-failure test rejects in the opposite order, and the new test has only one rejection. Inference: deleting the branch that retains the lower index would leave both tests green. - Run the two-failure test in both settlement orders and assert the same rejection value in each. - class: untested failure-retention branch
    • [LOW] Maintainability - cli/test/unit/engine-di.test.ts:112-124 - If the pool regresses and rejects early with a non-undefined reason, the callback throws before recording settlement. Inference: settled can emit an unhandled rejection during nextTurn(), while the pending assertion still sees no events. - Record the settlement and reason without asserting in the callback. Check that the pool is pending before releasing the active task, then await and assert the recorded outcome. - class: assertion in a deferred rejection observer

    Spec

    None.

  9. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 2, delta

    Code-review: pass

    Previous findings

    • Round-1 spec-and-tests finding on cli/src/engine-native/syncConcurrency.ts:14-17, cli/test/unit/engine-di.test.ts:75-124: fixed - cli/test/unit/engine-di.test.ts:91-94,119-127 asserts the exact lower-index reason in both rejection orders.
    • Round-1 spec-and-tests finding on cli/test/unit/engine-di.test.ts:112-124: fixed - cli/test/unit/engine-di.test.ts:112-127 records settlement without asserting in the handler, releases the held task in finally, and checks the reason in the test body.
    • Round-1 text-and-safety finding on cli/src/engine-native/syncConcurrency.ts:14-17, cli/test/unit/engine-di.test.ts:75-124: fixed - cli/test/unit/engine-di.test.ts:119-127 checks that a later failure during drain does not replace the retained undefined reason.
    • Round-1 text-and-safety finding on cli/test/unit/engine-di.test.ts:112-124: fixed - cli/test/unit/engine-di.test.ts:112-127 records rejection before the pending-state check can fail and no longer throws an assertion from the rejection handler.

    Standards

    • [LOW] Bug - cli/test/unit/engine-di.test.ts:100-105,119-124 - If the pool regresses to one worker, the pending-state assertion fails before the second task starts. The finally block then rejects a fixture promise that no worker has observed. Inference: Vitest reports an extra unhandled rejection alongside the assertion failure. - Have finally resolve a release gate and make the second task throw after awaiting that gate. If the task never starts, cleanup creates no rejection. - class: rejecting an unobserved fixture promise during cleanup

    Spec

    None.

    Manager response to round 1

    Repaired:

    • Spec-and-tests and text-and-safety, retaining the lower-index failure: 37dfb4a makes the higher-index held worker reject during drain. Its error must not replace the existing undefined rejection. The earlier case covers the opposite order.
    • Both lenses, assertion in a delayed rejection observer: 37dfb4a records the rejection without asserting in the callback, releases the held task in finally, and checks the returned reason after settlement.

    Rejected: none.
    Redesigned: none.

  10. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 3, delta

    Code-review: pass

    Previous findings

    • Round-2 finding on cli/test/unit/engine-di.test.ts:100-105,119-124: fixed - Both failure-order tests now resolve gates. Only a task the pool starts can reject, so the finally block cannot create an unhandled rejection if the second worker never starts (cli/test/unit/engine-di.test.ts:12-20,76-96,99-128).

    Standards

    None.

    Spec

    None.

    Manager response to round 2

    Repaired:

    • Round 2, unobserved fixture rejection: bb9b23b replaces externally rejected fixture promises with release-only gates. Each task throws its configured reason only after the pool invokes it. This covers both failure-order cases, including a regression that never starts one of the workers.

    Rejected: none.
    Redesigned: none.

  11. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Archived with landing pull request #274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions