Repository navigation
investigate: opt-in gate that holds root cause before fix, through Bash too (GST-1461) - #4045
Conversation
…sh too (GST-1461) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
😎 This pull request was merged. |
- hook: the edit branch computes the repo-relative path once in posix form, so the marker and deny text read src/total.ts on Windows too - lib/review-depth.ts is back to main's pinned bytes; lib/investigate-gate.ts keeps its own copy of TEST_PATH - gstack-skill-gates report: destructure session_id (the pregate secrets scan read the old line as a secret-named assignment) - tests: pin core.autocrlf=false in the git fixtures, skip the symlink swap on Windows, give setup-hook-syntax-gate's fixture the shared TypeScript entry a shim runs, unit-test excludedReason, and check the smoke's pinned Claude Code version against docs/skill-gates.md Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
- checkTree saves the bytes a restore replaces in the session directory and the block names the copy, so a concurrent editor save is never lost - a new commit is undone to its newest ancestor that existed before the baseline or that a remote-tracking ref holds, not to the baseline HEAD: a fix committed on another branch moves that branch back to its own tip, and pull/merge of fetched upstream commits is not undone; the block lists the commit's other changes left staged - runGateHook takes the switch reading from its caller, so the investigate_gate config key has a literal reader (gstack-config-defaults) - the slow checkout case gets an explicit 30 s test timeout Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/red-team#1 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
- an amend or rebase of commits from before the baseline on the same branch is undone to the baseline HEAD, not to its parent; on a different branch the gate blocks but leaves the commit in place - existedBefore answers reachability with one rev-list call instead of one merge-base per ref, so a fix commit in a repo with hundreds of refs is still undone inside the 5 s hook deadline Review-Finding: p2/specialist-batched#1 reader=testing Review-Finding: p2/red-team#1 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
E2E Evals: ✅ PASS (flaky: 1 case(s) passed on their one rerun)101 executed, 0 reused rule/judge records | 0 manual accepted (unscored; no score-cache credit) | $32.20 rule/judge cost | reconcile exit: 0 Profile: pr / mode Rule and judge shards
Fail-closed reconciliationSliced lane: planner → duration-packed executors → fail-closed report. Behavior cases run a pre-registered 3-trial panel (PASS at 2/3 with no contract violation); a PASS 2/3 is shown with its failed trial, never as a clean pass. Reused results retain their original provenance and expiry. Flaky: failed once, passed on its one rerun (rule 16)Each failed and passed on its rerun in run 42093259982 at the attempts named above. Logged for the daily flaky-fix pass in this run's Dispatched narrow screen (gstack-ship-queue ready --screen) of merge commit |
…nger fails open (#4072) * skill gates: the hook timeout outlives the clamped gate deadline (GST-1615) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: #4045/#4047 narrow screens select the bin/gstack-config gate case once setup runs gstack-skill-gates (GST-1615) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
What changed
An opt-in gate for /investigate that holds "no fix before a root cause" mid-run, including fixes made through the shell. Off by default; the /investigate skill text is unchanged byte for byte.
investigate_gateswitch inSWITCH_DEFAULT(off),./setup --investigate-gate/--no-investigate-gate,GSTACK_INVESTIGATE_GATE,gstack-config set investigate_gate._skill_hook_gatenow registers several events per source; each event gets its own shim and KNOWN_HOOKS row;gstack-settings-hookaccepts PostToolUseFailure.gstack-skill-gates settings --investigateprints a--settingsJSON for headlessclaude -pruns.hosts/claude/hooks/investigate-gate.ts,lib/investigate-gate.ts): after /investigate loads, Edit/Write/MultiEdit/NotebookEdit on tracked source are denied, and Bash writes are caught by comparing the tree with one per-session baseline at every PreToolUse, PostToolUse, PostToolUseFailure and Stop, then put back and reported. A revert to HEAD, a checkout of an existing commit and a stash pop pass; a new commit that carries a fix is reset. Tests, docs, lockfiles, generated files and new untracked files are never blocked. It releases on aRoot cause: <value>line in the assistant's reply after some evidence (not a placeholder or hedge).lib/skill-gates.ts):GSTACK_GATE <hook> <event> session=<id> ...for fired, blocked, released, observed, skipped and error, counted in$GSTACK_STATE_ROOT/skill-gates/<session>/record.json, traced inhooks/investigate-gate.log, and recorded in the transcript (blocks in the reason the model sees; the rest ashook_system_message). Any hook error fails open witherror code=….gstack-skill-gates report --expect armedexits 2/3 for a session that never armed or errored.Before: on main the gate's tests fail because there is no gate. After: the real Claude Code CLI is blocked on Edit and on sed -i, then released by a Root cause line.
Before/after as text: Before: on main the gate's tests fail because there is no gate. After: the real Claude Code CLI is blocked on Edit and on sed -i, then released by a Root cause line
Why
GEVA-2's only clean frontier win so far is the /review contract hook (+22.6 pts blocking recall on Opus 5.5), and Garry picked building hook-enforced /investigate and CEO review next (E1, GST-1461). GST-938's Edit/Write-only gate held in only 13 of 28 Opus 5.5 sessions because Opus edits through Bash, so this gate checks the tree rather than the command name.
Blast radius
The gate is off by default, so nothing changes for anyone who doesn't turn it on. Setup registers the four investigate-gate hooks only with
--investigate-gate, and the shared pieces it touches (SWITCH_DEFAULT,_skill_hook_gate,gstack-settings-hook,gstack-config) keep their existing defaults, which test/setup-skill-hooks-gate.test.ts and test/gstack-config-defaults.test.ts check (script ran). With the gate on, it rewrites files in your worktree. Every restore saves the replaced bytes in the session directory first, and every hook error fails open (walked failure path, test/investigate-gate.test.ts).Approvals
Approved: yes (record r-9ce4a0558028). The full approval record stays private: this repository is public or its visibility is unknown.
Summary
"Garry picked building hook-enforced /investigate next." Opus 5.5 edits through the shell, so an Edit/Write-only gate held in 13 of 28 sessions. This gate compares the tree instead, puts fix writes back and says so. The /ship review added four fixes on top: restores keep a copy of what they replace, a fix commit is undone to its own branch's tip instead of the baseline HEAD, an amend of the baseline commit is undone to that commit, and the reachability check is one git call so repos with hundreds of refs stay inside the 5 s hook deadline.
Tests
test/investigate-gate.test.ts(30 cases with native hook payloads in a temp repo: every Bash write form above, write-then-fail, write-then-commit, background writes, dirty files, symlink swaps, restore failure, release rules, fail-open errors),test/skill-gates.test.ts,test/skill-gates-advisory-bytes.test.tsand the setup gate cases. On main (37d5532) 34 of them fail andskill-gates.test.tscan't load.$0headless smoke, real Claude Code CLI 2.1.318 against a local fake Messages API (bun scripts/skill-gates-smoke.ts): 12/12 checks pass, markers fired → blocked via=edit → blocked via=bash → released.Test Coverage
Coverage: deterministic (each of 15 changed runtime files has a changed test naming it; no audit reader).
Tests ran: focused 93 (test/investigate-gate, skill-gates, skill-gates-advisory-bytes, setup-skill-hooks-gate, setup-hook-syntax-gate, review-packets-removed, test-of-test-ratchet at e64c3a0).
Regression proof for the review fixes: the five new cases fail on the head before each fix (~/.capy/work/gst1461/ship/failing-first-p1.txt at 7c6cd32, failing-first-p2.txt at ff26c5c) and pass at e64c3a0.
Pre-Landing Review
Pre-Landing Review: 13 issues found across 2 rounds and 1 fix-check. 4 blocking fixed, 1 blocking left open as a known gap under a Captain ruling, the rest noted.
REVIEW_LOOP: passes=2 blocking_found=10 deferred=0 noted=19 fixed=4 scope=frozen ledgers_read=6 fix_checks=1 dispatches=10
Gate edits: none detected (GATE_SCAN tagged=0 at e64c3a0)
Outside review: completed (openai/gpt-6.1-sol, host subagent). Its verdict was "request changes"; its five findings are listed under Review notes with the lead's reading against the blocking floor.
Review-loop exception: accepted by GStack Minder (relayed by GSTA-317) 2026-11-05 via Captain ruling B, recorded as approval a-7e3ca9cbb6f2: ship e64c3a0 as is; fc/fix-check#1 (a fix committed on a branch behind the baseline is blocked but kept) is a known gap fixed in the stacked PR 2 (fix-check at e64c3a0, 2 findings)
Fixed:
git commit --amendof the baseline commit dropped that commit. On the same branch it is now undone to the baseline HEAD.rev-list --stdincall.Known gap (fc/fix-check#1, fixed in the stacked PR 2)
If the session starts on one branch and the model commits a fix on a branch that sits behind it (for example, the baseline is on
feature, thengit checkout main && sed -i … && git commit -am fix), the commit is blocked but kept: the block is reported, butmainkeeps the fix commit and the file is not put back. docs/skill-gates.md's sentence "a fix committed on another branch moves that branch back to its own tip" holds only for a branch that has diverged from the baseline. The stacked PR 2 fixes this by resetting a different branch to its own tip.Review notes
Informational, below the blocking floor (would fail a test, break production, or lose data or secrets). Not fixed in this PR:
git addstays staged (p2/red-team#2, outside-voice#2).existedBeforeaccepts a backdated commit (GIT_COMMITTER_DATE=…) as one that existed before the baseline (p1/red-team#2, p2/red-team#3, adversarial#1).stop_hook_active, so a background writer that keeps rewriting a tracked file can keep a turn from ending (p2/red-team#5).Also noted from the voices: a real 3-way
git pullmerge whose result matches neither parent is undone (adversarial#2).git checkout HEAD~1 -- fcounts as a fix write, though the docs say content from an earlier commit is not one (adversarial#3). The saved copies are pruned with the session directory after 7 days (adversarial#5). From the outside voice: the raw backups of dirty-at-baseline files are keyed by the filtered blob id, so two dirty files that differ only in line endings can share one backup (outside-voice#1). Clean files come back as 0644 or 0755, not their old mode (outside-voice#3). An untracked.gitattributesmarking*.ts linguist-generatedexempts source edits (outside-voice#4).gstack-skill-gates settingsdoesn't shell-quote the hook path, so headless hooks don't launch from a gstack root that contains a space (outside-voice#5). Per-ref performance was noted in round 1 (p1/specialist-batched#2) and fixed in round 2.The stacked #4047 fixes review note 1 and outside-voice #1 to #5, each with a test that fails first. The hooks are opt-in, so nobody runs this gate before #4047 lands.
Exploratory QA
Smoke probe: the $0 headless smoke (
bun scripts/skill-gates-smoke.ts --claude <claude 2.1.318>) at e64c3a0 ran with SMOKE_RESULT: pass checks=12 failed=0, the same as at ff26c5c. No other exploratory charters ran.Eval Results
No prompt-related files changed, so evals were skipped (the /investigate and /plan-ceo-review skill text is byte-identical, checked by test/skill-gates-advisory-bytes.test.ts).
Plan Completion
Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). The plan is the autoplan run approved in the Approvals record.
Issues
Refs p2/specialist-batched#1, p2/red-team#1, p1/specialist-batched#1, p1/red-team#1 (review findings, not GitHub issues).
TODOS
No TODO items completed in this PR.
Security read
The hook runs git and writes under the gstack state root (0600/0700). It makes no network calls and reads no secrets. Its one write outside the state root is putting a gated file back inside the repository it pinned, through a rename that never follows a symlink. The smoke script fetches the pinned Claude Code CLI with npm at run time (not vendored) and points it at a localhost server with a dummy key.
Documentation
Status: one known overstatement. docs/skill-gates.md says a gated commit on another branch is always undone, but a commit on a branch behind the baseline is kept (fc/fix-check#1). The stacked #4047 fixes the code and corrects that paragraph.
Scope: 23 committed files from 37d5532 to e64c3a0 (nothing staged, unstaged or untracked). The authored docs are docs/skill-gates.md (new), docs/skill-routing-and-contracts.md (a cross-link) and changelog.d/capy-gst-1461-investigate-gate.md. I checked their claims against lib/skill-gates.ts, lib/investigate-gate.ts, lib/skill-route.ts, bin/gstack-skill-gates, bin/gstack-config, setup and scripts/skill-gates-smoke.ts.
Documentation health:
Coverage debt:
investigate_gate,gstack-skill-gates settings|reportand theGSTACK_GATEmarkers have reference and how-to coverage in docs/skill-gates.md, but no tutorial. The page is reachable only through docs/skill-routing-and-contracts.md, which nothing in README links (a common gap).Diagram drift: none; the changed docs have no diagrams.
Test plan