Skip to content

fix(gateway): preserve recorded replies when chat completion settles - #147656

Merged
vincentkoc merged 3 commits into
mainfrom
fix/chat-wait-terminal-reply
Sep 14, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
fix/chat-wait-terminal-reply

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: a chat-scoped agent.wait loses the run's recorded reply and receipt, and can report success after an authoritative timeout or cancellation.

User Impact

A completed chat wait returns the same recorded reply and canonical outcome as the run owner, while still waiting for chat delivery to finish. Silent or empty replies remain intentional outcomes; no transcript-history guessing is added.

Why This Change Was Made

Require the selected chat completion before merging its same-run lifecycle observation through the existing terminal outcome and reply owners. A separate agent request with the same identifier cannot satisfy or contaminate that chat wait.

This repairs the Gateway completion contract used by public Ask OpenClaw App Intents: #147668.

Evidence

  • The test-only control at 23ba71221f6478d15603039e80c4120c1e560a0b reproduced exactly eight intended failures in CI attempt 1, with 4,367 tests passing and five skipped in that shard.
  • Regression coverage preserves the original waiter-before-lifecycle-before-chat order, the chat readiness barrier, visible/silent/empty replies, and sticky timeout/cancellation in both cached arrival orders. Existing sibling coverage protects independent agent-source selection and reset behavior.
  • Repaired head 6664cc5 passed all 16 settlement cases in Gateway core1, including the original eight failures, and all 19 dedupe siblings in Gateway core2.
  • Current signed head 6e054798584e5e9d6b9014c12b18da147dbdd494 composes main 3cfc0ade66c68092051ec372632bf6d71611e8e2, including the canonical QA fixture repair from fix(ci): tooling shard fails on QA Profile Evidence routing after #143968 #147293. The two-file wait patch payload is unchanged; independent integration review and diff checks passed. Main adds one settlement test, so this head has 17 cases.
  • Normal PR CI attempt 1 passed at head 6e054798584e5e9d6b9014c12b18da147dbdd494: 119 jobs succeeded, 17 were intentionally out of scope, and none failed. The tested merge commit was 0627265442a6268aee112c3a19c0d51f6587b44e, with that exact head as a parent.
  • All 17 settlement cases passed in job 103834754737, and all 21 dedupe siblings passed in job 103834754790. The original eight failures are repaired. Workflow Sanity and the required CI gate passed.
  • ClawSweeper revision 3 covers the current head and reports no actionable findings or remaining pre-merge items. Production adds six lines at the canonical completion owner; regression tests add 104.

Release-validation follow-up: the SDK API diff snapshot worker exhausted its 6 GiB heap in both test-only control and repaired-head manual CI. The report scripts are outside this repair; normal PR CI intentionally does not run that release-only report. This stack does not claim to fix the heap failure.

@vincentkoc vincentkoc self-assigned this Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 10:10 PM ET / September 14, 2026, 02:10 UTC (Revision 3).

ClawSweeper review

What this changes

Preserves recorded replies, receipts, and canonical failure outcomes when a chat-scoped completion wait finishes, with regression coverage for event ordering.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main and v2026.9.4. No introduced correctness defect was found; the patch preserves the delivery barrier while reusing existing outcome and reply precedence.

Priority: P2
Reviewed head: 6e054798584e5e9d6b9014c12b18da147dbdd494

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with useful ordering regressions and successful prior-head Gateway CI; no actionable patch defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The member-authored PR is exempt from the external-contributor proof gate; supplied evidence exercises completion tracking through tests and CI, without claiming a live agent.wait run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The member-authored PR is exempt from the external-contributor proof gate; supplied evidence exercises completion tracking through tests and CI, without claiming a live agent.wait run.
Evidence reviewed 8 items Current main still contains the defect: Current main selects only the chat snapshot for source-scoped waits, bypassing lifecycle reply and receipt merging.
Latest release also lacks the repair: The v2026.9.4 source uses the same direct chat-snapshot selection. GitHub's contents API supplied the release source after local historical blob retrieval failed.
Selected-source barrier and canonical merge: The introduced change requires a chat terminal observation before merging lifecycle evidence, excludes the agent dedupe source from that selection, and retains the existing reply and terminal-outcome owners.
Findings None None.
Security None None.

How this fits together

Gateway completion tracking combines runtime lifecycle events with chat delivery completion. Clients use agent.wait to retrieve the completed run’s outcome and recorded reply.

flowchart TD
 A[Client waits for run] --> B[Gateway completion tracker]
 C[Runtime outcome and reply] --> B
 D[Chat delivery completion] --> E{Chat barrier complete?}
 E -->|No| F[Continue waiting]
 E -->|Yes| B
 B --> G[Canonical outcome and recorded reply]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +104. Total +110 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 6 +6
Tests 1 104 0 +104
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 116 6 +110

Review metrics

None.

Technical review

Best possible solution:

Keep chat delivery as the readiness barrier and derive its final response from the existing canonical run outcome and reply owners.

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

Yes, from source: record lifecycle reply evidence, then complete chat delivery while a chat-scoped wait is active; current main returns the chat snapshot without that evidence. No runtime reproduction was executed here.

Is this the best way to solve the issue?

Yes. The patch repairs the existing projection through its canonical merge owner without adding a second reply store, history inference, or configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1b2bf44220e6.

Labels

Label justifications:

  • P2: Repairs a bounded Gateway completion-result defect affecting callers waiting for chat replies.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The member-authored PR is exempt from the external-contributor proof gate; supplied evidence exercises completion tracking through tests and CI, without claiming a live agent.wait run.

Evidence

What I checked:

  • Current main still contains the defect: Current main selects only the chat snapshot for source-scoped waits, bypassing lifecycle reply and receipt merging. (src/gateway/agent-turn/agent-job.ts:588, 1b2bf44220e6)
  • Latest release also lacks the repair: The v2026.9.4 source uses the same direct chat-snapshot selection. GitHub's contents API supplied the release source after local historical blob retrieval failed. (src/gateway/agent-turn/agent-job.ts:573, 3a9d69db306c)
  • Selected-source barrier and canonical merge: The introduced change requires a chat terminal observation before merging lifecycle evidence, excludes the agent dedupe source from that selection, and retains the existing reply and terminal-outcome owners. (src/gateway/agent-turn/agent-job.ts:568, 6e054798584e)
  • Established reply contract and production caller: The agent-loop documentation specifies terminalReply and terminalReceipt in wait results. The turn service selects chat-scoped waiting for active chat runs and forwards those fields; chat dispatch records completion after reply finalization. (src/gateway/agent-turn/agent-turn-service.ts:648, 6e054798584e)
  • Meaningful regression coverage: Added cases exercise waiter-before-lifecycle-before-chat ordering, visible/silent/empty replies, receipts, and sticky timeout/cancellation in both cached arrival orders. Existing dedupe siblings cover source selection and lifecycle reset. Tests were inspected, not executed in this read-only review. (src/gateway/agent-turn/agent-job.execution-settlement.test.ts:63, 6e054798584e)
  • Prior-head validation and review continuity: GitHub confirms successful Gateway core-1 and core-2 jobs on repaired head 6664cc5, and a failed core-1 job on the test-only control. The PR body reports eight intended failures corrected. Inspection of the earlier head confirms the same changed selection logic; the previous completed review retained no findings. These are CI results, not live runtime proof. (6664cc5b4559)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-14T01:28:46.905Z sha 23ba712 :: blocked before merge. :: none
  • reviewed 2026-09-14T01:49:20.427Z sha 6664cc5 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review September 14, 2026 02:00
@vincentkoc
vincentkoc merged commit 63f4812 into main Sep 14, 2026
264 of 266 checks passed
@vincentkoc
vincentkoc deleted the fix/chat-wait-terminal-reply branch September 14, 2026 02:38
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…penclaw#147656)

* test(gateway): reproduce missing chat completion replies

* fix(gateway): retain canonical replies after chat completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant