Skip to content

fix(hook): ignore typed non-chat rows that carry a chat role - #108

Merged
hassiebp merged 1 commit into
langfuse:mainfrom
pushkar:fix/ignore-typed-non-chat-rows
Oct 26, 2026
Merged

hassiebp merged 1 commit into
langfuse:mainfrom
pushkar:fix/ignore-typed-non-chat-rows

Conversation

@pushkar

@pushkar pushkar commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Recent Claude Code versions write api-request-blob transcript rows. These are request records whose nested message.role is user or assistant, and they have no timestamp. The role fallback read them as chat rows.

What this broke, seen on a self-hosted Langfuse 4.38:

  • A user-role blob became the turn's prompt. The root span started at hook time and ended before it started, and the trace input showed the raw request (system reminders, the /usage caveat).
  • An assistant-role blob added a model-less LLM Call that copied the previous reply.

Fix: only untyped rows fall back to message.role.

Testing

  • Two new unit tests. Full suite: 280 pass and 1 fails; the failure, tests/integration/test_state_lock_contention.py::test_entry_of_another_session_survives_the_emit, also fails on main without this change.
  • ruff check --select F,E9 is clean.
  • Live end-to-end runs against Langfuse through both claude -p and ACP: sequential tools, multi-turn, parallel and nested subagents, MCP failures, background agents, slash commands, an API-error final turn, SIGTERM, and kill-and-resume. 8/8 pass with the fix; 0/8 passed before.

Claude Code now writes request records (type "api-request-blob") whose nested message has role user or assistant but no timestamp. The role fallback read them as chat rows: a user-role blob became the turn's prompt, so the root span started at hook time and ended before it started, and an assistant-role blob added a model-less "LLM Call". Only untyped rows fall back to message.role now.

@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.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 05:44

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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.

5 participants