Skip to content

Commit 3b691b5

Browse files
VJ-yadavVijay Yadav
andcommitted
fix: re-trace system prompt on agent switch
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 #291 Co-Authored-By: Vijay Yadav <vijay@studentsucceed.com>
1 parent 0d34855 commit 3b691b5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/opencode/src/session/prompt.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export namespace SessionPrompt {
325325
let planHasWritten = false
326326
let planLastUserMsgId: string | undefined
327327
// altimate_change end
328+
let tracedAgent = ""
328329
let emergencySessionEndFired = false
329330
// altimate_change start — quality signal, tool chain, error fingerprint tracking
330331
let lastToolCategory = ""
@@ -855,18 +856,18 @@ export namespace SessionPrompt {
855856
system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT)
856857
}
857858

858-
// altimate_change start - trace system prompt once per loop() call.
859-
// The system prompt is functionally identical across steps within a single
860-
// loop() invocation (same agent, same environment). Agent switches re-enter
861-
// loop() with step reset to 0, so each agent's prompt is traced separately.
862-
if (step === 1) {
859+
// altimate_change start - trace system prompt once per agent.
860+
// The step counter is never reset on agent switches, so we track the
861+
// last-traced agent to ensure each agent's system prompt is logged.
862+
if (step === 1 || agent.name !== tracedAgent) {
863863
Tracer.active?.logSpan({
864864
name: "system-prompt",
865865
startTime: Date.now(),
866866
endTime: Date.now(),
867867
input: { agent: agent.name, step },
868868
output: { parts: system.length, content: system.join("\n\n") },
869869
})
870+
tracedAgent = agent.name
870871
}
871872
// altimate_change end
872873

0 commit comments

Comments
 (0)