Skip to content

fix(agents): preserve pending reply delivery custody - #170937

Merged
steipete merged 2 commits into
mainfrom
codex/qa1122-pending-custody
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/qa1122-pending-custody

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes duplicate replacement replies when the original source reply may already have been sent but delivery is still pending. This is a corrective follow-up to #170916.

User Impact

Pending delivery now holds replacement text, attachments, errors, heartbeat responses, and timeout-recovered answers until the outcome is known. Already committed reply mirrors, their owned attachments, and answers for preceding inputs remain available. Confirmed missing delivery still produces the appropriate answer or error. No configuration or migration is required.

Why This Change Was Made

Delivery has three states: delivered, pending, and missing. The payload owner previously treated pending like missing. In addition, terminal preparation discarded the delivery observation supplied by settled-turn finalization, allowing its payloads to disagree with the terminal result's state.

Terminal preparation now reconciles attempt and observed delivery through the existing resolver once and carries that fact into payload selection, receipts, media merging, timeout recovery, and the returned prepared result. The per-input payload owner retains pending custody without falsely marking it delivered. Heartbeat response selection follows the same state. Current and carried terminal media is held without consuming the carry, so a later missing observation can release it.

Evidence

Negative tests reproduced duplicate text/media, provider errors, tool warnings, remote attachment reads, heartbeat replies, and timeout recovery. Actual settled-turn finalization through terminal resolution reproduced nine ordinary-path failures and seven heartbeat-path failures before their fixes, while missing-delivery controls continued to pass. The regressions preserve earlier-input answers and committed tool-authored media and verify delivered-state precedence.

261 distinct focused tests across eight files pass, including 27 actual terminal-composition cases and finalizer admission/re-observation controls. Core and owning test typechecks, scoped lint, formatting, and independent complete-patch review through P2 pass. Final focused groups took 125.621 and 88.303 seconds including worker compilation; the affected finalizer controls took 23.654 seconds. Fresh exact-head GitHub CI is pending; previous-head CI is not treated as proof of this expanded correction. These tests exercise real production composition with deterministic fixtures; they do not claim a real external channel send. This changes backend reply selection, with no UI layout change.

Keep unresolved source delivery separate from missing delivery when selecting replacement answers, attachments, and errors. Preserve committed mirrors and recovery for later steered inputs with missing delivery. Corrects the pending-custody case from #170916.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling labels Oct 13, 2026
@steipete
steipete marked this pull request as ready for review October 13, 2026 10:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T10:45:38.681647Z 657c28e New commits
ℹ️ 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.

@steipete
steipete enabled auto-merge (squash) October 13, 2026 10:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cdaa942cd2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +192 to +193
if (sourceReplyDeliveryState === "pending") {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass observed custody into payload selection

When resolveReplyDelivery reports pending or throws, settled-turn-finalization.ts passes that fact as replyDeliveryState, but terminal-preparation.ts:192-226 never forwards input.replyDeliveryState to buildEmbeddedRunPayloads; its spread supplies only the attempt's normally missing state. This guard and the warning guard are therefore bypassed in the real embedded-agent terminal path, leaving replacement answer, attachment, or error payloads that outer dispatch can deliver even though the result is marked pending. Pass the effective observed state into the payload builder and cover this production composition.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 657c28e. Terminal preparation now reconciles attempt and observed delivery through the existing resolver and passes that state to payload construction, receipts, media merging, timeout recovery, and the prepared result. Actual settled-finalization-to-terminal-resolution regressions reproduced the discarded observation for text, errors, media, and timeout recovery; heartbeat bypasses are covered too. The complete patch passes independent P2 review and 261 focused tests. Fresh CI is running for this head; the earlier green run is not used for this correction.

@steipete
steipete disabled auto-merge October 13, 2026 10:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 657c28e23f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +231 to +233
const payloadsWithToolMedia =
replyDeliveryState === "pending"
? payloads

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve earlier-input media while current delivery is pending

When a steered run has undelivered tool media from an earlier input and the current input's delivery observation is pending, this branch returns the attempt's preceding-input payloads without calling mergeToolMedia. pendingToolMediaUrls is not cleared when a new user message seals an answer segment, so attempt.toolMediaUrls can still belong to the earlier payload that remains deliverable; the result then contains that earlier text but silently drops its attachment. Scope the pending suppression to current-input media rather than bypassing the attempt-wide merge.

AGENTS.md reference: src/agents/AGENTS.md:L28-L31

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 9354a2c into main Oct 13, 2026
124 of 129 checks passed
@steipete
steipete deleted the codex/qa1122-pending-custody branch October 13, 2026 11:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
* fix(agents): preserve pending reply delivery custody

Keep unresolved source delivery separate from missing delivery when selecting replacement answers, attachments, and errors. Preserve committed mirrors and recovery for later steered inputs with missing delivery. Corrects the pending-custody case from openclaw#170916.

* fix(agents): propagate observed delivery custody through terminal preparation
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 size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant