Skip to content

fix: preserve operator access when policy evaluation fails - #198245

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-assert-sources-recursive-plugin-scope-20260919
Nov 13, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-assert-sources-recursive-plugin-scope-20260919

Conversation

@steipete

@steipete steipete commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

An internal exception during a plugin access-policy assertion, including a closed invocation scope, was treated as a permanent denial. That revoked live operator authority, closed the connection, and invalidated admitted descendant runs even when the underlying grant still allowed access.

User Impact

Temporary policy failures refuse the affected operation while keeping authorized users connected and their admitted runs usable. Real revocation still stops access. An uncertain write outcome requires checking operation status before retrying.

Why This Change Was Made

Keep denial separate from evaluation failure at the access-policy owner. Log the redacted inner error, recompute an unsignaled grant before declaring it revoked, and refuse the failed operation with an unavailable error. Run and model authority retain their live state across that error. Actual grant revocation, ended/replaced grants, identity changes, and plugin disposal still fail closed. Plugin scope entry and isolation remain intact; this adds no config, schema, or cross-request authority cache.

WebSocket failures before actual method execution are retryable. Once a method may have written, the response explicitly says its outcome may be complete and does not promise a safe retry. HTTP policy outages return 503 instead of invalid-credential 401. The router owns the actual handler-start boundary, after lazy preparation and final authorization. Post-authentication HTTP revalidation failures also return 503; the outer response owner warns of a possible completed operation instead of promising a safe retry, and closes partial streams.

Evidence

  • An identical isolated production-code probe fails on exact parent 4aa0168e1f2a17608fa6dbb8d7d07a406794fd96: a real closed invocation scope aborts live authority. It passes with this fix for closed scopes, ordinary policy errors, same-run recovery, and actual grant revocation.
  • Regression coverage includes prepared principal authority with four admitted descendants and a bound model; unsignaled ended-grant recomputation; real-router lazy preparation and response publication; and HTTP assertion/authorization failures and recovery.
  • Focused validation: 113 unique tests pass across the gateway, admitted-run and plugin owners. The two committed lineage regressions fail on exact parent 4aa0168e1f2a17608fa6dbb8d7d07a406794fd96 and pass with the fix. All five real-router policy-failure phases and six existing cancellation cases pass. The database-backed regression uses the existing forked database-worker suite.
  • The first expanded run exposed a test fixture that did not actually throw during lazy preparation. The final test-only correction invokes the policy assertion inside that preparation step; its targeted replay passes all 11 cases.
  • Worker and UI runtime builds passed. pnpm check:changed --base 7010ba500068cff1d49f9e211873871107b16008 passes on committed head ed77b3583db8e57dc9d562ee95dce78208470fc6, including core/extension/test types, lint, format, and all dead-export scans. The optional-grant test type error found during the previous run is repaired and its four cross-profile revocation cases pass. The first local browser invocation passed the guest-question lifecycle but timed out at 120 seconds during sidebar Gateway startup, before browser assertions. One same-order replay with unchanged timeouts and assertions passed both browser cases, including the sidebar behavior in 30.3 seconds. The startup timeout is retained as an unresolved local failure, not a repaired or attributed inherited regression.
  • The final HTTP finisher and cookie regressions are red before their fixes and green afterward: 77 shared-owner cases and all 14 cookie cases pass. The read-only Home browser scenario also passes with its existing assertions and timeout; its earlier CI timeout is not claimed as a repaired defect.
  • Final consumer validation passes 94 cases: response authority, read-only Home, OIDC invitation admission, visitor lifecycle, and visitor service. The two wrapper extraction cases and the two applicable originally failing provisioning cases pass on the frozen tree; the unsupported-filesystem case is Linux-only.
  • A separate macOS cold/warm sparse-provisioning case timed out at its existing 120-second limit both in the broader tooling run and a bounded unchanged replay. The same timeout reproduces on exact parent 4aa0168e1f2a17608fa6dbb8d7d07a406794fd96. Its timing-regression introducer is not established; this remains an investigated local failure, not a claimed CI exception.
  • Final Codex autoreview is scoped-clean through P2. Native scripts/pr exact-head review and GitHub-gated preparation are complete. The final-head ClawSweeper review has zero open items. Exact-head CI completed with the inherited Goal expectation failure documented below; no full-CI-green claim is made.

Production LOC delta is +205. The growth carries one unavailable result through the existing independent run and transport owners and distinguishes uncertain write outcomes; no new authority owner or cache is introduced.

The bundled visitor policy now reports an absent invitation through its existing required-role binding, while startup/internal errors remain unavailable. Cookie admission and revalidation preserve that distinction, and the extracted PR wrapper includes the shared error dependency.

This correctness change is separate from the source-lineage allocation optimization. The detached agent_end hydration ordering is already addressed by open #197990 and is not duplicated here.

CI qualification

Exact-head CI run 43439889097, attempt 1 completed with one failing test job, plus the dependent CI gate. The failed job contains two Goal continuation cases expecting “Paused after Stop” but receiving “Paused after an interruption.”

Both failures reproduce unchanged on the exact CI main parent 5dfccbb92b2ab016c8c2082968f0b87798dc13bb (2/2 fail), while both pass on this PR head and its original base. The CI checkout was b8fd70b604087814cc820852d7a123369954a9f6, whose ordered parents are that main commit and this PR head. The failing test, its continuation helper, and the lifecycle projection are unchanged between the main parent and tested merge.

The introducing change is #198276, commit 64fd44bdaae8434611e841f4fb50d2443c9461f6: it changes the pause note to neutral wording but leaves these two continuation expectations unchanged. This is a newly exposed main test regression that still needs its owning test expectations repaired, not noise or a defect introduced by this PR. The scoped checks above remain green. Landing uses the explicitly authorized, pinned-head inherited-failure exception and preserves the failed CI result.

Release-note context

Prevent temporary plugin access-policy failures from disconnecting authorized users and aborting their live runs; preserve genuine revocation and provide visible operation failures.

@clawsweeper

clawsweeper Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling plugin: file-transfer size: M labels Nov 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review the distinction between policy denial and internal evaluation failure at head 379569e, including descendant/model cancellation and WebSocket response guards. Plugin isolation must remain intact, unavailable operations must not disclose protected payloads, and real revocation must still fail closed.

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR separates temporary policy evaluation failures from revocation and carries that distinction through operator runs, WebSocket responses, and HTTP authentication.

Example: An authorized visitor's policy assertion throws "Plugin invocation scope is closed".

  • Before: The Gateway permanently invalidates the captured authority, disconnects the client, and invalidates descendant runs.
  • After: The affected operation returns UNAVAILABLE while the authority remains usable after recovery; genuine revocation still ends access.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source repair is coherent and earlier findings are resolved, but required real-behavior proof remains uncovered.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Authorized operators lose their connection and admitted work when a policy check encounters an internal exception.
Reason: The maintainer-approved direction preserves useful work while continuing to refuse operations whose access cannot be evaluated.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed repair addresses a current source failure, and no blocking code defect remains after checking the earlier findings and the accepted logging exception.

Priority: P1
Reviewed head: ed77b3583db8e57dc9d562ee95dce78208470fc6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted logs, terminal output, or a recording from an isolated running Gateway with a real agent and model showing policy failure, recovery on the same admitted authority, and subsequent genuine revocation.
Agent review details

How this fits together

Plugin access policies supply grant assertions and cancellation signals to Gateway admission; authenticated requests and admitted runs consume them before protected operations and responses.

flowchart TD
  A[Authenticated operator] --> B[Gateway admission]
  B --> C[Plugin access policy]
  C --> D[Captured operator authority]
  D --> E[Admitted agent runs]
  D --> F[HTTP and WebSocket responses]
  C --> G[Unavailable or revoked outcome]
Loading

Technical review

Best possible solution:

Retain the existing grant owner and propagate unavailable outcomes without discarding the original authority or permitting the failed operation.

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

Current main visibly turns any policy assertion exception into permanent invalidation, and the submitted regression exercises the reported closed-scope trigger; no target code was executed during this review.

Is this the best way to solve the issue?

The patch repairs the distinction at the existing policy owner and preserves it through affected consumers without introducing another authority owner, cache, configuration option, or stored format.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Captured grant revocation changes intended behavior with a stated reason (552b54b: End visitor authority when its original invitation, identity, or plugin lifetime ends.)
  • Policy failure cause classification changes intended behavior with a stated reason (7154e4e: Distinguish invalidation causes and stop automatic reconnect loops; unknown failures remained terminal.)
  • Delegated run authority keeps the original intent (715077a: Keep accepted queued and child work bound to its original operator and permission ceiling.)
  • Request preparation and handler entry keeps the original intent (3ed226a: Keep asynchronous preparation inside the Gateway lifetime and make the final handoff to execution synchronous.)
  • Policy diagnostic redaction changes intended behavior with a stated reason (379569e: The maintainer explicitly confirms redacted inner exception names and messages as the task-specific logging requirement.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2444aae adds src/gateway/operator-access-policy.ts:242 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2444aae8f8f9; files: src/gateway/operator-access-policy.ts)
  • Shakker: Raw commit 552b54b adds src/gateway/operator-access-policy.ts:142 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 552b54b86c13; files: src/gateway/operator-access-policy.ts)
  • Jason (Json): Raw commit b8c3169 adds src/gateway/channel-operator-revocation.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b8c316977b60; files: src/gateway/channel-operator-revocation.ts)

PR surface

Source +205, Tests +400, Docs +9, Other +1. Total +615 across 30 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 16 273 68 +205
Tests 12 485 85 +400
Docs 1 17 8 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 30 776 161 +615

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.

Review metrics

Metric Value Why it matters
Production versus test growth Production +273/-68; tests and test support +485/-85 Production growth carries one failure classification through existing authority and transport owners; added coverage protects distinct lineage, retry, HTTP, and cookie boundaries.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A temporary plugin exception can disconnect authorized operators and invalidate their admitted agent work.
  • merge-risk: 🚨 compatibility: The maintainer-directed change deliberately makes plugin exceptions unavailable outcomes; definitive denial uses ended authority or an absent required grant, with the bundled consumer and SDK documentation updated together.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-11-13T11:54:48.179Z sha 379569e :: needs changes before merge. :: [P2] Avoid advertising a safe retry after a mutation has committed | [P2] Carry the unavailable outcome through HTTP authentication
  • reviewed 2026-11-13T12:39:31.763Z sha 9f0a7d0 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-13T12:46:33.988Z sha 9f0a7d0 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-13T13:34:22.366Z sha 7010ba5 :: needs changes before merge. :: [P2] [P2] Translate unavailable errors during HTTP revalidation | [P2] [P2] Preserve unavailable responses for plugin-cookie authentication | [P2] [P2] Preserve definitive Visitor Access admission denials | [P2] [P2] Include the new import in the extracted PR wrapper
  • reviewed 2026-11-13T14:28:43.494Z sha ed77b35 :: needs changes before merge. :: [P2] Preserve raw policy diagnostics until log egress

Reviewed November 13, 2026, 9:40 AM ET / 14:40 UTC (Revision 6).

@steipete

Copy link
Copy Markdown
Contributor Author

Both items from the latest review are addressed at 9f0a7d05ab2a9fc31286b56b666acf0232e92138:

  1. Unsafe retry after a possible committed mutation: the WebSocket response owner reports an uncertain, nonretryable outcome once a handler may have executed. The router marks actual invocation, after lazy preparation and final authorization; pre-handler refusals remain retryable. Shared reads cannot write and retain retryable delivery failures. The regression drives the real router through lazy preparation, handler failure, a pre-shaped handler error, response-time failure, and recovery, checking that protected payloads are suppressed without disconnecting the caller.

  2. HTTP policy outage misclassified as authentication failure: HTTP profile authentication preserves the unavailable cause. The HTTP response owner returns 503 with a safe retryable error, including assertion failure when binding the response. Genuine denial retains its existing 403 behavior. The HTTP regression covers both authorize and assertCurrent exceptions and recovery without aborting the live authority.

Codex autoreview is scoped-clean through P2 after these repairs. Final focused tests, exact-parent regression, affected UI e2e tests, and check:changed are still running; no incomplete run is claimed as passing. The PR remains draft while those gates finish.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. labels Nov 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed every open item in the review of 7010ba500068cff1d49f9e211873871107b16008:

  1. HTTP revalidation (shared finisher): the shared response finisher recognizes unavailable authority, returns 503 with retryable: false after a possible side effect, and closes already-started responses. The real-server core/plugin cases fail before this repair (500 rather than 503) and pass afterward; the live grant remains active.
  2. Plugin cookies (cookie owner): cookie admission sends the shared 503 response, and revalidation without a response object propagates the typed unavailable error to its outer response owner. The regression fails before the repair (401 rather than 503); all 14 cookie tests pass afterward, including genuine revocation and independent owner credentials.
  3. Visitor denials (visitor owner): the bundled visitor owner returns undefined for an absent invitation, which the existing required-role binding denies. Service startup and internal evaluation errors still throw. Consumer fixtures now express actual absent/aborted grants instead of treating generic exceptions as denials.
  4. Extracted wrapper (inventory): added src/infra/operator-authority-error.ts to the existing wrapper inventory. This fixes the missing import reported by the closure and provisioning tests.

The earlier unsafe-retry and HTTP-authentication items remain fixed: only failures before actual handler execution promise a retry, and HTTP policy outages are distinct from invalid credentials. The regression for closed invocation scopes retains the same admitted descendants and model authority through failure and recovery, then proves that genuine revocation still stops them.

Final repair head: ed77b3583db8e57dc9d562ee95dce78208470fc6. The two extraction cases and two applicable originally failing provisioning cases pass in the frozen replay. The separate macOS sparse-provisioning timeout remains recorded in the PR evidence and is not claimed as inherited.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed77b3583d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

function unavailablePolicy(error: unknown, pluginId?: string) {
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
log.warn(
`Access policy${pluginId ? ` ${pluginId}` : ""} evaluation failed: ${redactSensitiveText(detail, { mode: "tools" })}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve raw policy diagnostics until log egress

When an access-policy exception contains text matched by the redactor, this call irreversibly removes it before log.warn reaches the file sink, losing the original diagnostic even in local logs. Root AGENTS.md explicitly requires “Logs: write raw; redact only at egress”; createSubsystemLogger already separates file logging from redacted console output. Pass the unredacted diagnostic to the logger and leave redaction to the established egress boundaries.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot removed merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Review item 1 (raw policy diagnostics): retaining the current implementation deliberately. The explicit requirement for this fix is to record the inner exception's name and message, redacted, in the log. That task-specific requirement overrides the repository's general raw-local-log default. At src/gateway/operator-access-policy.ts:37-42, the owner preserves the exception name and message while applying the existing redaction utility before logging; the documentation describes that intended behavior. Removing this redaction would violate the requested contract. No new logging format, secret policy, or redaction implementation is introduced.

The four items from the preceding review remain fixed on ed77b3583db8e57dc9d562ee95dce78208470fc6, with individual code-line references and proof in #198245 (comment). This response addresses the sole open item from revision 5; no source change is needed for it.

The evidence remains qualified as production-owner integration and a standalone production-path probe with synthetic state, not a live-provider end-to-end run. The closed-scope regression fails on the exact parent and passes here; it covers recovery on the same admitted authority and real revocation of its descendants. The PR body retains the proof limits and investigated timing failures.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@steipete
steipete merged commit 5a1c9b5 into main Nov 13, 2026
229 of 236 checks passed
@steipete
steipete deleted the steipete/perf-micro-assert-sources-recursive-plugin-scope-20260919 branch November 13, 2026 15:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…198245)

* fix: preserve operator access when policy evaluation fails

* fix(gateway): preserve policy outage retry and HTTP semantics

* test(gateway): exercise unavailable policy during lazy preparation

* fix: preserve policy outcomes across HTTP and visitor admission
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer plugin: visitor-access rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts security-sensitive-changed size: L 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