Skip to content

fix(reply): keep queued messages through a temporary access-policy outage - #200413

Closed
obviyus wants to merge 1 commit into
mainfrom
fix/followup-policy-outage-withheld
Closed

obviyus wants to merge 1 commit into
mainfrom
fix/followup-policy-outage-withheld

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

A message queued while a turn is running is dropped when a Gateway access policy is briefly unavailable.

The authority contract says an unavailable policy evaluation is temporary: "An unavailable evaluation returns UNAVAILABLE with details.code: OPERATOR_ACCESS_UNAVAILABLE; before dispatch, it is retryable and does not authorize the failed operation" (docs/plugins/sdk-runtime/gateway-and-nodes.md). Two readers of queued-input custody did not follow it. Both treated any exception from assertCurrent() as a revocation:

  • isFollowupOperatorAuthorityCurrent (auto-reply/reply/queue/types.ts), made the single rule by fix(auto-reply): show revoked queued input as a withheld failure instead of a silent cancel #200213: the queued input was consumed and the chat showed withheld: Gateway access policy is unavailable; retry the operation.
  • releaseSessionControllerClaim (sessions/session-controller.mailbox-claim.ts): a second, older reader. On release it marked the claim's authority as not current, so the drain dropped the input even when the first reader kept it.

Affected installs: those with an access-policy plugin (registerGatewayAccessPolicy) whose evaluation can fail. No built-in policy reaches this path.

Fix

  • infra/operator-authority-error.ts gets isOperatorAuthorityRetryableError, next to the existing isOperatorAuthorityUnavailable: a policy outage (also nested) or a retryable GatewayDispatchUnavailableError.
  • Both readers use it. A temporary outage keeps the input queued; admission still refuses the operation during the outage, so nothing runs without a current check. Any other failure is still a revocation.

Production code: +16 / −4.

Accepted edge: while an outage lasts, the input is retried on the drain's existing cadence (observed about 1.4 refused attempts per second, each refused before any model call, with one log line each). A policy that never recovers keeps the input owed until the policy is fixed or the chat is stopped. This replaces silently losing the message.

User impact

  • A message queued during a brief access-policy outage runs after the policy recovers instead of being dropped as withheld.
  • A real revocation still never runs the queued turn.

Not changed: when a grant is revoked while the input is queued, it is cancelled without a visible withheld notice (same as before this PR).

Evidence

  • Regression tests, red on the merge base 941ae776, green on this head:

    • followup-runner.test.ts: retains queued input after a temporary admission refusal (direct policy error, nested policy error, retryable dispatch error); ordinary revocation and non-retryable dispatch still withhold visibly. Base 3 failed; head 33 passed.
    • session-controller.mailbox.test.ts: the exact controller input survives a temporary run/adapter policy failure through real reservation, claim deferral, release and reclaim. Base 2 failed (consumed instead of waiting); head 29 passed.
  • Real Gateway from source (ocx src, isolated state, real model), base vs head. A test access-policy plugin, loaded through plugins.load.paths and using only the documented plugin SDK, reads its grant from a file. A non-owner sends a second message while the agent runs a 20 s command; once the queue receipt shows the input queued, the grant file is renamed away for 30 s and back:

    Base 941ae776 Head
    Queued input during the outage consumed as withheld; never answered kept; the same queued run answers after the file returns
    Grant revoked while retrying — cancelled, zero model calls
  • Reader audit: the predicate's callers (followup-runner.ts, queue/drain.ts, agent-runner-execute.ts, goal-continuation-return.ts) and every other authority assertion on the queued-input path (queue/delivery-context.ts, queue/lifecycle.ts, queue/enqueue.ts, queue/drain.ts) were checked; only the two readers above treated a temporary failure as revocation.

- Share policy and retryable dispatch classification between follow-up custody and mailbox claim release.
- Preserve the exact controller input through temporary policy failures; keep definite revocations terminal.
- Reproduce with an installed SDK file-access policy on an isolated real Gateway; the built-in policy does not exercise file-store outages.
@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves queued messages through temporary authority-check failures so the existing drain can retry them.

Example: A second message is queued while an agent runs a 20-second command, and the access-policy service becomes unavailable for 30 seconds.

  • Before: The queued message is consumed as withheld and never answered.
  • After: The same message remains queued and can run after policy recovery and successful admission.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with distinct custody regressions and passing exact-head gates; the reported live outcomes lack independently inspectable output.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; its body reports real-Gateway outage recovery and zero-model-call revocation controls, but supplies no attached output or artifact for independent inspection.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A queued message can disappear during a temporary access-policy outage even though its operator has not lost access.
Reason: The maintainer-authored direction restores the existing temporary-failure contract and explicitly accepts retaining owed input until recovery or Stop.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a current queued-message loss path, and no definite introduced regression was found.

Priority: P2
Reviewed head: e3b89f814722b3c41d236c3818b549aedd2a686c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The session mailbox retains queued user input, the follow-up runner prepares agent turns, and authority admission determines whether execution may start.

flowchart TD
  A[Queued user message] --> B[Session mailbox]
  B --> C[Follow-up runner]
  C --> D[Authority admission]
  D --> E[Agent execution]
  D --> F[Temporary refusal]
  F --> B
  E --> G[Source reply]
Loading

Technical review

Best possible solution:

Distinguish temporary failures in both existing custody owners while preserving FIFO ordering, successful admission checks, and terminal revocation.

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

Current source establishes both discard paths, and the body describes a concrete base/head Gateway reproduction; this read-only review executed no target code.

Is this the best way to solve the issue?

The change repairs both independent custody checks through one reused classifier without introducing another queue, retry mechanism, or state owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit d981eaa adds src/auto-reply/reply/queue/types.ts:56 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d981eaa83bce; files: src/auto-reply/reply/queue/types.ts)

PR surface

Source +12, Tests +67. Total +79 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 16 4 +12
Tests 2 69 2 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 85 6 +79

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Temporary failures in an installed access-policy plugin can discard queued messages, with limited affected scope.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Temporary failures in an installed access-policy plugin can discard queued messages, with limited affected scope.
  • 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.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 12:00 AM ET / 05:00 UTC.

@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of a fix at the owner layer.

This PR teaches two queue readers which assertCurrent() errors count as temporary. The underlying problem is that queued-input custody ends on an inferred cause (a failed check) instead of a recorded one, at four more sites than these two, and the authority owners already decide revoked vs temporary. The replacement makes the owners abort their signal when they latch a revocation, and removes the inferred custody ends (the same predicate deletions as #200231), so a temporary outage only defers the message. It also avoids two problems found here: a deferred message showed "Your request couldn't be completed." before its real answer, and a remote-ingress "owner changed" error would be retried forever because this helper calls temporary what the owner latches as revoked.

The real-Gateway reproduction and outage matrix from this PR are reused for the replacement.

@obviyus obviyus closed this Nov 17, 2026
obviyus added a commit that referenced this pull request Nov 17, 2026
## Problem

A message queued while a turn runs could be dropped because a check failed, not because anything ended it.

The custody contract (`docs/concepts/session-controller.md`) lets an accepted input end only as consumed, deliberately dropped, cancelled or interrupted, and requires every accepted input to stay accounted for. The access-policy contract (`docs/plugins/sdk-runtime/gateway-and-nodes.md`) says an owner aborts its signal when a source is revoked, and that an internal assertion error "refuses the operation without revoking the person or their admitted runs".

The code did the opposite in two places:

- The authority owners latched a revocation they found inside `assertCurrent()` without aborting their signal (`operator-run-authority.ts`, `admitted-run-context.ts`). Revocations found by event rechecks were recorded; ones found by a direct check were not.
- Seven queue and mailbox readers ended custody when `assertCurrent()` threw: `isFollowupOperatorAuthorityCurrent` and its four callers (followup runner, drain retry filter, stalled-turn handoff, goal return), mailbox claim release, early injection and steer admission, `reserveSteerCandidate`, and the channel steer caller. Each re-derived the owner's decision from the thrown error with its own rule.

On a real Gateway with an access-policy plugin, a 30 s policy outage while a message was queued dropped it as `withheld`; it never ran after the policy returned.

## Fix

- Owners record revocation: `assertCurrent` in `operator-run-authority.ts` uses its existing `revoke()`, and `createAdmittedRunOperatorAuthority` aborts a local revocation signal, composed with the upstream one, instead of keeping a private latch. A policy outage stays non-terminal.
- Queue and mailbox custody end only on recorded facts: the input's abort signal (which already includes the source authority's signal), retirement, cancellation, or consumption. A failed check now only refuses that attempt; the input stays queued and the drain retries it.
- Deleted `isFollowupOperatorAuthorityCurrent` and every inferred custody end listed above. The deletions in `drain.ts`, `agent-runner-execute.ts` and `goal-continuation-return.ts` match #200231.
- Notices survive the owner's new revocation signal. The stalled-turn handoff refuses a continuation while the source authority is aborted or refusing, without ending custody, so the original dispatch keeps its fallback notice. `runReplyAgent` still returns a prepared preflight failure notice when the operation was aborted by the source authority's own revocation; an explicit Stop, supersession or restart stays silent.

No new helper, flag, retry, backoff, schema or config. Production code: net −43 lines.

Replaces #200413, which taught two of these readers a wider "temporary" rule; that rule disagreed with the owner on remote-ingress "owner changed" errors and would have retried such an input forever.

## User impact

- A message queued during a temporary access-policy outage runs after the policy recovers.
- An internal policy error no longer silently drops a queued message.
- Revocation, Stop, delete and graceful restart behave as before: revoked, stopped and deleted messages are cancelled with zero model calls.

Affected installs: those using an access-policy plugin whose evaluation can fail. No built-in policy reaches the outage path.

## Evidence

- Regression tests, red on the merge base `b4254cb2`, green on this head:
  - mailbox: the exact controller input survives a refusing run or adapter authority (base: consumed);
  - followup runner: policy outage and an unsignaled internal assertion error keep the input (base: dropped);
  - authority owners: a revocation found by `assertCurrent` aborts the owner's signal, including remote-ingress owner replacement (base: signal not aborted);
  - steering: early and guarded steer assertions, `reserveSteerCandidate`, and the channel steer caller keep the source after an unsignaled failure and still end it on recorded cancellation (base: retired).
- Real Gateway from source (`ocx src`, isolated state, real model, a test access-policy plugin loaded through `plugins.load.paths` that reads its grant from a file; non-owner sender), base vs head, with the message confirmed queued before each event:

  | Event | Base `b4254cb2` | Head |
  |---|---|---|
  | 30 s policy outage (grant file moved away and back) | withheld; never answered | same queued run answered after restore; 0 model calls during the outage; no failure notice for the queued message |
  | Grant revoked | cancelled, 0 model calls, socket 4001 `grant-revoked` | same |
  | Outage, then grant revoked | already withheld during the outage | kept through the outage, then cancelled; 0 model calls |
  | Stop | cancelled, 0 model calls | same |
  | Delete | removed, 0 model calls | same |
  | Graceful restart | resumed and answered | same |

  During the outage the head logs 14 refused attempts in 30 s (peak 2/s), each refused before any model call.
- Accepted edge: a long outage keeps the message queued on the drain's existing retry cadence.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
## Problem

A message queued while a turn runs could be dropped because a check failed, not because anything ended it.

The custody contract (`docs/concepts/session-controller.md`) lets an accepted input end only as consumed, deliberately dropped, cancelled or interrupted, and requires every accepted input to stay accounted for. The access-policy contract (`docs/plugins/sdk-runtime/gateway-and-nodes.md`) says an owner aborts its signal when a source is revoked, and that an internal assertion error "refuses the operation without revoking the person or their admitted runs".

The code did the opposite in two places:

- The authority owners latched a revocation they found inside `assertCurrent()` without aborting their signal (`operator-run-authority.ts`, `admitted-run-context.ts`). Revocations found by event rechecks were recorded; ones found by a direct check were not.
- Seven queue and mailbox readers ended custody when `assertCurrent()` threw: `isFollowupOperatorAuthorityCurrent` and its four callers (followup runner, drain retry filter, stalled-turn handoff, goal return), mailbox claim release, early injection and steer admission, `reserveSteerCandidate`, and the channel steer caller. Each re-derived the owner's decision from the thrown error with its own rule.

On a real Gateway with an access-policy plugin, a 30 s policy outage while a message was queued dropped it as `withheld`; it never ran after the policy returned.

## Fix

- Owners record revocation: `assertCurrent` in `operator-run-authority.ts` uses its existing `revoke()`, and `createAdmittedRunOperatorAuthority` aborts a local revocation signal, composed with the upstream one, instead of keeping a private latch. A policy outage stays non-terminal.
- Queue and mailbox custody end only on recorded facts: the input's abort signal (which already includes the source authority's signal), retirement, cancellation, or consumption. A failed check now only refuses that attempt; the input stays queued and the drain retries it.
- Deleted `isFollowupOperatorAuthorityCurrent` and every inferred custody end listed above. The deletions in `drain.ts`, `agent-runner-execute.ts` and `goal-continuation-return.ts` match openclaw#200231.
- Notices survive the owner's new revocation signal. The stalled-turn handoff refuses a continuation while the source authority is aborted or refusing, without ending custody, so the original dispatch keeps its fallback notice. `runReplyAgent` still returns a prepared preflight failure notice when the operation was aborted by the source authority's own revocation; an explicit Stop, supersession or restart stays silent.

No new helper, flag, retry, backoff, schema or config. Production code: net −43 lines.

Replaces openclaw#200413, which taught two of these readers a wider "temporary" rule; that rule disagreed with the owner on remote-ingress "owner changed" errors and would have retried such an input forever.

## User impact

- A message queued during a temporary access-policy outage runs after the policy recovers.
- An internal policy error no longer silently drops a queued message.
- Revocation, Stop, delete and graceful restart behave as before: revoked, stopped and deleted messages are cancelled with zero model calls.

Affected installs: those using an access-policy plugin whose evaluation can fail. No built-in policy reaches the outage path.

## Evidence

- Regression tests, red on the merge base `20a8025c`, green on this head:
  - mailbox: the exact controller input survives a refusing run or adapter authority (base: consumed);
  - followup runner: policy outage and an unsignaled internal assertion error keep the input (base: dropped);
  - authority owners: a revocation found by `assertCurrent` aborts the owner's signal, including remote-ingress owner replacement (base: signal not aborted);
  - steering: early and guarded steer assertions, `reserveSteerCandidate`, and the channel steer caller keep the source after an unsignaled failure and still end it on recorded cancellation (base: retired).
- Real Gateway from source (`ocx src`, isolated state, real model, a test access-policy plugin loaded through `plugins.load.paths` that reads its grant from a file; non-owner sender), base vs head, with the message confirmed queued before each event:

  | Event | Base `20a8025c` | Head |
  |---|---|---|
  | 30 s policy outage (grant file moved away and back) | withheld; never answered | same queued run answered after restore; 0 model calls during the outage; no failure notice for the queued message |
  | Grant revoked | cancelled, 0 model calls, socket 4001 `grant-revoked` | same |
  | Outage, then grant revoked | already withheld during the outage | kept through the outage, then cancelled; 0 model calls |
  | Stop | cancelled, 0 model calls | same |
  | Delete | removed, 0 model calls | same |
  | Graceful restart | resumed and answered | same |

  During the outage the head logs 14 refused attempts in 30 s (peak 2/s), each refused before any model call.
- Accepted edge: a long outage keeps the message queued on the drain's existing retry cadence.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
A message queued while a turn runs could be dropped because a check failed, not because anything ended it.

The custody contract (`docs/concepts/session-controller.md`) lets an accepted input end only as consumed, deliberately dropped, cancelled or interrupted, and requires every accepted input to stay accounted for. The access-policy contract (`docs/plugins/sdk-runtime/gateway-and-nodes.md`) says an owner aborts its signal when a source is revoked, and that an internal assertion error "refuses the operation without revoking the person or their admitted runs".

The code did the opposite in two places:

- The authority owners latched a revocation they found inside `assertCurrent()` without aborting their signal (`operator-run-authority.ts`, `admitted-run-context.ts`). Revocations found by event rechecks were recorded; ones found by a direct check were not.
- Seven queue and mailbox readers ended custody when `assertCurrent()` threw: `isFollowupOperatorAuthorityCurrent` and its four callers (followup runner, drain retry filter, stalled-turn handoff, goal return), mailbox claim release, early injection and steer admission, `reserveSteerCandidate`, and the channel steer caller. Each re-derived the owner's decision from the thrown error with its own rule.

On a real Gateway with an access-policy plugin, a 30 s policy outage while a message was queued dropped it as `withheld`; it never ran after the policy returned.

- Owners record revocation: `assertCurrent` in `operator-run-authority.ts` uses its existing `revoke()`, and `createAdmittedRunOperatorAuthority` aborts a local revocation signal, composed with the upstream one, instead of keeping a private latch. A policy outage stays non-terminal.
- Queue and mailbox custody end only on recorded facts: the input's abort signal (which already includes the source authority's signal), retirement, cancellation, or consumption. A failed check now only refuses that attempt; the input stays queued and the drain retries it.
- Deleted `isFollowupOperatorAuthorityCurrent` and every inferred custody end listed above. The deletions in `drain.ts`, `agent-runner-execute.ts` and `goal-continuation-return.ts` match #200231.
- Notices survive the owner's new revocation signal. The stalled-turn handoff refuses a continuation while the source authority is aborted or refusing, without ending custody, so the original dispatch keeps its fallback notice. `runReplyAgent` still returns a prepared preflight failure notice when the operation was aborted by the source authority's own revocation; an explicit Stop, supersession or restart stays silent.

No new helper, flag, retry, backoff, schema or config. Production code: net −43 lines.

Replaces #200413, which taught two of these readers a wider "temporary" rule; that rule disagreed with the owner on remote-ingress "owner changed" errors and would have retried such an input forever.

- A message queued during a temporary access-policy outage runs after the policy recovers.
- An internal policy error no longer silently drops a queued message.
- Revocation, Stop, delete and graceful restart behave as before: revoked, stopped and deleted messages are cancelled with zero model calls.

Affected installs: those using an access-policy plugin whose evaluation can fail. No built-in policy reaches the outage path.

- Regression tests, red on the merge base `b4254cb2`, green on this head:
  - mailbox: the exact controller input survives a refusing run or adapter authority (base: consumed);
  - followup runner: policy outage and an unsignaled internal assertion error keep the input (base: dropped);
  - authority owners: a revocation found by `assertCurrent` aborts the owner's signal, including remote-ingress owner replacement (base: signal not aborted);
  - steering: early and guarded steer assertions, `reserveSteerCandidate`, and the channel steer caller keep the source after an unsignaled failure and still end it on recorded cancellation (base: retired).
- Real Gateway from source (`ocx src`, isolated state, real model, a test access-policy plugin loaded through `plugins.load.paths` that reads its grant from a file; non-owner sender), base vs head, with the message confirmed queued before each event:

  | Event | Base `b4254cb2` | Head |
  |---|---|---|
  | 30 s policy outage (grant file moved away and back) | withheld; never answered | same queued run answered after restore; 0 model calls during the outage; no failure notice for the queued message |
  | Grant revoked | cancelled, 0 model calls, socket 4001 `grant-revoked` | same |
  | Outage, then grant revoked | already withheld during the outage | kept through the outage, then cancelled; 0 model calls |
  | Stop | cancelled, 0 model calls | same |
  | Delete | removed, 0 model calls | same |
  | Graceful restart | resumed and answered | same |

  During the outage the head logs 14 refused attempts in 30 s (peak 2/s), each refused before any model call.
- Accepted edge: a long outage keeps the message queued on the drain's existing retry cadence.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit d979dba)

Release adaptation: preserve both baseline occurrence-retirement and session-replacement cases; expect permanent authority failures to record cancellation in each.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit fb38fcadada62aadc8d0b94265dd9123df11f8c6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant