Skip to content

perf(auth): reuse ordered provider alias entries - #138805

Merged
steipete merged 1 commit into
mainfrom
codex/perf-sep04-provider-alias-entries
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-sep04-provider-alias-entries

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Provider auth lookup materializes and locale-sorts the same freshly selected alias map separately for env candidates and auth evidence, then enumerates it again for fallback references. This PR prepares the insertion-ordered entries once and derives one sorted array for the two sorted consumers. Fallback references keep their original insertion-order pass, which matters for one-pass alias-chain expansion.

Why This Change Was Made

The owning flow remains resolveProviderAuthLookupMaps in src/secrets/provider-env-vars.ts. The env-only public export still computes only env candidates; its single-use wrapper is folded into that caller.

User Impact

No process cache, config/schema option, trust/enablement change or credential-resolution fallback is introduced. Core env arrays keep their shared identity and override precedence; evidence elements keep their canonical references; non-core result containers stay fresh. Production changes are +18/−24, net −6 lines; one preservation test adds 41 lines.

Evidence

Validation

The same four complete files passed before and after: 53/53 cases each, with identical per-file case order and outcomes. The new alias-chain case passes on the original owner too; it protects existing propagation order, fresh containers, evidence identity and shared core arrays rather than claiming a bug reproduction. The files are provider-env-vars.test.ts, provider-env-vars.dynamic.test.ts, provider-auth-aliases.test.ts and model-auth-env.provider-aliases.test.ts.

The normal changed-file gate passed all 29 stages. One managed Codex P0–P2 review completed two partitioned passes with no findings, aggregate scoped-clean confidence 0.94; the per-pass scope limits remain retained. Normal shard/Vite warnings were preserved. No product/test retry was used to obtain these results.

Measurement and tradeoffs

A fixed macOS/Node 26.8.1 cohort measured the complete synchronous public exports with canonically prepared metadata: B0/C0/C1/B1, 5,620 calls, 1,536 batch means, plus 26 separate correctness calls. Every full output, ordered key set and recorded ownership fact passed readback. The reducer retains 934 comparisons and all 286 adverse values. No numerical threshold or aggregate numeric pass was defined.

Median latency in microseconds (negative change means lower latency):

Complete operation / inventory B0 → C0 B1 → C1
Full lookup, 8 provider owners / 24 aliases 42.375 → 37.198 (−12.22%) 39.062 → 37.938 (−2.88%)
Full lookup, synthetic 32 owners / 128 aliases 164.396 → 144.480 (−12.11%) 159.230 → 149.625 (−6.03%)
Full lookup, empty/core-only 1.096 → 1.096 (0.00%) 1.115 → 0.966 (−13.31%)
Full lookup, mixed chain/origin/core override 11.578 → 10.328 (−10.80%) 11.219 → 10.391 (−7.38%)
Full lookup, live trust/enablement policy 10.765 → 10.286 (−4.45%) 10.417 → 10.739 (+3.10%)
Env-only sibling, same ordinary metadata 8.792 → 8.521 (−3.08%) 8.542 → 8.469 (−0.86%)

The means and tails are mixed. Ordinary full-lookup mean is +10.44% forward and −17.31% reverse; the forward candidate retains a 1.188 ms individual sample and 617.063 µs maximum batch mean. Mixed-control mean is −15.05% forward but +19.04% reverse, with a retained 799.625 µs sample. Policy mean is −25.07% / +1.14%, and reverse policy p95 is +7.00%. Empty-control p95 increases 17.60% / 13.99%. Larger-inventory means improve 18.81% / 0.36%, but its reverse candidate still has an 852.667 µs maximum sample. These values are retained without a causal explanation or dismissal as noise.

First calls are also mixed: the env-only sibling increases 42.79% / 10.44%, empty lookup 1.43% / 2.14%, forward policy 2.35%, reverse mixed lookup 5.14%, and reverse larger lookup 0.16%. Sampled process-tree peak RSS changes −1.40% / +2.94%; kernel child maximum RSS changes +0.79% / +4.15%. This is not evidence of a memory reduction. Native wall decreases 6.16% / 4.98%, while forward user/system CPU increases 0.95% / 5.54%; these include setup/import/encoding and are separate from target latency.

Hosts ran in the fixed order but were not equally spaced: the first inter-host gap was 45.987 s, then 175/179 ms. Samples within each process are correlated, and “first” does not guarantee cold state. Metadata preparation is outside the target clock but inside the bounded native host. This measures lookup preparation from an available snapshot, not disk discovery, credential lookup, provider requests or Gateway latency. No Gateway speedup is claimed. Earlier R2/R3 harness setup failures occurred before target calls and remain retained; the fixed R4 numerical cohort was not rerun or tuned.

The engineering case is a smaller canonical preparation flow with both ordinary and larger-inventory medians lower in both orders. The adverse mean/tail, first-call and RSS results remain part of the decision; they do not support a universal performance claim.

Named follow-up

The prototype-key accumulation boundary remains separate. Source inspection found a possible mismatch between accepted manifest target strings and ordinary-object env/evidence buckets. It has not been runtime-reproduced or established as a credential-disclosure/prototype-pollution exploit. This PR preserves the existing property access and error behavior; a normal-manifest reproduction must precede any dictionary or validation-policy repair.

@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@steipete
steipete marked this pull request as ready for review September 5, 2026 02:54
@steipete
steipete requested a review from a team as a code owner September 5, 2026 02:54
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 11:03 PM ET / September 5, 2026, 03:03 UTC.

ClawSweeper review

What this changes

Reuses prepared provider aliases during authentication lookup, preserving lookup order and adding coverage for result ownership.

Merge readiness

✅ Ready for maintainer review

Keep open: this optimization remains absent from current main, and the reviewed patch has no blocking correctness or security findings.

Priority: P3
Reviewed head: 2dd0f32a8a83034be671854da48c32a907c22c76

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving refactor with relevant coverage and appropriately qualified performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored internal refactor; the supplied body reports complete-export benchmarks and correctness readback for prepared metadata, without claiming credential-I/O or Gateway performance coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored internal refactor; the supplied body reports complete-export benchmarks and correctness readback for prepared metadata, without claiming credential-I/O or Gateway performance coverage.
Evidence reviewed 10 items Verified introduced change and merge result: The pinned merge-base-to-head diff contains only the resolver refactor and preservation test. The test merge has the exact recorded base and head parents, and its resolver diff against the base matches the introduced change.
Current-main necessity: Current main still independently enumerates and sorts aliases for environment candidates and auth evidence, then enumerates them again for fallback references. It does not contain this preparation reuse.
Ordering and ownership preserved: The alias producer returns a fresh null-prototype map after current-call trust selection. The patch shares one sorted entries array between two read-only consumers while retaining insertion-order entries for fallback expansion; core override precedence and fresh result containers remain intact.
Findings None None.
Security None None.

How this fits together

Provider authentication lookup combines plugin metadata with current trust settings to identify credential environment variables, local credential evidence, and setup fallbacks. Agent authentication and provider discovery consume these results.

flowchart TD
  A[Plugin metadata] --> C[Select eligible aliases]
  B[Current trust settings] --> C
  C --> D[Prepare alias entries once]
  D --> E[Sorted environment and evidence lookup]
  D --> F[Insertion ordered fallback expansion]
  E --> G[Agent authentication and discovery]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -6, Tests +41. Total +35 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 18 24 -6
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 24 +35

Review metrics

Metric Value Why it matters
Production versus test LOC Production −6 net; tests +41 The refactor removes a single-use wrapper while adding preservation coverage without a new production seam.
Alias preparation per full lookup Enumerations 3 → 1; alias sorts 2 → 1 Removes repeated preparation while retaining separate sorted and insertion-order consumption.

Technical review

Best possible solution:

Keep alias preparation within each lookup operation, sharing ordered entries while preserving current trust evaluation and result ownership.

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

Not applicable: this is a behavior-preserving optimization, and current-main source directly confirms the repeated preparation it removes.

Is this the best way to solve the issue?

Yes: operation-local reuse addresses the duplication at its owner; process caching would add invalidation concerns, and sorting fallback expansion would alter existing behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal performance improvement with no demonstrated user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored internal refactor; the supplied body reports complete-export benchmarks and correctness readback for prepared metadata, without claiming credential-I/O or Gateway performance coverage.

Label justifications:

  • P3: This is a bounded internal performance improvement with no demonstrated user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored internal refactor; the supplied body reports complete-export benchmarks and correctness readback for prepared metadata, without claiming credential-I/O or Gateway performance coverage.

Evidence

What I checked:

  • Verified introduced change and merge result: The pinned merge-base-to-head diff contains only the resolver refactor and preservation test. The test merge has the exact recorded base and head parents, and its resolver diff against the base matches the introduced change. (src/secrets/provider-env-vars.ts:287, 2dd0f32a8a83)
  • Current-main necessity: Current main still independently enumerates and sorts aliases for environment candidates and auth evidence, then enumerates them again for fallback references. It does not contain this preparation reuse. (src/secrets/provider-env-vars.ts:212, 790fbf0304a6)
  • Ordering and ownership preserved: The alias producer returns a fresh null-prototype map after current-call trust selection. The patch shares one sorted entries array between two read-only consumers while retaining insertion-order entries for fallback expansion; core override precedence and fresh result containers remain intact. (src/agents/provider-auth-aliases.ts:73, 2dd0f32a8a83)
  • Caller and sibling contracts: Agent auth obtains these maps through the existing facade and uses them for environment lookup, local evidence, and deferred setup fallback. The SDK-exported environment-only sibling retains its public signature and still computes only environment candidates. (src/agents/model-auth-env.ts:153, 2dd0f32a8a83)
  • Preservation and trust coverage: The new test distinguishes sorted one-pass propagation from insertion-order fallback expansion and checks fresh containers, retained evidence references, and shared core arrays. Existing tests cover changing enablement, workspace trust, alias precedence, and scoped runtime lookup. All four cited test files were read; tests were not executed during this read-only review. (src/secrets/provider-env-vars.dynamic.test.ts:869, 2dd0f32a8a83)
  • Implementation boundary: The changed operation prepares OpenClaw-owned manifest metadata. Documentation defines auth evidence as cheap local credential-marker metadata; the patch does not import, execute, or change a Codex runtime or protocol contract, so the dependency-specific Codex inspection gate does not apply. Public docs: docs/plugins/manifest.md. (docs/plugins/manifest.md:761, 2dd0f32a8a83)

Likely related people:

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

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

steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

The shared alias-entry preparation is ready for the native landing checks at 2dd0f32a8a83034be671854da48c32a907c22c76. The owner and public env-only sibling preserve traversal order, live policy and result ownership; production is net −6 lines.

The same four whole files passed 53/53 before and after:

pnpm test src/secrets/provider-env-vars.test.ts src/secrets/provider-env-vars.dynamic.test.ts src/agents/provider-auth-aliases.test.ts src/agents/model-auth-env.provider-aliases.test.ts -- --reporter=verbose --reporter=json --outputFile=<variant-report.json>
node scripts/check-changed.mjs --base c26e46b2f87ad50d2f655e44975eafc8d394527f --head HEAD -- src/secrets/provider-env-vars.ts src/secrets/provider-env-vars.dynamic.test.ts

All 29 normal changed-file stages passed. The separate managed Codex review completed two clean partitions with scoped confidence 0.94. Exact-head CI is successful, and the current complete check rollup has no pending or failed checks. Native review artifacts have validated.

I accept this smaller canonical flow with the disclosed component-level tradeoff: ordinary and larger-inventory medians improve in both orders, while the complete report retains all 286 adverse comparisons, unequal host spacing and mixed memory/tail results. There is no aggregate numeric pass or Gateway/memory-reduction claim. The prototype-key follow-up is unexecuted and outside this unchanged property-access behavior.

The completed ClawSweeper review covers this exact head and has no correctness/security findings, before-merge items or Rank-up moves. I read the complete review. Native preparation completed successfully with the unchanged head and hosted CI/Testbox gates.

@steipete
steipete merged commit fcb8eb4 into main Sep 5, 2026
246 checks passed
@steipete
steipete deleted the codex/perf-sep04-provider-alias-entries branch September 5, 2026 03:09
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
vincentkoc added a commit to LiuwqGit/openclaw that referenced this pull request Sep 5, 2026
* refs/remotes/origin/main: (602 commits)
  fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746)
  perf(sqlite): reuse compiled plugin state point reads (openclaw#138758)
  refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793)
  ci: reduce Doctor test startup and core lint jobs (openclaw#138796)
  feat(update): retain run history and share outcome reports (openclaw#138690)
  chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500)
  fix: preserve global board ownership from pinning to notifications (openclaw#138675)
  fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674)
  perf(sessions): index pending conversation replies (openclaw#127182)
  perf(auth): reuse ordered provider alias entries (openclaw#138805)
  docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804)
  perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766)
  fix: allow older source on newer Testbox checkouts (openclaw#138782)
  fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785)
  perf(codex): reduce rollout tail scan CPU (openclaw#138784)
  perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655)
  fix(build): bound native declaration inputs to checkout (openclaw#138742)
  fix(cli): preserve foreground Gateway argument handling (openclaw#138765)
  fix(ui): align task toolbar with side-panel tabs (openclaw#138769)
  fix(logbook): drain accepted work before closing SQLite (openclaw#138754)
  ...

# Conflicts:
#	src/agents/embedded-agent-runner/compact.queued.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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