Repository navigation
docs(plugins): say where before_model_request messages differ from the payload - #201020
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR clarifies how compaction summaries and CLI side questions represent conversation history in before_model_request events. Example: A scanner receives a compaction event with messages=1 and tagged=0.
Review scores
ProductKind: Docs · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR accurately documents two existing request shapes, with no actionable defects found. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe final model-request hook exposes outgoing payloads and detached message context to trusted plugins before provider or CLI dispatch. flowchart TD
A[Conversation history] --> B[Compaction summary context]
A --> C[CLI side question prompt]
B --> D[Final model request hook]
C --> D
D --> E[Provider or CLI dispatch]
Technical reviewBest possible solution: Merge the focused clarification while leaving any runtime provenance enhancement to separate work. Do we have a high-confidence way to reproduce the issue? Source inspection confirms both documented shapes; the PR also supplies trimmed Gateway observations, and no target code was executed during review. Is this the best way to solve the issue? The existing hook documentation and type comment are the appropriate owners, and every changed hunk serves the clarification without adding machinery or tests. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d905d8a68570. Provenance checked
SecurityNone. EvidenceWhat I checked:
PR surfaceSource +3, Docs +9. Total +12 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 18, 2026, 1:08 AM ET / 06:08 UTC. |
|
Merged via squash.
|
…e payload (openclaw#201020) Co-authored-by: VACInc <[email protected]>
Summary
High Level TLDR
The
before_model_requestdocs saymessagesis the model-facing history with sender metadata, and tell scanners to decide sender trust from that metadata. Two request kinds do not work that way: a compaction summary request packs the older history into one text message, somessageshas no per-message metadata at all, and a CLI/btwside question puts the history intopayload.promptas text. A scanner that follows the docs screens nothing on compaction and nothing in a CLI side question. This PR documents both shapes so plugin authors know where the history is and what metadata they get.What Problem This Solves
A plugin author writing a
before_model_requestcontent scanner follows the docs and keys sender trust onmessagesmetadata. On a compaction summary request that metadata does not exist, and on a CLI side question the history the model reads is text inpayload.prompt, so the scanner silently lets outside content through on those two request kinds.User Impact
Plugin authors can see, in the hook docs and the type comment, which request kinds carry history as text and what metadata
messagesholds for them. No runtime change.Why This Change Was Made
Root Cause
createModelRequestTransformerpassesstructuredClone(context.messages)asmessages. For a compaction summary, the context is built bycreateSummarizationContextinpackages/agent-core/src/harness/compaction/summarization-completion.tsfrom one string:<conversation>\n${conversation.text}\n</conversation>..., whereserializeConversationturns every user, assistant and tool result entry into text. Somessagesis that single synthetic user message, and nothing in it says which parts came from an outside sender or a tool. For a CLI side question,btw-runtime.tsbuilds the prompt withbuildBtwCliPrompt, which writes the history asUser:/Assistant:text inside<conversation_history>, whilemessagesholds the history plus the side question. The docs added with the hook (#193550) describe neither.Behavior before: a sender-trust scanner that keys on
messagesmetadata (as the docs instruct) found zero outside messages in a compaction summary request, so content it had withheld from every earlier turn request reached the summarizer unscreened.Exact change
docs/plugins/hooks/prompt-and-session.md: one bullet under the event contract sayingmessagesdoes not always map ontopayload, describing the compaction summary and CLI side question shapes, and what a metadata-based handler can and cannot do with them.src/plugins/hook-model.types.ts: the same two facts in the type comment.Docs and comment only. No runtime change.
Scope boundary
This does not add per-message provenance to compaction requests; that is a separate host change. Embedded side questions and session forks send real provider messages and are unchanged.
Evidence
Real behavior proof
Environment: OpenClaw 2026.11.5 Gateway on Linux, a local trusted plugin with
allowModelRequest: truethat logs one metadata row perbefore_model_requestcall (runtime, requestKind, message count, count of messages carryingprovenanceor__openclaw). Test sessions only; an embedded session on a hosted model and aclaude-clisession.Steps: one embedded turn whose tool output held a test canary, then
sessions.compacton that session; one CLI turn, then/btwthroughchat.send.Observed rows (trimmed):
The compaction summary written to the session then described the canary tool output as visible, although every turn request had withheld it. That is the outcome the new bullet warns about.
What was not tested
isResponsesCompactRequest) was not exercised; the new text names only the summary request.Verification
node scripts/check-docs-mdx.mjs docs/plugins/hooks/prompt-and-session.md: passed.oxfmt --checkwith the repo config on both files: correct format.main:src/agents/embedded-agent-runner/model-request-hook.ts(messages: structuredClone(context.messages)),src/agents/embedded-agent-runner/compaction-session-agent.ts(summary stream wrapped with requestKindcompaction),packages/agent-core/src/harness/compaction/summarization-prompts.ts(createSummarizationContextreturns one user message),src/agents/btw-runtime.tsandsrc/agents/btw-prompts.ts(CLI side question prompt carries the history as text; gatemessagesis the history plus the question).