From 634cf1183240ba089d7ec40789b78915d3919948 Mon Sep 17 00:00:00 2001 From: kulvirgit Date: Wed, 18 Mar 2026 19:02:47 -0700 Subject: [PATCH] fix: trace system prompt only once per session to avoid duplication The system-prompt span was logged inside the while(true) loop, causing it to fire on every LLM generation step. A session with N tool-calling rounds produced N identical system-prompt spans in the trace. Guard with step === 1 so the full system prompt content is traced only once. The system prompt is functionally identical across steps within a single loop() invocation (same agent, same environment). Agent switches re-enter loop() with step reset to 0, so each agent's prompt is traced separately. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/opencode/src/session/prompt.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index b16976047f..63cc6dd801 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -728,14 +728,19 @@ export namespace SessionPrompt { system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT) } - // altimate_change start - trace system prompt - Tracer.active?.logSpan({ - name: "system-prompt", - startTime: Date.now(), - endTime: Date.now(), - input: { agent: agent.name, step }, - output: { parts: system.length, content: system.join("\n\n") }, - }) + // altimate_change start - trace system prompt once per loop() call. + // The system prompt is functionally identical across steps within a single + // loop() invocation (same agent, same environment). Agent switches re-enter + // loop() with step reset to 0, so each agent's prompt is traced separately. + if (step === 1) { + Tracer.active?.logSpan({ + name: "system-prompt", + startTime: Date.now(), + endTime: Date.now(), + input: { agent: agent.name, step }, + output: { parts: system.length, content: system.join("\n\n") }, + }) + } // altimate_change end const result = await processor.process({