swarm harness: #2106's execute-lib sink read is defeated in production by main.mts's driveMirrorStop teardown (reconcile still degrades to the truncatable log grep) #2112

Closed
opened 2026-10-30 12:28:40 +00:00 by matou-build-agent · 1 comment

Found while fixing #2110 (the #574 record-run-result.sh telemetry parse). Out of #2110's scope — a different consumer of the same SANDCASTLE_ATTEMPT line (the #283 stranded-close reconcile that #2106 fixed), so filed separately per ADR 0174 rule 1.

Symptom

#2106 taught execute-lib.sh's execute_sandcastle_run to read close-report's SANDCASTLE_ATTEMPT lines from a host-mounted sink (EXECUTE_ATTEMPTS_SINK = $SWARM_HOST_ATTEMPTS_DIR/attempts.log) in union with the sandcastle-log grep, so a worker that pipes close-report through | tail/| head no longer starves the reconcile. In production that sink read always comes up empty, so the union silently degrades to the very log grep #2106 set out to stop trusting — the reconcile is still defeated by a trailing | tail.

Cause (deletion-before-read ordering)

execute_sandcastle_run reads EXECUTE_ATTEMPTS_SINK only after pnpm run sandcastle (i.e. main.mts) exits (execute-lib.sh, the if [ -n "${EXECUTE_ATTEMPTS_FILE:-}" ] block). But main.mts's driveMirrorStop() does rmSync(HOST_ATTEMPTS_DIR, { recursive: true, force: true }) on every exit path — and HOST_ATTEMPTS_DIR is $SWARM_HOST_ATTEMPTS_DIR (same env var), i.e. the same directory EXECUTE_ATTEMPTS_SINK points inside. So by the time control returns to execute-lib, attempts.log and its dir are already gone → [ -r "$EXECUTE_ATTEMPTS_SINK" ] is false → only the log grep runs.

Why the green tests missed it: execute-lib-test.sh shims pnpm, so the real main.mts (and its driveMirrorStop deletion) never runs — the test writes the sink itself and asserts the union reads it, which it does in the test.

