Repository navigation
Stop ask shows as feedback, not a hook error - #845
anirudhkumar-nanonets wants to merge 3 commits into
Conversation
🌱 graft blast radius2 areas changed → 10 areas can be affected. 36 dependent symbols, depth 2. flowchart TB
A0(("Claude Session State<br/>17 symbols"))
A1(("Onboarding Flow<br/>4 symbols"))
A2(("Event Telemetry<br/>3 symbols"))
A3(("Note Persistence<br/>3 symbols"))
A4(("Cloud Integration<br/>3 symbols"))
AX(("5 smaller areas<br/>6 symbols"))
classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
class A0,A1,A2,A3,A4 reached;
classDef tail fill:#EEF2F3,stroke:#9AA4A9,stroke-width:1px,color:#3A4247;
class AX tail;
Who knows this code — 5 people across 12 areas
Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no All 36 dependent symbols, grouped by areaClaude Session State — 17 symbols in 13 files
Onboarding Flow — 4 symbols in 4 files
Event Telemetry — 3 symbols in 3 files
Note Persistence — 3 symbols in 3 files
Cloud Integration — 3 symbols in 3 files
MCP Server — 2 symbols in 2 files
CLI Skills — 1 symbol in 1 file
CLI Entry Point — 1 symbol in 1 file
Learning Sessions — 1 symbol in 1 file
Workspace CLI — 1 symbol in 1 file
Test signal per changed area — 1 ✓ · 1 –Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.
64 test suites also reference this code76 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.
Open the interactive graph → — click an area to see its dependent symbols at file:line. |
The issue
When trail's Stop hook asks Claude Code to save a learning, Claude Code shows it as an error: a red
Ran 1 stop hookrow,⎿ Stop hook error: [trail] …, and the footer notice "Stop hook error occurred · ctrl+o to see". A teammate saw this on 3 Nov and read it as trail crashing. The ask was working. The label was wrong.Why
Claude Code labels every Stop
decision: block, and every exit 2, as a hook error. Since 2.1.163 a Stop hook can instead returnhookSpecificOutput.additionalContext. The changelog says it gives Claude feedback and keeps the turn going "without being labeled a hook error". The person sees a gold⎿ Stop hook feedback: …row and no error notice. The model reads "Stop hook additional context: …" where it read "Stop hook blocking error from command: …".The continuation works the same way. Claude Code puts a Stop's additionalContext on the same list as a block's reason, and that list drives the next turn with
stop_hook_active: true. trail's never-ask-twice-in-a-row guard andnote_askedstill fire on the stop after. The cap of 8 hook continuations in a row counts both forms.Older Claude Code builds drop a Stop's additionalContext and end the turn, so sending it everywhere would lose the ask there.
The fix
stopTakesContext(src/claude/stop.ts) is true only for Claude Code's main agent at 2.1.163 or later, outside a bare run (CLAUDE_CODE_SIMPLE). The Stop payload carries no version, so trail reads the newestversionin the last 256 KB of the transcript. When it's true,emitHooksends the ask ashookSpecificOutput.additionalContext.decision: block, which each of them acts on. The skills offer is also a Stop block, so it gets the same treatment on Claude Code.askAnswer(src/claude/note-signals.ts) finds the ask in either form: the old isMeta "Stop hook feedback" line, or thehook_additional_contextattachment that additionalContext leaves in the transcript.note_askedgainsform(block/feedback), so the save rate can be compared by form. TELEMETRY.md and the telemetry contract list the new property.Checks
Updated 18 Nov, after merging main into the branch (
49d36b7c: #727, plus #757, #842, #844 and #847). The merge had no conflicts.#727 and this PR. Both edit
stop.ts,contract.tsandTELEMETRY.md, in different places. #727's "did it help?" vote is marked inturnEnd, fromlast_assistant_message, before the save ask runs, and the next prompt settles it. It reads neither form of the ask, and both forms continue the turn the same way, so which form the ask takes doesn't change a waiting vote. #727 adds its own event,learning_rated.note_askedkeepskindandsaved, plus this PR'sform.formproperty. After the merge, those suites plus the learning vote, skills telemetry, session start, learning-on-touch and scenario-hook suites pass 103/103 with a scratch HOME.graft-to-trail,hosts-trail,upkeep-hooks), and twoinit-first-minutetests that expect a name where this machine's git user prints "you".askAnswertwice: once as written (block form), and once with that line rewritten as thehook_additional_contextattachment (feedback form). Both forms gave the same answers: 62 save asks (11 saved in the repo, 10 personal, 41 not saved), and 82 other trail Stop blocks (skills offers, older ask wording) left out. The attachment's shape matches about 3,800 real ones from other hook events (UserPromptSubmit, PostToolUse, SessionStart, PreToolUse). None comes from a Stop hook yet, since nothing sent one before this change.claudeCLI on the test machine is still signed out (loggedIn: falseon 18 Nov), so no real Claude Code session ran this hook. The label and continuation behaviour come from Claude Code's changelog and its 2.1.317 build.trail checkflags seven conflicts. All seven are word matches, not reversals:claude -pwhen the prompt, Stop and PostToolUse hooks went quiet in a sandbox" (TELEMETRY.md, note-signals.ts). That learning is about how trail's hooks load in a sandbox, which this PR doesn't touch.hook_msfor the Stop hook" and "A property onnote_savedalone" (note-signals.ts, stop.ts, contract.ts). The newformproperty goes onnote_asked, the event that learning chose instead of either.Moves:
learnings_committed, through the save rate ofnote_asked(savedinrepo/personalover all asks) split by the newformproperty. PostHog events in Metabase db 11,posthog_event_full_view. Value on 17 Nov, the day this PR opened: not read, because Metabase was unreachable from the VPN-less machine. On 16 Nov db 11 had nonote_askedevents, since #739, which adds the event, wasn't released (from #739's description).🤖 Generated with Claude Code