Skip to content

[codex] fix(agents): run reply payload hooks for agent delivery - #90293

Closed
spacegeologist wants to merge 1 commit into
openclaw:mainfrom
spacegeologist:codex/restart-recovery-reply-payload-hook
Closed

spacegeologist wants to merge 1 commit into
openclaw:mainfrom
spacegeologist:codex/restart-recovery-reply-payload-hook

Conversation

@spacegeologist

@spacegeologist spacegeologist commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #90282.

  • Thread the existing reply_payload_sending hook metadata through agent-command durable delivery.
  • Add regression coverage for restart-recovered agent delivery so final replies still enter the documented pre-delivery hook pipeline.

Root Cause

Restart recovery resumes interrupted main sessions by calling Gateway agent with deliver: true. That path eventually uses deliverAgentCommandResult, which sends final payloads through sendDurableMessageBatch. The normal inbound auto-reply path already passes replyPayloadSendingHook, but the agent-command durable delivery path did not, so channel plugins relying on reply_payload_sending never saw recovered final replies.

Real behavior proof

Behavior addressed: restart-recovered agent final delivery now carries reply_payload_sending hook metadata into durable outbound delivery, giving channel plugins the same pre-delivery hook opportunity as normal inbound replies.

Real environment tested: local OpenClaw checkout on branch codex/restart-recovery-reply-payload-hook, Node v24.13.1, dependencies installed with corepack pnpm install --frozen-lockfile.

Exact steps or command run after this patch:

node scripts/run-vitest.mjs src/agents/command/delivery.test.ts
node scripts/run-vitest.mjs src/agents/main-session-restart-recovery.test.ts src/agents/agent-command.live-model-switch.test.ts src/agents/command/delivery.test.ts src/infra/outbound/deliver.test.ts src/auto-reply/dispatch.test.ts
node scripts/run-vitest.mjs src/auto-reply/reply/route-reply.test.ts
corepack pnpm exec oxfmt --check --threads=1 src/agents/command/delivery.ts src/agents/command/delivery.test.ts
git diff --check

Evidence after fix:

src/agents/command/delivery.test.ts: 21 passed
issue acceptance set: 3 Vitest shards passed, 203 tests passed
src/auto-reply/reply/route-reply.test.ts: 31 passed
oxfmt: All matched files use the correct format
git diff --check: clean

Additional equivalent live channel-plugin proof run locally after ClawSweeper feedback:

corepack pnpm exec tsx .artifacts/issue-90282-proof/run-proof.ts

This proof harness used the real global hook runner, active plugin registry, durable outbound queue, deliverAgentCommandResult, sendDurableMessageBatch, and a local proof channel plugin with a real outbound.sendText adapter. It did not mock deliverOutboundPayloadsInternal or the channel send call.

Redacted output:

{
  "proof": "issue-90282-recovered-agent-delivery-reply-payload-hook",
  "assertion": "reply_payload_sending ran before recovered agent final reply reached the channel adapter",
  "hookCalls": [
    {
      "kind": "final",
      "channel": "issue-90282-proof",
      "sessionKey": "agent:main:issue-90282-proof:direct:redacted",
      "runId": "run-redacted",
      "context": {
        "channelId": "issue-90282-proof",
        "accountId": "account-redacted",
        "conversationId": "conversation-redacted",
        "sessionKey": "agent:main:issue-90282-proof:direct:redacted",
        "runId": "run-redacted"
      },
      "inputText": "recovered final reply",
      "outputText": "recovered final reply [hook-proof]"
    }
  ],
  "outboundSends": [
    {
      "channel": "issue-90282-proof",
      "to": "conversation-redacted",
      "accountId": "account-redacted",
      "threadId": null,
      "text": "recovered final reply [hook-proof]",
      "messageId": "proof-message-1"
    }
  ],
  "deliveryStatus": {
    "requested": true,
    "attempted": true,
    "status": "sent",
    "succeeded": true,
    "resultCount": 1,
    "payloadOutcomes": [
      {
        "index": 0,
        "status": "sent",
        "resultCount": 1
      }
    ]
  },
  "durableQueue": {
    "stateDir": "<local-artifact-state-dir>",
    "pendingAfter": 0
  }
}

