Skip to content

fix: route agent command replies through reply hooks - #90300

Closed
sweetcornna wants to merge 1 commit into
openclaw:mainfrom
sweetcornna:fix/90282-reply-payload-hook
Closed

sweetcornna wants to merge 1 commit into
openclaw:mainfrom
sweetcornna:fix/90282-reply-payload-hook

Conversation

@sweetcornna

@sweetcornna sweetcornna commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes agent-command durable final delivery so recovered/main-session replies carry reply_payload_sending hook metadata into the existing outbound send path.
  • Lets channel plugins that rely on reply_payload_sending observe, rewrite, cancel, or fallback-deliver recovered agent replies instead of missing them.
  • Keeps recovery events, plugin API shape, session schema, and delivery queue schema unchanged.

Linked context

Closes #90282.

Related #90282.

Real behavior proof

Behavior or issue addressed: restart-recovered agent-command final replies now pass replayable reply_payload_sending hook metadata into durable outbound delivery before the outbound adapter receives the payload.

Real environment tested: Windows local OpenClaw checkout. Direct runtime proof was captured at PR head 445bb4a60 with Node v26.1.0, isolated temporary OPENCLAW_STATE_DIR and OPENCLAW_HOME. The branch was later rebased onto current origin/main and reverified at PR head 7c28e8b60f; the remaining source delta is the same delivery hook wiring plus conflict resolution in the touched test file.

Exact steps or command run after this patch: original runtime proof ran node_modules\.bin\tsx.cmd %TEMP%\openclaw-pr90300-proof-...\proof.mts, which registered a reply_payload_sending hook, delivered one agent-command reply to slack/#proof, and printed the payload received by the outbound adapter. Fresh verification at rebased head 7c28e8b60f ran:

node scripts/run-vitest.mjs src/agents/command/delivery.test.ts
node_modules\.bin\oxfmt.cmd --check src\agents\command\delivery.ts src\agents\command\delivery.test.ts
git diff --check origin/main..HEAD
node scripts/run-oxlint.mjs src/agents/command/delivery.ts src/agents/command/delivery.test.ts
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo
python .agents\skills\autoreview\scripts\autoreview --mode branch --base origin/main

Evidence after fix:

proof: deliveryStatus=sent deliverySucceeded=true
proof: hookCalls=1
proof: hookKind=final hookChannel=slack hookSession=agent:tester:slack:direct:alice hookRun=run-proof-1
proof: hookContext={"channelId":"slack","accountId":"workspace-1","conversationId":"#proof","sessionKey":"agent:tester:slack:direct:alice","runId":"run-proof-1"}
proof: deliveredText=hooked: final answer
proof: deliveredTo=#proof deliveredChannel=slack
proof: isolatedStateDir=true

rebased head 7c28e8b60f:
src/agents/command/delivery.test.ts: 21 passed
oxfmt: All matched files use the correct format
git diff --check: clean
run-oxlint: exit 0
run-tsgo core test lane: exit 0
autoreview: clean, no accepted/actionable findings

Observed result after fix: delivery completed with deliveryStatus=sent; the hook ran once for the final payload with channel/session/run context; the outbound adapter received hooked: final answer, proving the delivered reply was the hook-mutated payload. The rebased head keeps the same delivery behavior and the focused regression still observes the durable delivery hook metadata.

What was not tested: a live gateway restart with external Slack/Discord credentials was not run in this local environment.

Proof limitations or environment constraints: this is local runtime proof for the OpenClaw delivery/hook/outbound path plus fresh source-level verification at the rebased PR head. It does not prove third-party transport delivery after a full gateway process restart.

Before evidence: the added regression first failed before implementation because durable delivery args had replyPayloadSendingHook as undefined.

Tests and validation

  • node_modules\.bin\tsx.cmd %TEMP%\openclaw-pr90300-proof-...\proof.mts
  • node scripts/run-vitest.mjs src/agents/command/delivery.test.ts
  • node_modules\.bin\oxfmt.cmd --check src\agents\command\delivery.ts src\agents\command\delivery.test.ts
  • git diff --check origin/main..HEAD
  • node scripts/run-oxlint.mjs src/agents/command/delivery.ts src/agents/command/delivery.test.ts
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo
  • python .agents\skills\autoreview\scripts\autoreview --mode branch --base origin/main

Regression coverage added:

  • Added deliverAgentCommandResult coverage asserting durable final delivery receives replayable reply_payload_sending hook metadata.
  • Made two existing workspace-dir assertions platform-neutral with path.resolve(...) so the focused file passes on Windows too.

Risk checklist

  • User-visible behavior changed: yes. Recovered/main-session agent-command final replies can now run the existing reply_payload_sending hook path before delivery.
  • Config, environment, or migration behavior changed: no.
  • Security, auth, secrets, network, or tool execution behavior changed: no.
  • Highest-risk area: plugin hooks now run for this agent-command durable final delivery path, matching the existing reply delivery contract.
  • Mitigation: the change uses the already-supported durable outbound hook field and keeps queue/replay behavior in the existing outbound delivery layer; focused regression coverage checks the metadata passed to durable delivery.

Current review state

  • Branch rebased onto 6868cde4d4 and pushed as 7c28e8b60f.
  • Local focused test, format, lint, whitespace, core test type lane, and autoreview are clean on the rebased head.
  • Runtime proof above has been added for the proof gate; the rebased head is waiting on GitHub CI.
  • Remaining maintainer judgment: whether a full live gateway restart with external channel credentials is required beyond this local runtime delivery proof.
  • Next action: CI/proof-gate completion and maintainer review.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 4, 2026
@clawsweeper

clawsweeper Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 30, 2026, 11:19 AM ET / 15:19 UTC.

Summary
The PR threads existing reply_payload_sending hook metadata into agent-command durable final delivery and adds focused regression coverage for the send arguments.

PR surface: Source +13, Tests +51. Total +64 across 2 files.

Reproducibility: yes. at source level. Restart recovery calls Gateway agent with delivery enabled, current main sends the recovered final payload without replyPayloadSendingHook, and the sibling routed reply path already passes that hook into the same durable sender.

Review metrics: 1 noteworthy metric.

  • Mergeability: 1 conflicting delivery block. The live PR is CONFLICTING/DIRTY, and the conflict is in the same durable send block that now owns restart-abort delivery behavior.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #90282
Summary: The linked open issue is the canonical user report for restart-recovered replies missing reply_payload_sending; this PR is the active candidate fix, the earlier equivalent PR is closed unmerged, and the busy-state issue is adjacent but broader.

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:

  • Resolve the current-main conflict while preserving restart-abort delivery handling.
  • [P2] Rerun the focused delivery test, whitespace check, lint, and core test type lane after the repair.
  • Use live restart transport proof if maintainers require external-channel evidence.

Proof path suggestion
A real transport restart proof would reduce the remaining message-delivery uncertainty beyond local runtime output. Mantis is currently scoped to Telegram, Discord, and web UI chat proof, so it is not the right proof path for this surface.
Use maintainer screenshot/manual proof, browser or Playwright proof, Crabbox where appropriate, or normal local artifact proof instead.

Risk before merge

  • [P1] The live PR is CONFLICTING/DIRTY; the hook must be rebased into current main's durable send block without losing restart-only abort signal wiring, delivery intent disposal, or cleanup.
  • [P2] Merging the repaired version intentionally lets reply_payload_sending hooks mutate, suppress, or fallback-deliver recovered agent-command final replies before adapter delivery.
  • [P1] The supplied proof covers local runtime hook-to-adapter behavior, but not a full external-channel gateway restart with real Slack, Discord, Telegram, or another third-party transport credential.

Maintainer options:

  1. Rebase onto current delivery handling (recommended)
    Add the hook metadata to current main's sendDurableMessageBatch call while preserving assertDeliveryCurrent, restart-only abort signal wiring, onDeliveryIntent, and finally cleanup.
  2. Accept local runtime proof after repair
    Maintainers can treat the terminal hook-to-adapter proof as sufficient for the core path once the branch is conflict-free and validation reruns.
  3. Request live restart transport proof
    If local runtime proof is not enough, require a redacted gateway restart run showing a hook-mutated recovered reply reaching a real channel.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Resolve the current-main conflict in `src/agents/command/delivery.ts` by adding `replyPayloadSendingHook` to the current `sendDurableMessageBatch` call while preserving `params.assertDeliveryCurrent`, `createRestartOnlyAbortSignal`, `signal`, `onDeliveryIntent`, and `finally` cleanup; update `src/agents/command/delivery.test.ts` only as needed for combined hook and restart-abort coverage.

Next step before merge

  • [P2] A narrow automated repair can resolve the current-main conflict and preserve restart-abort behavior while keeping this PR's hook metadata fix.

Security
Cleared: The diff touches agent delivery code and tests only; no dependency, workflow, package, secret, permission, or supply-chain surface changed.

Review findings

  • [P1] Rebase the hook onto current delivery handling — src/agents/command/delivery.ts:720-732
Review details

Best possible solution:

Rebase the hook metadata onto current main's restart-abort-aware durable send block, keep the focused regression coverage, and land this as the canonical fix once checks and proof remain clean.

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

Yes at source level. Restart recovery calls Gateway agent with delivery enabled, current main sends the recovered final payload without replyPayloadSendingHook, and the sibling routed reply path already passes that hook into the same durable sender.

Is this the best way to solve the issue?

Yes after rebase. Reusing the existing durable reply_payload_sending hook path is narrower than adding a new recovery event or last-reply API, but the branch must be repaired against current delivery handling first.

Full review comments:

  • [P1] Rebase the hook onto current delivery handling — src/agents/command/delivery.ts:720-732
    The PR adds replyPayloadSendingHook to an older sendDurableMessageBatch block, but current main's same call now includes assertDeliveryCurrent, restart-only signal, onDeliveryIntent, and finally cleanup, and GitHub reports this head as CONFLICTING/DIRTY. Rebase the hook into the current block without dropping that restart-abort handling.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR targets a broken restart-recovered agent/channel workflow where users can miss final replies after a gateway restart.
  • merge-risk: 🚨 message-delivery: The diff changes the pre-adapter path so reply hooks can mutate, suppress, or fallback-deliver recovered agent-command final replies.
  • 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 (terminal): The PR body includes after-fix terminal output showing the hook ran, mutated the final reply, and the outbound adapter received the mutated text; full external restart transport proof remains untested.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output showing the hook ran, mutated the final reply, and the outbound adapter received the mutated text; full external restart transport proof remains untested.
Evidence reviewed

PR surface:

Source +13, Tests +51. Total +64 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 0 +13
Tests 1 69 18 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 82 18 +64

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/command/delivery.test.ts.
  • [P1] git diff --check origin/main..HEAD.
  • [P1] node scripts/run-oxlint.mjs src/agents/command/delivery.ts src/agents/command/delivery.test.ts.
  • [P1] node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo.

What I checked:

  • Repository policy read: Root AGENTS.md plus scoped src/agents/AGENTS.md and src/infra/outbound/AGENTS.md were read fully; their review guidance applies because this PR touches agent delivery, outbound delivery, plugin hooks, and message delivery risk. (AGENTS.md:1, 6cb82eaab865)
  • Current main still misses agent-command hook metadata: Current main's deliverAgentCommandResult calls sendDurableMessageBatch with payloads/session/reply/thread fields and restart-abort delivery handling, but without replyPayloadSendingHook. (src/agents/command/delivery.ts:750, 6cb82eaab865)
  • PR head adds the intended hook on an older block: The PR head adds final replyPayloadSendingHook metadata with channel, session key, run id, and context to the agent-command durable send call. (src/agents/command/delivery.ts:720, 7c28e8b60ff0)
  • Current main delivery block has restart-abort handling absent from the PR head: Current main wraps the same durable send call with assertDeliveryCurrent, createRestartOnlyAbortSignal, signal, onDeliveryIntent, and finally cleanup, while live GitHub mergeability reports the PR as CONFLICTING/DIRTY. (src/agents/command/delivery.ts:747, 6cb82eaab865)
  • Sibling routed reply path already supplies the hook: Normal routed replies pass replyPayloadSendingHook into the same durable send API, supporting this PR as a narrow sibling-surface repair rather than a new hook mechanism. (src/auto-reply/reply/route-reply.ts:278, 6cb82eaab865)
  • Outbound layer applies supplied hook before channel send: deliverOutboundPayloadsInternal applies params.replyPayloadSendingHook before the later message-sending hook and platform delivery, so the current source gap is the agent-command caller not supplying it. (src/infra/outbound/deliver.ts:1653, 6cb82eaab865)

Likely related people:

  • piersonr: PR 82823 introduced the reply_payload_sending hook surface, routed reply wiring, outbound support, queue metadata, and docs that this PR extends to agent-command delivery. (role: introduced hook surface; confidence: high; commits: b474f429ee4b; files: src/plugins/hooks.ts, src/auto-reply/reply/route-reply.ts, src/infra/outbound/deliver.ts)
  • MertBasar0: PR 75280 introduced the main-session durable delivery path involving src/agents/agent-command.ts, src/agents/command/delivery.ts, and restart-recovery delivery. (role: feature introducer; confidence: medium; commits: c240e718e91e; files: src/agents/agent-command.ts, src/agents/command/delivery.ts, src/agents/main-session-restart-recovery.ts)
  • samzong: PR 86089 changed restart-recovery reply delivery in the same recovery-to-agent-command-delivery product path. (role: restart-recovery delivery contributor; confidence: high; commits: 4decdf6245a1; files: src/agents/agent-command.ts, src/agents/main-session-restart-recovery.ts, src/infra/outbound/targets-session.ts)
  • joshavant: PRs 83835 and 83928 recently hardened final-delivery routing and session refresh in the same agent-command delivery surface. (role: recent area contributor; confidence: high; commits: 2c8f78e723ec, e99615973810; files: src/agents/agent-command.ts, src/agents/command/delivery.ts, src/agents/command/delivery.test.ts)
  • ooiuuii: PR 91357 added restart-abort handling around the same durable send block that this PR must preserve while adding hook metadata. (role: recent adjacent contributor; confidence: high; commits: d20fdf3b3842; files: src/agents/command/delivery.ts, src/agents/command/delivery.test.ts, src/agents/main-session-restart-recovery.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.
Review history (1 earlier review cycle)
  • reviewed 2026-06-21T11:37:26.781Z sha 7c28e8b :: needs changes before merge. :: [P1] Rebase the hook onto current restart-abort delivery

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 4, 2026
@sweetcornna

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

PR body now includes local runtime delivery proof for deliverAgentCommandResult -> sendDurableMessageBatch -> deliverOutboundPayloadsInternal -> reply_payload_sending -> direct outbound adapter, and the latest Real behavior proof workflow passed.

@clawsweeper

clawsweeper Bot commented Jun 4, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 4, 2026
@sweetcornna
sweetcornna force-pushed the fix/90282-reply-payload-hook branch from 445bb4a to 7c28e8b Compare June 5, 2026 01:59
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@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 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 21, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@vincentkoc

Copy link
Copy Markdown
Member

The current-main successor is #115711.

This PR was already closed and its contributor fork is not maintainer-editable, while the landed version must include the restart-recovery path and updated proof. The successor preserves @sweetcornna as co-author and links this PR for provenance.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S stale Marked as stale due to inactivity 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.

restart-recovery 不触发 reply_payload_sending event,导致渠道插件丢失回复

2 participants