Skip to content

fix(sdk): invalidate cached secrets after invalid-secrets responses#3957

Merged
bekossy merged 5 commits intorelease/v0.94.2from
codex/implement-cache-invalidation-for-api-key-failures
Mar 12, 2026
Merged

fix(sdk): invalidate cached secrets after invalid-secrets responses#3957
bekossy merged 5 commits intorelease/v0.94.2from
codex/implement-cache-invalidation-for-api-key-failures

Conversation

@mmabrouk
Copy link
Member

@mmabrouk mmabrouk commented Mar 11, 2026

Motivation

  • Provider key or custom provider updates could remain stale until middleware cache TTL expired because there is no targeted invalidation path for credential-scoped secrets cache entries.
  • Evicting the credential-scoped secrets cache when an invocation returns an invalid-secrets error lets the next request fetch fresh secrets immediately.

Description

  • Added delete() to TTLLRUCache to support targeted cache eviction via TTLLRUCache.delete().
  • Added invalidate_secrets_cache(credentials) to the running vault middleware and wired it to remove the credential-scoped get_secrets cache entry when a workflow response contains a status.type ending with #v0:schemas:invalid-secrets.
  • Updated the routing invoke flow to call invalidate_secrets_cache(credentials) when a workflow invocation returns the invalid-secrets status so SDK-run invocations trigger eviction.
  • Updated the FastAPI vault middleware to parse JSON 400 responses and invalidate the cache when the response detail contains "No API key found for model" to cover serving-mode responses.
  • Added unit tests covering TTLLRUCache.delete() and invalidate_secrets_cache() behavior.

Testing

  • Ran formatting with ruff format on modified files which completed successfully.
  • Ran linter/fixes with ruff check --fix which reported all checks passed.
  • Added unit tests sdk/tests/pytest/unit/test_vault_cache_invalidation.py and attempted to run them via pytest, but execution in this environment failed due to repo pytest addopts/plugins and missing runtime dependency pydantic required to import the agenta package.
  • Verified Python byte-compilation with python -m compileall for modified modules which succeeded.

Codex Task


Open with Devin

@vercel
Copy link

vercel bot commented Mar 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Mar 12, 2026 9:19am

Request Review

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 11, 2026
@dosubot dosubot bot added bug Something isn't working SDK labels Mar 11, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@mmabrouk mmabrouk requested a review from jp-agenta March 11, 2026 12:43
@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Railway Preview Environment

Status Destroyed (PR closed)

Updated at 2026-03-12T14:59:32.739Z

- Add TTLLRUCache.pop() method that removes and returns the cached value
- Refactor get/set/invalidate secrets cache into dedicated helper functions
- Invalidate secrets cache when a 400 response containing 'No API key found for model' is detected (FastAPI middleware)
- Invalidate secrets cache when _has_invalid_secrets_error detects an invalid-secrets status type or message (workflow service middleware)
- Add _has_invalid_secrets_error() helper for structured response inspection
- Add unit tests covering pop, cache roundtrip, and error detection
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 11, 2026
@junaway junaway changed the base branch from main to release/v0.94.1 March 12, 2026 09:18
@mmabrouk mmabrouk marked this pull request as draft March 12, 2026 09:24
@mmabrouk mmabrouk marked this pull request as ready for review March 12, 2026 10:19
@bekossy bekossy changed the base branch from release/v0.94.1 to release/v0.94.2 March 12, 2026 14:58
@bekossy bekossy merged commit 1f01203 into release/v0.94.2 Mar 12, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codex SDK size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants