Repository navigation
Description
Symptoms
Two sequant run sessions over a single quiet-mode batch (npx sequant run 504 505 -q) accepted sequant prompt messages cleanly but never produced any reply:
| Issue | Prompt sent | Phase at archive | Outcome |
|---|---|---|---|
| #504 | 03:33:57Z ("what's taking so long?") |
qa archived at 03:39:21Z (5m 24s later) |
inbox.jsonl archived under .sequant/logs/relay/504-qa-2026-05-14T03-39-21-296Z/ with messageCount: 1; no outbox.jsonl in archive |
| #505 | 03:37:22Z ("why are we stalled?") |
still in qa | live inbox.jsonl has the entry, no outbox.jsonl, state.json shows relay.messageCount: 1 |
sequant watch 504 is still running and producing nothing — the underlying run advanced to ready_for_merge, the pidfile for #504 was removed, and the live relay dir is empty.
Both runs had relay.enabled: true in state.json and a populated pidfile; relay infrastructure was healthy. The issue is that the agent never wrote a reply.
Hypothesized gaps (each worth verifying individually)
Gap 1 — Cursor advances on hook render, not on agent reply (HIGH CONFIDENCE)
templates/hooks/relay-check.sh:101-105 unconditionally advances _CURSOR after rendering the frame to stdout. The frame instructs the agent to write outbox.jsonl, but the hook has no way to enforce that the agent actually did so. If the agent ignores the framing prompt (focused task, context pressure, parsed as tool output rather than directive), the message is silently consumed.
Verify: check whether either archive shows a cursor file matching the inbox line count with no outbox written.
Gap 2 — Sub-agent (Agent() sub-spawn) hook behavior unverified
The QA phase delegates to sequant-qa-checker sub-agents via Agent() tool calls. SEQUANT_RELAY / SEQUANT_WORKTREE are inherited via process env (phase-executor.ts:632-669), but it's unverified whether:
- Sub-agent PostToolUse hooks run with the same
.claude/settings.jsonconfig - The framing prompt reaches the sub-agent's context vs. the outer agent's
- The sub-agent has write permission to
<worktree>/.sequant/relay/outbox.jsonlunder its tool allowlist
If the sub-agent does most of the QA tool calls but the framing prompt only reaches the outer agent (or vice versa), the user-facing latency claim ("after the next tool call") breaks for any phase that delegates heavily.
Verify: instrument relay-check.sh to log when it fires + which PID / which SEQUANT_ISSUE env is set; run a phase that delegates and inspect the log.
Gap 3 — sequant watch silently tails dead relays
Once a phase deactivates, the live <worktree>/.sequant/relay/outbox.jsonl is moved to .sequant/logs/relay/<archive>/ and the live dir becomes empty. sequant watch <issue> keeps tailing forever with no signal. Should detect via the pidfile being removed OR state.json relay being cleared, and exit with a clear message ("Run for #N ended at HH:MM:SS, N messages archived to , 0 replies").
Gap 4 — sequant prompt "Message sent" is misleading after phase ends
The CLI confirms the file write but has no liveness check. A "sent" message can be archived seconds later without ever being read. The prompt CLI already reads state.json (uses relay.pid for liveness on other paths) — could add a "warning: phase has ended since this message was queued, your message may not be answered" follow-up check, or refuse to send if the pidfile is stale.
Gap 5 — Archive meta.json doesn't surface unanswered messages
meta.json records messageCount: 1 (inbox) but not replyCount. A diff would let sequant logs / sequant status retrospectively report "N messages with no reply" so silent losses are at least visible.
Gap 6 — sequant prompt phase label is stale
Both prompts confirmed "exec phase, Nm Ns elapsed" while state.json showed phase: qa. The elapsed counter also appears run-relative rather than phase-relative. Minor UX bug compared to the others, but worth folding in.
Suggested approach
Treat gaps 1, 3, 4 as the user-visible "messages disappear" bug surface — each is a separate small fix. Gap 2 is the highest-impact behavioral question (whether sub-agent-heavy phases like QA can use relay at all) and needs an instrumented run before designing a fix. Gaps 5 and 6 are minor polish.
References
- Parent: Interactive relay: bidirectional communication with headless runs #383 (interactive relay)
- Hook:
templates/hooks/relay-check.sh,templates/relay/frame.txt - Env wiring:
src/lib/workflow/phase-executor.ts:632-669 - Activation:
src/lib/relay/activation.ts - Docs:
docs/features/interactive-relay.md
Activity
admarble commentedon May 14, 2026
Update — new evidence invalidates Gap 1, promotes Gap 2 to near-confirmed
After filing, I sent
npx sequant prompt 505 --type abortto test the abort path. State after 30+ minutes of live activity on #505:relay-check.sh:101-105creates/updates.cursorafter every successful render. No.cursorfile across 30 min of execution meansrelay-check.shhas never fired in this session's PostToolUse chain — for either the query OR the abort.Corrections to original framing
Gap 1 — invalidated. I assumed "hook fires → cursor advances → agent ignores frame." Wrong. The frame is never rendered in the first place. The agent has nothing to ignore.
Gap 2 — promoted from hypothesis to likely confirmed. Most plausible explanation for no-cursor over a long execution: PostToolUse hooks aren't firing in the active execution context. Whether that's because the active context is a sub-spawned
Agent()whose hook chain doesn't inheritpost-tool.sh, or a broader env/wiring issue, needs the instrumented sentinel log proposed in Gap 2's verify step.New Gap 7 —
--type abortis dead when the hook chain is brokenIf the hook never fires, no message type lands — query, directive, AND abort are all silently consumed. Abort is supposed to be the user's escape hatch when the agent is misbehaving; it's the path that needs to work even when other relay flow is broken.
Suggested mitigation: an additional out-of-band abort path. Options:
sequant prompt <issue> --type abort --signal→ after a short grace period (e.g. 30s) with no acknowledgment in outbox, send SIGINT tostate.json:relay.pid. The signal goes to the parentsequant runorchestrator, which already has a cleanShutdownManagerpath that deactivates relay and releases locks.sequant abort <issue>command that bypasses the inbox entirely and signals the recorded PID directly, distinct from the relay channel.The CLI flag already exists (
prompt --type abort); the missing piece is the fallback that doesn't depend on the agent honoring it.Practical guidance for users hitting this today
The relay-channel abort cannot recover from the broken-hook state. The reliable escape:
Followed by SIGTERM then SIGKILL if needed.
admarble commentedon May 14, 2026
/spec — Plan
Root cause identified
Issue title mentions Gap 2 (sub-agent hook firing) as "near-confirmed." After empirical inspection, the root cause is simpler and more concrete: the installed hook file
.claude/hooks/post-tool.shis stale and does not sourcerelay-check.sh, and.claude/hooks/relay-check.shdoes not exist at all.templates/hooks/post-tool.sh515b616(#383 / #638, May 13)templates/hooks/relay-check.sh515b616(#383 / #638, May 13).claude/hooks/post-tool.shbb51991(Mar 25).claude/hooks/relay-check.shPR #638 added the relay feature to the templates but never updated the active hooks in
.claude/hooks/. Every worktree in this repo inherits the stale checked-in copy, so the PostToolUse hook never sourcesrelay-check.sh, never advances.cursor, and never renders the framing prompt. That explains the no-cursor / no-outbox / no-reply behavior on #504 and #505 directly — no sub-agent hook-inheritance investigation needed to close the user-visible bug.A secondary contributing factor:
DEFAULT_MIRROR_PAIRSinsrc/lib/merge-check/types.ts:196lists{ source: "hooks", target: "templates/hooks" }—hooks/doesn't exist; the correct source is.claude/hooks. The mirror check that should have caught this drift at merge time silently no-op'd.Acceptance Criteria
.claude/hooks/relay-check.shexists and is byte-identical totemplates/hooks/relay-check.sh..claude/hooks/post-tool.shcontains theif [[ "${SEQUANT_RELAY:-}" == "true" ]]block that sourcesrelay-check.sh(matching the shape oftemplates/hooks/post-tool.sh:16-26).sequant run+sequant prompt <n> "status?"produces an outbox reply in the live worktree within a reasonable timeout. Documented in PR body.src/lib/relay/__tests__/hook-sync.test.ts) asserts byte-equality ofrelay-check.shand substring presence of the SEQUANT_RELAY block inpost-tool.sh. Deliberately corrupting either file fails the test.DEFAULT_MIRROR_PAIRSuses.claude/hooksas the source (nothooks). Matching test insrc/lib/merge-check/merge-check.test.tsupdated if needed.sequant watch <n>detects relay deactivation (pidfile removed) and exits cleanly with an end-of-run summary instead of polling forever.meta.jsonincludesinboxCount+outboxCountas separate fields.messageCountis preserved as the sum for backward compatibility.Implementation plan
Phase 1 — Root-cause fix
.claude/hooks/relay-check.shas a verbatim copy oftemplates/hooks/relay-check.sh(chmod 0755).SEQUANT_RELAYsourcing block fromtemplates/hooks/post-tool.sh:16-26into.claude/hooks/post-tool.shimmediately after theCLAUDE_HOOKS_DISABLEDrollback check. Do not wholesale-overwrite the file — it contains two local-only features (test coverage analysis, post-merge worktree cleanup) that are not in the template.Phase 2 — Drift guard
3. Fix
DEFAULT_MIRROR_PAIRSinsrc/lib/merge-check/types.ts:"hooks"→".claude/hooks". Update any test expectations.4. Add
src/lib/relay/__tests__/hook-sync.test.tswith the three assertions in AC-4.Phase 3 — Watch + archive metadata (Gaps 3, 5)
5.
src/commands/watch.ts: in the polling loop, also checkreadPidFile(). When the pid file is removed during a watch session, print a clean-exit message (referencing the most recent archive path vialistArchives()) and exit 0.6.
src/lib/relay/types.ts+src/lib/relay/archive.ts: extendRelayArchiveMetaSchemawithinboxCount+outboxCount.archiveRelayDir()writes both alongside the existingmessageCount.Phase 4 — Verification
7. Run
npm run buildandnpm test -- relay. Document a livesequant run+promptrepro in the PR body.Explicitly out of scope (filed as follow-ups iff requested)
sequant promptUX when phase has ended (cleanupStalePid already mostly covers it).currentPhaselabel in the prompt confirmation (state-manager timing investigation).--type abortfallback. Re-evaluate once Gap 2 is closed and we verify the in-band path works end-to-end..claude/hooks/drift (pre-tool.sh, etc.). Touches behavior outside relay; separate reconciliation issue.Design review
.claude/hooks/), template source-of-truth (templates/hooks/), and a CI-enforced parity test (src/lib/relay/__tests__/). Same pattern as the existing.claude/skills/↔templates/skills/mirroring documented in CLAUDE.md.post-tool.shhas local-only features that should not be lost in this PR.DEFAULT_MIRROR_PAIRSwas intended to enforce the same rule for hooks but used the wrong source path.Open questions
.claude/hooks/pre-tool.shalso be synced? Recommendation: no for this PR — separate reconciliation issue. pre-tool.sh has its own drift but doesn't affect relay.relay-check.sh(no legitimate divergence ever expected); substring match forpost-tool.sh(it has local-only features).Recommended workflow
Phases: spec → exec → qa
Quality loop: disabled
Reasoning: Bug fix with concrete root cause, ~150 LOC, no UI/browser surface.
/qavalidates AC.admarble commentedon May 14, 2026
/qa — Inline review
Verdict: NEEDS_VERIFICATION (6/7 AC verified via Vitest + grep; AC-3 requires live smoke)
AC walk-through
diff -q .claude/hooks/relay-check.sh templates/hooks/relay-check.shreturns clean;hook-sync.test.tsasserts byte equality.claude/hooks/post-tool.shcontain theSEQUANT_RELAY:-guard;hook-sync.test.tsasserts substring# corruptedto relay-check.sh causeshook-sync.test.tsto fail; restoration passessrc/lib/merge-check/types.ts:196now reads.claude/hooks; merge-check.test.ts fixture updated to.claude/hooks/pre-tool.shwatch-dead-relay.test.tscovers both startup-no-relay (immediate exit with archive hint) and mid-watch pidfile removal (drain + exit with end-of-run message)archive-split-counts.test.tsconfirms inboxCount=3, outboxCount=1, messageCount=4; schema accepts legacy archives without the new fieldsTest results
npm run build(tsc) — cleanRisk assessment
Likely failure mode in production: If the SDK ever bypasses
.claude/settings.jsonPostToolUse hooks (e.g., during sub-agent tool calls), the relay would still be silent. The drift guard catches our own breakage; it does NOT catch an upstream Claude Code behavioral change. Original Gap 2 hypothesis (sub-agent hook isolation) remains worth re-evaluating after AC-3 smoke confirms the single-agent path works.Not tested:
sequant run+sequant promptround-trip (AC-3) — requires interactive processsequant-qa-checker) — relevant to whether the fix fully closes the user's arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504/arch: phase plugin registry — user-extensible workflow phases #505 evidence, but distinct from the missing-hook root causeManual verification plan (post-PR)
Notes for the merger
d901eb5— primary fix + drift guard + watch dead-relay + archive split945a531— small follow-up: passcwdtooutboxPathForfor consistencyCo-Authored-Byper CLAUDE.md.claude/hooks/drift) documented in spec; file follow-up issues only if the live smoke surfaces residual relay silencefix(#645): install relay hook + drift guard so messages reach the age…
admarble commentedon May 14, 2026
All-gaps progress
After PR #646 closed the user-visible bug, three follow-up PRs cover the remaining gaps:
sequant abort(Gap 7) +prompt --wait(Gap 4) + accurate phase label (Gap 6).claude/hooks/↔templates/hooks/reconciliation + widened drift guard +npm run sync:hooksGap-by-gap
.cursoradvances when SEQUANT_RELAY=true). Sub-agent context proven on architectural reading; a sub-agent-heavy smoke run is the last empirical validation worth doing post-merge.sequant watchexits with archive pointer on relay deactivation (#646)sequant prompt --wait <seconds>tails outbox for matching reply (#648)meta.jsoncarries splitinboxCount+outboxCount(#646)sequant abort <issue>— out-of-band SIGINT→SIGTERM→SIGKILL escalation, bypasses inbox (#648).claude/hooks/reconciliation + byte-equality test for all hook files +npm run sync:hooks(#649)Test counts
Remaining manual smoke (after #648 + #649 merge)
If the sub-agent-heavy smoke fails, file a follow-up; PR #649's new hook environment (sourced relay-check.sh + correct env propagation) makes the only remaining failure mode an upstream Claude Code hook-firing behavior — which would need its own investigation cycle.
feat(#645): relay CLI UX — abort, prompt --wait, accurate phase label (…
chore(#645): reconcile .claude/hooks/ with templates/hooks/ (#649)
admarble commentedon May 14, 2026
All gaps merged
Three PRs merged in order. All gaps from this issue are now resolved on
main:watchdead-relay) + Gap 5 (archive split counts) + initial drift guardprompt --wait) + Gap 6 (accurate phase label) + Gap 7 (sequant abort).claude/hooks/↔templates/hooks/reconciliation + widened byte-equality drift guard +npm run sync:hooksPost-merge verification
npm run build(tsc): cleannpx vitest run src/lib/relay src/commands/__tests__: 37/37 passingnpx sequant doctor: 15/18 passed, 3 warnings (all pre-existing — upstream #43869 model-routing notice, etc.); no new regressionsRemaining manual smoke
The only verification I couldn't do from inside the agent context is the live sub-agent-heavy relay round-trip:
If
--phases qaproduces an outbox reply, the original Gap 2 hypothesis (sub-agent contexts not firing PostToolUse) is fully invalidated and the issue can be closed. If it doesn't, file a follow-up — the upstream Claude Code behavior would need investigation since all sequant-side wiring is now correct and CI-locked against drift.Closing this issue as resolved unless that smoke surfaces a regression.
feat(#645): relay CLI UX — abort, prompt --wait, accurate phase label
chore(#645): reconcile .claude/hooks/ with templates/hooks/