avoid duplicate compaction system prompt#2647
Conversation
Create the synthetic compaction agent without an instruction because the compaction system prompt is already inserted into the child session. Otherwise session.GetMessages prepends the agent instruction and the sub-run sends the same system prompt twice. Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The fix is correct and well-motivated. The root cause is clear: explicitly prepends as a system message into the session items it builds, so when is later called inside the sub-run, would prepend the agent's own instruction a second time — producing a duplicate. Passing as the instruction causes to skip the instruction block entirely (the guard is ), so the system prompt arrives exactly once via the session items.
The new test accurately validates the regression by counting system messages matching inside the closure and asserting the count is exactly 1. The correctly implements the interface.
No high- or medium-severity issues found.
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The fix is correct and well-motivated.
Root cause: extractMessages() explicitly prepends compaction.SystemPrompt as a system-role message into the session items it builds. When compactionSession.GetMessages(compactionAgent) is later called inside the sub-run, buildInvariantSystemMessages would also prepend the agent's own Instruction() — causing the compaction system prompt to appear twice. Passing "" as the instruction causes buildInvariantSystemMessages to skip the instruction block entirely (guarded by if instructions := a.Instruction(); instructions != "") so the system prompt arrives exactly once via the session items.
Test: TestRunLLM_DoesNotDuplicateSystemPrompt accurately validates the fix. It counts system messages matching compaction.SystemPrompt inside the RunAgent closure and asserts the count is exactly 1. The fakeProvider correctly satisfies the provider.Provider interface.
No high- or medium-severity issues found.
Create the synthetic compaction agent without an instruction because the compaction system prompt is already inserted into the child session. Otherwise session.GetMessages prepends the agent instruction and the sub-run sends the same system prompt twice.