Skip to content

fix(agents): freeze every embedded dispatch and let harnesses declare who builds the prompt - #207022

Merged
obviyus merged 5 commits into
mainfrom
core/capture-before-dispatch
Nov 28, 2026
Merged

obviyus merged 5 commits into
mainfrom
core/capture-before-dispatch

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

#206969 stopped a fallback model from failing a turn that an earlier model had already sent without a frozen model prompt (a "projection"). It did that by tolerating the missing projection for every harness. That tolerance also hid real gaps in the embedded runner, which is supposed to freeze every turn before sending it:

  • An inter-session message (sessions_send) whose text was unchanged was sent without a projection. This is the case that failed a production turn.
  • A turn that compaction removed from the request (a keyless turn) was sent without a projection.

Fix

  • Harnesses declare who builds the prompt with a new optional field, promptProjection: "captures" | "external". The default is "external", so undeclared third-party harnesses behave as before.
    • The built-in embedded harness declares "captures". Codex declares "external", because its app-server builds its own turn input.
    • The harness lifecycle records the declaration for one attempt only. The first send locks it in, and an attempt that never sent clears it.
  • After a "captures" send, a late capture is an error again. The fix(sessions): let a fallback run after the turn was dispatched without a projection #206969 tolerance now applies only to "external" sends.
  • The embedded runner makes that true. Unchanged inter-session text is now frozen too. Before the first send of an attempt, a turn that the prompt transform could not project is frozen as its own transcript text, so no fallback ever re-captures it.
  • The new field is documented in docs/plugins/sdk-agent-harness/core-ownership.md.

User impact

None visible on the normal path. A turn the embedded runner sends now always carries the text the provider received, so a later fallback on any harness replays the same bytes. Third-party harnesses that do not declare the field keep the current behavior.

Evidence

  • Red on main, green here:
    • The compacted keyless turn is frozen before dispatch, and the retained turn keeps no projection.
    • Inter-session turns are stored with their sent envelope (plain, forwarded and hook bodies).
  • A built-in ("captures") send without a projection makes a later capture throw; an undeclared harness keeps the tolerance.
  • An attempt that never sent cannot apply its "captures" declaration to a later send outside the lifecycle.
  • Projection and fallback suites on both routes pass: embedded submit, context and boundary, the recorder, the harness lifecycle, and the Codex app-server prompt projection.

- Held, not pushed: Fable found the captures check fails fallbacks after embedded image-only
  or targetless dispatches. See DECISIONS.md D32 execution note.
…aration per attempt

- The embedded runner freezes a turn the prompt transform could not project (it left the
  request, or has no text) as its own transcript text before marking it sent.
- A harness declaration binds one attempt; an attempt that never sent clears it.
- An empty projection of a text-free turn replays without an empty text block.
…ree handling

- Fable review: skip the freeze after this attempt's first send; no producer stores a
  text-free array, so the empty-projection replay change and its tests go.
@clawsweeper

clawsweeper Bot commented Nov 27, 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 agents Agent runtime and tooling extensions: codex size: S labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR freezes previously uncaptured embedded prompts and lets harnesses declare whether they capture model-facing text.

Example: An embedded candidate sends “Continue the delegated task.” through sessions_send and then encounters a rate limit.

  • Before: The unchanged inter-session turn can reach the provider without a recorded projection.
  • After: The embedded candidate records the provenance-wrapped text before sending, and fallback candidates reuse that projection.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and has meaningful boundary regressions, but required production-path proof is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Fallback attempts can otherwise lack a frozen record of the text an earlier embedded candidate sent.
Reason: The maintainer-authored direction restores an existing prompt-stability invariant using the current recorder and lifecycle owners.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR provides a focused follow-up to the fallback repair, and no definite introduced correctness defect was found.

Reviewed head: f71f476cce6d333f210d4216d075ab85b6a33bff

Before merge

None.

Findings

None.

Agent review details

How this fits together

The harness lifecycle selects an attempt’s projection contract; the embedded submission boundary records user text through the transcript recorder before sending a provider request.

flowchart LR
  A[Admitted user turn] --> B[Harness lifecycle]
  B --> C[Embedded prompt boundary]
  B --> D[Native runtime]
  C --> E[Transcript recorder]
  E --> F[Stored projection]
  C --> G[Provider request]
  F --> B
