Skip to content

refactor(acp): make reply projector single-dispatch - #120560

Merged
steipete merged 1 commit into
mainfrom
repair/acp-projector-single-dispatch
Aug 8, 2026
Merged

steipete merged 1 commit into
mainfrom
repair/acp-projector-single-dispatch

Conversation

@steipete

@steipete steipete commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw’s ACP reply projector still modeled reuse across multiple turns even though production creates one projector per logical dispatch and the outer dispatcher already settles output on success and failure. That duplicated lifecycle ownership let terminal events recreate streaming state inside the projector and kept an unsupported multi-turn test as policy.

This is an ownership cleanup with one narrow observable retry-status change. It does not claim to fix #92199, supersede the retained-text behavior discussion in #119589, or harden malformed third-party terminal streams.

Why This Change Was Made

The projector now owns one block-reply pipeline for its single dispatch lifetime. Projector-local terminal flushing, turn-state reset, pipeline recreation, and the artificial reused-projector test are removed; tryDispatchAcpReply remains the canonical success/error force-flush owner.

A forced flush already clears the projector idle timer, drains the coalescer timer and buffers, and awaits ordered delivery. Modern ACPX separates live events from terminal results, while legacy terminal normalization and recoverable backend attempts remain manager-owned.

Rejected alternatives:

User Impact

Normal reply text and tool delivery are unchanged. During the supported recoverable pre-output retry path, visible status projection now follows the logical dispatch instead of each backend attempt:

  • Live delivery emits the first status immediately, suppresses an identical retry status, preserves distinct retry statuses, then emits the final reply.
  • Final-only delivery keeps statuses buffered until overall dispatch settlement, suppresses an identical retry status, preserves distinct retry statuses, then emits one final reply.

The previous implementation already delivered the losing attempt’s status before resetting; this change removes duplicate/early status delivery rather than newly retaining hidden reply content.

  • Config/default surfaces changed: 0
  • Production LOC: +8 / -32, net -24
  • Test LOC: +4 / -25, net -21
  • Exact head: b14a6861fd98e956b24e892f06be899b40e4a943
  • AI-assisted: yes

Maintainer Decision

Dispatch-scoped retry statuses are the intended contract for this cleanup. Recoverable backend attempts are internal to one logical OpenClaw dispatch; identical visible statuses dedupe across attempts, distinct statuses remain ordered, and outer settlement produces one final reply.

A committed manager retry-contract test is intentionally not added here. Task #18 is the frozen two-file projector lifecycle cleanup with the requested test delta; the separate repair-sweep task #17 owns retry-boundary contract coverage. Adding that third owner surface here would collapse the task boundary the sweep explicitly reserved.

Direct current Codex-source inspection was completed at 3aae5d885bac39c1262491aa3fd100dfd8b3919f: core emits TurnComplete only after turn completion and final-message collection (tasks/mod.rs); app-server handles that terminal event and publishes turn/completed (bespoke_event_handling.rs, completion builder). No supported producer needs projector reuse across separate logical turns.

Evidence

Focused lifecycle and boundary suite:

node scripts/run-vitest.mjs \
  src/auto-reply/reply/acp-projector.test.ts \
  src/auto-reply/reply/dispatch-acp.test.ts \
  src/auto-reply/reply/dispatch-from-config.test.ts \
  src/acp/control-plane/manager.turn-results.test.ts \
  extensions/acpx/src/runtime-turn.test.ts \
  extensions/acpx/index.test.ts

Result: 6 files passed across 3 routed shards; 485 tests passed.

Boundary proof through the real dispatchReplyFromConfig → ACP hook → dispatch/projector → channel dispatcher seam:

node scripts/run-vitest.mjs \
  src/auto-reply/reply/dispatch-from-config.test.ts \
  -t "coalesces tiny ACP token deltas into normal Discord text spacing"

Result: passed. The production route consumed multiple deltas plus the terminal event and emitted one correctly coalesced reply after outer settlement.

Recoverable-retry proof used a temporary, uncommitted Vitest harness wiring the real AcpSessionManager to the production projector, then removed the file before publication:

node scripts/run-vitest.mjs src/acp/control-plane/task18-retry-boundary.proof.test.ts

Result: 2 tests passed, one for each delivery mode. Both observed two backend attempts and the forwarded sequence status → error → status → status → text_delta → done. The first and identical retry status produced one visible status, the distinct status remained ordered, the transient error was not delivered, and outer flush(true) produced exactly one final reply.

Additional proof:

./node_modules/.bin/oxfmt --check \
  src/auto-reply/reply/acp-projector.ts \
  src/auto-reply/reply/acp-projector.test.ts
git diff --check
OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs --timed

Result: formatting, whitespace, typechecks, changed-file lint, dead-export scans, plugin boundaries, database-first guards, and runtime cycle checks passed. Remote proof backends were unavailable, so the trusted-source local fallback ran per repository policy; no credentialed external ACP smoke is claimed.

Review:

  • Autoreview: clean, no accepted/actionable findings.
  • Independent exact-head read-only review: clean; best-fix verdict confirmed, with no correctness or regression findings.
  • ClawSweeper retry-boundary finding: mechanism confirmed, severity disputed. The updated proof demonstrates dispatch-scoped status semantics; restoring projector reset would be the wrong owner boundary. If losing-attempt statuses should be discarded entirely, that is a separate typed manager policy decision.

@steipete
steipete marked this pull request as ready for review August 8, 2026 09:59
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 8:39 AM ET / 12:39 UTC.

ClawSweeper review

What this changes

This PR makes the ACP reply projector serve one logical dispatch by removing projector-local terminal settlement and per-turn pipeline recreation.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer review. The exact head has no source-level correctness finding, but the mandated local Codex dependency inspection could not be completed because ../codex is absent.

Priority: P2
Reviewed head: b14a6861fd98e956b24e892f06be899b40e4a943

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is a coherent, net-negative owner-boundary cleanup with supportive evidence, but the Codex dependency citation is unavailable for independent review.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This maintainer-owned PR is exempt from the external-contributor proof gate; its documented two-mode manager-to-projector harness remains supportive but was not independently rerun in this read-only review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-owned PR is exempt from the external-contributor proof gate; its documented two-mode manager-to-projector harness remains supportive but was not independently rerun in this read-only review.
Evidence reviewed 5 items Single-dispatch owner boundary: The dispatcher creates one projector, forwards manager events to it, then force-flushes only after run completion or in its error path.
Retry boundary: The manager marks text and tool events as output, and only then evaluates fresh-handle retry; retry therefore remains a pre-output internal attempt of the same dispatch.
Terminal-order sibling coverage: The manager coordinates separate startTurn event and result streams before sending one normalized terminal event; its committed test drains queued output before terminal completion.
Findings None None.
Security None None.

How this fits together

ACP session events pass through the reply projector into the channel delivery coordinator. The outer ACP dispatcher owns final success and error settlement after the manager completes one logical dispatch.

flowchart LR
  A[ACP session manager] --> B[Runtime events]
  B --> C[Reply projector]
  C --> D[Channel delivery coordinator]
  D --> E[Outer dispatch settlement]
  E --> F[Visible reply]
Loading

Before merge

  • Resolve merge risk (P1) - A merge verdict cannot independently validate the cited Codex terminal-order contract until a checkout with ../codex is available.
  • Complete next step (P2) - The protected maintainer-owned PR needs normal merge review and an environment capable of the required direct Codex source check, not an automated repair.
Agent review details

Security

None.

PR surface

Source -24, Tests -21. Total -45 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 32 -24
Tests 1 4 25 -21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 12 57 -45

Review metrics

Metric Value Why it matters
Production versus test delta production +8/-32; tests +4/-25 The refactor is net-negative, but its deletion changes the reply-delivery lifecycle and therefore needs owner-boundary evidence.

Merge-risk options

Maintainer options:

  1. Revalidate terminal ordering before merge (recommended)
    Review the cited Codex terminal path from a checkout containing ../codex, then confirm the recorded dispatch-scoped status contract still matches the exact head.

Technical review

Best possible solution:

Keep one dispatch-scoped projector and one outer settlement path, then revalidate the cited Codex terminal ordering in an environment that contains the required sibling source checkout.

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

Not applicable: this is a lifecycle cleanup rather than a report with an independently reproducible failure; source inspection establishes the affected dispatch path.

Is this the best way to solve the issue?

Yes for the OpenClaw owner boundary: the manager retries before output and the outer dispatcher already owns settlement, so restoring projector-local reset would recreate duplicate lifecycle ownership; Codex terminal ordering remains unverified locally.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-owned PR is exempt from the external-contributor proof gate; its documented two-mode manager-to-projector harness remains supportive but was not independently rerun in this read-only review.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded ACP reply-delivery lifecycle change with limited user-visible status and final-output impact.
  • merge-risk: 🚨 message-delivery: Terminal flushing and status deduplication determine which ACP updates and final replies are delivered to channels.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-owned PR is exempt from the external-contributor proof gate; its documented two-mode manager-to-projector harness remains supportive but was not independently rerun in this read-only review.

Evidence

What I checked:

  • Single-dispatch owner boundary: The dispatcher creates one projector, forwards manager events to it, then force-flushes only after run completion or in its error path. (src/auto-reply/reply/dispatch-acp.ts:551, b14a6861fd98)
  • Retry boundary: The manager marks text and tool events as output, and only then evaluates fresh-handle retry; retry therefore remains a pre-output internal attempt of the same dispatch. (src/acp/control-plane/manager.turn-runner.ts:268, b14a6861fd98)
  • Terminal-order sibling coverage: The manager coordinates separate startTurn event and result streams before sending one normalized terminal event; its committed test drains queued output before terminal completion. (src/acp/control-plane/manager.turn-stream.ts:129, b14a6861fd98)
  • History and current-main status: The cleanup is commit b14a686; it is not an ancestor of current main, whose projector still has terminal reset behavior, so this PR is neither implemented nor superseded on main. (src/auto-reply/reply/acp-projector.ts:190, e5d4fe02a46a)
  • Codex contract availability: The required sibling Codex source checkout is absent; network resolution also failed, so the PR's cited external terminal-order source could not be independently checked here.

Likely related people:

  • steipete: Authored the exact-head lifecycle cleanup and is the strongest recent contributor on the changed projector path. (role: recent area contributor; confidence: high; commits: b14a6861fd98; files: src/auto-reply/reply/acp-projector.ts, src/auto-reply/reply/acp-projector.test.ts)
  • Gio Della-Libera: Introduced the projector and dispatcher foundation whose ownership boundary this cleanup narrows. (role: original ACP boundary contributor; confidence: medium; commits: 7774f9a36c12; files: src/auto-reply/reply/acp-projector.ts, src/auto-reply/reply/dispatch-acp.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Recheck the cited Codex source from a checkout containing ../codex before a merge verdict.

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-08-08T10:43:03.695Z sha b14a686 :: found issues before merge. :: [P1] Reset projector state at recoverable retry boundaries
  • reviewed 2026-08-08T11:40:46.397Z sha b14a686 :: found issues before merge. :: [P2] Add a committed retry-boundary regression

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the retry-boundary finding in the PR description and evidence without changing the head.

A temporary manager→projector boundary harness passed in both live and final-only modes: two backend attempts, forwarded status → error → status → status → text_delta → done, one identical status after dedupe, distinct status preserved, no transient error delivery, and exactly one final reply after outer settlement. The scratch test was removed afterward.

I am intentionally not restoring projector reset/recreation: recoverable attempts are internal to one logical dispatch, text/tool output already disables retry, and the previous implementation already delivered the losing attempt’s status before resetting. Discarding losing-attempt statuses would require a separate typed manager policy, not projector-local terminal ownership.

@clawsweeper re-review

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision recorded in the PR body: retry statuses are dispatch-scoped. Identical statuses dedupe across recoverable attempts, distinct statuses remain ordered, and outer settlement owns the single final reply.

I also completed the required direct current Codex-source inspection: core emits its terminal completion only after turn completion/final-message collection, and app-server publishes the corresponding final turn/completed notification. The exact source revision and links are now in the PR body.

The requested committed retry-contract test is intentionally left to the already separate repair-sweep task #17. Task #18 is the frozen two-file projector cleanup and requested negative test delta; adding the manager owner surface here would collapse the explicitly reserved task boundary. The temporary two-mode manager→projector proof remains documented in Evidence.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready maintainer proof for exact head b14a6861fd98e956b24e892f06be899b40e4a943:

  • Focused lifecycle/boundary suite: node scripts/run-vitest.mjs src/auto-reply/reply/acp-projector.test.ts src/auto-reply/reply/dispatch-acp.test.ts src/auto-reply/reply/dispatch-from-config.test.ts src/acp/control-plane/manager.turn-results.test.ts extensions/acpx/src/runtime-turn.test.ts extensions/acpx/index.test.ts — 6 files, 485 tests passed.
  • Dispatch boundary: node scripts/run-vitest.mjs src/auto-reply/reply/dispatch-from-config.test.ts -t "coalesces tiny ACP token deltas into normal Discord text spacing" — passed.
  • Two-mode temporary retry boundary: node scripts/run-vitest.mjs src/acp/control-plane/task18-retry-boundary.proof.test.ts — 2 tests passed; scratch file removed before publication.
  • Static/local fallback: ./node_modules/.bin/oxfmt --check src/auto-reply/reply/acp-projector.ts src/auto-reply/reply/acp-projector.test.ts, git diff --check, and OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs --timed — passed.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/31251796796 — success, including openclaw/ci-gate.
  • Latest ClawSweeper: https://github.com/openclaw/clawsweeper/actions/runs/31257491660 — success; the durable exact-head review has no actionable finding and says the owner-boundary repair is best.
  • Direct dependency inspection: revision 3aae5d885bac39c1262491aa3fd100dfd8b3919f; codex-rs/core/src/tasks/mod.rs:564-570,778-811 collects the completed task/final message before emitting TurnComplete; codex-rs/app-server/src/bespoke_event_handling.rs:187-201,1277-1302 handles that terminal event and publishes TurnCompleted.
  • LOC: production +8/-32 (net -24); tests +4/-25 (net -21).

Known proof gap: no credentialed external live ACP smoke was run. Deterministic manager/projector/dispatcher boundary proof, direct dependency source inspection, and exact-head CI are used; no live proof is claimed.

@steipete
steipete merged commit 295c8df into main Aug 8, 2026
177 of 178 checks passed
@steipete
steipete deleted the repair/acp-projector-single-dispatch branch August 8, 2026 12:55
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

[Bug]: [ACP] Text before tool calls is lost in WeChat (intermediate messages dropped, not merged)

1 participant