Skip to content

Commit 89b8cbc

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 33c331b commit 89b8cbc

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
@@ -320,6 +320,7 @@ export namespace SessionPrompt {
320320
let compactionCount = 0
321321
let sessionAgentName = ""
322322
let sessionHadError = false
323+
let tracedAgent = ""
323324
let emergencySessionEndFired = false
324325
const emergencySessionEnd = () => {
325326
if (emergencySessionEndFired) return
@@ -728,18 +729,18 @@ export namespace SessionPrompt {
728729
system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT)
729730
}
730731

731-
// altimate_change start - trace system prompt once per loop() call.
732-
// The system prompt is functionally identical across steps within a single
733-
// loop() invocation (same agent, same environment). Agent switches re-enter
734-
// loop() with step reset to 0, so each agent's prompt is traced separately.
735-
if (step === 1) {
732+
// altimate_change start - trace system prompt once per agent.
733+
// The step counter is never reset on agent switches, so we track the
734+
// last-traced agent to ensure each agent's system prompt is logged.
735+
if (step === 1 || agent.name !== tracedAgent) {
736736
Tracer.active?.logSpan({
737737
name: "system-prompt",
738738
startTime: Date.now(),
739739
endTime: Date.now(),
740740
input: { agent: agent.name, step },
741741
output: { parts: system.length, content: system.join("\n\n") },
742742
})
743+
tracedAgent = agent.name
743744
}
744745
// altimate_change end
745746

0 commit comments

Comments
 (0)