Skip to content

Workspaces phase 4f: an end-to-end test of the phase; keys masked in errors (#277) - #352

Merged
antiv merged 1 commit into
mainfrom
workspaces-phase-4f
Nov 14, 2026
Merged

antiv merged 1 commit into
mainfrom
workspaces-phase-4f

Conversation

@antiv

@antiv antiv commented Nov 14, 2026

Copy link
Copy Markdown
Owner

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::TestPhase4EndToEnd runs over HTTP, as a platform administrator and the workspace's owner would:

  1. Platform → Workspaces creates a workspace with May use platform keys off.

  2. Models and keys stores an OpenRouter key and picks an OpenRouter image model.

  3. The owner creates a project, an agent with the image tool, and an llm_judge test case with an OpenRouter judge.

  4. 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 agent's model asks for an image;
    • the image tool calls the image model;
    • the agent answers;
    • the judge scores it.

    The test case passes.

  5. The provider then answers 401 and repeats the key in its error.

  6. 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:

  • each model call goes to openrouter.ai, carries the workspace's key and the expected model;
  • the only other request is MATE's own public price list (model_pricing), with no key;
  • no platform key appears in any request, response, log line or audit entry (read over HTTP);
  • the workspace's key appears in no response, log line or audit entry;
  • the provider's error shows the key as ••••1234.

This covers the phase's done conditions:

  • a conversation, an eval and an image tool call on the workspace's own OpenRouter key, with no fallback;
  • none of these calls reads a key from the environment. 4b's tests also run with the environment cleared.

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;
  • a streamed answer read later (_RedactingStream);
  • WorkspaceGemini;
  • the direct calls (redacting()): completion(), embeddings and the image tool.

The error keeps its type, so the fallback model decides as before.

Tests

  • The end-to-end test above.
  • TestRedaction (3 tests): the error and its cause, str and repr; 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:

  • the masking in the wrapper;
  • following the error chain;
  • masking attributes;
  • the async stream masking;
  • the masking in completion();
  • the create_model() hookup;
  • the judge context;
  • the image tool context.

The full suite passes: 2027 tests, 1 skipped. test_client_contract.py passes unchanged.

Docs

  • Updated:
    • 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.
  • drift also lists docs/dev/image-generation.md. It is still accurate: only the masking changed there.

…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.
@antiv
antiv merged commit 36445a7 into main Nov 14, 2026
2 checks passed
@antiv
antiv deleted the workspaces-phase-4f branch November 14, 2026 13:14
@antiv antiv mentioned this pull request Nov 14, 2026
22 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant