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

Open Beginner friendly
#291 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
observability

Research direction

Start in packages/opencode/src/session/prompt.ts and inspect the loop around the step === 1 guard, including how agent switches update lastUser.agent. Trace a session that switches agents, then verify that each agent's system prompt is logged once when it first becomes active without changing tool execution behavior.

Written by the indexing model from the issue text.

Description

What does this PR do?

Follow-up from PR #287. The if (step === 1) guard in packages/opencode/src/session/prompt.ts traces the system prompt only on the first step, but the comment claims "Agent switches re-enter loop() with step reset to 0" — this is incorrect. The step variable is initialized once and increments continuously; it is never reset on agent switches.

Current behavior: Only the first agent's system prompt is traced. If a session switches agents mid-conversation (e.g. builder → analyst), the second agent's system prompt is never logged.

Expected behavior: Each agent's system prompt should be traced once when it first becomes active.

Possible fixes
  1. Track the last-traced agent and re-trace when the agent changes:

    if (step === 1 || lastUser.agent !== previouslyTracedAgent) {
      Tracer.active?.logSpan({...})
      previouslyTracedAgent = lastUser.agent
    }
    
  2. Or fix the comment to accurately describe the current behavior (trace first agent only).

Priority

Low — tracing/observability only, no functional impact on tool execution or user experience.

Dominant language
TypeScript
Stars
813
Forks
134
Avg merge
2d 5h
Merged PRs (30d)
62

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AltimateAI/altimate-code

All issues in AltimateAI/altimate-code

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.