Repository navigation
fix(#645): install relay hook + drift guard so messages reach the agent - #646
Merged
admarble merged 2 commits intoMay 14, 2026
Merged
Conversation
Issue #645 reported that interactive relay messages disappear: inbox entries pile up while `.cursor` is never written and no outbox reply appears. Empirical evidence showed PostToolUse hooks were never advancing the read cursor. Root cause: PR #638 added `templates/hooks/relay-check.sh` and the SEQUANT_RELAY sourcing block in `templates/hooks/post-tool.sh`, but the installed copies in `.claude/hooks/` (referenced by `.claude/settings.json`) were never updated. Worktrees inherit the stale checked-in `post-tool.sh`, so the hook chain never sourced relay-check.sh. The mirror-pair config that should have caught this drift (`src/lib/merge-check/types.ts`) had `source: "hooks"` — a directory that doesn't exist — so the check silently no-op'd. Phase 1 — root-cause fix - Add `.claude/hooks/relay-check.sh` (byte-identical to template) - Surgically insert the 11-line SEQUANT_RELAY sourcing block into `.claude/hooks/post-tool.sh`. Wholesale sync is deferred because the installed file has two local-only features (test coverage, post-merge cleanup) that are not in the template. Phase 2 — drift guard - Fix DEFAULT_MIRROR_PAIRS source path: "hooks" -> ".claude/hooks" - Add Vitest assertion that relay-check.sh stays byte-identical to its template and that post-tool.sh keeps sourcing it Phase 3 — watch + archive metadata - `sequant watch` now detects relay deactivation (pidfile removed or absent at startup) and exits with a useful pointer to the archive instead of polling forever (Gap 3) - Archive `meta.json` records `inboxCount` + `outboxCount` separately so unanswered queries are visible post-hoc. `messageCount` preserved for back-compat; schema accepts older archives without the new fields (Gap 5) Out of scope: Gap 4 (prompt UX polish), Gap 6 (stale phase label), Gap 7 (signal-based abort fallback), broader `.claude/hooks/` drift reconciliation — separate follow-ups if requested.
watch.ts now passes the resolved cwd to outboxPathFor() so the watch command consistently uses the same root for pid + outbox + archive lookups. Pre-existing prod behavior unchanged (defaults to process.cwd()); enables clean test isolation.
admarble
deleted the
feature/645-bug-383-relay-messages-silently-lost-no-outbox
branch
May 14, 2026 07:28
This was referenced May 14, 2026
admarble
added a commit
that referenced
this pull request
May 14, 2026
…#648) Three independent CLI UX improvements that complete the user-visible gap list from #645 after the root-cause fix in #646. Each addresses one of the deferred gaps: Gap 7 — sequant abort <issue> Out-of-band escape hatch that bypasses the relay inbox entirely. Reads state.relay.pid (or the per-issue pidfile), sends SIGINT with a 10s grace, then escalates SIGTERM, then SIGKILL. Honors the existing ShutdownManager teardown so locks + relay archive run cleanly. Distinct from `prompt --type abort` by design: that is the polite path that needs the agent to read inbox; abort is the reliable kill that doesn't. Gap 6 — accurate currentPhase in prompt confirmation prompt now reads state.json with a fresh StateManager immediately before printing, bypassing any cached snapshot from the start of the command. When no fresh phase can be resolved, the label is omitted entirely — a wrong phase is worse than no phase. Gap 4 — sequant prompt --wait <seconds> Optional reply tailing: after appending to the inbox, poll the outbox for a response whose inReplyTo matches the new message ID. Print inline on hit, exit 1 with a "may be archived without response" message on timeout. Skipped for type=abort (no reply expected). Default behavior unchanged when --wait is absent. 11 new tests across abort + prompt-wait surfaces; 353 tests passing on the touched surface.
admarble
added a commit
that referenced
this pull request
May 14, 2026
Closes the broader hook-drift recurrence risk noted in #646. Before this commit, `.claude/hooks/post-tool.sh` carried two local-only features (test coverage analysis, post-merge worktree cleanup) that were not in `templates/hooks/post-tool.sh`, and `templates/hooks/` carried four improvements (CLAUDE_PLUGIN_DATA log dir, multi-PM test detection, cross-shell marker discovery, $HOOK_LOG variable) that were not in `.claude/hooks/`. PR #646 added a partial drift guard for relay-check.sh only; this commit closes the gap for the whole directory. Changes - templates/hooks/post-tool.sh: port the two local-only blocks (TEST COVERAGE ANALYSIS, POST-MERGE WORKTREE CLEANUP) into the template so it is a strict superset of every prior `.claude/hooks/` feature. - .claude/hooks/post-tool.sh, .claude/hooks/pre-tool.sh: replace with byte-identical copies of the now-superset templates. - src/lib/relay/__tests__/hook-sync.test.ts: widen drift guard from relay-check.sh-only to "every file in templates/hooks/ must be byte-identical in .claude/hooks/." Files local to .claude/hooks/ (e.g. capture-tokens.sh) are still permitted. - scripts/sync-hooks.sh + npm run sync:hooks: regenerate .claude/hooks/ from templates after editing a template hook. Adversarial verification: appending "# drift" to any hook file causes the test to fail; removing the line passes again. This removes the recurrence surface that originally caused #645.
admarble
added a commit
that referenced
this pull request
Sep 9, 2026
Three independent CLI UX improvements that complete the user-visible gap list from #645 after the root-cause fix in #646. Each addresses one of the deferred gaps: Gap 7 — sequant abort <issue> Out-of-band escape hatch that bypasses the relay inbox entirely. Reads state.relay.pid (or the per-issue pidfile), sends SIGINT with a 10s grace, then escalates SIGTERM, then SIGKILL. Honors the existing ShutdownManager teardown so locks + relay archive run cleanly. Distinct from `prompt --type abort` by design: that is the polite path that needs the agent to read inbox; abort is the reliable kill that doesn't. Gap 6 — accurate currentPhase in prompt confirmation prompt now reads state.json with a fresh StateManager immediately before printing, bypassing any cached snapshot from the start of the command. When no fresh phase can be resolved, the label is omitted entirely — a wrong phase is worse than no phase. Gap 4 — sequant prompt --wait <seconds> Optional reply tailing: after appending to the inbox, poll the outbox for a response whose inReplyTo matches the new message ID. Print inline on hit, exit 1 with a "may be archived without response" message on timeout. Skipped for type=abort (no reply expected). Default behavior unchanged when --wait is absent. 11 new tests across abort + prompt-wait surfaces; 353 tests passing on the touched surface.
admarble
added a commit
that referenced
this pull request
Sep 9, 2026
Closes the broader hook-drift recurrence risk noted in #646. Before this commit, `.claude/hooks/post-tool.sh` carried two local-only features (test coverage analysis, post-merge worktree cleanup) that were not in `templates/hooks/post-tool.sh`, and `templates/hooks/` carried four improvements (CLAUDE_PLUGIN_DATA log dir, multi-PM test detection, cross-shell marker discovery, $HOOK_LOG variable) that were not in `.claude/hooks/`. PR #646 added a partial drift guard for relay-check.sh only; this commit closes the gap for the whole directory. Changes - templates/hooks/post-tool.sh: port the two local-only blocks (TEST COVERAGE ANALYSIS, POST-MERGE WORKTREE CLEANUP) into the template so it is a strict superset of every prior `.claude/hooks/` feature. - .claude/hooks/post-tool.sh, .claude/hooks/pre-tool.sh: replace with byte-identical copies of the now-superset templates. - src/lib/relay/__tests__/hook-sync.test.ts: widen drift guard from relay-check.sh-only to "every file in templates/hooks/ must be byte-identical in .claude/hooks/." Files local to .claude/hooks/ (e.g. capture-tokens.sh) are still permitted. - scripts/sync-hooks.sh + npm run sync:hooks: regenerate .claude/hooks/ from templates after editing a template hook. Adversarial verification: appending "# drift" to any hook file causes the test to fail; removing the line passes again. This removes the recurrence surface that originally caused #645.
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 #645. Interactive relay messages were silently consumed because
.claude/hooks/post-tool.sh(the active PostToolUse hook) did not sourcerelay-check.sh, and.claude/hooks/relay-check.shdid not exist in this repo at all. PR #638 added both totemplates/hooks/but never updated the installed copies.relay-check.sh, insert the SEQUANT_RELAY sourcing block intopost-tool.sh(surgical — leaves local-only test-coverage + post-merge-cleanup blocks intact)DEFAULT_MIRROR_PAIRSsource path (hooks→.claude/hooks); new Vitest asserts byte equality + sourcing block presencesequant watchexits cleanly when relay deactivates instead of polling forever; archivemeta.jsonrecordsinboxCount+outboxCountseparately so unanswered queries are visible post-hocOut of scope: Gaps 4 (prompt UX polish), 6 (stale phase label), 7 (signal-based abort), and the broader
.claude/hooks/drift inpre-tool.sh. See issue comments for rationale.Test plan
Unit tests (already passing in CI):
npm run build(tsc) — cleannpx vitest run src/lib/relay src/lib/merge-check src/commands/__tests__— 7 new tests, 79 total touched, all passing.claude/hooks/relay-check.shmakeshook-sync.test.tsfail; restoring it passesManual verification (AC-3 — please run before merge):
Expected:
watchwithin ~30swatchprintsRun for #<issue> ended. Archive: …and exits 0cat <archive>/meta.jsonshows bothinboxCountandoutboxCountfieldsIf the smoke fails (no outbox reply), Gap 2 (sub-agent hook isolation) remains a live hypothesis; file a follow-up issue with the sentinel-log diagnostic plan in the original issue body.
Files touched
.claude/hooks/post-tool.sh(+11) — insert SEQUANT_RELAY sourcing block.claude/hooks/relay-check.sh(new, +107) — byte-identical to templatesrc/commands/watch.ts(+75 / −1) — dead-relay detectionsrc/lib/relay/archive.ts(+7) — inbox/outbox split countssrc/lib/relay/types.ts(+9) — schema additionssrc/lib/merge-check/types.ts(+1 / −1) — mirror-pair source pathsrc/lib/merge-check/merge-check.test.ts(+1 / −1) — fixture updatesrc/lib/relay/__tests__/hook-sync.test.ts(new, +44) — drift guardsrc/lib/relay/__tests__/archive-split-counts.test.ts(new, +91) — split-count coveragesrc/commands/__tests__/watch-dead-relay.test.ts(new, +71) — watch behaviorFixes #645