Observed result after fix: the recovered agent delivery test observes replyPayloadSendingHook with kind: "final", channel, conversation id, session key, and run id on the durable delivery call. The live channel-plugin proof also shows reply_payload_sending receiving the recovered final payload, mutating it, and the channel adapter receiving the mutated text before delivery completes with status: "sent"; the durable queue drains to pendingAfter: 0.

What was not tested: a full live Gateway process restart with an external network-backed third-party channel. The local proof covers the equivalent live channel-plugin setup and the missing core handoff that #90282 identified.

Verification

  • node scripts/run-vitest.mjs src/agents/command/delivery.test.ts
  • node scripts/run-vitest.mjs src/agents/main-session-restart-recovery.test.ts src/agents/agent-command.live-model-switch.test.ts src/agents/command/delivery.test.ts src/infra/outbound/deliver.test.ts src/auto-reply/dispatch.test.ts
  • node scripts/run-vitest.mjs src/auto-reply/reply/route-reply.test.ts
  • corepack pnpm exec oxfmt --check --threads=1 src/agents/command/delivery.ts src/agents/command/delivery.test.ts
  • git diff --check
  • corepack pnpm exec tsx .artifacts/issue-90282-proof/run-proof.ts (local proof harness; output redacted above)

Changelog

No CHANGELOG.md edit. This is a contributor fix; release-note context is in this PR body.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 4, 2026
@clawsweeper

clawsweeper Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as duplicate/superseded: this PR implements the same agent-command hook wiring as #90300, and that other PR is open, cleanly mergeable, proof-positive, and maintainer-editable.

Canonical path: Land #90300 as the canonical fix for #90282, then close this duplicate branch.

So I’m closing this here and keeping the remaining discussion on #90300 and #90282.

Review details

Best possible solution:

Land #90300 as the canonical fix for #90282, then close this duplicate branch.

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

Yes at source level: current main and v2026.6.1 call sendDurableMessageBatch from deliverAgentCommandResult without replyPayloadSendingHook, while normal routed replies pass it. I did not run tests in this read-only review.

Is this the best way to solve the issue?

No for this branch as the best landing path: the code shape is valid, but #90300 is the cleaner open canonical PR with equivalent behavior, sufficient proof, clean mergeability, and maintainer edits enabled.

Security review:

Security review cleared: The diff touches agent delivery code and tests only; no dependencies, workflows, package metadata, secrets handling, or supply-chain surface changed.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • joshavant: Recent merged commits hardened final-delivery routing refresh in src/agents/command/delivery.ts, the same delivery caller surface this PR changes. (role: recent area contributor; confidence: high; commits: e99615973810, 2c8f78e723ec; files: src/agents/command/delivery.ts, src/agents/agent-command.ts)
  • piersonr: Commit b474f429ee4b introduced reply_payload_sending, its plugin SDK contract, routed delivery behavior, queue metadata, docs, and tests that this PR extends to agent-command delivery. (role: introduced hook surface; confidence: high; commits: b474f429ee4b; files: src/plugins/hook-types.ts, src/plugins/hooks.ts, src/auto-reply/reply/route-reply.ts)
  • steipete: Remote path history and local blame show recent current-main touches across agent-command delivery, routed replies, and durable queue hook metadata, making this a likely routing candidate for review. (role: recent adjacent contributor; confidence: medium; commits: 82710b4f1f10, e12776037faf, 27dde7a4d69b; files: src/agents/command/delivery.ts, src/auto-reply/reply/route-reply.ts, src/infra/outbound/delivery-queue-storage.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 1a3ce7c2a8da.

@spacegeologist
spacegeologist marked this pull request as ready for review June 4, 2026 10:46
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added redacted equivalent live channel-plugin proof to the PR body. The proof uses the real global hook runner, active plugin registry, durable outbound queue, deliverAgentCommandResult, sendDurableMessageBatch, and a local proof channel plugin with a real outbound.sendText adapter. It shows reply_payload_sending mutating the recovered final payload before the channel adapter receives it, delivery completing with status: "sent", and the durable queue draining to pendingAfter: 0.

@clawsweeper

clawsweeper Bot commented Jun 5, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 5, 2026
@clawsweeper

clawsweeper Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly implements the same concrete hook-wiring fix for the same bug and is identified as the cleaner/current canonical review path; PR A's extra proof details are incidental and can be considered or linked from PR B rather than requiring separate review. Covering PR: fix: route agent command replies through reply hooks #90300.

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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 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.

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

1 participant