Loading

Technical review

Best possible solution:

Keep projection enforcement in the existing recorder and freeze embedded turns at the production submission boundary while retaining native-runtime tolerance.

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

Current-main source shows unchanged inter-session turns bypassing capture, and the changed database-backed submission tests exercise both that path and a compacted keyless turn; no target code was executed during this review.

Is this the best way to solve the issue?

The patch repairs the embedded producer and keeps enforcement in the existing transcript owner, with focused changes that preserve the intentional provenance envelope and undeclared harness behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 819935f64a4a.

Provenance checked

  • Immutable model-facing prompt projection keeps the original intent (6461c18: Preserve enriched prompt bytes across follow-up requests and reopened sessions without changing visible transcript content.)
  • Unchanged inter-session capture exclusion changes intended behavior with a stated reason (fix(agents): inter-session turns rewrite the provider prompt prefix on the next turn #169238: Keep the provenance envelope identical on first send and replay while avoiding capture that required an unavailable persisted recorder.)
  • Late-capture tolerance after provider dispatch changes intended behavior with a stated reason (d22090c: Prevent every fallback candidate from failing when an earlier candidate sent a turn without a projection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 22d075f adds src/agents/embedded-agent-runner/run/attempt-llm-boundary.ts:470 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 22d075f531ff; files: src/agents/embedded-agent-runner/run/attempt-llm-boundary.ts)
  • Ayaan Zaidi: Raw commit d22090c adds src/sessions/user-turn-transcript.ts:328 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d22090cfb0e0; files: src/sessions/user-turn-transcript.ts)

PR surface

Source +59, Tests +40, Docs +8. Total +107 across 13 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 9 68 9 +59
Tests 3 62 22 +40
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 138 31 +107

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 merge-risk: 🚨 compatibility: The public harness contract gains promptProjection; the maintainer-authored direction preserves undeclared plugins through the external default and makes stricter enforcement opt-in.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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:

  • merge-risk: 🚨 compatibility: The public harness contract gains promptProjection; the maintainer-authored direction preserves undeclared plugins through the external default and makes stricter enforcement opt-in.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the production-path evidence described in missingE2e.

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 27, 2026, 6:49 PM ET / 23:49 UTC.

@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: checks-node-changed-compact-large-2 (and openclaw/ci-gate, which only reflects it).

  • Failing test: test/plugins/codex-model-catalog.gateway.test.ts > models.list selects a native user-home API-key catalog through the prepared Gateway owner, expected 2 to be greater than 2 (the model/list poll after account/updated).
  • Fails on main: the same assertion, 3 of 3 runs on d3ddad3adf41 with --testTimeout=300000, one job at a time. The PR head f71f476cce6d fails the same way 3 of 3.
  • This PR does not touch the model catalog or models.list; nothing there reads the new optional promptProjection field.
  • Owner of the failing test: W12.

@obviyus
obviyus merged commit 4266586 into main Nov 28, 2026
146 of 150 checks passed
@obviyus
obviyus deleted the core/capture-before-dispatch branch November 28, 2026 00:37
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
… who builds the prompt (#207022)

## Problem

#206969 stopped a fallback model from failing a turn that an earlier model had already sent without a frozen model prompt (a "projection"). It did that by tolerating the missing projection for every harness. That tolerance also hid real gaps in the embedded runner, which is supposed to freeze every turn before sending it:

- An inter-session message (`sessions_send`) whose text was unchanged was sent without a projection. This is the case that failed a production turn.
- A turn that compaction removed from the request (a keyless turn) was sent without a projection.

## Fix

- Harnesses declare who builds the prompt with a new optional field, `promptProjection: "captures" | "external"`. The default is `"external"`, so undeclared third-party harnesses behave as before.
  - The built-in embedded harness declares `"captures"`. Codex declares `"external"`, because its app-server builds its own turn input.
  - The harness lifecycle records the declaration for one attempt only. The first send locks it in, and an attempt that never sent clears it.
- After a `"captures"` send, a late capture is an error again. The #206969 tolerance now applies only to `"external"` sends.
- The embedded runner makes that true. Unchanged inter-session text is now frozen too. Before the first send of an attempt, a turn that the prompt transform could not project is frozen as its own transcript text, so no fallback ever re-captures it.
- The new field is documented in `docs/plugins/sdk-agent-harness/core-ownership.md`.

## User impact

None visible on the normal path. A turn the embedded runner sends now always carries the text the provider received, so a later fallback on any harness replays the same bytes. Third-party harnesses that do not declare the field keep the current behavior.

## Evidence

- Red on main, green here:
  - The compacted keyless turn is frozen before dispatch, and the retained turn keeps no projection.
  - Inter-session turns are stored with their sent envelope (plain, forwarded and hook bodies).
- A built-in (`"captures"`) send without a projection makes a later capture throw; an undeclared harness keeps the tolerance.
- An attempt that never sent cannot apply its `"captures"` declaration to a later send outside the lifecycle.
- Projection and fallback suites on both routes pass: embedded submit, context and boundary, the recorder, the harness lifecycle, and the Codex app-server prompt projection.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 4266586)

Backport adaptation: Applies cleanly after the batch fallback-projection fix; retain the source harness declaration and transcript freeze unchanged.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
… who builds the prompt (openclaw#207022)

## Problem

openclaw#206969 stopped a fallback model from failing a turn that an earlier model had already sent without a frozen model prompt (a "projection"). It did that by tolerating the missing projection for every harness. That tolerance also hid real gaps in the embedded runner, which is supposed to freeze every turn before sending it:

- An inter-session message (`sessions_send`) whose text was unchanged was sent without a projection. This is the case that failed a production turn.
- A turn that compaction removed from the request (a keyless turn) was sent without a projection.

## Fix

- Harnesses declare who builds the prompt with a new optional field, `promptProjection: "captures" | "external"`. The default is `"external"`, so undeclared third-party harnesses behave as before.
  - The built-in embedded harness declares `"captures"`. Codex declares `"external"`, because its app-server builds its own turn input.
  - The harness lifecycle records the declaration for one attempt only. The first send locks it in, and an attempt that never sent clears it.
- After a `"captures"` send, a late capture is an error again. The openclaw#206969 tolerance now applies only to `"external"` sends.
- The embedded runner makes that true. Unchanged inter-session text is now frozen too. Before the first send of an attempt, a turn that the prompt transform could not project is frozen as its own transcript text, so no fallback ever re-captures it.
- The new field is documented in `docs/plugins/sdk-agent-harness/core-ownership.md`.

## User impact

None visible on the normal path. A turn the embedded runner sends now always carries the text the provider received, so a later fallback on any harness replays the same bytes. Third-party harnesses that do not declare the field keep the current behavior.

## Evidence

- Red on main, green here:
  - The compacted keyless turn is frozen before dispatch, and the retained turn keeps no projection.
  - Inter-session turns are stored with their sent envelope (plain, forwarded and hook bodies).
- A built-in (`"captures"`) send without a projection makes a later capture throw; an undeclared harness keeps the tolerance.
- An attempt that never sent cannot apply its `"captures"` declaration to a later send outside the lifecycle.
- Projection and fallback suites on both routes pass: embedded submit, context and boundary, the recorder, the harness lifecycle, and the Codex app-server prompt projection.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* fix: show Claude CLI document uploads only once in chat

* fix: show Claude CLI document uploads only once in chat

OpenClaw-Publication: 4555cb04-bff2-43b3-aff8-ec271d6567b2

* fix: keep Claude document uploads on the message that sent them

* fix: preserve the released message queue result contract

Release adaptation: Use an optional accepted-input observer instead of widening
queueMessage's released Promise<void> contract. Reuse the stable steering and
transcript-rewrite handlers; leave source admission, native image steering,
config, and all SQLite schemas unchanged. The existing history index columns
also carry exact document correlation. Keep the released model-hook test layout.

Companion audit through be407a4: no later #203866 reference. PRs #208535
(Claude compacted fork summaries), #206158 (native subagent status), and
#205663 (image dimensions) are separate. PRs #208252 (Codex source), #207022
(embedded prompt dispatch), #206969 (fallback), #205963 (Copilot question
policy), and 50a7368 (snooze) do not own this path. SHA mentions in
#204700 and #204685 are update/qualification records, not follow-ups.

(cherry picked from commit 269f884)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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