Skip to content

fix: stop message sends and actions after caller retirement - #149277

Merged
shakkernerd merged 3 commits into
mainfrom
fix/message-caller-lifetime
Sep 16, 2026
Merged

shakkernerd merged 3 commits into
mainfrom
fix/message-caller-lifetime

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Message sends and actions can continue after the tool invocation that authorized them has closed. The broader agent run may still be active, so checking only that run allows an operation held in target or session preparation to reach the provider after its caller has retired. Discord also loses that caller check when an action enters its shared request queue.

User Impact

A retired caller can no longer start a message send or Discord request after delayed preparation, queueing, or a retry wait. A request already dispatched to the provider still settles normally, so a successful operation is not reported as unsent or retried because its caller closed while the response was pending.

Existing account, requester, destination, action-permission, and read-access checks remain in force. This repairs the existing send/action path and requires no configuration, protocol, SDK, or stored-data migration.

Why This Change Was Made

The Gateway already carries an in-process caller assertion into handlers. The send and message-action handlers now include it in their existing run-authority guard and pass that guard to the provider handoff.

Discord forwards the existing handoff assertion through its lazy action runtime and captures it with the request's read assertion before enqueueing. Its current request envelope retains those checks through the shared scheduler, rate-limit retries, asynchronous endpoint preparation, and final fetch. The small private async context bridges Discord's API and runtime bundles without introducing a new authority owner or scheduler.

Evidence

On unchanged main 684e301de4100eb6fa2b1ac6c2b79e85363160fa, holding session-route preparation, retiring the caller while the admitted run remained active, and then releasing preparation produced exactly one stale outbound Slack delivery. The delegated-run retirement control passed. This uses the existing handler context without a CLI grant or new message capability.

The original propagation change passed 134 Gateway send cases and 12 Discord request-authority cases on the matching implementation. That retained source qualification covers composed read/action assertions, shared clients, queue and endpoint preparation, retries, requests after rejection, and settlement after dispatch. Fresh standalone execution at 59c6c738862b9c92cfc5079ab1f51296a66a1689 passed the two caller/delegated retirement rows and all 12 Discord request cases, followed by the affected types, typed lint, and full build. Hosted build-artifacts also passed for f6a9443ca5d57f138c31998fa7ad21e3cef7401e.

The direct Discord regression uses the actual registered Gateway send handler, real Discord plugin facade, default request scheduler, and isolated SQLite. Only provider HTTP is synthetic. Before the sender correction, retiring the caller during a 429 backoff produced two message POSTs instead of one. The active-caller retry and already-accepted response controls passed. Discord's message, sticker, poll, component, and voice entry points now enter the existing private request-authority scope, retaining the caller check through each scheduler retry.

The extended three-case harness follows the retired caller through durable state and recovery. It first observes a real queued intent while the initial 429 is held, then retires the caller and verifies that the live request makes no second POST. It closes SQLite and reloads persisted custody. For any unfinished intent, it advances only Date past the stored owner deadline and normal backoff and verifies the existing recovery admission and eligibility predicates. It invokes the real startup recovery owner with the real outbound delivery function and normal defaults. A second database reopen must find no unfinished custody or successful completion receipt, exactly one non-sent terminal, and no later provider write. Unexpected synthetic transport routes are separately rejected, so a caught mock error cannot hide a replay. Conservative unknown settlement remains valid; the test does not discard evidence of a previous platform attempt.

The active caller still retries and clears durable custody, and a 200 response whose body is pending still settles successfully after caller retirement. The same three cases pass on the published PR base plus this test extension, without importing the separate core patch. The tested tree is c39854bc62789b762bb1449771c33b6629daf6dd, published as 990273493c04cf2d8bfba268300e397b4bb01ca1. The extension passed its 23.5-second changed-path preflight and fresh independent review with no actionable P0–P2 findings. Its affected Gateway test type project and one-file typed lint passed on the identical test source in the combined candidate.

 ✓  gateway-methods  src/gateway/server-methods/send.discord-request-authority.integration.test.ts > Gateway send through Discord's default request scheduler > preserves the active caller across Discord 429 backoff and reopened-state recovery without replay 603ms
 ✓  gateway-methods  src/gateway/server-methods/send.discord-request-authority.integration.test.ts > Gateway send through Discord's default request scheduler > preserves the retired caller across Discord 429 backoff and reopened-state recovery without replay 235ms
 ✓  gateway-methods  src/gateway/server-methods/send.discord-request-authority.integration.test.ts > Gateway send through Discord's default request scheduler > settles an accepted Discord response after the Gateway caller retires 102ms
 Test Files  1 passed (1)
      Tests  3 passed (3)

#149370 separately owns caller rejection after durable admission and before the initial provider handoff, including interrupted rejection settlement. Its real custody/recovery and conversation-projection proof, together with the parent accepted-send/MCP-drain check, is retained through source qualification. The corrected core must be effective in the target branch before this PR lands; final target reconciliation and the remaining required CI/review gates continue through this PR.

@shakkernerd
shakkernerd requested a review from a team as a code owner September 15, 2026 16:43
@clawsweeper

clawsweeper Bot commented Sep 15, 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 channel: discord Channel integration: discord gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 7:34 PM ET / 23:34 UTC (Revision 4).

ClawSweeper review

What this changes

Carries caller-lifetime checks through Gateway message sends and Discord action queues and retries while allowing already-dispatched requests to settle.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains necessary: current main lacks caller-lifetime propagation. The new recovery evidence resolves the prior proof gap, and no new blocking code defect was found.

Priority: P2
Reviewed head: 990273493c04cf2d8bfba268300e397b4bb01ca1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful production-boundary recovery evidence and no new actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.
Evidence reviewed 8 items Current main still needs the propagation: The fetched main authority helper validates the admitted run but accepts no caller assertion; its Discord request envelope retains only read authority.
Request-specific authority reaches final dispatch: Discord captures both action and read assertions before enqueueing, retains them in the request envelope, and checks them immediately before fetch. Endpoint overrides receive the same callback for their asynchronous preparation boundary; response settlement does not recheck retired caller authority.
Recovery proof addresses the previous request: The fully supplied body snapshot, sourceRevision 2b7865c602eb71779ad7fe292be2d980624e34068fdfe7ee96df675c82818852, records three passing production-path cases qualified to this published head. The inspected harness uses the registered Gateway send handler, real Discord facade/client/scheduler, SQLite reopen, normal recovery admission, and the real recovery owner; only provider HTTP is synthetic. It checks active retry, retired-caller suppression with no later recovery write, and successful settlement after provider acceptance.
Findings None None.
Security None None.

How this fits together

The Gateway routes message operations into channel plugins and durable delivery. Discord’s request scheduler handles queued provider calls and retries, where the originating caller’s authority must remain enforceable.

flowchart TD
  A[Tool caller] --> B[Gateway authority guard]
  B --> C[Delivery preparation and custody]
  C --> D[Discord request queue]
  D --> E{Caller still authorized?}
  E -->|Yes| F[Discord provider request]
  E -->|No| G[Reject new request]
  F --> H[Settle dispatched result]
  F -->|Rate limited| D
Loading

Before merge

Agent review details

Security

None.

PR surface

Source +136, Tests +396. Total +532 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 9 175 39 +136
Tests 3 502 106 +396
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 677 145 +532

Review metrics

Metric Value Why it matters
Production versus test growth production +136 net lines; tests +396 net lines Production growth carries existing assertions across plugin and scheduler boundaries; most added coverage exercises retirement, retries, and durable recovery.

Merge-risk options

Maintainer options:

  1. Make rejection settlement effective first (recommended)
    Land the companion repair and reconcile this PR against the corrected target so caller rejection cannot leave a later recovery send.

Technical review

Best possible solution:

Combine caller checks at every new provider dispatch with permanent settlement of rejected pre-handoff custody, preserving successful settlement of already-dispatched operations.

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

Yes, from source: current main does not compose the supplied caller assertion into send authority, and Discord retains only read authority across retries. The body supplies before/after reproduction evidence; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, with the declared companion prerequisite: extending the existing authority guard and request envelope avoids a competing authorization owner or public API change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 60c24d7192c1.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded caller-retirement race in message delivery without evidence of a widespread urgent outage.
  • merge-risk: 🚨 security-boundary: Safe integration requires the companion settlement repair so rejected caller authority cannot survive as replayable delivery custody.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded production-path harness exercises the registered Gateway handler, real Discord client and scheduler, and reopened SQLite recovery with synthetic provider HTTP: active callers retry, retired callers produce no later write, and accepted requests settle successfully. This satisfies the prior scoped authority-proof request; pre-handoff rejection remains owned by the companion PR.

Evidence

What I checked:

  • Current main still needs the propagation: The fetched main authority helper validates the admitted run but accepts no caller assertion; its Discord request envelope retains only read authority. (src/gateway/server-methods/agent-runtime-authority.ts:4, 60c24d7192c1)
  • Request-specific authority reaches final dispatch: Discord captures both action and read assertions before enqueueing, retains them in the request envelope, and checks them immediately before fetch. Endpoint overrides receive the same callback for their asynchronous preparation boundary; response settlement does not recheck retired caller authority. (extensions/discord/src/internal/rest.ts:239, 990273493c04)
  • Recovery proof addresses the previous request: The fully supplied body snapshot, sourceRevision 2b7865c602eb71779ad7fe292be2d980624e34068fdfe7ee96df675c82818852, records three passing production-path cases qualified to this published head. The inspected harness uses the registered Gateway send handler, real Discord facade/client/scheduler, SQLite reopen, normal recovery admission, and the real recovery owner; only provider HTTP is synthetic. It checks active retry, retired-caller suppression with no later recovery write, and successful settlement after provider acceptance. (src/gateway/server-methods/send.discord-request-authority.integration.test.ts:168, 990273493c04)
  • Companion prerequisite remains open: fix: prevent rejected queued handoffs from replaying #149370 remains open and unmerged at c3d10731d272d0d61949c4a3eb3aab56188902e5. Its supplied body owns permanent settlement of caller rejection before initial adapter handoff, including interrupted settlement; this PR explicitly requires that correction before landing. (c3d10731d272)
  • Prerequisite is not effective in the inspected main: Current main invokes the handoff callbacks directly and then the adapter; it has not adopted the companion’s distinct permanent-rejection handling at this boundary. (src/infra/outbound/deliver-channel.ts:208, 60c24d7192c1)
  • Latest release does not contain this guard: The v2026.9.4 authority helper likewise checks run authority without accepting caller-lifetime assertions; the requested fix is not established as shipped. (src/gateway/server-methods/agent-runtime-authority.ts:4, 3a9d69db306c)

Likely related people:

  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • anyech: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

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 (3 earlier review cycles)
  • reviewed 2026-09-15T16:49:59.838Z sha 59c6c73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T16:59:32.933Z sha 59c6c73 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T21:30:57.705Z sha f6a9443 :: needs real behavior proof before merge. :: none

@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: 🦪 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 Sep 15, 2026
@shakkernerd shakkernerd self-assigned this Sep 16, 2026
@shakkernerd
shakkernerd merged commit 2426d0a into main Sep 16, 2026
194 of 197 checks passed
@shakkernerd
shakkernerd deleted the fix/message-caller-lifetime branch September 16, 2026 02:32
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: retiring a message caller now blocks its pending sends and Discord requests before provider dispatch.

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

Keep message sends and Discord requests bound to the caller that authorized them, preserving normal settlement after provider dispatch.
yy19971996 added a commit to yy19971996/openclaw that referenced this pull request Nov 4, 2026
The message tool gives Discord an abort signal, but message actions never
received it and queued REST requests had no cancellation path, so a cancelled
turn waited out a 429 Retry-After.

Thread the action cancellation through the shipped send path, keep one request
identity across rate-limit requeues, and drop only work that was never issued.
Requests already dispatched to Discord still settle normally (openclaw#149277), so an
accepted write is never reported as unsent or replayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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