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 so traces are emitted on the initial step and whenever a new agent begins execution. This reduces redundant trace noise and provides clearer visibility of agent transitions in session logs, ensuring each agent’s system prompt appears once per switch for more accurate and readable session traces.

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: 593d94ab-c29d-4f1c-8578-cc35020e96c8

📥 Commits

Reviewing files that changed from the base of the PR and between 89b8cbc and 3b691b5.

📒 Files selected for processing (1)
  • packages/opencode/src/session/prompt.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/opencode/src/session/prompt.ts

📝 Walkthrough

Walkthrough

Session prompt tracing now tracks the most-recently traced agent and re-traces the system prompt whenever the active agent changes, instead of only tracing on the loop's first step. This ensures each agent's system prompt is logged once when it becomes active.

Changes

Cohort / File(s) Summary
Agent Tracing Logic
packages/opencode/src/session/prompt.ts
Added a tracedAgent variable and changed the tracing guard from step === 1 to `step === 1

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

contributor

Poem

🐰 I hopped through prompts both near and far,

Traced each agent like a twinkling star.
No prompt left out, no trace misplaced,
Each furry name now gently traced.
Hop, log, repeat — a tidy little race.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: re-trace system prompt on agent switch' directly and precisely describes the main change—re-tracing system prompts when agents switch mid-session.
Description check ✅ Passed The PR description includes all required sections: Summary (root cause, implementation, comment fix), Test Plan (with specific verification steps), and Checklist (with all items addressed).
Linked Issues check ✅ Passed The implementation fully addresses issue #291: it tracks the last-traced agent via tracedAgent variable and re-traces when agent.name changes, ensuring each agent's system prompt is logged once when becoming active.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #291: adding tracedAgent tracking and updating the tracing condition and comment—no unrelated modifications introduced.
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.

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>
@VJ-yadav VJ-yadav force-pushed the fix/prompt-tracing-agent-switch branch from 89b8cbc to 3b691b5 Compare April 3, 2026 06:11
@dev-punia-altimate
Copy link
Copy Markdown

❌ Tests — Failures Detected

TypeScript — 15 failure(s)

  • connection_refused [2.73ms]
  • timeout [2.41ms]
  • permission_denied [2.67ms]
  • parse_error [2.35ms]
  • oom [2.49ms]
  • network_error [2.33ms]
  • auth_failure [2.50ms]
  • rate_limit [2.59ms]
  • internal_error [2.63ms]
  • empty_error [0.25ms]
  • connection_refused [0.16ms]
  • timeout [0.10ms]
  • permission_denied [0.07ms]
  • parse_error [0.07ms]
  • oom [0.07ms]

cc @VJ-yadav
Tested at 3b691b5a | Run log | Powered by QA Autopilot

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

2 participants