Skip to content

fix: the CEO review gate waits for Claude Code's transcript flush (GST-1701) - #4102

Merged
capy-ai[bot] merged 2 commits into
mainfrom
capy/gst-1701-ceo-gate-settle
Nov 7, 2026
Merged

capy-ai[bot] merged 2 commits into
mainfrom
capy/gst-1701-ceo-gate-settle

Conversation

@garrytan

@garrytan garrytan commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 4102,
  "head": "a8fbaaac1fcf1c27e94f56020a81c3cb0a517965",
  "version": "1.97.0.0",
  "base": "main",
  "gate": {
    "tests": {
      "pass": 1623,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "tests",
      "run": 42321726904,
      "attempt": 1,
      "tree": "4503e067827661326b59aeef48e56153a66b006b"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "4503e067827661326b59aeef48e56153a66b006b",
  "product_patch_id": "db0621e8ca53e561a4c959af599227914b4f5696",
  "gstack_version": "1.97.0.0",
  "review_depth": {
    "depth": "light",
    "class": "code",
    "runtime_lines": 78,
    "rules": "70895942bb8a8ee2",
    "base": "ca5dbfc7e0016e3a1511161dc8c094399a2e350b",
    "registry": "ca5dbfc7e0016e3a1511161dc8c094399a2e350b",
    "gate_scan": {
      "tagged": 0,
      "head": "a8fbaaac1fcf1c27e94f56020a81c3cb0a517965"
    },
    "reasons": [
      "runtime=78"
    ],
    "risk": [],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @4503e0678276 (8 checks, current for a8fbaaac1fcf)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/42321726904/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42321726904/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/42321726889/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=4503e0678276 tests=36132 skipped=111 runs=42321726904/1 profiles=ci-reuse/free-tests heads=a8fbaaac1fcf verified=2026-11-07T01:18:25.430Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [
      4100
    ],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CLAUDE.md, AGENTS.md, CONTRIBUTING.md against ca5dbfc..a8fbaaa"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 0,
    "fixed": 0,
    "scope": "frozen",
    "rounds": 1,
    "ledgers_read": 3,
    "dispatches": {
      "specialist": 1
    }
  }
}

What changed

The two early-Stop tests fail on the single-read hook (adbf169) and pass once the CEO gate waits for the flush (a8fbaaa)

The two early-Stop tests fail on the single-read hook (adbf169) and pass once the CEO gate waits for the flush (a8fbaaa).

Before/after as text: The two early-Stop tests fail on the single-read hook (adbf169) and pass once the CEO gate waits for the flush (a8fbaaa)
--- Before · before.txt · captured output
+++ After · after.txt · captured output
+$ bun test test/ceo-review-gate.test.ts   # head: a8fbaaa (settledTranscript)
+(pass) final turns only > a Stop that fires before the CLI flushes the turn waits for the final message: a review written outside the repo is released, not held [417.90ms]
+(pass) final turns only > a Stop that fires before the CLI flushes the load itself still judges the run once the final message lands [644.99ms]
+ 30 pass
+ 0 fail
+Ran 30 tests across 1 file. [10.61s]
-$ bun test test/ceo-review-gate.test.ts -t "fires before the CLI flushes"   # base: adbf169 (tests only, old hook)
-(fail) final turns only > a Stop that fires before the CLI flushes the turn waits for the final message: a review written outside the repo is released, not held [420.45ms]
-(fail) final turns only > a Stop that fires before the CLI flushes the load itself still judges the run once the final message lands [413.19ms]
- 0 pass
- 2 fail
-Ran 2 tests across 1 file. [873.00ms]
 

Why

GST-1701: the /plan-ceo-review stop gate read the transcript once at Stop, but Claude Code flushes the turn's last lines about 200 ms after Stop fires. A finished review written outside the repository was held because its Write had not landed yet, and a run whose load had not landed stopped unchecked. The gate now waits, like the /autoplan gate, until the transcript holds the stop's final message.

Blast radius

Both opt-in stop gates (ceo_review_gate and autoplan_gate, off by default) now read through settledTranscript in lib/skill-gates.ts; a stop whose payload has no last_assistant_message, or whose transcript already ends on it, is read once exactly as before (lib/skill-contract.ts:226-233 read: withFinalMessage returns the same transcript object, so the loop exits on the first read). The autoplan gate's own tests pass unchanged on the shared helper (43 of 43 with skill-gates.test.ts, probe 003), and every gate error still fails open with GATE_TRANSCRIPT.

Approvals

No approvals recorded for branch capy/gst-1701-ceo-gate-settle.

Summary

The CEO review gate judged a transcript Claude Code had not finished writing, so it could hold a finished review or wave through an unfinished one. It now re-reads until the stop's final message is on disk, for at most 2 s or half its deadline, through the same helper the /autoplan gate already used, which moved from the autoplan hook into lib/skill-gates.ts. Failing-first tests landed first (adbf169), then the fix (a8fbaaa).

Test Coverage

CODE PATHS
[+] lib/skill-gates.ts settledTranscript()
  ├── [★★★ TESTED] final msg already present → immediate return — ceo-review-gate.test.ts / autoplan-stop-gate.test.ts
  ├── [★★★ TESTED] late flush → re-read until final msg — autoplan-stop-gate.test.ts:179, ceo-review-gate.test.ts:223,:236
  ├── [★★  TESTED] deadline reached → judge stale transcript — final-msg-absent fixtures
  └── [★★★ TESTED] StateError/UnknownShape → GateError GATE_TRANSCRIPT — autoplan-stop-gate.test.ts:245, ceo-review-gate.test.ts:318
[+] hosts/claude/hooks/autoplan-stop-gate.ts handle()
  └── [★★★ TESTED] delegates to settledTranscript — autoplan-stop-gate.test.ts:179,:245
[+] hosts/claude/hooks/ceo-review-gate.ts handle()
  ├── [★★★ TESTED] Stop: settle then judge (release + block) — ceo-review-gate.test.ts:223,:236
  └── [GAP] SubagentStop: settle with includeSidechain on a late-flushed agent transcript
COVERAGE: 6/7 paths (86%) | QUALITY: ★★★:6 ★★:1 | GAPS: 1

Tests: 1748 → 1748 (+0 new in this /ship run; the PR's own commit adbf169 adds 2)
Coverage: 86% value-weighted (86% including 0 weakly covered paths)
Test value: 0 tests written, 1 rejected by the authoring gate, 0 existing tests extended, 0 paths weakly covered.

Proposed (not written): ceo SubagentStop late-flush settle. Rejected as duplicate_protects: the same loop is proven by the Stop flush tests, and the includeSidechain passthrough is covered by the existing SubagentStop sidechain tests on a pre-written transcript.

Regression proof — fails at HEAD's parent adbf169 (tests only, old hook: 2 of 2 fail) · passes after fix at a8fbaaa (30 of 30).

Tests ran: tests 1623 (files; carried from CI run 42321726904/1 at tree 4503e0678276)

Pre-Landing Review

1 issue (0 critical, 1 informational), 0 fixed. test/ceo-review-gate.test.ts:227 (testing specialist, also the checklist's Timing-Dependent Tests item): the two new early-Stop tests race a fixed Bun.sleep(300) against the hook's first read, so on a slow runner they could pass without exercising the settle loop; they cannot fail spuriously, because the 2 s settle window outlasts the 300 ms append. Skipped unattended with the specialist's own alternative: probe 002 below records both tests red against the pre-fix hook on this machine.

REVIEW_LOOP: passes=1 blocking_found=0 deferred=0 noted=0 fixed=0 scope=frozen ledgers_read=3 dispatches=1

Gate edits: none detected (2 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)

Outside review: openai/gpt-6.1-sol (host subagent), completed, no actionable findings. Native adversarial (claude-opus-5-5): 4 findings, none blocking, listed under Review notes.

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/skill-gates.ts:76 When last_assistant_message never matches the last text block, the settle loop spends min(2 s, half the 5 s deadline) before the CEO gate's sessionKind, gstack-slug and git scans, so a slow machine can fail open (GATE_SLUG/GATE_TIMEOUT). Opt-in gate; fails open; the autoplan gate already pays the same 2 s.
  • INFORMATIONAL lib/skill-contract.ts:230 A turn that repeats its final sentence before a Write can settle early on the first copy and hold a finished review written outside the repo; needs a repeated sentence plus the flush race; block cap 3 bounds it.
  • INFORMATIONAL lib/skill-gates.ts:86 A transcript whose only line is half-written throws UnknownShape outside the loop and fails open as GATE_TRANSCRIPT instead of retrying; such a transcript cannot hold a skill load, so no impact; same as before the change.
  • INFORMATIONAL lib/skill-gates.ts:79 Each 50 ms poll re-reads and re-parses the whole transcript (up to 32 MB) for at most 2 s; bounded latency, same as the autoplan gate before this change.

Exploratory QA

Functional surface, bounded smoke (300 s), 3 probes with repository-native bun test commands; verdict pass.

  • 001: bun test test/ceo-review-gate.test.ts at head: 30 pass, 0 fail.
  • 002 (checkpoint 002): the two new early-Stop tests against the pre-fix hook (worktree at adbf169): 2 fail, as required for them to prove the fix.
  • 003 (checkpoint 003): bun test test/autoplan-stop-gate.test.ts test/skill-gates.test.ts: 43 pass, 0 fail.

Not exercised: real Claude Code flush timing (fixture append at 300 ms) and a ceo SubagentStop late flush.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped. The selector's derived references put 265 dependent gate cases in scheduled/release coverage, not PR passes.

Review bot comments

No review bot comments (one trunk-io merge-status comment, no findings).

Scope Drift

Scope Check: CLEAN
Intent: the CEO review gate waits for the transcript flush, through #4100's settle helper (GST-1701).
Delivered: shared settledTranscript in lib/skill-gates.ts, both gates call it, two failing-first tests, docs paragraph and changelog fragment.

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). This is a bug fix with failing-first tests (R65), which skips plan review.

Issues

Refs #4100

Verification Results

No Step 8.1 obligations (no plan). Exploratory probes: 3 PASS, 0 FAIL, 0 BLOCKED, 0 NOT RUN.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. The docs already describe the shared transcript-settle helper, so nothing needed editing.

Scope: committed diff ca5dbfc..a8fbaaa (GST-1701): lib/skill-gates.ts adds settledTranscript, and the CEO review and /autoplan Stop hooks now use it. Nothing was staged, unstaged or untracked.

Documentation health

  • docs/skill-gates.md: current. The CEO gate settle paragraph (line 72) and the autoplan settle text (line 94) match the code's 2 s / half-deadline bound.
  • changelog.d/capy-gst-1701-ceo-gate-settle.md: current. It matches the behavior.
  • docs/skill-routing-and-contracts.md: current. It only links to the gate docs.

Coverage debt: settledTranscript is an internal helper with no public surface. The behavior it adds has reference and explanation coverage in docs/skill-gates.md, and no gaps are new. Diagram drift: none, since the touched docs have no diagrams.

Test plan

  • bun run test (free suite): carried from CI run 42321726904/1 at tree 4503e0678276, 1623 files, exit 0
  • bun test test/ceo-review-gate.test.ts: 30 pass, 0 fail
  • bun test test/autoplan-stop-gate.test.ts test/skill-gates.test.ts: 43 pass, 0 fail
  • pre-push guards: typecheck, skill-size, parity-suite, context-budget, module-size, goldens, conflict-markers passed

🤖 Generated with Claude Code

Open in Capy

garrytan and others added 2 commits November 7, 2026 00:59
…t before Claude Code flushes it (GST-1701)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…s shared settle helper (GST-1701)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

@capy-ai
capy-ai Bot merged commit 6c3d0ec into main Nov 7, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant