Repository navigation
v1.68.1.0 fix: phantom AskUserQuestion hooks — canonical-only registration + self-healing settings.json - #2631
Merged
Merged
Conversation
… mutation lock, fail-closed parse
Claude Code strips the unknown _gstack_source key when it rewrites
settings.json, so tag-based dedupe degraded to exact-command equality and
every Conductor worktree's setup appended a fresh hook entry; deleted
worktrees left dead hooks erroring on every AskUserQuestion fire.
- KNOWN_HOOKS identity table (shared JS prelude, single source of truth):
ownership is intrinsic and PER HOOK ITEM — basename + relpath suffix +
event (+ matcher where defined). Tags never claim foreign items.
- New `prune-stale [--repoint <root>] [--all]`: prune dead gstack items,
re-point survivors at the stable install (tag restore from the table),
exact-duplicate collapse, uninstall/no-team identity sweep. Explicit
plan_tune_hooks:no is honored (dead pruned, live never re-pointed).
- add-event / remove-source become item-aware: replace/remove only the owned
item; a user's co-located hook in the same entry is never collateral.
- Mutation safety: mkdir lock with owner token, ownership-checked release,
atomic stale takeover; per-process-unique tmp + backup names;
backup-on-change everywhere; fail-closed on parse failure (a corrupt
settings.json is never overwritten — previously catch{} clobbered it);
locked atomic rollback.
Co-Authored-By: Claude Fable 5 <[email protected]>
…ATE_DIR resolution `get` returns the DEFAULTS value for absent keys, so callers that need to know whether the USER decided something (vs inherited a default) had no correct primitive — setup's consent logic was about to grep a hardcoded ~/.gstack/config.yaml, which misclassifies under GSTACK_STATE_ROOT / GSTACK_HOME / GSTACK_STATE_DIR overrides. `has` exits 0 iff the key is literally present in the resolved config file, with the same C-locale key validation as get/set. Co-Authored-By: Claude Fable 5 <[email protected]>
… consent provenance
Three root causes of the phantom-AskUserQuestion-hooks class, all in the
registration path:
- Bug A: the Conductor auto-opt-in upgraded PT_DECISION "prompt" -> "yes"
even when "prompt" was dev-setup's EXPLICIT --plan-tune-hooks=prompt pin,
so every new Conductor workspace installed hooks. PT_EXPLICIT (flag/env/
config-key-presence via `gstack-config has`) now gates the auto-opt-in to
the true silent fall-through.
- Bug B: hook commands were baked from $SOURCE_GSTACK_DIR (`pwd -P` of the
running tree — ephemeral for worktrees). Registration is now CANONICAL-ONLY
via _hook_command_path (${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills/gstack);
missing canonical hook = skip + log, never a baked tree path. SessionStart
moves to schema-aware add-event under its identity source; whitespace paths
are quoted.
- Bug C: nothing ever pruned, and dead tagged entries blocked the
"already installed" guards forever. Setup now heals FIRST on every run
(prune-stale --repoint at the stable install), surfaces a one-line summary
only when something changed, surfaces the plan_tune_hooks:no-vs-live-hooks
contradiction, and --no-team tears down all three sources plus an identity
sweep for untagged strays.
dev-setup's no-mutation guarantee gains its stated repair exception (prune
dead / re-point existing, never ADD).
Co-Authored-By: Claude Fable 5 <[email protected]>
…identity sweep SETTINGS_HOOK resolves via $(dirname "$0") INSIDE the install root, but the cleanup ran after `rm -rf ~/.claude/skills/gstack` — a real global uninstall (running the installed copy) silently no-op'd and orphaned every hook entry. Tests masked it by running the uninstaller from the repo checkout. The relocated block also removes the auq-error-fallback source (registered by setup, previously never torn down) and finishes with a prune-stale --all identity sweep so untagged strays (Claude Code strips _gstack_source) go too. Co-Authored-By: Claude Fable 5 <[email protected]>
…ty, lock, canonical tripwires
- gstack-settings-hook-schema-aware: 16 new cases — identity re-point (tag
restore), foreign-basename rejection, mixed-entry per-item safety for
add-event/remove-source/--all, prune-stale modes incl. bash-prefix +
Windows-backslash + spaced-path idempotence, duplicate collapse preferring
the tagged twin, plan_tune_hooks:no split, backup-on-change no-churn,
fail-closed corrupt-JSON for every mutator, stale-lock takeover,
fresh-foreign-lock skip, two-writer concurrency smoke, and an INCIDENT
FACSIMILE replaying the exact 2026-08-17 production damage (6/3/2 entries,
mixed tags, live-ephemeral Stop) healing to 2/1/1 canonical.
- NEW setup-hook-canonical-paths: static tripwires — canonical-only resolver
(no $SOURCE_GSTACK_DIR anywhere in it), heal-before-guards ordering,
unsuppressed heal output, ${VAR:-0} counter idiom, shared-prelude
concatenation at every bun call site, KNOWN_HOOKS completeness vs setup's
registrations, uninstall cleanup-before-deletion ordering, defect-class
warning present.
- setup-plan-tune-hooks-noninteractive: PT_EXPLICIT pins + `gstack-config
has` provenance + has-subcommand behavior (env-resolution, malformed keys).
- auq-error-fallback-hook: registration + both-teardown wiring (previously
untested).
- uninstall: behavioral ordering test running the INSTALLED copy from inside
the root it deletes.
- setup-windows-fallback / gstack-config-key-locale: pins updated for the new
HOOK_CMD shape and the third C-locale validator.
Co-Authored-By: Claude Fable 5 <[email protected]>
…— vacuous pass + stray artifact
JSON escaping is not shell escaping. Interpolating JSON.stringify(script)
into `bash -c ${...}` left every JSON "\n" as a literal backslash-n inside
shell double quotes, collapsing the extracted release-body tripwire block
onto one line: `then\n` parsed as the command word `thenn`, and
`>&2\nelse\n` parsed as the redirect `>&2nelsen` — so every full-suite run
littered a `2nelsen` file (containing "bash: thenn: command not found") in
the repo root, and the test's single not-contains assertion passed
VACUOUSLY because all output had been redirected into that file. The
"and it actually fires" functional check never verified anything.
Fix: pass the script as an argv element (spawnSync array form) and assert
both branches for real — ABORT case must print the leak message to stderr,
clean case must print "banner tripwire clean" to stdout.
Verified: `bun test test/binding-template-drift.test.ts` previously created
the artifact deterministically; the full free suite now runs artifact-free.
The other shell-interpolation sites (evidence, schema-aware concurrency,
empty-find-fallthrough, branch-slug-hygiene) already use correct quoting.
Co-Authored-By: Claude Fable 5 <[email protected]>
…hip negatives Coverage-audit iron rule: the rewritten legacy `remove` action filters per-item (pre-v1.67.2 it dropped the whole entry, destroying a user's co-located SessionStart hook) — modified existing behavior, previously untested. Also pins two ownership negatives: an owned basename+relpath under the WRONG matcher stays foreign, and prune-stale on an absent settings file exits 0 with removed 0. Co-Authored-By: Claude Fable 5 <[email protected]>
Specialist review (testing, maintainability, security, performance,
data-migration) findings, each verified against code before fixing:
- legacy remove: preserve malformed/foreign entries (hooks absent, non-array,
or pre-existing empty) — only entries THIS pass emptied are dropped
- add-event: never tag a mixed entry (old gstack versions in sibling
worktrees treat tags as entry-level ownership and would destroy the user's
co-located items); tag only single-item entries; prune-stale drops tags
from mixed entries for the same reason
- prune-stale: within-entry twin collapse (two dead copies of one hook
re-pointed to the same canonical command no longer double-fire); command
quoting hardened via gsQuoteCmd (escapes \\ " $ backtick; gsStripWrap
unescapes so identity round-trips); NUL bytes in the dedupe key replaced
with a JSON.stringify key (bash silently dropped the NULs, degrading the
separator; the file also read as binary to tooling)
- gsIsAlive: only provable absence (ENOENT/ENOTDIR) counts as dead —
EACCES/EIO/unmounted volumes no longer prune (one-way-ratchet guard)
- gsWriteIfChanged: preserves the live settings.json mode across rewrites
(a user-tightened 0600 carrying API keys was silently broadened to 0644);
fresh files start 0600; backups rotate (keep 10)
- remove-source: command-less items default to foreign (gstack only writes
type:command items); single-item stray claim requires a command
- rollback: pointer target must be a sibling settings.json.bak.* file
- uninstall + setup --no-team + SessionStart registration: stderr stays
attached — a lock give-up or fail-closed parse during TEARDOWN must be
visible ("the next setup retries" does not apply after uninstall)
- setup: team-mode banner no longer claims an auto-update hook when
registration was skipped; heal log documents the rollback-pointer caveat;
SESSION_UPDATE_CMD quoting mirrors gsQuoteCmd; lock constants named
- list-sources: corrupt settings.json reports to stderr instead of silently
printing nothing (setup guards must not misread corrupt as no-hooks)
- tests: 10 new pins (malformed-entry preservation, mixed no-tag, twin
collapse, 0600 mode, metachar escaping round-trip, backup rotation,
rollback pointer refusal, held-lock uninstall warning, matcher-drift
tripwire, ownership negatives)
Co-Authored-By: Claude Fable 5 <[email protected]>
…ty, Windows paths Red-team pass over the hardened diff (several findings empirically verified by the reviewer before reporting): - KNOWN_HOOKS gains the sixth identity: gstack-verify-gate (README-documented opt-in Stop hook). A tag-stripped verify-gate entry previously survived prune-stale --all and errored at the end of EVERY turn after uninstall deleted the install root — the exact phantom-hook class this branch fixes. Uninstall also sweeps its tagged form. - add-event is now the single quoting authority: every registered command is normalized through the same gsQuoteCmd/gsStripWrap round-trip the healer uses. Pre-fix, only SessionStart got caller-side quoting — a spaced/metachar canonical root registered broken plan-tune/AUQ/timeline hooks that the very next heal rewrote (the codebase disagreed with its own registrations). - Windows: MSYS-form paths (/c/Users/...) are drive-translated for fs checks only (gsWinPath) — native bun resolved them drive-relative, so the heal judged every LIVE Windows hook dead and pruned it. The three AskUserQuestion hooks and the Stop hook now also get the mandatory 'bash ' prefix on Windows (previously only SessionStart did; extensionless bash shims otherwise hit the file-association dialog). - CANONICAL_GSTACK_ROOT falls back to $HOME/.claude/skills/gstack when a CLAUDE_CONFIG_DIR-derived root was never installed (the installer hardcodes the home path — split-brain left such users permanently hookless). - prune-stale preserves foreign entries that STARTED empty (they were silently deleted, uncounted, on every heal). - The timeline Stop registration and its list-sources guard join the zero-silent-mutations contract (stderr attached). Tests: verify-gate tag-stripped heal+sweep, started-empty preservation, add-event quoting-authority round-trip. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
README: document canonical-only hook registration + the prune-stale self-heal in the setup hooks section; expand the manual-uninstall note to cover every gstack hook identity, not just timeline-stop-hook. CONTRIBUTING: record PT_EXPLICIT provenance (Conductor auto-opt-in fires only on the true silent fall-through) and the heal-first repair exception in the dev-setup paragraph. Co-Authored-By: Claude Fable 5 <[email protected]>
…5, prototype-safe ownership bun in -e mode swallows uncaught exceptions thrown after a require() and exits 0 (verified on 1.3.13; uncaughtException handlers never fire either), so any runtime throw in a mutator was a SILENT SUCCESS. Every script body now runs inside a gsMain try/catch that prints "internal error ... refusing to mutate" and exits 4. Also: lock give-up now exits 5 instead of 0 (callers must not report a skipped mutation as registered); basename lookup uses hasOwnProperty so a foreign hook named "toString"/"constructor" can't resolve to an inherited Object.prototype member and abort the sweep; ownership-checked release also clears an empty/missing owner file; backup rotation sorts by mtime, not name; Windows-only backslash normalization (a legal Unix path containing a backslash is no longer rewritten); GSTACK_SWEEP_EXCLUDE_SOURCES lets a sweep spare named sources; lock tradeoffs documented at the lock helper. Co-Authored-By: Claude Fable 5 <[email protected]>
…clusion _install_plan_tune_hooks now propagates per-add-event failures (lock contention exits 5, fail-closed settings errors exit 3) and both caller sites branch on it: success logs the installed message, failure logs a visible "NOT registered — re-run ./setup" warning instead of claiming success for a mutation that never happened. --no-team's identity sweep runs with GSTACK_SWEEP_EXCLUDE_SOURCES= verify-gate: turning team mode off must not delete the user-registered verify-gate opt-in whose binary still exists (uninstall still sweeps it, correctly, because there the binary itself is being removed). Co-Authored-By: Claude Fable 5 <[email protected]>
…basename, sweep exclusion, lock exit 5
New pins for the fail-loud hardening: a wrong-shape hooks value (object
where an array belongs) exits 4 with "refusing to mutate" and leaves the
file byte-identical (pre-gsMain this was a silent exit-0 no-op); a foreign
hook whose basename collides with Object.prototype ("toString") survives
an --all sweep that still removes gstack rows; GSTACK_SWEEP_EXCLUDE_SOURCES
preserves the verify-gate row during --all; the fresh-foreign-lock test now
asserts the loud exit 5 instead of a quiet skip.
Co-Authored-By: Claude Fable 5 <[email protected]>
…tion banned setup now legitimately mentions verify-gate once: the --no-team identity sweep excludes it via GSTACK_SWEEP_EXCLUDE_SOURCES so team-mode teardown can't delete a user-registered gate. The opt-in pin tightens from a blanket not-contains to: every mention must be a comment or that exclusion, and no mention may sit on an add-event line. Co-Authored-By: Claude Fable 5 <[email protected]>
|
😎 This pull request was merged. |
Contributor
E2E Evals: ✅ PASS0/0 tests passed | $0 total cost
ubicloud-standard-8 runners (Docker: pre-baked toolchain + deps) | wall clock ≈ slowest suite |
…ort on held locks On Linux, BSD-style `stat -f %m` prints a multi-line FILESYSTEM block to stdout before exiting 1, so the BSD-first || chain captured that garbage concatenated with the real `stat -c %Y` epoch. The non-numeric mtime made `$(( now - mtime ))` a syntax error and set -e killed the binary with exit 1 whenever a lock dir already existed — every contention path (stale takeover, give-up, concurrent writers) broke on CI while staying green on macOS, where BSD stat -f succeeds cleanly. GNU `stat -c %Y` now goes first (BSD stat rejects -c with no stdout, so macOS falls through cleanly), and a numeric guard blanks any residual garbage so a future platform quirk degrades to the normal give-up path instead of an arithmetic abort. Same defect class as gstack-repo-mode's GNU-first ordering (#2195). Verified in an oven/bun Linux container: the four CI-failing lock tests now pass (62/62 across both files). Co-Authored-By: Claude Fable 5 <[email protected]>
…on-hooks # Conflicts: # CHANGELOG.md # VERSION # package.json
…tests Both tests spawn the copied uninstaller, which itself runs several settings-hook bun -e children (the lock-contention one also waits out a 300ms give-up per call). On a loaded box those cold starts blow bun's default 5s per-test timeout, and a timeout kill reports as a bare fail with no assertion diff — observed at 5.6-8.5s under load avg 25+. Co-Authored-By: Claude Fable 5 <[email protected]>
…on-hooks # Conflicts: # CHANGELOG.md # TODOS.md # VERSION # bin/gstack-settings-hook # package.json # setup
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
Fixes the phantom AskUserQuestion hooks that spammed
No such file or directoryerrors on every question: gstack installs were baking ephemeral Conductor worktree paths (biarritz-v3,taipei-v2, ...) into~/.claude/settings.json, and nothing ever cleaned them up.Root cause was a three-bug pileup:
setupupgraded--plan-tune-hooks=prompttoyeswhenever Conductor env vars were set, so every new workspace registered hooks non-interactively.pwd -Pof the running worktree), so deleting the workspace left dead absolute paths behind._gstack_sourcekey on its own rewrites, so each worktree's differently-pathed hook appended a fresh entry. No pruning existed anywhere.What ships:
bin/gstack-settings-hookrewritten around a KNOWN_HOOKS identity table (6 hook identities: basename + relpath suffix + event + matcher). Ownership is decided per hook ITEM; entry tags never claim foreign items; a user's co-located hook is never collateral damage.prune-stale [--repoint <root>] [--all]self-healer. Every./setupheals first: dead gstack entries pruned, stale ones re-pointed at the stable~/.claude/skills/gstackinstall, duplicates collapsed — one visible log line only when something changed._hook_command_pathresolves against${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills/gstackonly; the ephemeral-tree fallback is gone. A missing canonical hook means "don't register," never "bake the running tree's path."PT_EXPLICITconsent provenance via newgstack-config has <key>: the Conductor auto-opt-in fires only on the true silent fall-through (no flag, no env, no config key present). dev-setup's no-mutation guarantee now actually holds.gsMainfail-loud umbrella (bun-eswallows post-require uncaught exceptions and exits 0 — verified on 1.3.13 — so every script body now converts a runtime throw into stderr + exit 4). Lock give-up exits 5 and setup reports the skipped registration honestly.gstack-uninstallordering fix: hook cleanup ran AFTER the install root was deleted — from inside that root — so a real uninstall silently no-op'd. Cleanup now runs first, plus a full identity sweep (auq-error-fallback, verify-gate, untagged strays).--no-teamteardown removes the AskUserQuestion trio and sweeps identities while excluding the user-registered verify-gate opt-in (GSTACK_SWEEP_EXCLUDE_SOURCES).Local box verified: 11 hook entries healed to 5 canonical ones, idempotent on re-run, zero dead-worktree paths remaining.
Test Coverage
Ship coverage dashboard: 87% of changed behaviors pinned by free-tier tests.
gstack-settings-hookbehavioral (identity healer, per-item safety, lock, fail-closed, rollback, rotation, escape round-trip)test/gstack-settings-hook-schema-aware.test.ts— 51 tests incl. an incident facsimile seeding the exact live-box corruption (6/3/2 entries → 2/1/1 canonical)toString-basename foreign hook survives--all; verify-gate sweep exclusion; fresh-foreign-lock exits 5test/setup-hook-canonical-paths.test.ts(new)test/setup-plan-tune-hooks-noninteractive.test.ts— PT_EXPLICIT + Conductor condition pinstest/uninstall.test.ts— behavioral test runs the INSTALLED copy from inside the deleted roottest/setup-windows-fallback.test.ts,test/gstack-config-key-locale.test.tsUncovered (documented, accepted): interactive-TTY setup paths and the live
~/.claudeheal itself (exercised manually on this box instead).Pre-Landing Review
/review)-eswallows uncaught exceptions → gsMain umbrellaNotable rejected/deferred findings, on the record: PID-aware lock takeover deferred (owner file already carries the pid if it becomes worth it); Claude Code itself doesn't honor the mutation lock — lost updates against a live session remain possible and convergent (next heal repairs); consent posture: heal may prune/re-point but never ADDS entries.
Eval Results
Diff-selected paid E2E: 8/8 passed ($0.93, 178s). All other eval categories selected zero tests for this diff (no skill-behavior changes). Free suite green via the strict sharded runner; late singleton flakes in untouched areas (browse watchdog, make-pdf render, design daemon) were each verified green standalone and traced to a saturated box (sibling worktree running its own eval suite, load avg 25+).
Scope Check
CLEAN — every change traces to the approved plan (
fluttering-grahamplan file, NO UNRESOLVED DECISIONS) or to a review finding logged against it.Plan Completion
47/50 plan items DONE. The 3 remaining are documented deferrals, not gaps: PID-aware lock takeover,
setup:1601CLAUDE_CONFIG_DIR alignment (new TODO), and Windows bash-prefix on plan-tune/Stop add-events (new TODO).TODOS
setup:1601CLAUDE_CONFIG_DIR alignment; bool-parsing/validate_keycentralization (P3).Documentation
~/.claude/skills/gstackinstall, never the running tree) and the heal-firstprune-stale --repointpass (visible one-liner + backup only when something changed). The manual-uninstall note now covers every gstack hook identity — SessionStart auto-update, the AskUserQuestion PreToolUse/PostToolUse trio, and the Stop hooks (timeline, verify-gate) — not just timeline-stop-hook.gstack-config has) and the stated repair exception to dev-setup's no-mutation guarantee: heal may prune dead entries and re-point existing ones to canonical, never register new ones.Test plan
bun run test— full free suite via the strict sharded runnerbun test test/gstack-settings-hook-schema-aware.test.ts+ 12-file touched battery (194 tests)bash -non setup, gstack-settings-hook, gstack-uninstall, gstack-config, dev-setup🤖 Generated with Claude Code