Skip to content

fix(gateway): make scope errors machine-readable across clients - #111013

Merged
steipete merged 3 commits into
mainfrom
codex/gateway-missing-scope-consumers
Jul 19, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/gateway-missing-scope-consumers

Conversation

@steipete

@steipete steipete commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #110925

What Problem This Solves

Fixes an issue where gateway clients could receive machine-readable missing-scope details from the server but still had to parse the human message, or misclassified a permanent authorization failure as bad parameters or a transient error. Parameter-dependent methods also duplicated scope policy between dispatch and handlers, which made regressions easy: reset-style agent requests, privileged node invokes, and unredacted talk configuration did not share one authorization owner.

Why This Change Was Made

This adds a browser-safe protocol reader that prefers details.code = MISSING_SCOPE while retaining the existing message and legacy fallback, then migrates the CLI, probe/status paths, Control UI, Android, and Apple clients to it. Dynamic method scope requirements now live in the pre-dispatch method policy and are reused by handler defenses; direct invocation and pairing share one admin-only node-command classifier, while the persistent browser mutation guard remains fail-closed at its more precise handler boundary.

The Android error model now preserves generic gateway details instead of naming connect-only details, and both mobile clients clear stale operator-question state when operator.questions is unavailable. The protocol and operator-scope docs cover the additive contract and parameter-dependent scopes.

User Impact

Third-party and first-party clients can give actionable missing-permission guidance without regexing missing scope: .... Existing clients keep working because the message string and legacy parsing fallback remain intact. Operators also get consistent FORBIDDEN semantics for parameter-dependent scope failures instead of ambiguous INVALID_REQUEST handling.

Release-note context: gateway clients can now consume structured missing-scope details across method-level authorization failures, with legacy message compatibility retained.

Evidence

  • pnpm check:changed passed on Blacksmith Testbox, including generated protocol/API baselines, all TypeScript typechecks, full core/package lint, import-cycle and boundary guards, and macOS packaging tests.

  • Before the final main rebase, 273 focused gateway/protocol/UI/CLI tests passed; @openclaw/gateway-protocol and @openclaw/gateway-client package builds passed.

  • Before the final main rebase, Android ktlintCheck and targeted GatewayErrorDetailsTest, ChatQuestionTest, and GatewaySessionReconnectTest passed.

  • /tools ownership-boundary follow-up: 31 commands-info tests passed.

  • Current exact head passed native:i18n:check, the changed node-pairing test (15 assertions), all test typechecks, production/full-tree/script dead-code export scans, script-declaration validation, and targeted formatting.

  • Real provider proof: OpenAI Responses streaming test passed with the Molty-managed OPENAI_API_KEY on direct AWS Crabbox run run_90c1f5464f1c (cbx_63d01e15905d); the lease was stopped and the key was not printed.

  • Exact-head hosted CI run 29665168399 passed, including native i18n, Android builds/tests, iOS build, macOS Node, and the full 1,395-test macOS Swift suite. First-attempt Blacksmith macOS capacity was unavailable; attempt 2 exposed unrelated process/onboarding test flakiness, and the unchanged native job passed on attempt 3.

  • Multi-pass autoreview found and drove the node-pairing policy unification, then finished clean against current main with no accepted/actionable findings (0.90 confidence).

  • AI-assisted

  • I understand the change and verified the affected ownership boundaries.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android app: ios App: ios app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations size: XL maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 8:09 PM ET / July 19, 2026, 00:09 UTC.

Summary
This PR adds shared parsing of structured gateway missing-scope errors, migrates multiple clients to it, and makes selected gateway method scopes parameter-aware.

PR surface: Source +134, Tests +299, Docs +16, Config +8, Generated 0, Other +269. Total +726 across 54 files.

Reproducibility: yes. from source: seed an answered, cancelled, or expired Android question card, then make question.list fail as unavailable; the proposed catch branch clears the entire cached list. A live Android run is still needed to demonstrate the user-visible result.

