Skip to content

fix(agents): stabilize message tool definitions across session turns - #181279

Merged
steipete merged 2 commits into
mainfrom
steipete/prompt-prefix-restart
Oct 23, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/prompt-prefix-restart

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sub-agent fleet parents lost large parts of their prompt cache around Gateway restarts and child announcements. Tapped Responses request bodies from one parent session showed two causes.

1. The message tool definition was built from the current turn's source. message-tool-execution.ts passed the turn's channel, message, sender and authority into discovery. An operator-CLI turn advertised "Supports actions: broadcast, send." with enum [broadcast, send]. The restart-recovered and WebChat-sourced announce turns of the same session advertised "Supports actions: react, send. When the current WebChat prompt permits reactions, react…" with enum [react, send], and the definition flipped back afterwards. Each flip broke the cached prefix:

[prompt-cache] cache read dropped 43093 -> 26113 … tools(7 -> 7 tools; description: "message"; schema: "message")

This violates the prompt-prefix contract: tool definitions may depend only on session and config facts.

2. A false "history must be append-only" warning. message 31 (assistant) differs from the previous request; history must be append-only; changed fields: envelope.other was caused by persistence adding display: false (transcript-visibility.ts). The tapped provider bodies were byte-identical; the Responses converter omits that field.

User Impact

Fleet parents retain a stable message-tool definition across CLI, recovery, and child-announcement turns, preserving prompt-cache reuse. Persistence-only visibility metadata no longer triggers false history-rewrite warnings. No migration or operator action is required.

Why This Change Was Made

  • message tool discovery uses session and config facts only, keeping the session's persisted delivery account and the scheduled creator account, so non-default-account capabilities such as iMessage edit for a bound ops account are preserved. Per-turn facts no longer shape the definition. WebChat reaction guidance is stable, and execution checks the current grant, reporting an unavailable reaction clearly. Both synchronous and async factories are covered.
  • The prompt-cache history fingerprint excludes the persistence-only display field. A regression asserts byte-identical output from the real Responses converter.

Evidence

  • Red on base: agent-tools.prefix-stability.test.ts "keeps message definitions stable across CLI…" (2 failed), and prompt-cache-observability.history.test.ts "keeps recovered coordination history stable" (1 failed, prefix changed within session).
  • Green on a Crabbox host (Node 24.22.1), 288 tests: prefix-stability (8), message-tool.scheduled-writes (10, including the preserved iMessage non-default-account case), message-tool-discovery (40), prompt-cache history (43), current-prompt reaction (18), message-tool-execution (68), discovery enumeration (3), message-tool (98). pnpm prompt:snapshots:check reports snapshots current; format, lint and targeted typechecks pass.
  • Live Crabbox, Gateway kill -9 while two fleet parents were still in their first turn, with every Responses body recorded:
    • main: a message definition flip on the recovery turn and back on the yield turn, cache drops of 43K→26K and 63K→0, and the append-only warning.
    • this branch: 0 cache drops, 0 append-only warnings, and an identical message definition across every consecutive request of both parents.

Follow-up, not in this PR: settle-wake requests switch prompt_cache_key to an openclaw-webchat-… affinity key and back. That's a separate cache-identity owner, handled in its own PR.

CI follow-up: the snapshot reconstruction test still expected Discord's old override list (sessions_spawn only), while the regenerated catalog correctly contains both message and sessions_spawn. The exact list expectation is updated without weakening the assertion. The failure reproduced on Crabbox before the repair; all 13 tests in test/scripts/prompt-snapshots.test.ts pass afterward.

Discover message actions from persisted session delivery and scheduled account
bindings, preserving non-default capabilities across recovery and announce
turns. Keep current-prompt reactions gated by live turn authority.

Exclude persistence-only display metadata from prompt history fingerprints.
@clawsweeper

clawsweeper Bot commented Oct 23, 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.

@steipete
steipete marked this pull request as ready for review October 23, 2026 03:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T03:41:15.065643Z ebf5871 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: a2b1b4f37fee1cd466fe4a8c27d3efeb3a314e0b
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/tools/message-tool-turn-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR builds message definitions from session facts and excludes persistence-only display metadata from prompt history fingerprints.

Example: A fleet parent resumes after a Gateway restart through a WebChat-sourced announcement.

  • Before: Its message definition changes from broadcast/send to react/send, invalidating the reusable prefix.
  • After: The session keeps the same message definition across CLI, recovery, and announcement turns.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Reported shipped-Gateway evidence supports the central repair, but native-account compatibility and an exact-head CI failure prevent a clean correctness verdict.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports live Crabbox Gateway restart comparisons covering message-definition stability and persistence-only warning removal.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Fleet parent sessions repeatedly lose reusable prompt prefixes during recovery and child announcements and receive misleading history-rewrite warnings.
Reason: The maintainer-authored direction restores the documented stable-tools contract without adding configuration or a new state owner.

Merge readiness

⛔ Needs changes before merge - 3 items remain

This maintainer-authored PR addresses a current prompt stability defect, but native scheduled-account discovery and a diff-caused snapshot test failure need correction.

Priority: P2
Reviewed head: ebf587157e8bcc6c0b3ff82a7de780fb73b3c8f8

Before merge

  • Preserve the native requester account when caller origin is unknown (P2) - Native Discord scheduled jobs can retain an authenticated channelRequester with an unknown callerOrigin, as supported by cron provenance normalization and service.channel-requester.test.ts. Previously, matching requester.accountId added Discord to the creator-account discovery scope even in that case. This resolver now returns undefined, and the old requester fallback is deleted. With requester account ops, persisted Discord delivery account delivery, ops.actions.channels=true, and delivery.actions.channels=false, discovery uses delivery and removes channel-edit despite the job retaining native edit authority. Preserve that saved requester account through session-based discovery without restoring dependence on temporary turn authority.
  • Update the reconstruction test for the new message override (P2) - Adding this message replacement changes the Discord override keys to [message, sessions_spawn], but test/scripts/prompt-snapshots.test.ts still expects [sessions_spawn]. The exact-head checks-node-compact-small-3 job fails at line 109 with that mismatch. Update the expected replacement inventory while retaining the full reconstructed-catalog equality check.
  • Explain or restore the original intent of Native scheduled requester discovery - 9ee5c26: Discover through the saved native requester account even when delivery uses another account; the replacement does not explain removal of the unknown-origin requester fallback.

Findings

  • [P2] Preserve the native requester account when caller origin is unknown — src/agents/tools/message-tool-discovery.ts:278-283
  • [P2] Update the reconstruction test for the new message override — test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/codex-dynamic-tools.discord-group.json:3-4

Provenance

  • Native scheduled requester discovery changes intended behavior without addressing why it exists (9ee5c26: Discover through the saved native requester account even when delivery uses another account; the replacement does not explain removal of the unknown-origin requester fallback.)
Agent review details

How this fits together

Agent tool assembly projects session and channel configuration into provider-facing definitions, while message invocation separately resolves current authority before channel effects.

flowchart TD
  A[Session and configuration] --> B[Message discovery]
  B --> C[Provider tool definition]
  C --> D[Model tool call]
  D --> E[Live turn authority]
  E --> F[Channel action]
  A --> G[History fingerprints]
Loading

Technical review

Best possible solution:

Keep session-based definitions, preserve native scheduled requester account discovery, and update the snapshot reconstruction expectation.

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

Current-main discovery consumes changing ingress facts, and the PR reports red-on-base regressions plus comparative Gateway restart results; this review executed no target code.

Is this the best way to solve the issue?

Separating session discovery from live invocation authority is the appropriate owner-level fix, provided the existing native scheduled-account contract survives the cutover.

Full review comments:

  • [P2] Preserve the native requester account when caller origin is unknown — src/agents/tools/message-tool-discovery.ts:278-283
    Native Discord scheduled jobs can retain an authenticated channelRequester with an unknown callerOrigin, as supported by cron provenance normalization and service.channel-requester.test.ts. Previously, matching requester.accountId added Discord to the creator-account discovery scope even in that case. This resolver now returns undefined, and the old requester fallback is deleted. With requester account ops, persisted Discord delivery account delivery, ops.actions.channels=true, and delivery.actions.channels=false, discovery uses delivery and removes channel-edit despite the job retaining native edit authority. Preserve that saved requester account through session-based discovery without restoring dependence on temporary turn authority.
    Confidence: 0.89
  • [P2] Update the reconstruction test for the new message override — test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/codex-dynamic-tools.discord-group.json:3-4
    Adding this message replacement changes the Discord override keys to [message, sessions_spawn], but test/scripts/prompt-snapshots.test.ts still expects [sessions_spawn]. The exact-head checks-node-compact-small-3 job fails at line 109 with that mismatch. Update the expected replacement inventory while retaining the full reconstructed-catalog equality check.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9c05ca0d6ece.

Provenance checked

  • Stable message definitions keeps the original intent (b326dc0: Retain definitions across turn kinds and enforce per-turn permission at invocation.)
  • Bound-channel discovery keeps the original intent (536a87a: Reduce unrelated channel schema overhead while preserving account capabilities and delivery authorization.)
  • Persistence-only history metadata keeps the original intent (a770f7b: Exclude metadata absent from provider messages while retaining content and tool identity diagnostics.)
  • Snapshot representation keeps the original intent (c406ef4: Reconstruct full fixtures from canonical content and deterministic deltas; earlier fixture-name history was inspected, although one historical blob request encountered a local missing-object limit.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/tools/message-tool.scheduled-writes.test.ts src/agents/tools/message-tool-discovery.test.ts src/agents/agent-tools.prefix-stability.test.ts --maxWorkers=1
  • pnpm test test/scripts/prompt-snapshots.test.ts --maxWorkers=1
  • pnpm prompt:snapshots:check
  • git diff --check

What I checked:

  • Current main retains the reported source-dependent discovery: Fetched main passes current channel, message, account, sender, and turn-derived scheduled scope into message discovery; the introduced patch replaces those inputs with session-derived facts. (src/agents/tools/message-tool-execution.ts:153, 9c05ca0d6ece)
  • Exact-head CI identifies a patch-caused failure: The checks-node-compact-small-3 annotation reports test/scripts/prompt-snapshots.test.ts:109 expecting only sessions_spawn while the changed Discord fixture contains message and sessions_spawn. (test/scripts/prompt-snapshots.test.ts:109, ebf587157e8b)
  • Native requester discovery has an intentional historical contract: fix: retain the native requester for scheduled Discord edits #150308 explicitly preserves discovery through the saved native account independently of delivery; its implementation adds Discord requester scope even when caller origin cannot supply that channel. (src/agents/tools/message-tool-turn-authority.ts:43, 9ee5c26f4080)
  • Unknown-origin native requesters remain supported: Cron provenance normalization retains authenticated channelRequester facts without a known callerOrigin, and the service suite explicitly exercises that combination. (src/cron/service.channel-requester.test.ts:63, ebf587157e8b)
  • Live invocation checks remain separate: beginInvocation still resolves current authorization, and execution rechecks it after awaited preparation and passes current assertions into outbound dispatch; stored discovery facts do not authorize effects. (src/agents/tools/message-tool-execution.ts:257, ebf587157e8b)
  • Runtime evidence and review authority: The full PR body reports comparative live Crabbox restart runs with stable candidate definitions and no cache-drop or append-only warnings; the security guard confirms maintainer access and requires no secops approval. (ebf587157e8b)

Likely related people:

  • Peter Steinberger: Raw commit a770f7b adds src/agents/embedded-agent-runner/prompt-cache-history.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a770f7b30929; files: src/agents/embedded-agent-runner/prompt-cache-history.ts)
  • Shakker: Raw commit e3e3a34 adds src/agents/tools/message-tool-turn-authority.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e3e3a349b905; files: src/agents/tools/message-tool-turn-authority.ts)
  • Ayaan Zaidi: Raw commit b326dc0 adds src/agents/agent-tools.prefix-stability.test.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b326dc020122; files: src/agents/agent-tools.prefix-stability.test.ts)

PR surface

Source +94, Tests +473, Docs +3. Total +570 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 138 44 +94
Tests 7 522 49 +473
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 666 96 +570

Labels

Label changes:

  • add P2: This repairs prompt-cache invalidation in recovery and announcement workflows, with focused correctness and validation repairs remaining.
  • add merge-risk: 🚨 compatibility: Replacing native requester scope with caller-origin-only scope can remove previously available scheduled Discord actions for a non-default account.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This repairs prompt-cache invalidation in recovery and announcement workflows, with focused correctness and validation repairs remaining.
  • merge-risk: 🚨 compatibility: Replacing native requester scope with caller-origin-only scope can remove previously available scheduled Discord actions for a non-default account.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Preserve native requester discovery and verify unknown-origin jobs with a different delivery account.
  • Correct the snapshot replacement expectation and pass its reconstruction suite.

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 October 22, 2026, 11:54 PM ET / October 23, 2026, 03:54 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

The snapshot reconstruction finding is fixed in a2b1b4f, with all 13 snapshot tests passing and final-head CI green.

Follow-up from the completed review: preserve saved native Discord requester-account discovery for scheduled jobs with an unknown caller origin and a different delivery account. Per the scoped landing instruction, this capability-availability edge case is deferred; the review reports no security finding. It remains separate from this prompt-prefix repair.

@steipete
steipete merged commit 35cb5aa into main Oct 23, 2026
139 of 142 checks passed
@steipete
steipete deleted the steipete/prompt-prefix-restart branch October 23, 2026 04:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…penclaw#181279)

Stabilize message tool definitions across CLI, restart recovery, and subagent announcement turns by deriving discovery from session and config facts. Preserve persisted delivery and scheduled creator accounts while keeping live execution authority checks. Exclude persistence-only display metadata from prompt-history fingerprints.

Align the Discord snapshot reconstruction expectation with the regenerated message override. The failure reproduced before the repair; all 13 snapshot tests pass after it. Coordinator proof covers 288 focused tests and a live restart comparison, and CI is green for the final head.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant