Repository navigation
Workspaces phase 4f: an end-to-end test of the phase; keys masked in errors (#277) - #352
Merged
Merged
Conversation
…errors (#277) test_provider_keys_end_to_end.py sets up, over HTTP, a workspace with only an OpenRouter key and no use of the platform's, and runs a test case whose agent calls the image tool, judged by a model. Every outgoing request is caught at httpx: each carries the workspace's key and none the platform's keys in the environment. Without the key the workspace makes no call. It found that a provider repeating the key in its error put the key in the logs: ADK logs a failed call's traceback, with the errors it was raised from. A call made with a workspace key now masks it in the error and its chain (provider_keys.redact), on every path: the LiteLLM wrapper, streamed answers, native Gemini and the direct calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 4f of the 2.0 plan (#277): an end-to-end test of the phase. It found one leak, now fixed: a provider error that repeats the key put the key in the logs.
The test
shared/test/test_provider_keys_end_to_end.py::TestPhase4EndToEndruns over HTTP, as a platform administrator and the workspace's owner would:Platform → Workspaces creates a workspace with May use platform keys off.
Models and keys stores an OpenRouter key and picks an OpenRouter image model.
The owner creates a project, an agent with the image tool, and an
llm_judgetest case with an OpenRouter judge.Running the test case builds the agent from its stored config and runs it in the process, as the agent server would. The calls are:
The test case passes.
The provider then answers 401 and repeats the key in its error.
With the key deleted, the run fails with
This workspace has no key for openrouter, and no request is made.Every outgoing request is caught at httpx and answered as OpenRouter would. The platform's own keys (
OPENROUTER_API_KEY,OPENAI_API_KEY,GOOGLE_API_KEY,GEMINI_API_KEY,ANTHROPIC_API_KEY) are set in the environment, so a request that carried one would show. The test checks that:openrouter.ai, carries the workspace's key and the expected model;model_pricing), with no key;••••1234.This covers the phase's done conditions:
Whether each call is actually billed on the workspace's key can only be seen on OpenRouter's dashboard. That check stays manual, with a real key, before 2.0.0.
What it found
ADK logs a failed model call's traceback, and the traceback includes the errors it was raised from. One of those is the provider's own error, which may repeat the key it was sent.
A call made with a workspace key now masks the key in the error and in every error in its chain, as
••••and the last four characters (provider_keys.redact). It does so on every path:ProviderKeyCompletions;_RedactingStream);WorkspaceGemini;redacting()):completion(), embeddings and the image tool.The error keeps its type, so the fallback model decides as before.
Tests
TestRedaction(3 tests): the error and its cause,strandrepr; a sync and an async stream; a direct call.TestDirectCalls.test_a_direct_call_s_error_has_the_key_masked.Mutation checks: eight changes, each caught. They removed:
completion();create_model()hookup;The full suite passes: 2027 tests, 1 skipped.
test_client_contract.pypasses unchanged.Docs
docs/dev/agent-runtime.md: masking, and what the end-to-end test checks.docs/user/workspaces.md: the key never shows, not even in a provider's error.driftalso listsdocs/dev/image-generation.md. It is still accurate: only the masking changed there.