Architecture deepening: run state, real seam, bounded observation (spec) #20

Closed
opened 2026-12-01 10:49:16 +00:00 by alex · 2 comments
Owner

Context

The 2026-12-01 architecture review walked the post-0.3.0 hot spots — the workflow layer, the workflow-supervisor split (#12), the ultra layer — and surfaced seven candidates for deepening. A two-round grilling session settled every decision; the six accepted deepenings are ticketed as children of this spec. Provenance: research/architecture-review-2026-12-01.html (the review report; evidence, measurements, before/after diagrams). ADR amendments: 0006 (the pull path is bounded for runs too), 0004 (checkpoint granularity). GLOSSARY.md: "Expanded plan" renamed to "Start plan" with the corrected definition.

The six deepenings

  1. File split — workflow-plan.ts / workflow-run.ts / workflow-command.ts; one concern per module; the one-letter lookup trap dies.
  2. The seam — src/job-state.ts owns the shared state types and status predicates; the supervisor owns the run DAG index over shared records; the host interface carries effects only; one cancel policy; limits ride the run spec (no process.env reads — brings the code in line with the standing worker-rules convention).
  3. The run module — the journal becomes a projection of run state; the flat-snapshot reverse-engineering (itemsByStep, the positional fallback) dies.
  4. Step mirrors — WorkflowStep canonical behind a TypeBox schema (replaces STEP_FIELDS); ExpandedWorkflowStep deleted; inputHash hashes whole steps (payload v2); TypeBox schemas own TaskSnapshot, JobSnapshot, and the journal record — validator drift becomes a compile error.
  5. Observation — onJobEvent({jobId, kind}) replaces whole-snapshot callbacks; persistence checkpoints at start + terminal; a lazy snapshot cache; the runner's update carries the message delta; wait on a run returns the consolidated answer (byte-parity with the push notice).
  6. Presentation — present.ts owns one rulebook; render/job-format/dashboard become thin adapters; isFailedResult leaves the TUI renderer; one start formatter.

Shared decisions

  • Task records are shared by reference: the manager owns the flat collection (the job record), the supervisor owns the DAG index; settleTask settles the shared record once.
  • Cancel semantics are unchanged, only concentrated (immediate abort; drain the FIFO; settle queued + coordinator rows cancelled; finalize cancelled).
  • Restore stops fabricating AgentConfig records (rides the seam ticket).
  • A 256-child scale test guards the O(N²) → O(N) claim (property, not example).
  • The DAG algorithm is untouched; the TLA+ spec (spec/SubagentJobs.tla) and its modelcheck gate are unchanged.

Waves

Frontier ≤ 2 in flight: W1 file split → W2 the seam → W3 the run module ∥ step mirrors → W4 observation ∥ presentation → then the two-axis review on the integration branch, fix findings in one worker, close tickets, report, retro. The running state log lives in docs/wiki/goal-architecture-deepening.md.

Task list

  • #21 — T1: split workflow.ts/workflows.ts by concern; start-plan rename (Wave 1)
  • #22 — T2: the seam — job-state.ts, run-state ownership, one cancel policy, run-spec limits (Wave 2, blocked by #21)
  • #23 — T3: the run module — journal as a projection of run state (Wave 3, ∥ #24, blocked by #22)
  • #24 — T4: step mirrors — canonical step schema, whole-plan inputHash, TypeBox persisted shapes (Wave 3, ∥ #23, blocked by #22)
  • #25 — T5: observation — job events, checkpoint persistence, bounded pull for runs (Wave 4, ∥ #26, blocked by #23)
  • #26 — T6: one presentation rulebook — present.ts, thin adapters (Wave 4, ∥ #25, blocked by #22)
## Context The 2026-12-01 architecture review walked the post-0.3.0 hot spots — the workflow layer, the workflow-supervisor split (#12), the ultra layer — and surfaced seven candidates for deepening. A two-round grilling session settled every decision; the six accepted deepenings are ticketed as children of this spec. Provenance: `research/architecture-review-2026-12-01.html` (the review report; evidence, measurements, before/after diagrams). ADR amendments: 0006 (the pull path is bounded for runs too), 0004 (checkpoint granularity). `GLOSSARY.md`: "Expanded plan" renamed to "Start plan" with the corrected definition. ## The six deepenings 1. **File split** — `workflow-plan.ts` / `workflow-run.ts` / `workflow-command.ts`; one concern per module; the one-letter lookup trap dies. 2. **The seam** — `src/job-state.ts` owns the shared state types and status predicates; the supervisor owns the run DAG index over shared records; the host interface carries effects only; one cancel policy; limits ride the run spec (no `process.env` reads — brings the code in line with the standing worker-rules convention). 3. **The run module** — the journal becomes a projection of run state; the flat-snapshot reverse-engineering (`itemsByStep`, the positional fallback) dies. 4. **Step mirrors** — `WorkflowStep` canonical behind a TypeBox schema (replaces `STEP_FIELDS`); `ExpandedWorkflowStep` deleted; `inputHash` hashes whole steps (payload v2); TypeBox schemas own `TaskSnapshot`, `JobSnapshot`, and the journal record — validator drift becomes a compile error. 5. **Observation** — `onJobEvent({jobId, kind})` replaces whole-snapshot callbacks; persistence checkpoints at start + terminal; a lazy snapshot cache; the runner's update carries the message delta; `wait` on a run returns the consolidated answer (byte-parity with the push notice). 6. **Presentation** — `present.ts` owns one rulebook; `render`/`job-format`/`dashboard` become thin adapters; `isFailedResult` leaves the TUI renderer; one start formatter. ## Shared decisions - Task records are shared by reference: the manager owns the flat collection (the job record), the supervisor owns the DAG index; `settleTask` settles the shared record once. - Cancel semantics are unchanged, only concentrated (immediate abort; drain the FIFO; settle queued + coordinator rows cancelled; finalize cancelled). - Restore stops fabricating `AgentConfig` records (rides the seam ticket). - A 256-child scale test guards the O(N²) → O(N) claim (property, not example). - The DAG algorithm is untouched; the TLA+ spec (`spec/SubagentJobs.tla`) and its modelcheck gate are unchanged. ## Waves Frontier ≤ 2 in flight: W1 file split → W2 the seam → W3 the run module ∥ step mirrors → W4 observation ∥ presentation → then the two-axis review on the integration branch, fix findings in one worker, close tickets, report, retro. The running state log lives in `docs/wiki/goal-architecture-deepening.md`. ## Task list - [x] #21 — T1: split `workflow.ts`/`workflows.ts` by concern; start-plan rename (Wave 1) - [x] #22 — T2: the seam — `job-state.ts`, run-state ownership, one cancel policy, run-spec limits (Wave 2, blocked by #21) - [x] #23 — T3: the run module — journal as a projection of run state (Wave 3, ∥ #24, blocked by #22) - [x] #24 — T4: step mirrors — canonical step schema, whole-plan `inputHash`, TypeBox persisted shapes (Wave 3, ∥ #23, blocked by #22) - [x] #25 — T5: observation — job events, checkpoint persistence, bounded pull for runs (Wave 4, ∥ #26, blocked by #23) - [x] #26 — T6: one presentation rulebook — `present.ts`, thin adapters (Wave 4, ∥ #25, blocked by #22)
Author
Owner

Pipeline complete on architecture-deepening (tip 5cc0660): all six deepenings landed in four waves, two-axis review run, fix pass merged, all gates green at the tip (DRI own-run tails: typecheck clean, tests 239/239, TLC 142,834 states / no errors, smoke, wikicheck). Task list 6/6 ticked; evidence in each ticket's close comment; running log in docs/wiki/goal-architecture-deepening.md. This spec stays open pending the maintainer merge of architecture-deepening → main (ultra-layer precedent). Nothing pushed.

Pipeline complete on `architecture-deepening` (tip `5cc0660`): all six deepenings landed in four waves, two-axis review run, fix pass merged, all gates green at the tip (DRI own-run tails: typecheck clean, tests 239/239, TLC 142,834 states / no errors, smoke, wikicheck). Task list 6/6 ticked; evidence in each ticket's close comment; running log in docs/wiki/goal-architecture-deepening.md. This spec stays open pending the maintainer merge of `architecture-deepening` → `main` (ultra-layer precedent). Nothing pushed.
Author
Owner

Merged architecture-deepening → main as e25f733 (--no-ff; branch tip af420e8; 46 files, +3048/−1433). All five gates re-run green on main by the DRI — own-run tails: typecheck clean, tests 239/239 (11.9s), TLC 142,834 states / no errors (30s), smoke, wikicheck OK. All six deepenings landed in four waves (file split, the seam, journal projection + step mirrors, observation + presentation) with the two-axis review and fix pass complete; every ticket closed with evidence; tests grew 215 → 239 with TLC constant at 142,834 states throughout (the DAG algorithm and spec/ untouched). Full running log: docs/wiki/goal-architecture-deepening.md; retro: docs/wiki/retro-2026-12-01-architecture-deepening.md. Pushed to origin/main. Zero open issues.

Merged `architecture-deepening` → `main` as `e25f733` (--no-ff; branch tip `af420e8`; 46 files, +3048/−1433). All five gates re-run green on main by the DRI — own-run tails: typecheck clean, tests 239/239 (11.9s), TLC 142,834 states / no errors (30s), smoke, wikicheck OK. All six deepenings landed in four waves (file split, the seam, journal projection + step mirrors, observation + presentation) with the two-axis review and fix pass complete; every ticket closed with evidence; tests grew 215 → 239 with TLC constant at 142,834 states throughout (the DAG algorithm and `spec/` untouched). Full running log: docs/wiki/goal-architecture-deepening.md; retro: docs/wiki/retro-2026-12-01-architecture-deepening.md. Pushed to origin/main. Zero open issues.
alex closed this issue 2026-12-01 12:09:19 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alex/pi-subagent#20