Skip to content

fix: trace system prompt only once per session#287

Merged
anandgupta42 merged 1 commit into
mainfrom
trace-tracking-main
Mar 19, 2026
Merged

fix: trace system prompt only once per session#287
anandgupta42 merged 1 commit into
mainfrom
trace-tracking-main

Conversation

@kulvirgit

Copy link
Copy Markdown
Collaborator

Summary

  • The system-prompt tracing span was inside the while(true) loop, firing on every LLM generation step. A session with N tool-calling rounds produced N identical spans.
  • Added step === 1 guard so the system prompt is traced once per loop() call.
  • Agent switches re-enter loop() with step reset, so each agent's prompt is still captured.

Changes

  • Guard logSpan("system-prompt") with if (step === 1) to avoid duplication
  • Document the static-prompt assumption in comments
  • Keep step in span input for debugging context

Test plan

  • Verify traces contain exactly 1 system-prompt span per session
  • Verify agent switches still produce separate system-prompt spans
  • Verify no regression in tracing output format

🤖 Generated with Claude Code

Reviewed by 7 AI models (Claude, Codex, Kimi, Grok, MiniMax, GLM-5, Qwen). Unanimous APPROVE after 1 convergence round.

@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 repository is configured for manual code reviews. Comment @claude review to trigger a review.

The system-prompt span was logged inside the while(true) loop, causing
it to fire on every LLM generation step. A session with N tool-calling
rounds produced N identical system-prompt spans in the trace. Guard
with step === 1 so the full system prompt content is traced only once.

The system prompt is functionally identical across steps within a single
loop() invocation (same agent, same environment). Agent switches re-enter
loop() with step reset to 0, so each agent's prompt is traced separately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kulvirgit kulvirgit force-pushed the trace-tracking-main branch from ef6fc5e to 634cf11 Compare March 19, 2026 02:02

@suryaiyer95 suryaiyer95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can impact the behavior a lot right? Run the benchmark with it

@anandgupta42 anandgupta42 merged commit 0da1482 into main Mar 19, 2026
8 checks passed
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.

3 participants