Repository navigation
Stamp the session's opening user prompt as input.value on the trace - #9
Merged
Merged
Conversation
rite2hhh
approved these changes
Aug 18, 2026
UsamaAnser1518
added a commit
that referenced
this pull request
Aug 19, 2026
…race ids (#11) ## Why `handle_stop_hook` releases the session lock to parse the transcript, then re-acquires it and reloaded `state` from disk to persist `session_input` (added in #9). If `SessionEnd` ran in that unlocked window it had already emitted the final root and **deleted the session file**, so the reload returned a blank `SessionState`: the turn's spans went out with empty ids ->`build_span` generated a fresh random trace id **per span**, every span became a root, and the deleted session file was recreated with empty ids. ## What - `handlers.py`: keep the in-memory `state` (and its trace/span ids) authoritative for the turn's spans; set `session_input` in memory and persist through a **separate** loaded object, only if the session file still exists; never recreate a removed file. - `tests/test_handlers.py`: regression test that runs `SessionEnd` inside the parse window and asserts all Stop spans stay on the session trace (exactly one root), the stamp is present, and the file stays deleted. Fails on master, passes here. - Version 1.1.1 → 1.1.2. ## Verified `make test` (validate + lint + 27 tests + fixture replay) and `make smoke` (real session, in-process collector) green; live sessions through both SDKs' vendored copies land as single traces with all children linked to the root. Follow-up: re-vendor into python-sdk (#354) and js-sdk (#202) once this merges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The trace plugin now stamps
input.valueon the session root span with the session's first user prompt. The PromptLayer trace page reads that first for the trace-level Input, so Claude Code sessions show what the user asked instead of an empty headline (the session root is typedWORKFLOW, which has no request-log fallback for Input).Changes
state.py: newsession_inputfield onSessionState(backward-compatible —from_dictdefaults missing fields to"", so existing on-disk sessions load fine).stop_parser.py:session_input_from_parsed()— firstusermessage from the parsed turn'sgen_ai.prompt.*history (clipped to 4000 chars);session_input_attrs();build_stop_hook_span_specsacceptssession_inputand stamps the root spec.handlers.py: the Stop hook records the first prompt into state (later turns never replace it) and stamps the per-turn root re-emit; SessionEnd stamps the final root. Both emits carry it because the backend upserts by span id — last write wins.scripts/e2e_smoke.py: asserts the session root'sinput.valuecontains the run's prompt (new_string_attributehelper +session_root_inputmetric, gates the exit code). Also fixes a pre-existing rot: the hardcodedclaude-3-haiku-20240307no longer exists on the API (not_found_error), somake smokewas already failing onmaster; the model is nowPL_SMOKE_MODEL(defaultclaude-haiku-4-5).Test Plan
make test— manifest validation, shellcheck, 25 pytest (5 new: helper extraction from the real transcript fixture, root-only stamping, no stamp without a prompt, and end-to-end Stop → state → SessionEnd), fixture replaymake smoke— real Claude Code session via the Agent SDK against the local OTLP collector;session_root_input= the run's prompt,graph_errors: []Claude Code sessioncarriesinput.value; trace headline shows Input via root stamp, Output via the LLM call's request logFollow-up
Re-vendor into python-sdk (
vendor_metadata.jsonsha) and js-sdk (npm run vendor:claude-agents) once merged; both pin this repo by commit.