Repository navigation
Description
Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
The OpenClaw runtime invokes installed AgentToolResultMiddleware handlers without available agent, session, or run identity, even though those fields are part of the public middleware context and the Codex runtime forwards them.
Steps to reproduce
- On OpenClaw 2026.7.1, enable an installed plugin whose manifest declares
agentToolResultMiddleware: ["openclaw", "codex"]. - Register middleware that records only whether
ctx.agentId,ctx.sessionId,ctx.sessionKey, andctx.runIdare present. - Execute a harmless tool call through the OpenClaw runtime.
- Execute an equivalent harmless tool call through the Codex runtime with known agent/session/run context.
- Compare only the presence booleans.
Expected behavior
When the OpenClaw tool-result bridge has agent/session/run context, it should pass that context to createAgentToolResultMiddlewareRunner, matching the public AgentToolResultMiddlewareContext shape and the Codex integration.
Public references:
- The context type declares optional
agentId,sessionId,sessionKey, andrunId:openclaw/src/plugins/agent-tool-result-middleware-types.ts
Lines 23 to 30 in 345083a
export type AgentToolResultMiddlewareContext = { runtime: AgentToolResultMiddlewareRuntime; /** @deprecated Use runtime. */ harness?: AgentToolResultMiddlewareRuntime; agentId?: string; sessionId?: string; sessionKey?: string; runId?: string; - The Codex integration constructs its runner with
runtime: "codex"plus its tool-result hook context:openclaw/extensions/codex/src/app-server/dynamic-tools.ts
Lines 187 to 190 in 345083a
function readRouteToken(record: Record<string, unknown>, key: string): string | number | undefined { const value = record[key]; return typeof value === "string" || typeof value === "number" ? value : undefined; }
Actual behavior
The OpenClaw integration constructs the runner with only { runtime: "openclaw" }, despite receiving runId in the surrounding factory and retaining a session manager:
openclaw/src/agents/embedded-agent-runner/extensions.ts
Lines 52 to 56 in 345083a
| function buildAgentToolResultMiddlewareFactory( | |
| sessionManager: SessionManager, | |
| runId?: string, | |
| ): ExtensionFactory { |
As a result, middleware sees ctx.agentId, ctx.sessionId, ctx.sessionKey, and ctx.runId as absent on the OpenClaw path. The same middleware therefore cannot attribute or scope OpenClaw events at parity with Codex.
OpenClaw version
2026.7.1
Operating system
macOS
Install method
NOT_ENOUGH_INFO
Model
NOT_ENOUGH_INFO
Provider / routing chain
NOT_ENOUGH_INFO
Additional provider/model setup details
NOT_ENOUGH_INFO
Logs, screenshots, and evidence
No raw logs are included. The reproduction records presence booleans only. The public source links above show the context-construction difference directly.
Impact and severity
- Affected: installed middleware that performs per-agent/per-session audit, telemetry, or policy decisions on the OpenClaw runtime.
- Severity: medium; tool calls still complete, but middleware attribution and session scoping are unavailable.
- Frequency: every observed OpenClaw middleware invocation on 2026.7.1.
- Consequence: middleware must label OpenClaw events as unknown or fail closed; it cannot prove the expected agent/session identity for a denial canary.
Additional information
A focused regression test could construct the OpenClaw middleware runner from a known embedded run context and assert parity with the Codex path for agentId, sessionId, sessionKey, and runId.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jul 14, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 13, 2026, 8:26 PM ET / July 14, 2026, 00:26 UTC.
Summary
Keep open: current main still constructs OpenClaw tool-result middleware without execution identity, while the public middleware contract and Codex sibling path support carrying that context. No merged fix or canonical related item was found.
Likely related people
steipete— medium-confidence recent contributor to the embedded agent runtime.shakkernerd— medium-confidence contributor to recent run/session-context refactors.Reproducibility: yes. at source level: current main visibly discards the available
runId, and the public context plus sibling Codex implementation establish the expected path. A live plugin invocation was not executed during this read-only review.Next step
The defect has a narrow owner boundary, an existing context contract, a clear sibling implementation, and a focused regression-test path with no product-direction decision.
Review details
Best possible solution:
Forward canonical prepared agent, session, and run identifiers from the embedded-run attempt into the middleware runner, without request-time rediscovery, and add focused parity coverage for both OpenClaw and Codex contexts.
Do we have a high-confidence way to reproduce the issue?
Yes at source level: current main visibly discards the available
runId, and the public context plus sibling Codex implementation establish the expected path. A live plugin invocation was not executed during this read-only review.Is this the best way to solve the issue?
Yes, with one boundary constraint: pass the canonical prepared identifiers through the existing factory rather than querying the session manager during every tool result.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
sessionIdversussessionKey; deriving either from mutable session-manager state inside the tool-result hot path could associate middleware events with the wrong session.Codex review notes: model internal, reasoning high; reviewed against 0559bc22e0f6.
Label changes
Label justifications:
P2: This is a bounded public-middleware correctness bug affecting attribution and policy decisions without crashing the core runtime.impact:session-state: Tool-result middleware cannot reliably associate OpenClaw events with their agent, session, or run context.Evidence reviewed
Acceptance criteria:
What I checked:
{ runtime: "openclaw" }, so the runner cannot expose even the already-prepared run identity. (src/agents/embedded-agent-runner/extensions.ts:753, 0559bc22e0f6)src/plugins/agent-tool-result-middleware-types.ts:361, 0559bc22e0f6)extensions/codex/src/app-server/dynamic-tools.ts:324, 0559bc22e0f6)docs/plugins/sdk-migration.md. (docs/plugins/sdk-migration.md:668, 0559bc22e0f6)../codex/codex-rs/app-server/src/dynamic_tools/core.rs:279)src/agents/embedded-agent-runner/extensions.ts:753, 2d2ddc43d0dc)Likely related people:
src/agents/pi-embedded-runner/run/attempt.ts,src/agents/embedded-agent-runner/extensions.ts)src/agents/pi-embedded-runner/run/attempt.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.ruel225 commentedon Jul 14, 2026
Looking into this — PR #107023 adds agentId, sessionId, sessionKey, and runId to the OpenClaw tool result middleware context.
3 remaining items
ruel225 commentedon Jul 16, 2026
Reopened as #108952 (previous PR #107023 was closed due to stuck ClawSweeper review).
fix(agents): preserve tool-result middleware identity (#115821)
fix(agents): preserve tool-result middleware identity (openclaw#115821)