Skip to content

Fix Codex message-tool-only reply latency#95826

Closed
omarshahine wants to merge 3 commits into
mainfrom
omarshahine/codex-message-tool-terminal
Closed

Fix Codex message-tool-only reply latency#95826
omarshahine wants to merge 3 commits into
mainfrom
omarshahine/codex-message-tool-terminal

Conversation

@omarshahine

Copy link
Copy Markdown
Contributor

What Problem This Solves

In message_tool_only source-reply mode, Codex could successfully send the visible iMessage reply through the message dynamic tool but still leave the turn waiting for assistant synthesis. That produced the slow post-send tail we saw in logs, ending in an incomplete-turn path even though the user-visible reply had already been delivered.

Why This Change Was Made

The core embedded-agent path already knows when a message-tool-only source reply is delivered and should be treated as terminal. The Codex app-server dynamic tool bridge was not carrying that source-reply mode into its dynamic-tool termination decision, so delivered implicit source replies were not marked terminal for Codex runs.

This PR exports the existing delivery detector through the harness runtime barrel, passes sourceReplyDeliveryMode into the Codex dynamic tool hook context, and marks delivered implicit message-tool-only replies as terminal. Explicit cross-channel message sends are intentionally not treated as terminal source replies.

User Impact

This benefits setups that use the Codex app-server harness with a channel configured for sourceReplyDeliveryMode: message_tool_only, including iMessage-style flows where the model replies through the message tool instead of an assistant final message.

Expected benefit: removes the avoidable post-send wait/incomplete-turn tail after a successful visible message send. It does not address the separate cold plugin/provider discovery cost or the upstream model latency before the first tool call.

Evidence

  • node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tools.test.ts -- --reporter=verbose -t "message-tool-only source replies|explicit message-tool sends"
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/message-tool-terminal.test.ts -- --reporter=verbose
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tools.test.ts -- --reporter=verbose
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.turn-watches.test.ts -- --reporter=verbose -t "visible message call"
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode local

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: imessage Channel integration: imessage extensions: codex size: M maintainer Maintainer-authored PR labels Jun 22, 2026
@omarshahine

Copy link
Copy Markdown
Contributor Author

Closing this draft in favor of #95942.

This draft was useful during investigation, but the branch also carried earlier iMessage debounce/read-receipt/docs changes from the performance stack. #95942 is the clean replacement scoped to the Codex message_tool_only source-reply completion fix.

Proof carried forward into #95942:

  • Pre-fix live iMessage run, message 861: reply was sent, then OpenClaw logged incomplete turn detected and suppressed the fallback error; processed duration 18.115s.
  • Fixed live iMessage run, message 873: iMessage tool returned { ok: true, messageId: "95F25ADC-FA98-4FBC-8988-EB9A8018143F", repliedTo: "A873644F-204D-4807-8C3E-C14B50EE4A4A" }, terminal release happened immediately after the tool result, run completed without incomplete turn detected, processed duration 18.994s.
  • Clean branch validation: focused Vitest passed for extensions/codex/src/app-server/dynamic-tools.test.ts, extensions/codex/src/app-server/event-projector.test.ts, and src/agents/embedded-agent-message-tool-source-reply.test.ts; git diff --check passed; autoreview reported no accepted/actionable findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: imessage Channel integration: imessage docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant