factory gap: wire the TUI data layer — RunResult capture, attempts/spend writers, verdict.json, drive heartbeat #574

Closed
opened 2026-08-15 06:01:22 +00:00 by ben · 3 comments
Owner

Gap

The TUI's data layer is designed but not wired (survey: docs/research/2026-08-15-factory-reengineering-survey.md §state):

  1. main.mts discards the entire RunResult — iterations[].usage (the spend row, verbatim), sessionId, commits[].sha, logFilePath. Consequence: attempts and spend tables have zero production writers (only the test suite exercises them); swarm-db.sh issue N / spend-weekly return empty in production; the docker events worker-birth watcher exists only to reconstruct what the return value already knows.
  2. close_outcome wire cut at both ends: the column exists (swarm-db.py:57), close-report.sh:48 computes exactly that value, neither side connects.
  3. Drive run dirs have no verdict.json — the reporter must be handed the rc by argument; the "red drive with zero red legs" branch papers over it. verdict-lib.sh already implements the pattern; the drive just doesn't use it.
  4. No drive-status record — in-flight drive's PID/target/droplet name+IP exist only as prose in the executor log.
  5. legs.json records only completed legs — during a 20-minute leg budget, hung and working look identical. Add an in-flight {leg, status: "running", startedAt} record (single highest-value TUI addition).
  6. Repo-tag the three verdict files (/tmp/matou-{swarm,triage,seam}-verdict.txt) — two repos would stomp each other without the global lock.

All two-way doors; agent-shaped once approved. Filed ready-for-human per Ben's instruction — re-arm at will.

## Gap The TUI's data layer is designed but **not wired** (survey: `docs/research/2026-08-15-factory-reengineering-survey.md` §state): 1. **`main.mts` discards the entire `RunResult`** — `iterations[].usage` (the `spend` row, verbatim), `sessionId`, `commits[].sha`, `logFilePath`. Consequence: `attempts` and `spend` tables have **zero production writers** (only the test suite exercises them); `swarm-db.sh issue N` / `spend-weekly` return empty in production; the `docker events` worker-birth watcher exists only to reconstruct what the return value already knows. 2. **`close_outcome` wire cut at both ends**: the column exists (`swarm-db.py:57`), `close-report.sh:48` computes exactly that value, neither side connects. 3. **Drive run dirs have no `verdict.json`** — the reporter must be handed the rc by argument; the "red drive with zero red legs" branch papers over it. `verdict-lib.sh` already implements the pattern; the drive just doesn't use it. 4. **No drive-status record** — in-flight drive's PID/target/droplet name+IP exist only as prose in the executor log. 5. **legs.json records only completed legs** — during a 20-minute leg budget, hung and working look identical. Add an in-flight `{leg, status: "running", startedAt}` record (single highest-value TUI addition). 6. Repo-tag the three verdict files (`/tmp/matou-{swarm,triage,seam}-verdict.txt`) — two repos would stomp each other without the global lock. All two-way doors; agent-shaped once approved. Filed ready-for-human per Ben's instruction — re-arm at will.
Author
Owner

Ben ruled (2026-08-19, live session): the factory block is delegated under ADR 0174 — dispatched to the agent/session lanes with dependency edges wired; veto via the tracker anytime.

Ben ruled (2026-08-19, live session): the factory block is delegated under ADR 0174 — dispatched to the agent/session lanes with dependency edges wired; veto via the tracker anytime.
Author
Owner

Routed to ready-for-session — this slice edits protected .sandcastle/ paths

Picked up by swarm agent (run 7734). Stopping without code changes: every core part of this ticket edits protected .sandcastle/ machinery, which a swarm worker cannot land — the protected-paths fence (#445, .sandcastle/protected-paths-lib.sh) fingerprints .sandcastle/.forgejo before/after the run, rolls back any change, and reds the run. Per ADR 0174 §5 and docs/agents/triage-labels.md, protected .sandcastle/ paths are the ready-for-session lane, not ready-for-agent.

Where each part lives (protected unless noted):

  1. RunResult capture → .sandcastle/main.mts — protected
  2. close_outcome wire → .sandcastle/swarm-db.py + .sandcastle/close-report.sh — protected
  3. drive verdict.json → .sandcastle/verdict-lib.sh + .sandcastle/rehearsal-report.sh — protected (writer scripts/rehearsal-* is not, but the reporter is)
  4. drive-status record → writer scripts/rehearsal-executor.sh (unprotected) but consumed via .sandcastle/rehearsal-report.sh
  5. legs.json in-flight record → writer scripts/rehearsal-cycle.sh (unprotected) + reader .sandcastle/rehearsal-report.sh — protected reader
  6. repo-tag /tmp/matou-{swarm,triage,seam}-verdict.txt → .sandcastle/verdict-lib.sh + .sandcastle/run-*.sh — protected

Parts 4/5 have unprotected writer halves, but each is only useful once its protected reader half lands, so no closeable subset exists for the agent lane. The whole slice needs an interactive session's standing.

Re-arm: run this from a session (which can edit .sandcastle/), keeping the label ready-for-session. No one-way door here — nothing on ADR 0174 §3's list — so this is not ready-for-human.

## Routed to `ready-for-session` — this slice edits protected `.sandcastle/` paths Picked up by swarm agent (run 7734). Stopping without code changes: **every core part of this ticket edits protected `.sandcastle/` machinery**, which a swarm worker cannot land — the protected-paths fence (#445, `.sandcastle/protected-paths-lib.sh`) fingerprints `.sandcastle`/`.forgejo` before/after the run, rolls back any change, and reds the run. Per **ADR 0174 §5** and `docs/agents/triage-labels.md`, protected `.sandcastle/` paths are the **`ready-for-session`** lane, not `ready-for-agent`. Where each part lives (protected unless noted): 1. `RunResult` capture → `.sandcastle/main.mts` — **protected** 2. `close_outcome` wire → `.sandcastle/swarm-db.py` + `.sandcastle/close-report.sh` — **protected** 3. drive `verdict.json` → `.sandcastle/verdict-lib.sh` + `.sandcastle/rehearsal-report.sh` — **protected** (writer `scripts/rehearsal-*` is not, but the reporter is) 4. drive-status record → writer `scripts/rehearsal-executor.sh` (unprotected) but consumed via `.sandcastle/rehearsal-report.sh` 5. `legs.json` in-flight record → writer `scripts/rehearsal-cycle.sh` (unprotected) + reader `.sandcastle/rehearsal-report.sh` — **protected reader** 6. repo-tag `/tmp/matou-{swarm,triage,seam}-verdict.txt` → `.sandcastle/verdict-lib.sh` + `.sandcastle/run-*.sh` — **protected** Parts 4/5 have unprotected *writer* halves, but each is only useful once its protected *reader* half lands, so no closeable subset exists for the agent lane. The whole slice needs an interactive session's standing. **Re-arm:** run this from a session (which can edit `.sandcastle/`), keeping the label `ready-for-session`. No one-way door here — nothing on ADR 0174 §3's list — so this is not `ready-for-human`.
Author
Owner

Ruled by agent under ADR 0174 — veto anytime.

Session-runner (ADR 0174 / #538), re-armed per Ben's 2026-08-19 "re-arm at will" note on this ticket and the same day's factory-block delegation. A prior swarm attempt (run 7734, comment above) correctly stopped without code: every core part of this ticket edits protected .sandcastle/ machinery, which only a session's standing can land.

All six gaps landed, each with an offline test, commit 1980f6b:

  1. RunResult capture / attempts+spend writers — close-report.sh prints one structured SANDCASTLE_ATTEMPT issue=N outcome=O commits=csv stdout line in every outcome (success or gate-refused) — a deliberate protocol line, not worker chain-of-thought prose. main.mts now captures the RunResult it used to discard and shells out to a new .sandcastle/record-run-result.sh, which parses those markers out of the combined stdout, zips them against RunResult.iterations[] in iteration order (a same-issue retry within one iteration dedupes to its last outcome), and writes swarm.db's attempts/spend/events rows — previously zero production writers, only exercised by the test suite. run-swarm.sh exports SWARM_DB_RUN_ID so main.mts's writes land under the exact run id its own runs row uses.
  2. close_outcome wire — the value is the gate's verdict (refused when the gate refuses the close, never the agent's self-declared "success" claim), computed right where the ticket named it (close-report.sh:48's status var) and now carried through to swarm-db.py's attempts.close_outcome column via the same marker line.
  3. Drive verdict.json — journey.droplet.spec.ts / journey.selfhosted.spec.ts now write artifacts/verdict.json unconditionally in afterAll (ADR 0183 clause 5's exact schema), via a new computeVerdict() in legs.ts. rehearsal-report.sh treats it as authoritative over the caller-passed rc when present, closing the "red drive with zero red legs" rc-passing hazard structurally (the run dir now says green-or-red on its own).
  4. Drive-status record — new scripts/lib/drive-status-lib.sh writes a repo-tagged /tmp JSON record carrying the in-flight drive's PID/target, written by rehearsal-cycle.sh the moment its lock is held and cleared on every exit; oc_droplet_create (scripts/lib/rehearsal-droplet.sh) fills in the droplet name+IP once known.
  5. In-flight leg record — legs.ts's runRecordedLeg now pushes a {leg, status: "running", startedAt} record before a leg's fn() starts, replacing it in place once the leg settles — the survey's named highest-value TUI addition, so a hung leg is visible on disk instead of indistinguishable from a working one for the whole of a 20-minute budget. computeVerdict treats a leftover running record as forcing red.
  6. Repo-tagged verdict files — /tmp/matou-{swarm,triage,seam}-verdict.txt are now /tmp/matou-<repo-tag>-*-verdict.txt in run-swarm.sh/run-triage.sh/heal.sh (reader) and scripts/seam-smoke.sh (via a new dependency-free scripts/lib/repo-tag-lib.sh, since seam-smoke.sh has no FORGEJO_API/tracker env to derive a tag from — it uses the git remote instead, same "owner-repo" shape heal.sh's REPO_TAG already computed, so reader and writers always agree).

Why a two-way door: every change is a commit plus an offline .sandcastle/tests/*.sh / vitest test — no live-infra action, no credential, no destructive step. Nothing on ADR 0174 §3's one-way-door list.

Proof: all 39 .sandcastle/tests/*.sh scripts green, the extended app/tests/e2e/fixtures/legs.test.ts (7 vitest cases) green, and the full app/tests/e2e/fixtures vitest suite (78 tests) green — all run fresh after every change, including after a real ordering bug caught in self-review (the drive-status write in rehearsal-cycle.sh originally landed before .sandcastle/.env was sourced, which would have silently dropped .env's REHEARSAL_DRIVE_TARGET=selfhosted override — fixed before commit). pnpm exec tsc --noEmit clean on every touched TypeScript file (pre-existing unrelated errors in src/bootstrap.ts/tests/unit/appShell.test.ts confirmed present on origin/main before this change, via git stash).

Pushed to origin/main as 1980f6b. STATUS.md updated in the same commit (header, milestone log, and the "Blocked on Ben" queue entry marking #574 resolved).

Ruled by agent under ADR 0174 — veto anytime. **Session-runner (ADR 0174 / #538), re-armed per Ben's 2026-08-19 "re-arm at will" note on this ticket and the same day's factory-block delegation.** A prior swarm attempt (run 7734, comment above) correctly stopped without code: every core part of this ticket edits protected `.sandcastle/` machinery, which only a session's standing can land. All six gaps landed, each with an offline test, commit `1980f6b`: 1. **RunResult capture / attempts+spend writers** — `close-report.sh` prints one structured `SANDCASTLE_ATTEMPT issue=N outcome=O commits=csv` stdout line in every outcome (success or gate-refused) — a deliberate protocol line, not worker chain-of-thought prose. `main.mts` now captures the `RunResult` it used to discard and shells out to a new `.sandcastle/record-run-result.sh`, which parses those markers out of the combined stdout, zips them against `RunResult.iterations[]` in iteration order (a same-issue retry within one iteration dedupes to its *last* outcome), and writes `swarm.db`'s `attempts`/`spend`/`events` rows — previously zero production writers, only exercised by the test suite. `run-swarm.sh` exports `SWARM_DB_RUN_ID` so main.mts's writes land under the exact run id its own `runs` row uses. 2. **`close_outcome` wire** — the value is the *gate's* verdict (`refused` when the gate refuses the close, never the agent's self-declared `"success"` claim), computed right where the ticket named it (`close-report.sh:48`'s `status` var) and now carried through to `swarm-db.py`'s `attempts.close_outcome` column via the same marker line. 3. **Drive `verdict.json`** — `journey.droplet.spec.ts` / `journey.selfhosted.spec.ts` now write `artifacts/verdict.json` unconditionally in `afterAll` (ADR 0183 clause 5's exact schema), via a new `computeVerdict()` in `legs.ts`. `rehearsal-report.sh` treats it as authoritative over the caller-passed rc when present, closing the "red drive with zero red legs" rc-passing hazard structurally (the run dir now says green-or-red on its own). 4. **Drive-status record** — new `scripts/lib/drive-status-lib.sh` writes a repo-tagged `/tmp` JSON record carrying the in-flight drive's PID/target, written by `rehearsal-cycle.sh` the moment its lock is held and cleared on every exit; `oc_droplet_create` (`scripts/lib/rehearsal-droplet.sh`) fills in the droplet name+IP once known. 5. **In-flight leg record** — `legs.ts`'s `runRecordedLeg` now pushes a `{leg, status: "running", startedAt}` record *before* a leg's `fn()` starts, replacing it in place once the leg settles — the survey's named highest-value TUI addition, so a hung leg is visible on disk instead of indistinguishable from a working one for the whole of a 20-minute budget. `computeVerdict` treats a leftover `running` record as forcing `red`. 6. **Repo-tagged verdict files** — `/tmp/matou-{swarm,triage,seam}-verdict.txt` are now `/tmp/matou-<repo-tag>-*-verdict.txt` in `run-swarm.sh`/`run-triage.sh`/`heal.sh` (reader) and `scripts/seam-smoke.sh` (via a new dependency-free `scripts/lib/repo-tag-lib.sh`, since seam-smoke.sh has no `FORGEJO_API`/tracker env to derive a tag from — it uses the git remote instead, same "owner-repo" shape `heal.sh`'s `REPO_TAG` already computed, so reader and writers always agree). **Why a two-way door:** every change is a commit plus an offline `.sandcastle/tests/*.sh` / vitest test — no live-infra action, no credential, no destructive step. Nothing on ADR 0174 §3's one-way-door list. **Proof:** all 39 `.sandcastle/tests/*.sh` scripts green, the extended `app/tests/e2e/fixtures/legs.test.ts` (7 vitest cases) green, and the full `app/tests/e2e/fixtures` vitest suite (78 tests) green — all run fresh after every change, including after a real ordering bug caught in self-review (the drive-status write in `rehearsal-cycle.sh` originally landed *before* `.sandcastle/.env` was sourced, which would have silently dropped `.env`'s `REHEARSAL_DRIVE_TARGET=selfhosted` override — fixed before commit). `pnpm exec tsc --noEmit` clean on every touched TypeScript file (pre-existing unrelated errors in `src/bootstrap.ts`/`tests/unit/appShell.test.ts` confirmed present on `origin/main` before this change, via `git stash`). Pushed to `origin/main` as `1980f6b`. STATUS.md updated in the same commit (header, milestone log, and the "Blocked on Ben" queue entry marking #574 resolved).
ben closed this issue 2026-08-19 20:47:16 +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.

Reference
Matou/idss#574
No description provided.