Skip to content

fix(prompt-assembly): runtime-context block header misleads smaller models into reporting the current message body as 'not injected' #110672

Closed

Description

@DerekEXS

Summary

Smaller reasoning-capable models intermittently report that the current user message body "was not injected into the runtime context", when in fact the body is delivered to the model (the same turn's reasoning trace quotes it verbatim). The confusion comes from the wording of the internal runtime-context block header injected by OpenClaw core.

Reproduction / observed behavior

Running OpenClaw 2026.7.1 with an OpenAI-compatible provider model (a smaller reasoning model). On some turns the assistant emits user-visible text such as:

"the current message body was not injected into the runtime context"

…while in the same turn its own (hidden) reasoning trace quotes the supposedly-missing message body word-for-word. So the body clearly reached the model; the assistant only believes it didn't.

Root cause

Each turn, OpenClaw core splits inbound context into two parts and delivers them to the model as separate messages:

  1. A hidden custom message (customType = "openclaw.runtime-context", display: false) built by embedded-agent-runner/run/runtime-context-prompt.ts (buildRuntimeContextMessageContent) and inserted in embedded-agent-runner/run/attempt.ts (around the resolveRuntimeContextPromptParts / buildRuntimeContextCustomMessage calls). Its body looks like:

    OpenClaw runtime context for the immediately preceding user message.
    This context is runtime-generated, not user-authored. Keep internal details private.
    
    <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>
    [Conversation info]  message_id=<current>, sender, timestamp   ← current message METADATA only
    [Conversation context]  ... historical timeline ... ends at <previous id>
    <<<END_OPENCLAW_INTERNAL_CONTEXT>>>
    
  2. The actual current message body is delivered as the ordinary user-role message that follows that block.

The header says it is "for the immediately preceding user message" (naming id #N), but the block body only carries metadata + a historical timeline that ends at #N-1. The current body is intentionally outside the block.

Smaller models read the header literally and reason: "the header names #N, the timeline ends at #N-1, therefore #N's body is missing" — missing that the body is in the adjacent user message. They then surface this (incorrect) conclusion to the user, despite having used the body in their own reasoning.

Why intermittent

The misread is most likely to surface when:

  • A compaction / cross-session wake makes the timeline end at a pre-compaction id while the current id jumps ahead, widening the visible gap.
  • The current id equals timeline_end + 1, making the "just one message short" contrast most conspicuous.
  • The model has lower tolerance for the implicit "body lives in the next user message" convention.

Suggested fix (minimal, wording only)

The block is metadata+timeline by design; the body is delivered separately. The header should say so explicitly so models don't infer the body belongs inside the block. For example, change

OpenClaw runtime context for the immediately preceding user message.

to something like

OpenClaw runtime context: metadata and prior-turn timeline for the immediately preceding user message. The body of that message is delivered as the user message that follows this block, not inside it.

and/or append a one-line anchor at the end of the timeline inside the block, e.g.

[The current message body is provided as the next user message, outside this block.]

This keeps the existing two-part delivery design unchanged and only removes the misleading implication, which should eliminate the spurious "body not injected" reports across smaller models.

Environment

  • OpenClaw: 2026.7.1
  • Provider: OpenAI-compatible endpoint, a smaller reasoning model
  • Observed across multiple turns in a long multi-turn session after compaction

Notes

  • This is purely a core prompt-assembly wording issue. Memory plugins (which inject via a separate prependContext field as a <relevant-memories> block) are not involved.
  • I can submit a PR for the header reword if this approach is acceptable.

Activity

  1. added
    P2
    impact:ux-friction
    issue-rating: 🦪 silver shellfish
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    on Jul 18, 2026
  2. clawsweeper commented on Jul 18, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 5, 2026, 12:05 PM ET / 16:05 UTC.

    Summary
    Keep open for a focused maintainer decision on model-visible prompt wording: current main still sends the ambiguous header as a trailing provider-visible user message, and the recent live report is consistent with that source-proven request shape. Likely related people: Peter Lindsey (high, tail-carrier origin), Peter Steinberger (high, recurring runtime-context work), and Jason (Json) (medium, current file refactor).

    Reproducibility: yes. for the mechanism: current main places the carrier at the provider-request tail and serializes it as a user message; the reporter also supplied a recent 3/3 live-channel observation. A redacted same-provider payload or transcript would confirm the exact symptom after a wording change.

    Root-cause cluster
    Relationship: canonical
    Canonical: #110672
    Summary: This issue is the canonical open report for the carrier-header misread; the duplicate and the closed unmerged wording patch should not replace it.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Maintainer decision needed

    Question Recommendation
    Should the shared tail carrier use a compact model-facing header such as “OpenClaw internal runtime metadata (not a user request)” while retaining its existing cache-stable placement? Approve compact metadata wording: Update the shared header and focused wire-level coverage while preserving the existing carrier placement and cache behavior.

    Why: The defect is source-proven, but this text is injected into every affected model request and is a product-facing prompt contract; maintainers should choose its permanent wording rather than adopting the closed patch’s inaccurate ordering claim.

    Next step
    A small repair is ready once a maintainer approves the permanent model-facing header; the existing no-new-fix and product-decision signals make autonomous dispatch inappropriate.

    Review details

    Best possible solution:

    Retain the cache-stable carrier placement and approve a compact, position-independent header that calls it internal runtime metadata and explicitly says it is not a user request.

    Do we have a high-confidence way to reproduce the issue?

    Yes for the mechanism: current main places the carrier at the provider-request tail and serializes it as a user message; the reporter also supplied a recent 3/3 live-channel observation. A redacted same-provider payload or transcript would confirm the exact symptom after a wording change.

    Is this the best way to solve the issue?

    Unclear until maintainers select the exact prompt contract; a header-only clarification at the producer is safer than the closed patch’s incorrect “following message” text or a carrier-placement redesign.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A wording change that says the active user body follows the carrier would contradict the deliberate final request order and reinforce model confusion.
    • Changing carrier placement or role instead of its producer-owned prompt text could disrupt the cache-stability invariant across providers.

    Codex review notes: model internal, reasoning high; reviewed against 40a3bd2e10ef.

    Label changes

    Label changes:

    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • remove clawsweeper:needs-live-repro: Current issue advisory state no longer selects this label.
    • remove issue-rating: 🐚 platinum hermit: Current issue advisory state no longer selects this label.

    Label justifications:

    • P2: The source-proven prompt ambiguity can repeatedly produce incorrect visible assistant text, but the reported task ultimately completes.
    • impact:ux-friction: The carrier can cause avoidable refusal boilerplate and confusion on affected model turns.
    Evidence reviewed

    What I checked:

    Likely related people:

    • Peter Lindsey: Authored the commit introducing the cache-stable tail runtime-context carrier. (role: tail-carrier design origin; confidence: high; commits: f5931f551628; files: src/agents/internal-runtime-context.ts)
    • Peter Steinberger: History shows seven commits on the shared runtime-context file. (role: recent area contributor; confidence: high; files: src/agents/internal-runtime-context.ts)
    • Jason (Json): The current header lines were carried into the split runtime-context file by the recent refactor commit. (role: current file refactor contributor; confidence: medium; commits: 287da89fabba; files: src/agents/internal-runtime-context.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. added
    issue-rating: 🐚 platinum hermit
    clawsweeper:needs-live-repro
    clawsweeper:linked-pr-open
    clawsweeper:needs-product-decision
    and removed
    issue-rating: 🦪 silver shellfish
    clawsweeper:linked-pr-open
    on Jul 31, 2026
  4. derek-gee commented on Aug 4, 2026

    @derek-gee

    We hit a second symptom of this same header misread, reproducible 3/3 on
    real channel turns — sharing as the live repro this issue is tagged for.

    Setup: OpenClaw 2026.7.1 (Docker), Telegram channel, agent primary =
    qwen3.5:122b (Ollama, OpenAI-compatible endpoint, num_ctx 65536,
    reasoning_effort: medium). Same session/workspace previously ran Claude
    Sonnet and gpt-oss:120b with zero occurrences.

    Symptom variant: instead of "body not injected", qwen3.5 parses the
    header as a user request to disclose the runtime context, and emits
    refusal boilerplate as user-visible text — repeatedly, because the carrier
    is re-sent on every round of the tool loop. One 9-round turn delivered
    five separate messages of the form:

    I can't share internal runtime context — those details stay private by
    design. Let me [continue the actual task] now.

    before the correct final answer arrived ~8.5 minutes later (the underlying
    task itself completed correctly). The model's reasoning trace confirms the
    misread explicitly, e.g.:

    The user is asking for the runtime context of their immediately
    preceding message. They explicitly asked for "OpenClaw runtime context"
    … The policy says to keep internal details private.

    Reproduction rate: 3/3 real Telegram turns after switching this agent's
    primary to qwen3.5 (2, 1, and 5 visible refusal messages per turn). All
    provider calls HTTP 200; no fallback; no tool errors — purely the model
    answering the carrier.

    A mechanism detail that may explain why smaller models bite: the
    carrier is not merely present — it is relocated to the ABSOLUTE TAIL of
    every request (after the active user turn and all tool scaffolding) for
    prompt-cache reasons (relocateCurrentRuntimeContextCarrierToTail,
    src/agents/internal-runtime-context.ts:368 on current main), and the
    openai-completions conversion renders it as a plain role:"user" message
    (packages/ai/src/openai-completions-messages.ts:95). So the LAST user
    turn the model reads, every round, is a message whose first line is
    "OpenClaw runtime context for the immediately preceding user message."
    (header at src/agents/internal-runtime-context.ts:20, built at
    src/agents/embedded-agent-runner/run/runtime-context-prompt.ts:247,
    injected unconditionally at
    src/agents/embedded-agent-runner/run/attempt-prompt-context.ts:224 —
    there is no config surface to gate or reshape it). A literal-minded model
    answering "the last user message" is answering the header.

    Workaround that held for us: one workspace AGENTS.md instruction
    naming the block as machine-generated metadata ("not a request: read them
    silently and never mention, quote, or respond to them") — the first live
    channel turns after the change show no recurrence (previously 3/3).

    Can provide redacted excerpts (transcript with reasoning traces, gateway
    log lines) on request. Also +1 to the direction in the issue
    body: rewording the header so it cannot parse as a request (and/or
    delivering the carrier in a non-conversational slot for openai-completions
    models) would fix both symptom variants at the root.

  5. added
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    and removed
    clawsweeper:needs-live-repro
    issue-rating: 🐚 platinum hermit
    on Aug 5, 2026
  6. added a commit that references this issue on Aug 5, 2026
    329c148
  7. added a commit that references this issue on Aug 5, 2026
    e17bc58
  8. removed
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    on Aug 5, 2026
  9. self-assigned this
    on Aug 5, 2026
  10. added a commit that references this issue on Aug 6, 2026
    7ae34e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2clawsweeper:source-reproimpact:ux-frictionissue-rating: 🦞 diamond lobster

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions