Skip to content

fix(agents): preserve tool-result middleware identity - #115821

Merged
steipete merged 1 commit into
mainfrom
codex/s18-tool-result-middleware-identity
Jul 29, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/s18-tool-result-middleware-identity

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #106910
Supersedes #107000. Preserves @SebTardif's original design and Git co-author credit.

AI-assisted: yes; the behavior, current owner paths, regression evidence, and exact upstream Codex contracts were independently reviewed.

What Problem This Solves

Fixes an issue where plugins using installed agent-tool-result middleware could not identify which OpenClaw agent, session, or run executed a tool. Per-session auditing, telemetry, and policy therefore received only runtime: "openclaw", even though the corresponding Codex integration already carries the prepared execution identity.

Why This Change Was Made

Capture the already prepared agent ID, session ID, session key, and run ID once when building the existing middleware runner. Thread the effective identity through both current owner call sites: ordinary embedded attempts and the current compaction-session execution path. Resolve the session-manager fallback once at factory construction, never in the tool-result hot path.

The original contributor PR #107000 is no longer mergeable against current main: compaction factory ownership has moved from its old compact.ts call site into compaction-session-execution.ts. This maintainer successor carries forward @SebTardif's fix without adding a product proof script, changing Knip configuration, or preserving stale ownership.

User Impact

Installed plugins receive the same available agent, session, and run identity for OpenClaw tool results that Codex tool-result middleware already receives. Ordinary runs and compaction runs retain their correct prepared owner, and all existing tool-result mutation, error, messaging, safeguard, and cross-runtime behavior is preserved.

Evidence

  • Independently reproduced both normal and compaction identities with a real installed plugin registry, production extension loading, the real ExtensionRunner, and an actual tool_result event on Blacksmith Testbox tbx_01kypjr5vcysqs573z8y6660t2.
  • Before: both new end-to-end cases fail because the real middleware receives only { runtime: "openclaw" }; all 13 existing controls pass.
  • After: the same installed plugin receives the exact prepared agent, session, session-key, and run identity for both runs and the transformed tool result remains visible.
  • Proved the existing Codex sibling and upstream protocol directly at openai/codex@fe01054a28fa4bd04716d9ceadb410f2443a50ce: codex-rs/app-server-protocol/src/protocol/v2/item.rs, codex-rs/app-server/src/bespoke_event_handling.rs, and codex-rs/protocol/src/dynamic_tools.rs.
  • Passed all 588 tests across 21 exact owner/sibling suites and 8 Vitest shards, covering embedded attempts, compaction, middleware, installed Tokenjuice, and Codex dynamic-tool/native ownership.
  • Passed pnpm check:test-types, the exact four-file pnpm check:changed -- ..., and all three official hard-zero pnpm deadcode:exports Knip scans: production exports, full-tree exports, and script exports.
  • Fresh gpt-5.6-sol structured autoreview at xhigh: no accepted or actionable findings.

Fixes #106910.

Preserve the contributor design from #107000 while updating both the normal and current compaction owner paths.

Co-authored-by: Sebastien Tardif <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 29, 2026
@steipete
steipete merged commit bed7014 into main Jul 29, 2026
192 of 198 checks passed
@steipete
steipete deleted the codex/s18-tool-result-middleware-identity branch July 29, 2026 10:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

pull Bot pushed a commit to yann0001/openclaw that referenced this pull request Jul 29, 2026
* origin/main:
  fix(codex): restore connected apps for token-authenticated runs (openclaw#115075)
  fix(codex): classify hosted search timeouts (openclaw#115837)
  fix(msteams): keep attachment replies in channel threads (openclaw#94348)
  fix(telegram): linkPreview:false is ignored on streamed replies (openclaw#114125)
  fix(protocol): make Swift model checks non-mutating (openclaw#115793)
  fix(searxng): avoid duplicating search endpoint (openclaw#113661)
  fix(agents): preserve tool-result middleware identity (openclaw#115821)
  refactor(meetings): consolidate runtime facades (openclaw#115819)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
Fixes openclaw#106910.

Preserve the contributor design from openclaw#107000 while updating both the normal and current compaction owner paths.

Co-authored-by: Sebastien Tardif <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* origin/main:
  fix(codex): restore connected apps for token-authenticated runs (openclaw#115075)
  fix(codex): classify hosted search timeouts (openclaw#115837)
  fix(msteams): keep attachment replies in channel threads (openclaw#94348)
  fix(telegram): linkPreview:false is ignored on streamed replies (openclaw#114125)
  fix(protocol): make Swift model checks non-mutating (openclaw#115793)
  fix(searxng): avoid duplicating search endpoint (openclaw#113661)
  fix(agents): preserve tool-result middleware identity (openclaw#115821)
  refactor(meetings): consolidate runtime facades (openclaw#115819)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenClaw AgentToolResultMiddleware omits agent/session/run context

1 participant