Skip to content

Fix Codex message-tool-only source reply completion#95942

Merged
omarshahine merged 7 commits into
mainfrom
codex/message-tool-source-reply-terminal
Jun 28, 2026
Merged

Fix Codex message-tool-only source reply completion#95942
omarshahine merged 7 commits into
mainfrom
codex/message-tool-source-reply-terminal

Conversation

@omarshahine

@omarshahine omarshahine commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Codex message_tool_only turns over iMessage could send the visible reply through the message tool, then keep the turn open because OpenClaw did not recognize that tool result as the source reply. That left the run waiting until the no-visible-answer path emitted an incomplete-turn fallback.

This was visible in live iMessage proof as a sent reply followed by incomplete turn detected and a suppressed fallback error.

Why This Change Was Made

The fix teaches the Codex dynamic tool bridge to mark delivered message_tool_only source replies as terminal only when the delivery evidence belongs to the current source route/message:

  • passes the current message id and source-reply mode into Codex dynamic tool handling
  • recognizes current-source message tool replies from route matches, native target segments, provider/channel context, and current-message reply receipts
  • keeps explicit non-source routes non-terminal, even when a receipt mentions the current message id
  • avoids using prior message-send telemetry or bare route/target telemetry as terminal delivery evidence
  • preserves tool-owned terminal message results

User Impact

Users who run Codex through a messaging channel configured with sourceReplyDeliveryMode: "message_tool_only" benefit. For iMessage, this is the setup where Codex replies by calling the message tool instead of returning a final text answer for OpenClaw to send afterward.

In that setup, OpenClaw can complete the turn immediately after the message tool returns confirmed source-reply delivery instead of waiting for the incomplete-turn fallback path.

Performance Savings

The measured live proof removed the post-delivery incomplete/fallback wait from the successful source-reply path. In the failing run, the iMessage message tool released at 17:53:40.784, but OpenClaw did not mark the turn terminal; it logged incomplete turn detected at 17:53:41.389 and then suppressed the fallback error at 17:53:41.597. That left about 0.6s to incomplete detection and about 0.8s to fallback after the visible reply had already been sent.

In the fixed run, the iMessage tool output returned at 19:31:07.225, terminal release happened at 19:31:07.231, and the message finished processing at 19:31:07.449. That is about 6ms from confirmed delivery to terminal recognition and about 224ms from confirmed delivery to processed completion, while also eliminating the spurious fallback/error path.

Evidence

Focused local validation on the clean branch after rebasing onto latest origin/main:

  • node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tools.test.ts extensions/codex/src/app-server/event-projector.test.ts src/agents/embedded-agent-message-tool-source-reply.test.ts -- --reporter=dot
    • src/agents/embedded-agent-message-tool-source-reply.test.ts: 19/19 passed
    • extensions/codex/src/app-server/dynamic-tools.test.ts + event-projector.test.ts: 168/168 passed
  • git diff --check
  • autoreview: clean, no accepted/actionable findings reported

Live iMessage proof from the equivalent patched build:

  • Failing pre-fix run, message 861:
    • received 17:53:23.516
    • run started 17:53:26.657
    • message tool release 17:53:40.784
    • incomplete turn detected at 17:53:41.389
    • suppressed error fallback at 17:53:41.597
    • processed duration 18.115s
  • Fixed run, message 873:
    • received 19:30:48.452
    • message_start 19:30:48.474
    • run started 19:30:50.276
    • Codex emitted message tool call at 19:31:01.790
    • iMessage tool output returned at 19:31:07.225 with { ok: true, messageId: "95F25ADC-FA98-4FBC-8988-EB9A8018143F", repliedTo: "A873644F-204D-4807-8C3E-C14B50EE4A4A" }
    • terminal release at 19:31:07.231
    • run completed 19:31:07.375
    • message processed 19:31:07.449, duration 18.994s
    • no incomplete turn detected
    • no suppressed error fallback

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: codex size: L maintainer Maintainer-authored PR labels Jun 23, 2026
@omarshahine
omarshahine marked this pull request as ready for review June 23, 2026 03:26
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jun 23, 2026
@omarshahine
omarshahine force-pushed the codex/message-tool-source-reply-terminal branch from 4190fac to dd61c32 Compare June 23, 2026 05:01
@clawsweeper

clawsweeper Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed June 28, 2026, 2:56 PM ET / 18:56 UTC.

Summary
The PR teaches the Codex dynamic-tool bridge to recognize delivered current-source message_tool_only replies as terminal, propagate delivery telemetry, and add regression coverage.

PR surface: Source +304, Tests +633, Other 0. Total +937 across 9 files.

