Skip to content

docs(plugins): say where before_model_request messages differ from the payload - #201020

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:docs/model-request-compaction-messages
Nov 18, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:docs/model-request-compaction-messages

Conversation

@VACInc

@VACInc VACInc commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

The before_model_request docs say messages is 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, so messages has no per-message metadata at all, and a CLI /btw side question puts the history into payload.prompt as 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_request content scanner follows the docs and keys sender trust on messages metadata. On a compaction summary request that metadata does not exist, and on a CLI side question the history the model reads is text in payload.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 messages holds for them. No runtime change.

Why This Change Was Made

Root Cause

createModelRequestTransformer passes structuredClone(context.messages) as messages. For a compaction summary, the context is built by createSummarizationContext in packages/agent-core/src/harness/compaction/summarization-completion.ts from one string: <conversation>\n${conversation.text}\n</conversation>..., where serializeConversation turns every user, assistant and tool result entry into text. So messages is 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.ts builds the prompt with buildBtwCliPrompt, which writes the history as User: / Assistant: text inside <conversation_history>, while messages holds the history plus the side question. The docs added with the hook (#193550) describe neither.

Behavior before: a sender-trust scanner that keys on messages metadata (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 saying messages does not always map onto payload, 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: true that logs one metadata row per before_model_request call (runtime, requestKind, message count, count of messages carrying provenance or __openclaw). Test sessions only; an embedded session on a hosted model and a claude-cli session.

Steps: one embedded turn whose tool output held a test canary, then sessions.compact on that session; one CLI turn, then /btw through chat.send.

Observed rows (trimmed):

embedded turn          messages=4 tagged=3   (tool result present, screened and withheld)
embedded compaction    messages=1 tagged=0   (twice; nothing for a scanner to key on)
cli side_question      messages=7 tagged=6   (history with metadata; history text sits in payload.prompt)

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

  • No docs site build; only the MDX check and formatter on the two files.
  • Server-side compaction (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 --check with the repo config on both files: correct format.
  • Pre-commit hooks passed on the commit.
  • Each claim in the new text was re-checked against current 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 requestKind compaction), packages/agent-core/src/harness/compaction/summarization-prompts.ts (createSummarizationContext returns one user message), src/agents/btw-runtime.ts and src/agents/btw-prompts.ts (CLI side question prompt carries the history as text; gate messages is the history plus the question).

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS labels Nov 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:docs Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:docs Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The documentation implies that sender metadata is available in the model-facing history.
  • After: The documentation explains that the single synthetic message contains serialized history without per-message sender metadata.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, source-verified documentation correction with no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Documentation and comment only; the described request shapes were verified against their production owners.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Docs · Worth it: Yes · Fix scope: Complete
User problem: Plugin authors can incorrectly assume that every request exposes original per-message sender metadata alongside its payload.
Reason: The maintainer-authored clarification matches the implementation and makes an important existing limitation explicit.

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
Reviewed head: efe1735c6b144a28dfc86eb213cde4c11a7b2d4b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Final model-request documentation and type comment keeps the original intent (2b7950c: The original feature exposed final outgoing payloads and detached history for plugin screening, with stored transcript changes explicitly outside its scope.)

Security

None.

Evidence

What I checked:

PR surface

Source +3, Docs +9. Total +12 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 0 0 0 0
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 13 1 +12

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P3: This is a focused documentation correction with no executable behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is a focused documentation correction with no executable behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 18, 2026, 1:08 AM ET / 06:08 UTC.

@VACInc
VACInc merged commit 75a31ed into openclaw:main Nov 18, 2026
132 checks passed
@VACInc

VACInc commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the docs/model-request-compaction-messages branch November 18, 2026 06:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant