Repository navigation
Conversation
2 of 3 tasks
This was referenced May 12, 2026
Closed
Owner
Author
…egistry fix 7 tests verify that the 5-commit bisect-clean sequence is correctly ordered and each commit independently passes integration tests: - T7: commit subjects match source plan order exactly (ordering gate) - T1-T4: integration tests pass at each commit in isolation (git worktrees) - T5: commit 5 diff only touches buildKindInstructions and coverage regex - T6: no net diff lost in the split (pure history rewrite) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
anbangr
force-pushed
the
feat/gstack-gstack-this-issue-fluffy-twilight-20260511-195458-663567a2-5-bisect-clean-commit-split-of-6fc0410d
branch
from
May 12, 2026 03:30
a5c7795 to
b3fd837
Compare
anbangr
deleted the
feat/gstack-gstack-this-issue-fluffy-twilight-20260511-195458-663567a2-5-bisect-clean-commit-split-of-6fc0410d
branch
May 12, 2026 03:31
anbangr
added a commit
that referenced
this pull request
May 20, 2026
* docs: design for build plan-review convergence loop Spec for /build's planSynthesizer ↔ planReviewer loop: in-process round loop, mid-loop user triage gate, plan-file-as-ledger cross-round memory, set-aware adaptive cap. Triggering case was bundle-1 (5→3→2→manual r4, ~$5-10) where rigor caught real bugs but the operator was locked out until round 3. New default brings user in at round 1, makes each round cheaper via in-process loop, and adapts the cap to actual convergence. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(spec): pin adaptive-cap exit_reason mapping in convergence design Self-review caught a small ambiguity: the decision table listed two bail-out triggers (re-raises-only and regression) but the exit_reason enum had three adaptive-cap values without an explicit mapping. Fixed: enum now has exactly adaptive_cap_re_raises_only and adaptive_cap_regression, and the decision table rows reference which exit_reason each triggers. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(plan): implementation plan for build plan-review convergence 19-task TDD-structured plan for the convergence loop spec. Each task is self-contained: failing test → minimal impl → passing test → commit. Covers types (T1), annotation contract (T2), history JSONL (T3), convergence aggregate (T4), adaptive cap (T5), TTY triage (T6), non-TTY triage (T7), prompts (T8), main loop (T9), CLI wire-in (T10), disputed counting (T11), three integration tests (T12-T14), E2E (T15), SKILL.md shrink + version bump (T16), README (T17), CHANGELOG (T18), final verification (T19). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/types): add convergence types for plan-review loop Extends PlanReviewVerdict with optional triage_decisions, round_history_path, convergence, interrupted_at_objection fields. Adds TriageDecision and ConvergenceSnapshot interfaces and ROUND_HISTORY_FORMAT_VERSION constant. All new fields are optional so existing call sites compile unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(build/types): camelCase convergence field names; drop NEW: prefix Code-quality review flagged inconsistency: existing PlanReviewVerdict fields use camelCase (reviewedBy, round) but the new convergence fields landed as snake_case (triage_decisions, round_history_path, etc). Converts all new TypeScript interface fields to camelCase to match the file's established convention. JSONL wire formats in later tasks can still use snake_case via JSON.stringify of manually-shaped objects -- TypeScript types do not need to mirror JSONL key shape. Also drops the informal "NEW:" prefix from JSDoc comments and adds a one-line doc for TriageDecision.decision. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-reviewer): add round-annotation read/write contract Adds parseRoundAnnotations, writeRoundAnnotation, parseRoundHistoryHeader, updateRoundHistoryHeader exported from plan-reviewer.ts. These implement the cross-round memory contract: each round's triage decisions and synth resolutions are written into the plan file as HTML comment blocks above the matching '### Phase N' heading, plus a top-of-plan history block. The next round's reviewer reads these to know what's already been decided. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): ROUND N REVIEWER attaches to round N's entry The original Task 2 commit had the parser attach ROUND N REVIEWER lines to round N-1's entry. That choice was forced by a self-contradicting test fixture (a ROUND 2 REVIEWER: line inside an annotation the test required to have rounds.length === 1). Both the design spec and Task 9's planned writer in runPlanReviewLoop treat ROUND N REVIEWER as a round-N observation paired with round N's USER decision (if any). The N-1 offset would have corrupted every annotation round-trip in Tasks 9, 11, and the integration tests. Fixes the parser to attach directly to round N. Updates the broken test fixture to assert the realistic multi-round shape: round 1 carries USER/RESOLUTION, round 2 carries only REVIEWER (because no round-2 USER decision happened on this annotation -- the reviewer did not re-raise). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): silent corruption + missing JSDoc on annotation writers Three issues from code-quality review: 1. writeRoundAnnotation's two String.replace() call sites used string replacements, which interpret \$&, \$', \$\` and \$N as substitution patterns. A plan annotation whose field text contains those tokens (plausible when reviewing regex / shell / template code) would have produced silently corrupted output. Both call sites now use function replacements which suppress the interpolation. 2. Misleading comment in parseRoundAnnotations claimed the header always names "round 1". An annotation first written in round 2+ opens with ROUND 2 CRITICAL [...], which the parser already handles correctly -- the comment was the only wrong thing. 3. RoundHistoryEntry, parseRoundHistoryHeader, and updateRoundHistoryHeader gained JSDoc explaining purpose, the optional finalLine parameter (used on loop exit for the 'final: APPROVED after N rounds, ...' line), and the atomic-write invariant. New regression test covers the \$& interpolation foot-gun by round-tripping fields containing every replacement-pattern token. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): add round-history JSONL writer New module plan-review-loop.ts will house the in-process round loop, triage gate, and adaptive-cap. First commit establishes the per-build-state history JSONL: append-only, corruption-tolerant reads, round-counter derivation. appendHistoryEntry / readHistoryEntries / deriveRoundNumber pair with the existing plan-reviewer.ts::readPlanReviewRound for cross-launch resume. HistoryEntry uses camelCase field names (objectionCountRaw, noForwardProgress, reRaises, newObjections) matching the Task 1 convention; the JSONL on disk serializes the same camelCase, so jq queries can use the field names verbatim. Also registers plan-review-loop.ts in coverage-matrix.test.ts so the MODULE_TEST_OWNERS invariant stays green. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): cross-build convergence aggregate writer writeConvergenceAggregate appends one line per completed build to ~/.gstack/analytics/convergence.jsonl. Captures trajectory, exitReason, total accept/reject/defer counts, wall time, and annotation parse errors -- the tuning signal needed to validate MAX_ROUNDS=5 and the adaptive cap rule over weeks of builds. Best-effort write: aggregate analytics never block the build path. ConvergenceAggregate uses camelCase fields matching the Task 1 convention; jq queries use the field names verbatim. Adds the ExitReason union as a distinct exported type so Task 5's adaptive-cap decision and Task 9's loop exit can return values type-checked against it. Also extends MODULE_TEST_OWNERS coverage entry for plan-review-loop.ts to include the new test file. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): set-aware adaptive cap rule computeConvergenceSnapshot compares round-k accepted objections against prior-round annotations parsed from the plan file. Classifies each as re-raise (prior accepted-and-resolved, same (location, severity)) or new objection. Rejected-prior matches are deliberately neither -- they are reviewer-prompt-fidelity signals, not synth-failure signals. shouldBailAdaptive implements the decision table from the design spec: hard cap at MAX_ROUNDS triggers stalemate_gate, accepted-count regression triggers adaptive_cap_regression, re-raises-with-no-new triggers adaptive_cap_re_raises_only. Precedence is explicit and tested across six scenarios covering round 1, mid-loop continue, both bail paths, the hard cap, and adaptive-disabled. camelCase fields throughout (priorRoundAccepted, reRaises, newObjections, noForwardProgress) matching Task 1 convention. Exports ConvergenceSnapshotInput, RoundConvergenceSnapshot, AdaptiveCapInput, AdaptiveCapDecision so Task 9's runPlanReviewLoop can compose with them. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): TTY triage gate for per-objection decisions runTriageGateTTY prompts user per CRITICAL objection with the 8-key menu (a/r/d/v/A/R/s/q + Enter), captures optional rationale, surfaces re-raises with prior rejection context, and supports fast-path A/R or early quit. Stream-based input/output so tests can drive it without a real TTY, following the existing build/orchestrator/__tests__/feature-review-prompt.test.ts pattern: Readable.push(Buffer.from(...)) to avoid object-mode readline pitfalls. Uses a line-queue/waiter pattern to decouple readline event emission from the sequential ask() calls — avoids the ERR_USE_AFTER_CLOSE trap that occurs when readline output ownership conflicts with the injected output stream. 8 tests cover: per-objection accept with rationale capture, mixed reject/defer/accept, [A]ccept-ALL and [R]eject-ALL fast paths, [s]top remainder, [q]uit early, and re-raise framing with prior-rejection context. Returns TriageGateResult with quitEarly / fastPathed flags so Task 9's loop can route exit codes correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): non-TTY triage modes for CI / scripts / agents runTriageGateNonTTY: synchronous, no readline. Three modes, picked via the --plan-review-noninteractive CLI flag added in Task 10: - auto-accept (default, extends the existing IMPORTANT-objection non-TTY behavior to CRITICAL): accept every objection, re-synth, continue - fail-fast: exit code 3 on the first round with CRITICAL — strict CI gate - auto-reject: reject every objection, annotate as rejected, proceed — escape hatch for known-noisy reviewer runs Returns NonTTYTriageResult with decisions[] (one per input objection) and shouldFailFast flag. camelCase fields throughout matching Task 1 convention. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-reviewer): annotation-aware reviewer + synth prompts Extends PLAN_REVIEW_PROMPT with a paragraph teaching the reviewer to read prior-round annotations (USER:accept/reject, RESOLUTION:pending/disputed, REVIEWER:re-raised) and not re-raise settled concerns. Promotes the const to an export so the new snapshot test can verify it without dynamic import gymnastics. Adds new exported SYNTH_REVISION_PROMPT (formerly inline in build/SKILL.md.tmpl Step 5.5 -- moved to plan-reviewer.ts so Task 10's cli.ts can use it from a typed import) instructing the synthesizer to honor user triage decisions, write RESOLUTION lines, and mark disputes when the user accepted something the synth thinks is wrong. Snapshot-tested so unintended drift surfaces in CI; non-snapshot assertions pin the core annotation contract phrases. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): in-process round loop runPlanReviewLoop Composes the reviewer call, triage gate (TTY or non-TTY), annotation writes, convergence snapshot, adaptive-cap decision, history JSONL append, top-of-plan history header update, and synth dispatch -- all in-process so re-launch overhead between rounds is eliminated. runStalemateGate handles the user-facing AskUser at adaptive-cap-bail or MAX_ROUNDS exit. Uses the same line-queue/waiter readline pattern as runTriageGateTTY (Task 6) to work around Bun's readline ERR_USE_AFTER_CLOSE on multi-question sequences. Single-readline-per-loop: when isTTY, runPlanReviewLoop stands up one shared readline + ask function and threads it into runTriageGateTTY and runStalemateGate via an optional askFn injection point. Per-call readlines drain the entire buffered input stream on the first close, starving later rounds. Existing standalone-call tests for the gates keep working because askFn defaults to undefined and each gate opens its own readline in that case. Tests cover: APPROVE round 1 (no synth, fastest path), bundle-1 trajectory 5->3->2->0 with three synth invocations, adaptive bail on re-raises stall at round 2. disputed_resolutions per-round count is a placeholder zero in this commit; Task 11 wires it to the real RESOLUTION: disputed annotation detection after each synth call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/cli): wire runPlanReviewLoop into startup path Replaces the single-shot runPlanReview + reconcilePlanReview call with the new in-process loop. Adds three CLI flags: --plan-review-max-rounds=N (default 5; range 1..20) --plan-review-no-adaptive-cap (off; disables forward-progress bail) --plan-review-noninteractive=<auto-accept|fail-fast|auto-reject> (default auto-accept) Exit codes preserved on the existing side (0 approve, 1 runtime, 2 test fail); new contract: 3 = stalemate (user picked [m] or non-TTY fail-fast hit CRITICAL) 4 = user abort (user picked [q] at gate) 130 = SIGINT during triage (unchanged) Legacy plan-review-report.json is still written from loopResult.finalVerdict so SKILL.md.tmpl Step 5.5 stalemate handler keeps working without changes until Task 16 shrinks it. synthFn adapter dispatches a configured Claude role with the SYNTH_REVISION_PROMPT from Task 8 against the now-annotated plan file. Since the dedicated planSynthesizer role does not yet exist in role-config.ts, the adapter falls back to planReviewer's role config and the timeout falls back to BUILD_DEFAULTS.timeoutsMs.planReview. Both are forward-compatible: once planSynthesizer lands, the `as any` accessors pick it up automatically. reconcilePlanReview and readPlanReviewRound are no longer imported in cli.ts now that the loop owns reconciliation and round tracking; they remain exported from plan-reviewer.ts for tests that exercise them. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): count disputed resolutions per round Replaces the Task 9 placeholder disputedResolutions.push(0) after the synth call with a real count: re-parse plan annotations, find this round's entries with RESOLUTION starting "disputed", tally them. The synth writes RESOLUTION: disputed -- <reason> when it disagrees with a user-accepted objection. Each disputed entry surfaces in the next round's triage so the user can re-decide. The aggregate count in convergence.jsonl is the tuning signal for "how often does synth disagree with user accepts" -- high counts suggest reviewer prompt fidelity issues or user triage rationale weakness. Annotation parse errors during this re-parse increment annotationParseErrors and log to console.warn; they do not crash the loop. The placeholder pushes on adaptive-bail-continue and on APPROVE paths stay 0 (no synth invocation means no resolutions to count). Also fixes annotationParseErrors declaration from const to let, which was previously a no-op placeholder but now receives increments inside the error catch path. New test covers the disputed-resolution path: round 1 has 2 accepted CRITICAL, synth marks one disputed and one applied, aggregate's disputedResolutions[0] is 1. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): bundle-1 trajectory converges 5→3→2→0 Integration test using stub reviewer (replaying fixture data from the real bundle-1 trajectory: 5 CRITICAL → 3 new → 2 new → APPROVE) and a stub synth that replaces RESOLUTION:pending with RESOLUTION:applied. Verifies the end-to-end story: - 4 rounds, 3 synth invocations, exit APPROVE - history JSONL has 4 lines (one per round) - convergence aggregate has correct trajectory and totals: trajectoryRaw [5, 3, 2, 0], totalAccepted 10, finalVerdict APPROVE - plan file accumulates ROUND 1/2/3 annotations + top-of-plan history block Fixture data lives in test/fixtures/build-convergence/ for sharing across Tasks 13, 14, 15 (the other integration + E2E tests). Coverage-matrix updated: plan-review-loop.ts now lists the integration test as an additional owner alongside the unit tests. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): adaptive cap bails on re-raises-only Integration test verifying the no-forward-progress bail path: Round 1 raises 2 CRITICAL, user accepts both, synth marks RESOLUTION non-pending (a real fix attempt). Round 2 raises the same 2 CRITICAL with zero new objections — adaptive cap detects this as a true stall (reRaises=2, newObjections=0). Bail-out gate fires. User picks [m]anual mode → exit code 3, outcome user_manual, exit_reason user_manual in convergence.jsonl. Synth is invoked exactly once (round 1) — the bail-out fires before the round-2 synth call, saving the wasted API spend the design was built to prevent. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): synth disputes a user-accepted objection Integration test for the synth-dispute escape hatch: Round 1 reviewer raises 1 CRITICAL ("use bcrypt"). User accepts. Synth disagrees -- instead of applying the fix, it writes RESOLUTION: disputed -- bcrypt conflicts with FIPS in this build. The dispute is captured in two telemetry surfaces: - disputedResolutions[0] === 1 in convergence.jsonl - The plan annotation preserves the synth's reasoning verbatim so the next round's reviewer (or user, if it re-surfaces) sees WHY synth declined to apply the fix. Round 2 reviewer reads the disputed annotation and approves (validating that a dispute does not force a re-raise -- the reviewer can decide). Loop exits clean with outcome "approved". Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(e2e): real Codex respects round-annotation contract Layer 4 E2E from the convergence design spec. Drives runPlanReviewLoop with the real Codex planReviewer against the bundle-1 fixture plan created in Task 12. Stub synth rewrites RESOLUTION: pending so the round-2 reviewer call sees a non-pending resolution annotation. Asserts that once round 1's objections are accepted and annotated as RESOLUTION: applied, round 2's Codex call does not re-raise them (reRaises[1] === 0) -- proving the reviewer prompt addition (Task 8) actually changes real-Codex behavior, not just our parser tests. Classified gate tier per CLAUDE.md; ~$0.50/run. Gated by EVALS=1; free tests run without invoking Codex. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/skill): shrink Step 5.5 to handle exit codes only The in-process loop in plan-review-loop.ts now resolves most rounds inside the CLI. Step 5.5 shrinks to a four-branch dispatch on exit codes 0/3/4/130, plus the existing exit-1/2 paths. The cross-round annotation history lives in the plan file, so manual edits between launches just need to preserve those annotations so the next round's reviewer has context. Bumps skill version 1.24.0 -> 1.25.0 (MINOR -- new capability). NOT bumping top-level VERSION per fork rule in CLAUDE.md. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(build/orchestrator): document the plan-review convergence loop Adds a section to the orchestrator README covering the loop architecture, exit code contract, flags, telemetry file layout, triage gate key map, and module boundaries. Cross-references the design spec. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(changelog): build skill 1.25.0 — in-process plan-review loop User-facing entry for the convergence loop change. NOT bumping top-level VERSION per CLAUDE.md fork rule -- only the build skill frontmatter bumped (Task 16). Entry covers what changed for the user, projected metrics from the bundle-1 case study, itemized add/changed/contributor changes, with spec cross-reference. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(build/orchestrator): clarify exit code 3 ambiguity + fix dropped indent Pre-landing review surfaced two README findings: 1. Exit code 3 has two meanings since this PR: lock contention at startup AND plan-review stalemate. The general exit-code table now reflects both. Exit codes 4 (user abort) and 130 (SIGINT) added to the table for completeness. 2. The troubleshooting bullet for --mark-phase-committed lost its 2-space leading indent during the table reformatting pass. Restored so the bullet continuation renders correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/orchestrator): strengthen 8 test gaps from pre-landing review Pre-landing review found 8 test-quality findings. Addressed here: 1. types-convergence.test.ts: trivial echo-assertions replaced with behavioral tests that exercise types via real function calls. 2. plan-annotation-round-trip.test.ts: new test for the fallback-prepend path in writeRoundAnnotation when the referenced Phase heading is absent from the plan text. 3. loop-converge-bundle-1.test.ts: added structural placement assertion to confirm annotations land in the expected position (the fixture intentionally exercises the fallback-prepend path for rounds 2-3 which raise objections at non-existent phases). 4. plan-reviewer-triage-tty.test.ts: new test for the [v]iew prose key path, verifying the assessment text is shown before the re-prompt. 5. skill-e2e-build-convergence.test.ts: tier-gate pattern aligned with other E2E tests (EVALS=1 && EVALS_TIER==='gate', no 'all' fallback). Core contract assertion no longer wrapped in a conditional that would let the test pass vacuously if Codex approves round 1. 6. plan-reviewer-loop.test.ts: new test exercising the max-rounds stalemate path (reviewer always REVISE, non-TTY auto-accept, confirms rounds === maxRounds at exit). 7. adaptive-cap-set-aware.test.ts: new test for the 'fewer accepted with new objections' branch, confirming the loop continues when accepted count decreases but new dimensions appeared. 8. History-entry expectations updated for tests where the production fix (IMPORTANT/SUGGESTION counts now recorded) changes the asserted shape. Most tests use CRITICAL-only fixtures and are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): restore IMPORTANT/SUGGESTION handling + 9 cleanups Pre-landing review surfaced one CRITICAL contract violation and 9 informational items. All addressed in this commit: CRITICAL — IMPORTANT/SUGGESTION objections silently dropped (regression). The early-return at the APPROVE / zero-CRITICAL branch treated REVISE-with- non-CRITICAL-only as APPROVE without annotating IMPORTANT/SUGGESTION objections in the plan file or recording them in the history. The pre- loop reconcilePlanReview path handled them via inline annotate-and- proceed; that path is no longer reached because cli.ts dropped the reconcilePlanReview call when wiring runPlanReviewLoop. Restored by filtering important/suggestion, calling writeRoundAnnotation for each, and recording real counts in HistoryEntry. Maintainability cleanups: - LoopOutcome aliased to ExitReason (byte-identical union); the as-cast in writeAggregate removed. - Dead sigint literal removed from ExitReason; SIGINT handling lives in cli.ts signal handler, not the loop return type. - ROUND_HISTORY_FORMAT_VERSION removed from types.ts; was never imported. - Always-false interrupted field removed from ConvergenceAggregate; no code path mutated it. - Stale "Task 11 placeholder" comment on disputedResolutions replaced with accurate description of what the array contains. - makeReadlineAsk helper extracted; the ERR_USE_AFTER_CLOSE workaround for Bun readline is now in one place instead of three duplicated blocks (triage TTY standalone, loop shared, stalemate standalone). Performance cleanups: - Two redundant readFileSync calls per round eliminated: the plan-text read for re-raise detection is reused for annotation-write, and the in-memory updatedPlan is passed to updateRoundHistoryHeader instead of re-reading from disk after writing. - existsSync + statSync collapsed to statSync with try/catch. Performance finding #4 (pre-parse annotations once before writeRoundAnnotation loop) deferred — requires writeRoundAnnotation signature change in plan-reviewer.ts; sub-ms cost at typical scale (K=5-10 objections, 20-50KB plan). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): close 4 silent-data-loss annotation bugs Red Team review verified 4 round-trip corruption modes in the annotation parser/writer. Each fails silently with no warning. 1. '-->' in any user-supplied field closes the HTML comment early. Subsequent lines bleed into plan text; parser silently drops rounds[]. 2. '"' in rationale stops the [^"]* regex group at the first inner quote. Rationale field silently dropped. 3. ']' in location stops the [^\]\n]+ regex group at the first inner bracket. ENTIRE annotation silently lost. 4. Non-canonical whitespace in existing in-file annotations makes writeRoundAnnotation's merge path a silent no-op. Round 2's decision silently lost. Fix #1-3: HTML-entity encoding on serialize, decode on parse. Encode ampersand first (so user input containing literal escape sequences round-trips correctly); decode ampersand last. Encoded sequences: ']' -> ']', '"' -> '"', '-->' -> '-->', '&' -> '&'. Applied to userRationale, issue, suggestion, location, resolution. userDecision is a fixed enum (no encoding). Operator warning logged on first character requiring encoding per field so silent encoding never lands without an audit trail. Fix #4: writeRoundAnnotation merge path walks the regex over planText directly to locate the actual byte range of each existing block (handling non-canonical whitespace, CRLF, external-editor reformat). A fresh local regex avoids the shared ANNOTATION_BLOCK_RE's lastIndex being reset inside parseRoundAnnotations during the loop, which otherwise caused infinite loops on the same span. Twelve new tests pin the round-trip invariants: - '-->' / '"' / ']' / '%' / '&' all round-trip correctly - merge into non-canonical 8-space-indent block preserves round 2 - literal ']' does not decode to ']' on parse Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop, cli): close 8 Red Team findings CRITICAL #1 (regression from round-1 fix): TTY mode now prompts per IMPORTANT objection (y/skip/all) instead of unconditionally auto-accepting. Restores the pre-loop reconcilePlanReview contract that was lost when the loop went in-process. SUGGESTION objections remain auto-annotated (no prompt). Non-TTY mode still auto-accepts per existing CI contract. CRITICAL #6: runPlanReviewLoop now calls deriveRoundNumber on startup, reads prior history, and starts the round counter at the next available number on resume. Trajectory arrays are hydrated from history so shouldBailAdaptive has the right context. Resume after exit-3 or exit-130 no longer duplicates round numbers in history.jsonl or writes a second convergence aggregate record. INFO #7: objectionCountRaw set to critical.length only (matches JSDoc and other paths). Verdict written as verdict.verdict, not hardcoded "APPROVE", in the REVISE-with-zero-CRITICAL branch. INFO #8: Early-exit paths (user quit, non-TTY fail-fast) now push sentinel -1 to trajectoryAccepted, reRaisesArr, reRejectedArr, disputedResolutions to maintain length parity with trajectoryRaw. User-quit path also writes an INTERRUPTED history entry. INFO #9: synthFn rejection wrapped in try/catch. On failure, the loop writes an INTERRUPTED history entry, writes the aggregate with exitReason: reviewer_unavailable, closes shared resources, and exits with code 1. INFO #10: Plan-file writes use atomic tmp + rename pattern. SIGINT during a write can no longer leave a half-written plan that the parser would silently skip on resume. INFO #11: HOME fallback uses os.homedir() with os.tmpdir() as secondary. Containers without HOME no longer pollute the project worktree. INFO #12: [s]top key in runTriageGateTTY no longer prompts for the current-objection rationale before exiting. The current decision is pushed with empty rationale and the loop moves on. Tests added: resume-from-history, synth-failure-handled, TTY IMPORTANT prompt, array-length parity on quit. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): close adversarial review CRITICALs Claude adversarial review found two real bugs the 3-specialist + Red Team rounds missed. Both verified by reading the code. C1 (CRITICAL): TTY infinite-loop on stdin close. The decision-loop default case in runTriageGateTTY (and two siblings in the IMPORTANT prompt + runStalemateGate) was `opts.output.write("Invalid input '${ans}'...")` with no EOF handling. Once makeReadlineAsk's streamClosed sets the internal flag, ask() resolves with "" forever, and the while-loop spins at 100% CPU printing "Invalid input ''" until externally killed. Triggered by routine Ctrl+D, piped stdin closing, or terminal disconnect mid-triage. All three sites now treat empty input as a quit/abort/skip-all signal. C2 (CRITICAL): Convergence aggregate array-length skew on reviewer_unavailable exit. planFileSizeBytes was pushed unconditionally at the top of every round iteration, but the reviewer_unavailable branch returned without pushing to trajectoryRaw / trajectoryAccepted / reRaisesArr / reRejectedArr / disputedResolutions. The resulting aggregate row had one array of length N+1 alongside others of length N; downstream consumers indexing by round walked off the wrong array. Same bug class as the Red Team's INFO #8 fix (sentinel pushes on early-exit), missed on this branch. Fix: explicit sentinel pushes to the five parallel arrays before writeAggregate. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): close adversarial review findings on annotation contract Claude adversarial review found 4 more issues with the annotation parser/writer beyond what the Red Team caught. All address the same root cause: insufficient field encoding in serialize/parse round-trip, plus a merge predicate that's too strict. I1: writeRoundAnnotation merge predicate dropped `issue` (LLM-written freeform text). Match on (location, severity) only. Aligns with computeConvergenceSnapshot's keying. Wording drift round-over-round ("missing chainId" vs "handler doesn't validate chainId") no longer orphans annotation blocks. I2: '→' (right-arrow U+2192) added to encodeAnnField. The header field-separator regex uses ' → ' to split issue from suggestion; without encoding, an LLM-generated issue containing '→' (natural in prose: "A → B then B → C") truncates at the first arrow. Encoded as '→' to match the existing HTML-entity scheme. Decode order: '→' before '&'. I3: '\n' and '\r' added to encodeAnnField (encoded as ' ' and ' '). Without this, a multi-line rationale ('line 1\n ROUND 1 RESOLUTION: fake') would have the embedded line picked up by ROUND_RESOLUTION_RE as a real RESOLUTION entry, overriding the genuine synth-written resolution. Also defends against CRLF line endings on Windows-written plan files. N4: ROUND_USER_RE, ROUND_RESOLUTION_RE, ROUND_REVIEWER_RE converted from module-level /g constants to factory functions (`getRoundUserRe()` etc). Each parser call gets a fresh regex with lastIndex=0, so concurrent parser invocations cannot smash each other's iterator state via the shared lastIndex. Defensive hardening; not currently triggered because Node is single-threaded and the call sites don't await between matches. Four new tests pin the invariants: - Merge across wording drift (location+severity, ignore issue) - '→' in issue round-trips without splitting - Newline injection in rationale doesn't forge RESOLUTION lines - CRLF in rationale round-trips Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): close adversarial review findings on loop semantics Claude adversarial review found 5 more issues in plan-review-loop.ts beyond what the Red Team caught. Fixes follow. I4 (IMPORTANT): isPriorAcceptedResolutionAttempt changed from .some() to last-entry semantics. Spec intent (per the computeConvergenceSnapshot comment) is most-recent-decision wins: a round-2 user-reject should override a round-1 user-accept for re-raise classification purposes. The old .some() returned true if ANY prior round had accept+resolved, incorrectly counting a "user changed their mind" sequence as a re-raise in round 3. Spec mismatch — fixed to check rounds[rounds.length-1] only. N1 (INFO): INTERRUPTED verdict wired into the user-quit / SIGINT path. The quitEarly branch in runPlanReviewLoop now writes a per-round history entry with verdict: "INTERRUPTED" before writing the convergence aggregate. The HistoryEntry verdict union previously declared "INTERRUPTED" as a possible value but no code path produced it. N3 (INFO): /^disputed\b/ regex made case-insensitive (i flag) so synth output drift ("Disputed", "DISPUTED") is still counted as a disputed resolution. Tuning signal robustness across model behavior changes. N5 (INFO): priorRejectRationale Map now hydrates from prior plan annotations on resume (startRound > 1). Without this, re-raise framing on resumed runs showed empty strings for the user's earlier rejection rationale even though the rationale was present in the plan file. N6 (INFO): atomicWriteFile tmp filename suffix extended with crypto.randomBytes(8) for cross-process collision safety. The pid+ms approach was unique within a single Node process but container-in-container scenarios could share both. N7 (empty rationale to undefined on round-trip) is owned by plan-reviewer.ts (parallel scope) — not addressed here. Three new tests cover: - last-round-wins re-raise classification (positive + negative) - case-insensitive 'Disputed' counted as disputed resolution - priorRejectRationale hydration on resume shows prior rationale Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop, cli): close 3 Codex HIGH findings on loop semantics H2: synthFn now propagates the SubAgentResult's exit-code as `ok`, and runPlanReviewLoop checks the returned ok. A synth that hit a timeout, model-not-found error, or non-zero exit no longer silently masquerades as a successful round. Failure routes through the synth_failure exit reason added in c5e7b3e. H3: [c] Continue anyway at the adaptive bail gate now runs the synth before looping. Previously the `continue` statement jumped straight to the next round iteration, skipping synth dispatch entirely — the next paid reviewer round then reviewed the same unresolved plan with RESOLUTION: pending unchanged, virtually guaranteeing re-raises and burning the round. Extracted the synth-call into a helper so the normal-flow path and the continue path share one code path. H4: Resume past maxRounds (startRound > maxRounds, e.g., user re- launched after exiting manual mode at the cap) no longer falls through the empty for-loop to a `lastVerdict!` non-null assertion on a null value. Added a startRound > maxRounds guard that synthesizes an APPROVE verdict ("Resume past maxRounds; review skipped.") and returns with outcome: "approved", round: startRound - 1. Three new tests pin the invariants: - synthFn returning ok:false routes to synth_failure exit code 1 - [c] continue invokes synth before next reviewer round - resume with startRound > maxRounds doesn't crash Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/cli, plan-review-loop): close 3 Codex structured review P1/P2 findings Codex structured review (the formal --base main P0/P1/P2/P3 pass) found three issues that bypass the plan-review gate. All closed here. P1 #1: cli.ts:9935-9963 only handled exit codes 3 / 4 / 130 then fell through to `state.planReview = loopResult.finalVerdict; saveState; ...` and proceeded into implementation. exitCode 1 (synth_failure) silently bypassed the gate. Now exitCode 1 persists state.planReview with status: "synth_failure" and throws ExitError(1). The build stops; the resume gate (see next fix) picks it up. P1 #2: cli.ts:9814-9818 resume gate only re-ran the loop when state.planReview was missing or status === "critical_exit_pending". Status values "user_aborted" and "synth_failure" were treated as "already reviewed" — the next resume saw a REVISE verdict and proceeded to phases. Both pending statuses now route through the gate so resume picks up the loop as the docs promise. P2: plan-review-loop.ts:851 resume-past-maxRounds auto-approved with a synthetic APPROVE verdict purely based on history length. A user who typed `gstack-build resume` without actually editing the plan bypassed the review gate. Now runs ONE more verification reviewer call on the (potentially-edited) plan. APPROVE → proceed. REVISE with CRITICAL → exit STALEMATE (3); the user must edit further or pass --no-plan-review to explicitly override. The existing H4 test ("returns approved with synthetic verdict") was updated to assert the new behavior (one reviewer call, APPROVE result), and a companion H4-P2 test covers the REVISE-from-verification path that exits STALEMATE. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs: post-ship documentation update for plan-review convergence (v1.40.5.0) - CHANGELOG.md: remove stray merge-artifact line (> > > > > > > origin/main) and fix stray # in Design spec bullet point in For contributors section - build/orchestrator/README.md: add plan-reviewer.ts, plan-review-loop.ts, drain-faults.ts, halt-event-helpers.ts, halt-events.ts to Architecture module map (all added on this branch, were missing from the module list) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete fix for the exit-13 active-run registry bug. Builds that exit with code 13 (FINALIZATION_REQUIRED / --skip-ship) were being recorded as `failed` in the active-run registry instead of `paused`. This blocked new runs from starting.
The branch contains 5 bisect-clean commits verified by a TDD test suite — each commit independently passes `bun test build/orchestrator/tests/integration.test.ts`.
Commit sequence
fix(build): add FINALIZATION_REQUIRED constant, replace magic 13 in cli.ts(879528ba)Named constant replaces all magic
13literals. No behavior change.fix(build): active-run registry shows "paused" for exit-13 (FINALIZATION_REQUIRED)(85414052)Ternary:
exitCode === 0 || exitCode === FINALIZATION_REQUIRED ? "paused" : "failed". Exit-13 builds now showpausedinstead offailed.fix(build): auto-clean stale paused active-run records when process is dead(4ed525cb)plan-selection.ts: paused active-run records whose PID is no longer alive are auto-removed on plan selection, unblocking new runs.test(build): regression test — exit-13 active-run registry status is "paused"(9b64aad3)Integration regression test: spawns a real gstack-build
--skip-shiprun and asserts the active-run registry entry hasstatus === "paused"after exit-13.fix(build): add buildKindInstructions export and fix decimal coverage regex(6f3a0119)Unrelated cleanup: export
buildKindInstructions, fix\d+%→\d+\.?\d*%coverage regex.Test plan
bun test build/orchestrator/__tests__/bisect-clean.test.ts— 7/7 passbuildKindInstructionsand coverage regex — not the ternary fixgit diff <pre-split-tip>..HEADis empty (pure history rewrite, no net diff lost)bun test build/orchestrator/__tests__/integration.test.ts— all pass🤖 Generated with Claude Code