Reproducibility: yes. Current main lacks the source-reply mode/current message id in the Codex dynamic-tool terminalization decision, and the PR body gives live before/after iMessage logs showing the incomplete-turn fallback disappears after the patch.

Review metrics: 1 noteworthy metric.

  • Plugin SDK public surface: 4 public exports added, 4 public function exports added. The budget increase confirms this PR expands plugin-facing API surface, which needs maintainer review before merge.

Root-cause cluster
Relationship: canonical
Canonical: #95942
Summary: This PR is the canonical open implementation candidate for the Codex/iMessage message-tool-only completion fix; related latency and cascade work is adjacent or broader follow-up work.

Members:

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

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Get maintainer approval for the new public SDK exports, or move the detector behind an approved narrow seam.
  • Enable maintainer edits or be ready to update the branch if maintainers request the SDK-seam change.

Risk before merge

  • [P1] The public Plugin SDK expansion is a compatibility decision because third-party plugins may depend on new detector helpers once they are exported.
  • [P2] A false positive in the new route/receipt classifier could suppress fallback or final output after a message-tool reply.
  • [P1] The PR has a protected maintainer-review signal and maintainerCanModify: false, so requested SDK-seam changes may require contributor updates or a replacement branch.

Maintainer options:

  1. Decide the SDK seam before merge (recommended)
    Have maintainers decide whether the detector helpers belong in public Plugin SDK; if not, move the Codex fix to a narrower approved seam before merge.
  2. Accept the detector helpers as public API
    Maintainers can intentionally accept the new exports as supported Plugin SDK API if they are comfortable with the contract and docs state for this release.
  3. Pause for a narrow replacement
    If the public SDK expansion is not worth carrying, pause this PR and land a smaller replacement that keeps the detector out of the broad SDK barrel.

Next step before merge

  • [P2] Manual maintainer review is needed for the protected label and Plugin SDK public-contract decision; this is not a safe automated repair task.

Security
Cleared: The diff changes TypeScript runtime/test logic and SDK surface budgets only; no dependency, workflow, secret, install, or downloaded-code execution surface changed.

Review findings

  • [P1] Keep source-reply detectors out of the broad SDK barrel — src/plugin-sdk/agent-harness-runtime.ts:31-34
Review details

Best possible solution:

Land the Codex terminalization fix after maintainers either approve and document the public SDK exports or move the detector behind a narrower approved seam.

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

Yes. Current main lacks the source-reply mode/current message id in the Codex dynamic-tool terminalization decision, and the PR body gives live before/after iMessage logs showing the incomplete-turn fallback disappears after the patch.

Is this the best way to solve the issue?

Mostly yes. The Codex bridge/projector is the right layer because upstream Codex dynamic-tool responses only carry returned content and success; the unresolved part is whether the detector should be public SDK API or a narrower seam.

Full review comments:

  • [P1] Keep source-reply detectors out of the broad SDK barrel — src/plugin-sdk/agent-harness-runtime.ts:31-34
    Exporting these helpers from agent-harness-runtime turns internal agent delivery classifiers into public Plugin SDK API while the PR only raises surface budgets. Please either move the Codex fix behind an approved narrow seam or add the maintainer-approved SDK contract, docs, and tests before merge.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR fixes a normal-priority Codex message-tool-only completion bug with limited channel/runtime blast radius and strong proof.
  • merge-risk: 🚨 compatibility: The diff expands public Plugin SDK by exporting internal source-reply detector helpers through agent-harness-runtime.
  • merge-risk: 🚨 message-delivery: The diff changes when Codex treats message-tool delivery as the terminal source reply, which can affect fallback and final message delivery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (logs): The PR includes redacted live iMessage before/after logs showing terminal release after message-tool delivery and no incomplete-turn fallback on the fixed run, plus later QA/Testbox validation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes redacted live iMessage before/after logs showing terminal release after message-tool delivery and no incomplete-turn fallback on the fixed run, plus later QA/Testbox validation.
Evidence reviewed

PR surface:

Source +304, Tests +633, Other 0. Total +937 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 312 8 +304
Tests 3 636 3 +633
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 2 0
Total 9 950 13 +937

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tools.test.ts extensions/codex/src/app-server/event-projector.test.ts src/agents/embedded-agent-message-tool-source-reply.test.ts test/scripts/plugin-sdk-surface-report.test.ts.
  • [P1] node scripts/run-node.mjs qa suite --provider-mode mock-openai --scenario message-tool-stranded-final-reply --concurrency 1 --fast --output-dir .artifacts/qa-e2e/message-tool-source-reply-confidence-95942.
  • [P2] node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json -- env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed.

What I checked:

Likely related people:

  • vincentkoc: Recent history touches Codex dynamic tool protocol/quarantine work and harness SDK boundary work in the affected files. (role: recent adjacent Codex runtime and SDK contributor; confidence: high; commits: ab1e5832d2fb, 3ffb3609a141, d3019e612705; files: extensions/codex/src/app-server/dynamic-tools.ts, extensions/codex/src/app-server/run-attempt.ts, src/plugin-sdk/agent-harness-runtime.ts)
  • joshavant: PR fix(agent): continue after source message tool replies #92343 introduced the related message_tool_only continuation behavior and shared detector path this PR now reuses. (role: introduced related source-reply behavior; confidence: high; commits: 462092936a5c; files: src/agents/embedded-agent-message-tool-source-reply.ts, src/agents/embedded-agent-runner/run/message-tool-terminal.ts)
  • steipete: Recent commits in the Codex dynamic-tool and agent terminal-classifier paths changed nearby behavior and tests. (role: recent adjacent Codex and terminal-outcome contributor; confidence: medium; commits: a09f6b1b2787, 0314819f918a, 7139f473332f; files: extensions/codex/src/app-server/dynamic-tools.ts, src/plugin-sdk/agent-harness-runtime.ts)
  • jalehman: Recent history touched the harness runtime SDK surface and Codex run-attempt transcript mirror path adjacent to this change. (role: recent adjacent SDK and transcript contributor; confidence: medium; commits: b5e91790630e, 258b83c4386c; files: src/plugin-sdk/agent-harness-runtime.ts, extensions/codex/src/app-server/run-attempt.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 23, 2026
@omarshahine
omarshahine force-pushed the codex/message-tool-source-reply-terminal branch from dd61c32 to d72b96b Compare June 23, 2026 23:53
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 24, 2026
@omarshahine
omarshahine force-pushed the codex/message-tool-source-reply-terminal branch from d72b96b to d5335b0 Compare June 25, 2026 02:32
@omarshahine
omarshahine force-pushed the codex/message-tool-source-reply-terminal branch from d5335b0 to 432b941 Compare June 27, 2026 22:48
@clawsweeper clawsweeper Bot added 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 rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 27, 2026
@omarshahine
omarshahine force-pushed the codex/message-tool-source-reply-terminal branch from 432b941 to f6a06ae Compare June 28, 2026 18:49
@omarshahine
omarshahine merged commit 9b9a124 into main Jun 28, 2026
95 checks passed
@omarshahine
omarshahine deleted the codex/message-tool-source-reply-terminal branch June 28, 2026 19:02
@omarshahine

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
* fix(codex): recognize message tool source replies

* fix(codex): accept numeric source message ids

* fix(codex): account for source reply SDK surface

* fix(codex): require delivered reply receipts

* fix(codex): reject alias-routed source replies

* fix(codex): require delivered non-send telemetry

* fix(codex): honor normalized source routes

---------

Co-authored-by: Omar Shahine <[email protected]>
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
* fix(codex): recognize message tool source replies

* fix(codex): accept numeric source message ids

* fix(codex): account for source reply SDK surface

* fix(codex): require delivered reply receipts

* fix(codex): reject alias-routed source replies

* fix(codex): require delivered non-send telemetry

* fix(codex): honor normalized source routes

---------

Co-authored-by: Omar Shahine <[email protected]>
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
* fix(codex): recognize message tool source replies

* fix(codex): accept numeric source message ids

* fix(codex): account for source reply SDK surface

* fix(codex): require delivered reply receipts

* fix(codex): reject alias-routed source replies

* fix(codex): require delivered non-send telemetry

* fix(codex): honor normalized source routes

---------

Co-authored-by: Omar Shahine <[email protected]>
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 3, 2026
* fix(codex): recognize message tool source replies

* fix(codex): accept numeric source message ids

* fix(codex): account for source reply SDK surface

* fix(codex): require delivered reply receipts

* fix(codex): reject alias-routed source replies

* fix(codex): require delivered non-send telemetry

* fix(codex): honor normalized source routes

---------

Co-authored-by: Omar Shahine <[email protected]>
becksclair added a commit to becksclair/openclaw that referenced this pull request Jul 7, 2026
…urn termination

Upstream openclaw#95942 (v2026.7.1-beta.1 base) classifies every delivered
implicit-route message(action=send) as the completed source reply and
releases the Codex app-server turn, which turned mid-turn progress
updates into turn-enders. Adds an optional progress boolean to the
message tool send schema; progress sends are excluded from source-reply
classification (shared classifier + codex receipt-confirmed path) and
do not set didDeliverSourceReplyViaMessageTool. Fork carry documented
in bex-fork.md; upstream-PR candidate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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