Review metrics: 2 noteworthy metrics.

  • Parameter-aware authorization surfaces: 3 methods changed: agent, node.invoke, and talk.config. These changes can alter authorization outcomes for existing operator scopes and need upgrade-path evidence beyond type and unit checks.
  • Public protocol export: 1 new package subpath: gateway-error-details. The new browser-safe reader becomes a client-facing protocol contract and should retain a clear compatibility boundary.

Stored data model
Persistent data-model change detected: unknown-data-model-change: packages/gateway-protocol/src/schema/error-codes.test.ts, unknown-data-model-change: packages/gateway-protocol/src/schema/error-codes.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Preserve terminal Android question outcomes and add focused regression coverage.
  • [P2] Post redacted real gateway evidence for structured missing-scope handling and legacy fallback.
  • Rebase or refresh review against current main once the native Apple checks finish.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The cited live OpenAI streaming run does not show the changed restricted-scope gateway behavior; add a redacted live gateway transcript or terminal capture covering structured details and legacy fallback, then update the PR body for re-review.

Risk before merge

  • [P1] Merging as written can erase Android terminal question-card outcomes when question.list becomes unavailable after a scope change or against an older gateway.
  • [P1] Changing agent, node.invoke, and talk.config to parameter-aware scope checks can make established operator-write workflows fail with FORBIDDEN; upgrade behavior needs targeted proof.
  • [P2] The published protocol reader is additive, but the client migration needs real restricted-scope evidence to confirm structured details and legacy fallback remain interoperable.

Maintainer options:

  1. Preserve terminal question outcomes (recommended)
    Change the Android unavailable-list branch to remove only actionable pending or submitting prompts, matching the existing reconciliation and Apple behavior, then add focused coverage.
  2. Require authorization-path proof
    Add a redacted restricted-scope gateway transcript or terminal capture showing a migrated client consuming structured details and falling back to the legacy message.
  3. Pause the broad migration
    Pause this branch if the intended cross-client handling and scope-tightening semantics cannot be demonstrated consistently before release.

Next step before merge

  • [P1] A narrow Android repair is clear, but the contributor must separately supply real restricted-scope behavior proof before merge.

Security
Cleared: The diff changes authorization classification and protocol details but adds no dependency, workflow, secret, or supply-chain execution path.

Review findings

  • [P2] Preserve terminal question cards when list access is unavailable — apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt:2248-2249
Review details

Best possible solution:

Preserve terminal Android question cards when list access is unavailable, then add a redacted real gateway run that exercises both structured missing-scope handling and the legacy-message fallback before merge.

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

Yes, from source: seed an answered, cancelled, or expired Android question card, then make question.list fail as unavailable; the proposed catch branch clears the entire cached list. A live Android run is still needed to demonstrate the user-visible result.

Is this the best way to solve the issue?

No. The shared protocol reader and central policy direction are sound, but clearing every question card is broader than necessary; retain terminal cards and remove only still-actionable prompts when access is unavailable.

Full review comments:

  • [P2] Preserve terminal question cards when list access is unavailable — apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt:2248-2249
    This branch clears every cached card when question.list is unavailable, including answered, cancelled, and expired outcomes. The normal Android reconciliation path preserves those terminal cards, and the Apple sibling only clears pending/submitting prompts; filter only actionable cards here so a scope change does not discard a just-recorded outcome.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add merge-risk: 🚨 session-state: The Android unavailable-question branch currently clears cached terminal question outcomes rather than only actionable prompts.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: This is a meaningful gateway and mobile-client correctness issue with bounded user impact, but the evidence does not show an emergency outage.
  • merge-risk: 🚨 compatibility: Parameter-aware scope enforcement can reject existing operator-write calls for reset, host-sensitive node, and unredacted Talk configuration paths.
  • merge-risk: 🚨 session-state: The Android unavailable-question branch currently clears cached terminal question outcomes rather than only actionable prompts.
  • merge-risk: 🚨 auth-provider: The PR changes how clients classify and react to gateway authorization and missing-scope failures across several authentication scopes.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The cited live OpenAI streaming run does not show the changed restricted-scope gateway behavior; add a redacted live gateway transcript or terminal capture covering structured details and legacy fallback, then update the PR body for re-review.
Evidence reviewed

PR surface:

Source +134, Tests +299, Docs +16, Config +8, Generated 0, Other +269. Total +726 across 54 files.

