Skip to content

fix(hooks): give SessionEnd a timeout so shutdown does not cancel it - #101

Open
overkamperic wants to merge 1 commit into
langfuse:mainfrom
overkamperic:fix/sessionend-hook-timeout
Open

overkamperic wants to merge 1 commit into
langfuse:mainfrom
overkamperic:fix/sessionend-hook-timeout

Conversation

@overkamperic

Copy link
Copy Markdown

Relates to #13.

Problem

On native Windows the SessionEnd hook is cancelled on every exit (failed: Hook cancelled), and since the final turn is held back until SessionEnd, that turn is never exported. v1.2.0's lazy-import fast path does not avoid it here: starting the hook through uv run --script alone takes about 1.3 s, which together with the processing time exceeds the shared 1.5 s SessionEnd window.

The hooks reference documents the fix: SessionEnd hooks share a 1.5-second budget, and if a hook sets a longer timeout, Claude Code raises the budget to match (up to 60 s). This PR sets "timeout": 10 on the SessionEnd hook only. Stop is unchanged.

Evidence

Environment: Windows 11, Claude Code 2.1.285, uv 0.12.15 (d35f1f270 2026-09-15 x86_64-pc-windows-msvc), plugin 1.2.0, self-hosted Langfuse. Each run was a fresh one-turn claude -p session.

hooks.json "Hook cancelled" on exit Final turn exported (hook log)
stock 1.2.0 3 of 3 runs no (only the Stop run's Processed 0 turns)
with "timeout": 10 0 of 2 runs yes (Processed 1 turns about 4 s after exit)

The same before/after held on 1.1.0: cancelled without the timeout, clean with it. User settings also had another SessionEnd hook with timeout: 10, and the plugin's hook was still cancelled until the plugin's own entry set one.

Checks

  • hooks/hooks.json parses; only the SessionEnd entry changes.
  • CI smoke check: echo '{}' | uv run --script hooks/langfuse_hook.py exits 0.
  • No Python changes, so the pytest suite was not re-run.

SessionEnd hooks share a 1.5 s budget unless a hook sets its own timeout
(Claude Code raises the budget to match, up to 60 s). The hook needs about
1.3-1.6 s to start through uv on native Windows, so it is cancelled on every
exit and the session's held-back final turn is never exported. See langfuse#13.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants