Skip to content

fix(hook): persist open turns across Stop firings#19

Draft
milanagm wants to merge 2 commits into
langfuse:mainfrom
milanagm:feature/lfe-10747-claude-code-hook-open-turns-are-dropped-across-stop-firings
Draft

fix(hook): persist open turns across Stop firings#19
milanagm wants to merge 2 commits into
langfuse:mainfrom
milanagm:feature/lfe-10747-claude-code-hook-open-turns-are-dropped-across-stop-firings

Conversation

@milanagm

@milanagm milanagm commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes LFE-10747. Addresses point 1b of #5.

Stop fires multiple times within one logical turn and at the same time turn assembly was stateless per hook run. Meaning that the trailing turn was emitted at every Stop, and continuation rows arriving in the next batch (task notifications followed by assistant messages) were silently dropped.

This PR:

  • holds the trailing turn in session state (open_turn_rows) and re-attaches
    it to the next batch; emitted once a new user row closes it or SessionEnd
    flushes it
  • delivers notifications to turns closed earlier in the same batch
  • keeps unmatched stashed notifications (their turn may still be open) and
    replays them once at session end

Known limits (unchanged from before): a hard-killed session that never resumes
loses its last open turn until SessionEnd reliability is improved (#13), and
late notifications for non-deferrable background tools (e.g. background Bash)
cannot attach once their turn is emitted.

Testing

  • added 4 new regression tests
  • Replayed local JSONL transcripts at their real stop_hook_summary
    boundaries vs. single-pass ground truth: 11 previously truncated turns are
    now complete, no duplicates
  • Live-verified in Langfuse Cloud

@milanagm milanagm marked this pull request as draft July 9, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant