Skip to content

fix(hook): emit teammate turns at Stop instead of deferring - #114

Open
Kiko0301 wants to merge 1 commit into
langfuse:mainfrom
Kiko0301:fix/teammate-turn-stop-emission
Open

Kiko0301 wants to merge 1 commit into
langfuse:mainfrom
Kiko0301:fix/teammate-turn-stop-emission

Conversation

@Kiko0301

Copy link
Copy Markdown

Summary

A teammate launch (toolUseResult.status == "teammate_spawned") was treated as an async agent launch. get_pending_agent_tool_use_ids() therefore held the entire turn open until a <task-notification> arrived. Teammates never send one — they report through team-message rows — so the turn was only emitted at SessionEnd, which Claude Code often cancels during shutdown (#100). In the reported data, 18 of 220 agent-team members were emitted, and the main turn was held with them.

Changes

  • Stop treating teammate_spawned as an async launch in get_async_launch_flag_from_row(). Async Agent/Task launches (status: async_launched) keep the existing deferral until their notification arrives.
  • A teammate turn now ships at its own Stop. The launch's transcript is attached on a later firing when the meta/JSONL appears, using the existing subagent progress cursors; the already-emitted root is not duplicated.
  • Updated test_named_teammate_transcript_attaches_to_its_launch_at_session_end_flush to model the late transcript: first Stop emits the root + Tool: Agent, then the transcript appears, then SessionEnd attaches Subagent: Build issue 4 without a second root.

Tests

  • uv run --group dev pytest -q tests/integration/test_emit_new_turns_from_transcript.py -k teammate: 1 passed.
  • Full suite: 273 passed, 7 failed, 1 skipped. The 7 failures are the pre-existing Windows-only tests (POSIX lock/permission, HOME/~, log encoding) that fail identically on unmodified main.
  • uvx ruff check --select F,E9 .: all checks passed.

This fixes the teammate-deferral cause in #100. Resumed and nested teammate transcripts described in the same issue need separate offset/recursion work and are not changed here.

A teammate launch was marked async, so get_pending_agent_tool_use_ids
held the whole turn open until a task-notification arrived. Teammates
never send one: they report through team-message rows. The turn only
shipped at SessionEnd, which is often cancelled during shutdown, so the
main turn, its generations and tool spans were lost entirely.

Emit teammate turns at their own Stop. The teammate transcript is
attached on a later firing when it is on disk; the emission progress
cursors already support adding children to an emitted root without
duplicating it.

Part of langfuse#100.

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

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