-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Bug: before_prompt_build hook's prependContext/appendContext stripped into system prompt #86849
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Bug:
before_prompt_buildhook'sprependContext/appendContextstripped into system promptSummary
The
prependContextandappendContextreturned bybefore_prompt_buildhooks are not kept alongside the user message. Instead,resolveRuntimeContextPromptPartsstrips them out and places them into the system prompt area.Actual behavior
Expected behavior
Hook-injected context should be adjacent to the user message when sent to the model, so the model can associate the context with the user's question.
Requirements
The ideal behavior requires a three-layer separation:
Hook context stays in the prompt area —
prependContext/appendContextshould be sent to the model alongside the user message in the same prompt area, not stripped into the system prompt.Not persisted in conversation history — Hook-injected content should NOT be written into the transcript / history. Only the user's raw message should be saved in history. Otherwise the history becomes bloated — injecting hundreds of lines (e.g. AGENTS.md) on every single turn will quickly overflow the context window.
Not echoed to the user-facing UI — The user should only see their own raw message in webchat, Feishu, and other clients. Hook-injected prompts should only be injected during server-side prompt construction and only be visible to the model.
In summary:
prependContext/appendContext)Root cause
The
resolveRuntimeContextPromptPartsfunction inruntime-context-prompt.ts:The core issue:
transcriptPrompt = raw user messageduring agent run setup (source:transcriptCommandBodyinget-reply-*.js,queued.transcriptPromptinagent-runner.runtime-*.js).before_prompt_buildhooks execute,effectivePrompt = transcriptPrompt + prependContext + appendContext, which is never equal totranscriptPrompt.Scope of impact
In
selection-BmjEdnnA.js(lines ~14326-14450), the hook assembleseffectivePromptthen callsresolveRuntimeContextPromptPartsto split it.This splitting logic affects all plugins that use
before_prompt_buildto returnprependContext/appendContext. The hook-injected context is completely separated from the user message when sent to the model.Relevant files
dist/runtime-context-prompt-*.js:18-34resolveRuntimeContextPromptPartseffectivePromptdist/selection-*.js:14349-14355prependContext/appendContext→effectivePromptdist/selection-*.js:14438-14447resolveRuntimeContextPromptPartseffectivePromptis splitdist/get-reply-*.jstranscriptPrompt: transcriptCommandBodytranscriptPromptsourcedist/agent-runner-execution-*.jstranscriptPrompt: params.transcriptCommandBodytranscriptPromptsourcedist/agent-runner.runtime-*.jstranscriptPrompt: queued.transcriptPrompttranscriptPromptpassthrough