(#2110 avoided this for its own consumer by having main.mts read the sink into the record-run-result payload before driveMirrorStop — record-run-result.sh runs after the teardown too and would hit the same empty dir.)

Fix shape (design left to the session)

Symmetric to #2110's read-before-teardown. Likely either:

  • (a) stop deleting HOST_ATTEMPTS_DIR in driveMirrorStop; move that cleanup to run-swarm.sh's EXIT trap, which runs after execute-lib has read the sink (the host-signals dir can stay as-is); or
  • (b) have main.mts copy the captured sink out to a path execute-lib reads post-run.

Vendored files (ADR 0180): main.mts, execute-lib.sh, maybe run-swarm.sh — dev-factory backport branch + re-vendor, as #2106/#2110 did. Add an execute-lib-test.sh case that exercises the real deletion ordering (not just a pre-written sink) so the regression can't re-hide behind the pnpm shim.

Ruled by agent under ADR 0174 — veto anytime.

Found while fixing #2110 (the #574 `record-run-result.sh` telemetry parse). Out of #2110's scope — a *different* consumer of the same `SANDCASTLE_ATTEMPT` line (the #283 stranded-close reconcile that #2106 fixed), so filed separately per ADR 0174 rule 1. ## Symptom #2106 taught `execute-lib.sh`'s `execute_sandcastle_run` to read close-report's `SANDCASTLE_ATTEMPT` lines from a host-mounted sink (`EXECUTE_ATTEMPTS_SINK` = `$SWARM_HOST_ATTEMPTS_DIR/attempts.log`) in union with the sandcastle-log grep, so a worker that pipes close-report through `| tail`/`| head` no longer starves the reconcile. **In production that sink read always comes up empty**, so the union silently degrades to the very log grep #2106 set out to stop trusting — the reconcile is still defeated by a trailing `| tail`. ## Cause (deletion-before-read ordering) `execute_sandcastle_run` reads `EXECUTE_ATTEMPTS_SINK` only **after** `pnpm run sandcastle` (i.e. `main.mts`) exits (`execute-lib.sh`, the `if [ -n "${EXECUTE_ATTEMPTS_FILE:-}" ]` block). But `main.mts`'s `driveMirrorStop()` does `rmSync(HOST_ATTEMPTS_DIR, { recursive: true, force: true })` on every exit path — and `HOST_ATTEMPTS_DIR` *is* `$SWARM_HOST_ATTEMPTS_DIR` (same env var), i.e. the same directory `EXECUTE_ATTEMPTS_SINK` points inside. So by the time control returns to `execute-lib`, `attempts.log` and its dir are already gone → `[ -r "$EXECUTE_ATTEMPTS_SINK" ]` is false → only the log grep runs. Why the green tests missed it: `execute-lib-test.sh` shims `pnpm`, so the real `main.mts` (and its `driveMirrorStop` deletion) never runs — the test writes the sink itself and asserts the union reads it, which it does *in the test*. (#2110 avoided this for its own consumer by having `main.mts` read the sink into the record-run-result payload **before** `driveMirrorStop` — `record-run-result.sh` runs after the teardown too and would hit the same empty dir.) ## Fix shape (design left to the session) Symmetric to #2110's read-before-teardown. Likely either: - (a) stop deleting `HOST_ATTEMPTS_DIR` in `driveMirrorStop`; move that cleanup to `run-swarm.sh`'s EXIT trap, which runs **after** `execute-lib` has read the sink (the host-signals dir can stay as-is); or - (b) have `main.mts` copy the captured sink out to a path `execute-lib` reads post-run. Vendored files (ADR 0180): `main.mts`, `execute-lib.sh`, maybe `run-swarm.sh` — dev-factory backport branch + re-vendor, as #2106/#2110 did. Add an `execute-lib-test.sh` case that exercises the real deletion ordering (not just a pre-written sink) so the regression can't re-hide behind the pnpm shim. Ruled by agent under ADR 0174 — veto anytime.
Author
Member

close-report — #2112 landed on main

Ruled by agent under ADR 0174 — veto anytime. Two-way door (revertible: git revert the idss commit + reset the dev-factory backport branch; provable: the vendored red-before-green offline suite).

What landed

  • idss ffdb7171 on main — re-vendored FACTORY_REF e77a951→40d60ac, updating main.mts + run-swarm.sh + tests/execute-lib-test.sh; FACTORY_MANIFEST no churn; STATUS.md milestone entry.
  • dev-factory backport/idss-2112 40d60ac (off the pin e77a951, stacked on #2110) — the upstream source of the vendored change (ADR 0180).

The fix

Confirmed the symptom in the code: EXECUTE_ATTEMPTS_SINK was wired to $SWARM_HOST_ATTEMPTS_DIR/attempts.log (run-swarm.sh), which main.mts's driveMirrorStop() rmSync's on every exit path — yet execute-lib's execute_sandcastle_run reads the sink only after pnpm run sandcastle (main.mts) returns. So the dir was already gone, [ -r "$EXECUTE_ATTEMPTS_SINK" ] was false, and #2106's union degraded back to the truncatable log grep — the reconcile was still defeated by a trailing | tail.

Symmetric to #2110's read-before-teardown:

  • run-swarm.sh points EXECUTE_ATTEMPTS_SINK at a durable host file outside the mount (SWARM_HOST_ATTEMPTS_SINK, mktemp'd, cleaned by the EXIT trap).
  • main.mts persists the captured sink to SWARM_HOST_ATTEMPTS_SINK before driveMirrorStop — a path the teardown doesn't touch.
  • execute-lib.sh is unchanged (it already reads EXECUTE_ATTEMPTS_SINK post-run). run-swarm.sh dropped its local var to stay under the 200-line stage-extraction cap (199).
  • Best-effort throughout: a bare run or a write error leaves the sink empty and execute-lib falls back to the log grep, exactly as before #2106.

Proof (red-before-green)

  • execute-lib-test.sh gains case 1f, whose pnpm shim MODELS the real exit ordering — it persists the mounted sink to the host path and then rmSync's the run-scoped mount dir (driveMirrorStop) before execute-lib reads — so the regression can no longer re-hide behind a pre-written, never-deleted sink (the chosen test the ticket asked for).
  • Demonstrated the red: with the pre-fix wiring (sink inside the torn-down mount, no persist) the attempt is lost (reconcile degrades to the log grep); with the fix it survives the teardown and is recovered.
  • Green: execute-lib-test.sh (19 groups), run-swarm-stages-test.sh (13), run-swarm-landing-test.sh (13), record-run-result-test.sh (14), close-report-test.sh (139). check-harness-drift OK inline @ 40d60ac. The pre-push eslint TS gate passed.

Closing — landed on main, nothing left outstanding for this ticket.

## close-report — #2112 landed on `main` **Ruled by agent under ADR 0174 — veto anytime.** Two-way door (revertible: `git revert` the idss commit + reset the dev-factory backport branch; provable: the vendored red-before-green offline suite). ### What landed - **idss** `ffdb7171` on `main` — re-vendored `FACTORY_REF` `e77a951`→`40d60ac`, updating `main.mts` + `run-swarm.sh` + `tests/execute-lib-test.sh`; `FACTORY_MANIFEST` no churn; `STATUS.md` milestone entry. - **dev-factory** `backport/idss-2112` `40d60ac` (off the pin `e77a951`, stacked on #2110) — the upstream source of the vendored change (ADR 0180). ### The fix Confirmed the symptom in the code: `EXECUTE_ATTEMPTS_SINK` was wired to `$SWARM_HOST_ATTEMPTS_DIR/attempts.log` (`run-swarm.sh`), which `main.mts`'s `driveMirrorStop()` `rmSync`'s on **every** exit path — yet `execute-lib`'s `execute_sandcastle_run` reads the sink only **after** `pnpm run sandcastle` (`main.mts`) returns. So the dir was already gone, `[ -r "$EXECUTE_ATTEMPTS_SINK" ]` was false, and #2106's union degraded back to the truncatable log grep — the reconcile was still defeated by a trailing `| tail`. Symmetric to #2110's read-before-teardown: - `run-swarm.sh` points `EXECUTE_ATTEMPTS_SINK` at a durable host file **outside** the mount (`SWARM_HOST_ATTEMPTS_SINK`, `mktemp`'d, cleaned by the EXIT trap). - `main.mts` persists the captured sink to `SWARM_HOST_ATTEMPTS_SINK` **before** `driveMirrorStop` — a path the teardown doesn't touch. - `execute-lib.sh` is **unchanged** (it already reads `EXECUTE_ATTEMPTS_SINK` post-run). `run-swarm.sh` dropped its local var to stay under the 200-line stage-extraction cap (199). - Best-effort throughout: a bare run or a write error leaves the sink empty and `execute-lib` falls back to the log grep, exactly as before #2106. ### Proof (red-before-green) - `execute-lib-test.sh` gains **case 1f**, whose `pnpm` shim MODELS the real exit ordering — it persists the mounted sink to the host path and **then `rmSync`'s the run-scoped mount dir** (`driveMirrorStop`) before `execute-lib` reads — so the regression can no longer re-hide behind a pre-written, never-deleted sink (the chosen test the ticket asked for). - Demonstrated the **red**: with the pre-fix wiring (sink inside the torn-down mount, no persist) the attempt is **lost** (reconcile degrades to the log grep); with the fix it **survives** the teardown and is recovered. - Green: `execute-lib-test.sh` (19 groups), `run-swarm-stages-test.sh` (13), `run-swarm-landing-test.sh` (13), `record-run-result-test.sh` (14), `close-report-test.sh` (139). `check-harness-drift` OK inline @ `40d60ac`. The pre-push eslint TS gate passed. Closing — landed on `main`, nothing left outstanding for this ticket.
matou-build-agent 2026-10-30 13:21:19 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#2112
No description provided.