Skip to content

fix: re-trace system prompt on agent switch#548

Open
VJ-yadav wants to merge 1 commit intoAltimateAI:mainfrom
VJ-yadav:fix/prompt-tracing-agent-switch
Open

fix: re-trace system prompt on agent switch#548
VJ-yadav wants to merge 1 commit intoAltimateAI:mainfrom
VJ-yadav:fix/prompt-tracing-agent-switch

Conversation

@VJ-yadav
Copy link
Copy Markdown

@VJ-yadav VJ-yadav commented Mar 28, 2026

Summary

  • The step === 1 guard in prompt.ts only traced the first agent's system prompt because step increments continuously and is never reset on agent switches
  • Added a tracedAgent variable to track the last-traced agent name, so each agent's system prompt is logged when it first becomes active
  • Fixed the inaccurate comment that claimed agent switches reset step to 0

Fixes #291

Test Plan

  • Verify typecheck passes on prompt.ts (pre-existing test file failures are unrelated)
  • Start a session, switch agents mid-conversation, confirm both agents' system prompts appear in trace output
  • Confirm single-agent sessions still trace the system prompt exactly once

Checklist

  • Change is minimal and focused on the reported issue
  • No functional behavior change — tracing/observability only
  • Comment updated to accurately describe the logic

Summary by CodeRabbit

  • Refactor
    • Improved session tracing accuracy to emit tracing spans when a new agent begins execution or on initial step, reducing unnecessary trace emissions and providing clearer agent transition visibility in session logs.

The `step === 1` guard only traced the first agent's system prompt
because `step` increments continuously and is never reset on agent
switches. Track the last-traced agent name so subsequent agents also
get their system prompts logged.

Fixes AltimateAI#291

Co-Authored-By: Vijay Yadav <vijay@studentsucceed.com>
Copy link
Copy Markdown

@claude claude bot left a comment

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.

@github-actions
Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 24008581-d1e1-4ab0-b105-5deff75be41c

📥 Commits

Reviewing files that changed from the base of the PR and between 33c331b and 89b8cbc.

📒 Files selected for processing (1)
  • packages/opencode/src/session/prompt.ts

📝 Walkthrough

Walkthrough

Modified system prompt tracing in the session loop to track the current agent and re-trace whenever the agent changes, rather than only on the first step. This fixes an issue where subsequent agents in multi-agent sessions had their system prompts skipped during tracing.

Changes

Cohort / File(s) Summary
Agent Tracing Logic
packages/opencode/src/session/prompt.ts
Introduced tracedAgent variable to track the last-traced agent name. Changed system prompt tracing condition from step === 1 to `step === 1

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Hop by hop, each rabbit's traced,
No more agents left erased!
When the builder hands the wheel,
The analyst's song we now can feel.
One variable to remember true,
Which furry friend was logged through.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: re-tracing system prompts when agents switch mid-session.
Description check ✅ Passed The description covers all template sections with clear explanations of the problem, solution, test plan, and confirms minimal focused changes.
Linked Issues check ✅ Passed The PR fully addresses issue #291 by implementing the first proposed fix: tracking the last-traced agent and re-tracing when the agent changes.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the system prompt tracing bug in prompt.ts; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: system prompt tracing skips subsequent agents due to step counter not resetting

1 participant