View PR surface stats
Area Files Added Removed Net
Source 19 256 122 +134
Tests 12 314 15 +299
Docs 2 22 6 +16
Config 2 9 1 +8
Generated 1 1 1 0
Other 18 355 86 +269
Total 54 957 231 +726

Acceptance criteria:

  • [P1] cd apps/android && ./gradlew testPlayDebugUnitTest --tests ai.openclaw.app.chat.ChatQuestionTest.
  • [P1] Run the relevant Android native CI lane after the focused unit test.
  • [P2] Capture a redacted live restricted-scope gateway transcript proving structured missing-scope handling and legacy fallback.

What I checked:

  • Concrete Android regression in proposed path: The new question.list unavailable handler replaces _questions with an empty list, while the review discussion identifies that normal reconciliation retains terminal cards and the Apple sibling only clears pending/submitting cards; this can discard a just-recorded answered, cancelled, or expired outcome. (apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt:2248, 4010203d68c8)
  • Protocol surface and compatibility impact: The branch adds the public @openclaw/gateway-protocol/gateway-error-details subpath and changes method-level authorization from static scopes to parameter-aware FORBIDDEN responses for agent, node.invoke, and talk.config. (packages/gateway-protocol/src/gateway-error-details.ts:1, 4010203d68c8)
  • Prior merged foundation: The related merged PR established the server-side MISSING_SCOPE contract; this follow-up remains distinct because it migrates consumers and extends parameter-aware policy rather than duplicating that merged server contract. (packages/gateway-protocol/src/schema/error-codes.ts:1, 5fe8d6a852ad)
  • Proof remains unrelated to changed behavior: The PR body cites an OpenAI Responses streaming run, but it does not provide a restricted-scope gateway transcript or capture showing structured MISSING_SCOPE consumption and legacy-message fallback across a migrated client. (4010203d68c8)

Likely related people:

  • steipete: Authored the merged predecessor that introduced the structured gateway authorization contract and the follow-up branch that migrates its consumers and policy owners. (role: feature introducer and recent area contributor; confidence: high; commits: 5fe8d6a852ad, dad0c184832e, 4010203d68c8; files: packages/gateway-protocol/src/schema/error-codes.ts, packages/gateway-protocol/src/gateway-error-details.ts, src/gateway/method-scopes.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-18T22:56:36.965Z sha e83dcedb246a3c879d748a2b6c4cae998eb5da7c :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the codex/gateway-missing-scope-consumers branch from e83dced to 4010203 Compare July 18, 2026 23:24

@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: 4010203d68

ℹ️ 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".

Comment on lines +2247 to +2249
if (_questions.value.isNotEmpty()) {
_questions.value = emptyList()
questionStateRevision += 1

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.

P2 Badge Preserve terminal question cards when list access is unavailable

When question.list is unavailable after a scope change or connection to an older gateway, this clears answered, cancelled, and expired cards along with pending ones. The normal reconciliation path deliberately retains non-pending cards in apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt:2299-2310, and the Apple sibling clears only pending/submitting cards, so Android users can lose a just-recorded terminal outcome prematurely. Filter out only actionable pending/submitting prompts here instead of replacing the entire list.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 19, 2026
@steipete
steipete merged commit 62c5a8b into main Jul 19, 2026
296 of 305 checks passed
@steipete
steipete deleted the codex/gateway-missing-scope-consumers branch July 19, 2026 00:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…claw#111013)

* fix(gateway): consume structured scope errors

* docs(gateway): clarify tools error boundary

* refactor(gateway): unify node admin policy
cxbAsDev pushed a commit to cxbAsDev/openclaw that referenced this pull request Jul 19, 2026
PR openclaw#111013 added missingScopeErrorShape but the agent-reset-phase
admin-scope and talk secrets-scope checks still used the legacy
errorShape without structured details. Switch them to emit machine-
readable MISSING_SCOPE details so clients can programmatically
identify these scope failures.
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…claw#111013)

* fix(gateway): consume structured scope errors

* docs(gateway): clarify tools error boundary

* refactor(gateway): unify node admin policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android app: ios App: ios app: web-ui App: web-ui cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant