Skip to content

fix(microsoft-foundry): bound Entra token retention across accounts - #127216

Merged
steipete merged 2 commits into
mainfrom
codex/bound-foundry-token-cache
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/bound-foundry-token-cache

Conversation

@steipete

@steipete steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #127196

What Problem This Solves

Long-lived Microsoft Foundry processes retain an Entra token and expiry value for every historical scope/subscription/tenant tuple. Expired entries and retired profile generations remain in the settled-token map until process exit.

Why This Change Was Made

The provider now retains at most 128 settled tuples, refreshes recency on valid hits, removes unusable exact-key entries, and reclaims expired entries before evicting live accounts. It reuses the existing insertion-order map pruning helper. Active Azure CLI refresh promises remain separately owned and single-flight; capacity eviction never removes active work.

User Impact

Repeated account/profile changes no longer grow settled credential retention without bound. Requests for an evicted tuple transparently use the existing Azure CLI refresh path. Text and image authentication share the repaired provider owner. Configuration, credential formats, Azure API arguments, and authentication decisions are unchanged.

Evidence

A fresh trusted-main proof on 95f963e342ab476912c23c0e7fb9660c69bb9980 registered the actual plugin, persisted a synthetic Entra profile through the public auth API, and invoked its public runtime-auth hook through the real process runner and an ordinary synthetic az executable. A separate Node 24 process used temporary home/state/Azure directories and a minimal environment; no genuine Azure credentials or production-owner mocks were involved.

After filling 128 tuples, touching the first, admitting a 129th, then rereading the touched and untouched oldest tuples, main still made only 129 Azure CLI refreshes. A bounded LRU must make 130, retaining the touched tuple and refreshing the evicted one. All returned credentials matched their selected synthetic tenant. The baseline recorded 30,201.58 ms end to end and RSS 579,354,624 bytes; these are single-run observations, not a memory-savings or speedup claim.

The existing plugin suite now also checks:

  • a touched account remains cached after overflow;
  • an expired recently inserted entry is reclaimed before an older live account;
  • one active refresh survives settled-cache churn and remains reusable after completion;
  • the same fully real isolated provider/profile-store/az flow refreshes the evicted tuple, reporting only counts, booleans, timing, and RSS.

CI #34027488799 completed successfully on exact PR head b6da19645b3e69905cf8428d09eec66c5e43d8d4. The provider shard passed 1,170 tests across 67 files, including the real process-boundary proof and the expiry, recency, active-refresh, and failure-cleanup cases. CI tested merge 1627f54002dc2147b631682c9ea178876a2a2ab3, combining main b75423c2fcc30bda76fbe0480662bcaaea54a5b4 with that exact PR head.

Observed candidate output:

{"seededTuples":128,"afterRetouched":129,"afterOldest":130,"allTenantBindingsCorrect":true,"elapsedMs":3201.19518,"rssBytes":647258112}

The touched account remained cached and the evicted account refreshed through az, with every credential bound to its selected synthetic tenant. The Mac baseline and Linux CI have different execution environments; no cross-platform timing or RSS ratio is claimed.

Existing scope separation, API-key behavior, near-expiry, invalid-clock, failed-refresh cleanup, and concurrent retry coverage remains intact. Independent Codex source review is clean through P2. No candidate application code ran on credentialed Macs.

Production delta: +14/-0. Tests: +265/-0 in the existing test file; no new test root or production test seam.

Follow-up

The provider reference page still describes native Anthropic support as absent despite the existing implementation. That separate documentation mismatch was recorded for follow-up; this PR changes only token retention and its proof.

@clawsweeper

clawsweeper Bot commented Aug 21, 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 August 21, 2026 14:15
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 21, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. 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 Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 6:34 AM ET / 10:34 UTC.

ClawSweeper review

What this changes

Bounds Microsoft Foundry’s cached Entra credentials to 128 recently used account tuples, removes expired entries during refresh, and adds eviction and concurrency coverage.

Merge readiness

✅ Ready for maintainer review

Still useful: current main and v2026.9.2 retain the unbounded cache. No blocking introduced defect found. The updated maintainer-authored description addresses the prior capacity-tradeoff question.

Priority: P2
Reviewed head: b6da19645b3e69905cf8428d09eec66c5e43d8d4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant regression coverage and no blocking finding; after-fix runtime execution is not claimed.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER-authored PR is exempt from ordinary contributor proof requirements. Its baseline exercised the public Foundry auth hook with synthetic az; the captured body does not record a completed candidate result, and this review does not claim one.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER-authored PR is exempt from ordinary contributor proof requirements. Its baseline exercised the public Foundry auth hook with synthetic az; the captured body does not record a completed candidate result, and this review does not claim one.
Evidence reviewed 11 items Current main still needs the repair: Successful refreshes insert tokens into the module-lifetime map; current main has no capacity pruning or expired-entry deletion.
Latest release retains the same behavior: The v2026.9.2 runtime also inserts settled tokens without pruning; no implemented-on-main or shipped-fix close is supported.
Repair stays at the cache owner: Refresh completion removes expired entries and prunes settled tokens; valid hits update recency. Active refresh promises remain separate, retain same-key deduplication, and clear on settlement.
Findings None None.
Security None None.

How this fits together

Microsoft Foundry prepares credentials for text and image requests using the selected profile’s scope, subscription, and tenant. Its in-memory token cache avoids repeated Azure CLI calls, while a separate map coordinates concurrent refreshes.

flowchart TD
  A[Text or image request] --> B[Selected account tuple]
  B --> C{Usable cached token?}
  C -->|Yes| D[Update recency]
  C -->|No| E[Join or start Azure CLI refresh]
  E --> F[Remove expired tokens and enforce capacity]
  D --> G[Authenticated provider request]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +14, Tests +265. Total +279 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 0 +14
Tests 1 265 0 +265
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 279 0 +279

Review metrics

Metric Value Why it matters
Production versus test growth Production +14/-0; tests and test support +265/-0 Production growth implements the missing credential-retention bound using an existing helper; test growth includes an isolated process-boundary scenario without a production test seam.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #127196
Summary: This PR is the candidate repair for the linked historical-account token-retention issue.

Members:

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

Technical review

Best possible solution:

Keep retention bounded inside the shared Foundry auth owner; the small growth supplies missing expiry and recency bookkeeping while reusing existing pruning and refresh paths.

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

Yes: successive distinct account tuples cause unconditional retained-map insertions on current main, with no deletion or capacity limit. This review established the path from source and did not execute it.

Is this the best way to solve the issue?

Yes: the patch repairs the shared producer and preserves refresh ownership. Moving the policy into callers would duplicate text/image behavior, while a new cache framework would add unnecessary surface.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • remove merge-risk: 🚨 auth-provider: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: Repairs bounded resource and credential retention in long-lived Foundry processes without evidence of an urgent outage or wrong-account delivery.
  • 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 supplied MEMBER-authored PR is exempt from ordinary contributor proof requirements. Its baseline exercised the public Foundry auth hook with synthetic az; the captured body does not record a completed candidate result, and this review does not claim one.

Evidence

What I checked:

  • Current main still needs the repair: Successful refreshes insert tokens into the module-lifetime map; current main has no capacity pruning or expired-entry deletion. (extensions/microsoft-foundry/runtime.ts:43, e74543854408)
  • Latest release retains the same behavior: The v2026.9.2 runtime also inserts settled tokens without pruning; no implemented-on-main or shipped-fix close is supported. (extensions/microsoft-foundry/runtime.ts:43, 3928bad9badf)
  • Repair stays at the cache owner: Refresh completion removes expired entries and prunes settled tokens; valid hits update recency. Active refresh promises remain separate, retain same-key deduplication, and clear on settlement. (extensions/microsoft-foundry/runtime.ts:47, b6da19645b3e)
  • Existing abstraction and shared callers: The plugin entry registers the text and image providers. The text provider binds prepareFoundryRuntimeAuth, and image authentication calls the same owner. The reused map-size helper removes oldest insertion-order entries and already has boundary coverage. (extensions/microsoft-foundry/provider.ts:262, b6da19645b3e)
  • Image authentication shares the repaired cache: The image provider resolves the selected credential, passes its profile and agent directory into the shared runtime-auth owner, and uses the returned bearer token for its request. (extensions/microsoft-foundry/image-generation-provider.ts:186, b6da19645b3e)
  • Regression coverage and proof boundary: New tests cover recency, expired-entry reclamation, active-refresh survival during churn, and an isolated public-provider/profile-store/process flow using synthetic az. Existing API-key, API-scope, invalid-clock, expiry-margin, and failed-refresh cases remain. Tests were inspected, not executed. (extensions/microsoft-foundry/index.test.ts:624, b6da19645b3e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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.

History

Review history (8 earlier review cycles)
  • reviewed 2026-08-21T14:22:23.588Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T15:05:44.864Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T18:57:38.413Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T19:40:26.654Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T18:08:35.339Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T18:19:58.528Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T21:46:28.402Z sha 8c6b853 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T05:20:04.734Z sha 8c6b853 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 22, 2026
@steipete steipete self-assigned this Sep 6, 2026
Preserve active refresh ownership while pruning settled credentials, and remove redundant refresh insertion bookkeeping. Extend recency, expiry, and cache-churn coverage and exercise the public provider with a persisted synthetic profile and isolated az process.
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Sep 6, 2026
@steipete
steipete merged commit 811eb13 into main Sep 6, 2026
105 of 106 checks passed
@steipete
steipete deleted the codex/bound-foundry-token-cache branch September 6, 2026 10:49
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to ylcn91/openclaw that referenced this pull request Sep 6, 2026
* origin/main: (47 commits)
  ci: record CPU time for Node test jobs (openclaw#140054)
  test(crabbox): consolidate wrapper boundary coverage (openclaw#140058)
  fix(test): keep native filesystem access checks portable (openclaw#140047)
  fix: preserve models when OAuth preparation fails (openclaw#139951)
  feat(update): recover failed updates with bounded repair (openclaw#139495)
  refactor(plugins): share managed npm package traversal (openclaw#140040)
  chore(ui): refresh control ui locales (openclaw#140059)
  refactor(auth): share profile failure state reset (openclaw#140049)
  fix(cron): surface skipped on-exit payloads when jobs are busy (openclaw#139987)
  fix(codex): preserve exec-server WebSocket backpressure under Bun (openclaw#140048)
  fix(agents): ground exec approvals in tool results (openclaw#140043)
  refactor(policy): reuse authored policy value helpers (openclaw#140019)
  docs: keep ClawSweeper status inspection read-only (openclaw#139958)
  fix: reduce task maintenance stalls with large histories (openclaw#140038)
  fix(code-mode): identify unawaited promise output (openclaw#140028)
  fix(test): release memory search fixtures after failed phases (openclaw#140013)
  test(gateway): isolate Serve hello lifecycle fixtures (openclaw#140044)
  fix(microsoft-foundry): bound Entra token retention across accounts (openclaw#127216)
  fix(process): preserve the cause of cleanup observation failures (openclaw#140015)
  fix: clear Side chat when its parent conversation is deleted (openclaw#139974)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
…penclaw#127216)

Bound settled Microsoft Foundry Entra credentials to 128 recently used account tuples. Remove unusable and expired entries before capacity eviction while preserving separate single-flight Azure CLI refresh ownership for text and image authentication.

Verified recency, expiry-first eviction, active refresh during cache churn, failure cleanup, and the real public-provider/profile-store/az boundary. After 129 distinct tuples, the touched account stays cached and the evicted account causes refresh 130 with correct tenant binding. Exact-head CI #34027488799 passed; no genuine Azure credentials or cross-platform performance ratio claimed.

Fixes openclaw#127196

Co-authored-by: Peter Steinberger <[email protected]>
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 16, 2026
…penclaw#127216)

Bound settled Microsoft Foundry Entra credentials to 128 recently used account tuples. Remove unusable and expired entries before capacity eviction while preserving separate single-flight Azure CLI refresh ownership for text and image authentication.

Verified recency, expiry-first eviction, active refresh during cache churn, failure cleanup, and the real public-provider/profile-store/az boundary. After 129 distinct tuples, the touched account stays cached and the evicted account causes refresh 130 with correct tenant binding. Exact-head CI #34027488799 passed; no genuine Azure credentials or cross-platform performance ratio claimed.

Fixes openclaw#127196

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 811eb13)
steipete added a commit that referenced this pull request Sep 21, 2026
…f 130 CLI spawns (#154223)

The Foundry cache-eviction boundary test spent over a minute booting a cold source runtime and launching 130 synthetic Azure CLI subprocesses. Seed cache pressure through the existing mocked CLI boundary, load the shared runtime once, and keep one real subprocess refresh for the evicted tenant.

Preserve assertions for the tenant-bound bearer token, Azure CLI arguments, and subsequent cache reuse. Existing provider tests continue to cover LRU recency, expired-token reclamation, and in-flight refresh ownership. Production code and user-visible behavior are unchanged; the test diff is +87/-140 lines.

Recorded proof: all 97 tests passed before and after; eviction-test execution fell from 65.061 s to 0.232 s. Linux Testbox proof passed all 97 tests in 640 ms of test execution, with an 18.63 s command wall time. Disabling capacity pruning made the replacement fail its bearer-token assertion. Exact-head CI passed, and the scoped review plus ClawSweeper review found no actionable defects.

Related: #127216
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…f 130 CLI spawns (openclaw#154223)

The Foundry cache-eviction boundary test spent over a minute booting a cold source runtime and launching 130 synthetic Azure CLI subprocesses. Seed cache pressure through the existing mocked CLI boundary, load the shared runtime once, and keep one real subprocess refresh for the evicted tenant.

Preserve assertions for the tenant-bound bearer token, Azure CLI arguments, and subsequent cache reuse. Existing provider tests continue to cover LRU recency, expired-token reclamation, and in-flight refresh ownership. Production code and user-visible behavior are unchanged; the test diff is +87/-140 lines.

Recorded proof: all 97 tests passed before and after; eviction-test execution fell from 65.061 s to 0.232 s. Linux Testbox proof passed all 97 tests in 640 ms of test execution, with an 18.63 s command wall time. Disabling capacity pruning made the replacement fail its bearer-token assertion. Exact-head CI passed, and the scoped review plus ClawSweeper review found no actionable defects.

Related: openclaw#127216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: microsoft-foundry maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Microsoft Foundry retains expired Entra tokens for historical accounts

2 participants