Skip to content

refactor(agents): consolidate session auth selection behind prepared-facts facade - #126084

Merged
steipete merged 2 commits into
mainfrom
steipete/session-auth-route-selection
Aug 19, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/session-auth-route-selection

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Two things, stacked as independent commits:

  1. fix(subagents): latent main breakage. fix(gateway): bind subagent completion dispatch to instance #126062 bound subagent completion dispatch to the Gateway instance (context now comes from the instance's own getContext), but left the old caller-supplied resolveGatewayContext plumbing threaded through the announce path. The forward into GatewayLifecycleAgentDispatchOptions fails check-prod-types (TS2353) in any CI lane that typechecks the gateway scope — fix(gateway): bind subagent completion dispatch to instance #126062's own changed-scope lanes never did, so main is latently red for every future gateway-touching PR (this one was the first to trip it).
  2. refactor(agents): auth-selection consolidation. fix: API-key sessions switch to OAuth after compaction #123894 fixed route-blind session rotation inside session-override.ts, but every caller still hand-rolls the same selection prelude, and the inference runtime still re-derives the selected profile's credential mode and route requirement that the resolver just computed.

Why This Change Was Made

The fix commit deletes the dead announce-path resolver plumbing (param decls, forwards, the now-unused getSharedGatewayContextResolver, and the stale forwarding assertions in the binding test). The spawn/tools resolver path is untouched — the in-process dispatch there still consumes it.

The refactor completes #123894's redesign at the call-site layer: a new resolveSessionAuthSelection façade returns prepared facts (profileId, source, routeRequirement) and owns provider expansion, provenance derivation, and explicit configured-default-profile precedence. All four callers (inference-runtime, get-reply-run-admission, btw, cron run-prepare) migrate to it and delete their preludes; inference-runtime drops its duplicate mode/route re-derivation and consumes the prepared route requirement directly. Rotation internals from #123894 are untouched.

User Impact

None intended — behavior-neutral consolidation plus a type-level repair of main. Sessions keep the route-aware rotation shipped in #123894; gateway-scope CI lanes typecheck again.

Evidence

  • Production LOC net −35 vs base (fix −21, refactor −14); tests +149 including façade-facts coverage, explicit configuredProfileId precedence, and a negative test that model@profile suffixes cannot imply pin precedence.
  • Suites: auth-profiles 27 files/385 tests PASS; subagents 39 files/1,095 tests PASS; announce delivery 169 tests PASS; inference-runtime 25, btw 57, reply media/admission 122, cron 13 PASS.
  • check:changed PASS (fails on unpatched main with the TS2353 above — reproduced and attributed to 2cd87d3); check:import-cycles 0; pnpm build PASS, no [INEFFECTIVE_DYNAMIC_IMPORT]; oxfmt clean; Codex autoreview clean on the final stack.
  • Route contract previously ground-truthed against sibling Codex source (codex-rs/model-provider-info/src/lib.rs, codex-rs/protocol/src/auth.rs).
  • Live gateway verification (OpenAI route-stay across compaction + Anthropic api→claude-cli fallback) to follow post-land; results will be posted here.

Follow-up candidate (out of scope): unify rotation onto the planner's ProviderModelAuthSourcePlan primitives so cooldown/order classification exists once.

AI-assisted: yes. Designed, reviewed, and verified by maintainer session.

Co-authored with @fuller-stack-dev (#123894 groundwork).

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 18, 2026 23:38
@steipete
steipete requested a review from a team as a code owner August 18, 2026 23:38
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 7:44 PM ET / 23:44 UTC.

ClawSweeper review

What this changes

This PR replaces direct session-profile rotation calls with a shared selection result that carries profile source and route requirements into inference, reply, background-question, and cron flows.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open for maintainer scope review: current main already fixes the central route-rotation regression, while this maintainer-labeled PR conflicts with that fix and proposes a broader auth-selection refactor whose distinct value needs proof.

Priority: P1
Reviewed head: 64b435850dd21115dba33cec9437a30fca5f32be
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has coherent source-level intent, but its broader scope overlaps the merged repair and needs maintainer-confirmed justification.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer PR is outside the external-contributor proof gate; its planned isolated Gateway trace remains useful pre-merge evidence for the expanded scope.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer PR is outside the external-contributor proof gate; its planned isolated Gateway trace remains useful pre-merge evidence for the expanded scope.
Evidence reviewed 6 items Current-main repair: Current main keeps automatic rotation within the current auth requirement when a provider exposes multiple routes, which directly prevents an API-key session from rotating to a subscription profile.
Current-main regression coverage: The merged repair tests both compaction and cooldown rotation for multi-route OpenAI sessions and preserves Anthropic’s API-key-to-CLI fallback.
Merged-fix provenance: The current-main commit is the merged repair for the same route-rotation behavior and records the PR author as co-author.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126084-hzQKEi/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 400.66 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 101.04 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 13.9s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4188ms (slowest: built plugin control-plane loads 3419ms)

OpenClaw 2026.8.1 (64b4358) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Session auth selection chooses a stored credential for an agent session and supplies route facts to the model runtime. Inference and other run-admission paths then use those facts to select the provider endpoint and preserve the session’s authentication route.

flowchart LR
  A[Session and model choice] --> B[Session auth selection]
  B --> C[Provider route resolution]
  C --> D[Route-compatible profile rotation]
  D --> E[Prepared runtime]
  E --> F[Model request]
  G[Cooldown state] --> D
Loading

Decision needed

Question Recommendation
Should the broader shared auth-selection façade proceed after current main already landed the narrow route-rotation repair? Keep the merged scoped repair: Pause or close this branch unless a current-main caller defect establishes that the broader façade is necessary.

Why: The central user problem is fixed on main, but this PR adds a wider, conflicting refactor across four call paths; choosing whether that extra architectural scope is worth carrying requires maintainer intent.

Before merge

  • Resolve merge risk (P1) - Current main already delivers the central fix, while this branch is reported as conflicted; rebasing must retain only independently necessary behavior.
  • Resolve merge risk (P1) - The PR’s route distinction cites Codex behavior, but direct sibling-source verification was unavailable.
  • Resolve merge risk (P1) - The stated isolated Gateway proof is planned post-land rather than attached for the broadened caller changes.
  • Complete next step (P2) - Maintainers need to choose whether any broader refactor remains worthwhile after the merged scoped fix.
Agent review details

Security

None.

PR surface

Source +8, Tests +275. Total +283 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 10 156 148 +8
Tests 10 442 167 +275
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 598 315 +283

Review metrics

Metric Value Why it matters
Production versus test LOC production +146/-137 (net +9); tests/test support +452/-178 (net +274) The bug fix expands runtime selection across four callers, so its positive production delta needs a distinct current-main justification.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/inference-runtime.test.ts, serialized state: src/agents/auth-profiles/session-override-rotation.test.ts, serialized state: src/agents/auth-profiles/session-override.test.ts, serialized state: src/agents/auth-profiles/session-override.ts, serialized state: src/agents/auth-profiles/session-override.user-pin.test.ts, unknown-data-model-change: src/agents/auth-profiles/session-override-rotation.test.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: partial_overlap
Canonical: #123894
Summary: The merged canonical PR fixes the stated rotation regression; this PR overlaps it but additionally proposes a broader caller refactor.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Keep the scoped main repair (recommended)
    Do not merge the conflicting broader refactor unless a current-main gap demonstrates that the existing route-owner repair is insufficient.
  2. Rebase with route evidence
    Reconcile with current main and show that preserved caller changes keep OpenAI route selection stable while retaining Anthropic fallback.

Technical review

Best possible solution:

Keep the merged scoped repair as the default; rebase this branch only if maintainers can demonstrate a remaining caller-level defect and verify the broader façade with route-stay and Anthropic-fallback Gateway proof.

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

No on current main: the merged route filter and focused compaction/cooldown tests cover the reported switch, although tests were not executed in this read-only review.

Is this the best way to solve the issue?

No as a replacement by default: current main has a narrower owner-level repair; the broader façade is justified only if it proves a remaining caller-level gap.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 19c916be139a; fix evidence: commit 19c916be139a, main fix timestamp 2026-08-18T16:38:56-07:00.

Labels

Label changes:

  • add P1: The change concerns agent authentication routing, where a wrong route can break a subsequent model turn.
  • add merge-risk: 🚨 compatibility: The shared selection façade changes how existing persisted session pins and configured default profiles are prioritized.
  • add merge-risk: 🚨 auth-provider: The PR changes credential-mode interpretation and endpoint route projection for OpenAI sessions.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer PR is outside the external-contributor proof gate; its planned isolated Gateway trace remains useful pre-merge evidence for the expanded scope.

Label justifications:

  • P1: The change concerns agent authentication routing, where a wrong route can break a subsequent model turn.
  • merge-risk: 🚨 compatibility: The shared selection façade changes how existing persisted session pins and configured default profiles are prioritized.
  • merge-risk: 🚨 auth-provider: The PR changes credential-mode interpretation and endpoint route projection for OpenAI sessions.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer PR is outside the external-contributor proof gate; its planned isolated Gateway trace remains useful pre-merge evidence for the expanded scope.

Evidence

What I checked:

Likely related people:

  • fuller-stack-dev: Authored the merged route-rotation implementation now on main. (role: introduced current-main repair; confidence: high; commits: 19c916be139a; files: src/agents/auth-profiles/session-override.ts, src/agents/auth-profiles/session-override.rotation.test.ts)
  • steipete: Authored this broader follow-up and is credited as co-author of the merged current-main repair. (role: recent area contributor; confidence: high; commits: 64b435850dd2, 19c916be139a; files: src/agents/auth-profiles/session-override.ts, src/gateway/worker-environments/inference-runtime.ts)

Rank-up moves

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

  • Rebase onto current main and remove any behavior already delivered by the merged repair.
  • Attach an isolated Gateway trace proving route stability and Anthropic fallback for any retained caller changes.

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.

steipete and others added 2 commits August 18, 2026 17:17
#126062 left caller-supplied announce gateway-context resolvers behind after binding dispatch to the Gateway instance. Remove the dead plumbing that broke prod-types in gateway-scope lanes.
…facts facade

Completes #123894's redesign by deduplicating the four session-auth call-site preludes and deleting inference-runtime's duplicate route re-derivation.

Co-authored-by: fuller-stack-dev <[email protected]>
@steipete
steipete force-pushed the steipete/session-auth-route-selection branch from 64b4358 to abb112c Compare August 19, 2026 00:40
@steipete steipete changed the title fix(agents): keep session auth rotation on one provider route refactor(agents): consolidate session auth selection behind prepared-facts facade Aug 19, 2026
@steipete
steipete merged commit 6d49503 into main Aug 19, 2026
228 checks passed
@steipete
steipete deleted the steipete/session-auth-route-selection branch August 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 Aug 20, 2026
…facts facade (openclaw#126084)

* fix(subagents): drop dead announce gateway-context resolver plumbing

openclaw#126062 left caller-supplied announce gateway-context resolvers behind after binding dispatch to the Gateway instance. Remove the dead plumbing that broke prod-types in gateway-scope lanes.

* refactor(agents): consolidate session auth selection behind prepared-facts facade

Completes openclaw#123894's redesign by deduplicating the four session-auth call-site preludes and deleting inference-runtime's duplicate route re-derivation.

Co-authored-by: fuller-stack-dev <[email protected]>

---------

Co-authored-by: fuller-stack-dev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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