Repository navigation
fix(agent-lifecycle): stop showing credentials_injection: failed for subscription agents (#612) - #663
Merged
Merged
Conversation
…subscription agents (#612) Subscription-mode agents authenticate via CLAUDE_CODE_OAUTH_TOKEN env var (SUB-002) and have no .credentials.enc file. The agent-start path ran inject_assigned_credentials unconditionally, the encryption service raised ValueError("No .credentials.enc file found in agent workspace"), and the caller's "not found" substring check missed it (the actual message contains "file found", not "not found"). The misleading status leaks to the start endpoint response and prompts operators to re-assign subscriptions / recreate containers — disrupting running state for no reason. Two-part fix: 1. CredentialsFileNotFoundError (ValueError subclass) in services/credential_encryption.py. import_to_agent now raises this specific type when .credentials.enc is absent, so callers can catch it without fragile substring matching. Subclassing ValueError preserves the admin import endpoint's existing 400 behavior — that path *should* surface a real error when the operator explicitly asked for an import. 2. Subscription-mode short-circuit in inject_assigned_credentials. db.get_agent_subscription_id() check fires before the import path runs; returns {"status": "skipped", "reason": "subscription_mode", "detail": "..."} with explicit mention of CLAUDE_CODE_OAUTH_TOKEN so operators see this is by design. The substring-match path is removed entirely — the explicit exception subclass replaces it. Tests: tests/unit/test_inject_assigned_credentials.py — 8 cases: - subscription mode short-circuits without consulting the service - file-missing returns skipped (not failed) - CredentialsFileNotFoundError remains a ValueError (admin path compat) - happy path still returns success with file list - empty decrypted dict returns skipped - other ValueError shapes retry then surface as failed - transient ValueError recovers on retry - missing CREDENTIAL_ENCRYPTION_KEY returns skipped Combined with the existing #421 skip-inject tests: 32 tests pass, no regression. Issue: #612 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
vybe
approved these changes
May 5, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Clean two-part fix — exception subclass removes the fragile substring match and the subscription short-circuit fires before the service is even consulted. 8 unit tests cover all the edge cases. LGTM.
2 of 3 tasks
6 tasks done
dolho
added a commit
that referenced
this pull request
Sep 21, 2026
…th metric freshness, readiness (Abilityai/trinity-enterprise#527) When a companion has a role (Tandem, ent#497), the Info rail shows a Role card: the role it fills, the objectives it owns or supports with each metric's value / target / freshness, the viewer's relationship, and its readiness. Framework §8's organisation UI shrunk to one agent — files are truth, the card is a projection. The Role + Readiness half; the relationship line reads ent#500's assignment when it lands and states "no assignment recorded" until then. Files are truth, read through the platform, never a second store: `client_portal/role_card.py` reads template.yaml (`x-role`, `x-canon`), `<canon>/roles/<id>.yaml`, `<canon>/objectives/*.yaml` and the agent's own `/api/metrics` through the agent door on every request; ids and paths that reach a read are validated, text is bounded, and every failure is named (`role.error`, `unavailable`) — no `x-role` means no card at all. A metric is stale when its value is missing, unstamped, or older than the framework's 30-day bound, and stale renders as stale, never as current. Readiness is the agent owner's stamp (#663, ruled 2026-09-20). `x-role.status` is agent-writable, so `agent_role_readiness` (dual-track: SQLite + Alembic 0065, CASCADE in AGENT_REFS) holds the state, when it changed and who flipped it; a template that says `ready` with no stamp is shown as calibrating with the note that no owner stamped it. The flip is `POST …/role/readiness`, gated on the platform's owner of the agent record (named 403 for everyone else, no route for the agent), behind a confirm that says it does not switch any schedule on. While calibrating the card shows the viewer's own walkthrough count (asks in their Main, capped at ten, and their thumbs-down). `PortalAgentRole.vue` is mounted-tested (#2918); the backend card is driven through a fake agent door; the stamp against a real SQLite file. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vybe
pushed a commit
that referenced
this pull request
Sep 22, 2026
…th metric freshness, readiness (Abilityai/trinity-enterprise#527) (#2927) * fix(skills): refuse to overwrite an agent-authored skill of the same name (#2914) Assigning a library skill whose name matched a `.claude/skills/<name>/` the agent wrote itself overwrote the agent's copy, gitignored and untracked the directory, and buried an `unmanaged_dir_overwritten` warning in the assignment response. The library and the agent's repo share one flat namespace on the agent side, so a name match is not proof of the same skill — the library silently won. The inject path now refuses a directory that exists without the platform's `.trinity-skill.json` marker before a byte is staged: no archive, no restore, no `.gitignore` line, no untracking, not listed under CLAUDE.md Platform Skills. `force` (manual Sync) does not override it; a platform-managed dir keeps upgrading in place; an unreadable probe keeps the pre-existing fail-open direction. The per-skill status is `conflict` — neither `injected` nor `failed` (overall `success` stays true so the fleet re-inject does not alarm on a standing conflict every auto-sync); `skills_conflict` + `conflicts[]` carry it, and `deliver_assigned` reports `conflict` / `partial` + `conflicts[]`. The verdict is recorded on the assignment row (`agent_skills.delivery_status`, SQLite `agent_skills_delivery_status` + Alembic `0065`), carried across the bulk-replace PUT for retained names, cleared by the next injection where the name lands, and gone on unassign. The Skills tab reads it off the rows so the badge, the explanation (which skill, the agent's own copy is what runs) and an inline "Unassign library skill" action show on a fresh load; `inject()` re-reads the rows so a resolved conflict clears without a reload. MCP passes the delivery block through, `sync_agent_skills` names conflicts on its success branch, and `get_agent_skills` carries `delivery_status` per row. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * docs(learnings): #2914 — warnings on unread responses are not protection; the #2662 class inside BaseButton (#2921) * fix(skills): the platform never leaves a marker-less directory behind; delivery copy and draft fixes (#2914) Merge-train review on #2920: marker-absence was read as "the agent authored this" and refused, but the platform itself wrote marker-less directories on two live paths — the pre-#384 legacy fallback (SKILL.md only) and a restore that dropped the meta member — so each would have turned its own package into a permanent, unrepairable conflict on the next sync (AC#6 violated). Both are closed at the write: `_legacy_fallback` writes the marker beside SKILL.md (manifest = what was actually written), and `_restore_skill` writes the marker back directly when the agent's `restored` list lacks it (`marker_written_directly`). If the marker cannot be written the injection is reported `failed` (`marker_not_written`; the legacy write is rolled back) rather than a half-managed directory. Five tests cover the two paths, their failure arms, and the legacy-marker round trip that closes AC#6. Also from the review: `deliveryText` grammar ("its own a skill") with a real plural arm; the `not_delivered` arm now names conflicts beside the failure it retries; the Skills tab resets its draft only when the assigned SET changes, so a Sync (which re-reads the rows for the verdict) no longer wipes unsaved ticks; the conflict copy says "a directory the platform did not create — usually a skill it authored" rather than asserting authorship. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(ent332): the legacy fallback now writes the marker beside SKILL.md (#2914) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(schedules): a schedule that names a user runs as that seat — reads and writes their memory (Abilityai/trinity-enterprise#637) A role companion's proactive brief is a scheduled run, and a scheduled run could not touch an individual user's memory: `write_user_memory` refused every `schedule` trigger, so a brief could not carry the open loops and commitments that make the next brief better than the last. That gap is what forced "one agent per seat"; operator ruling R26 removed it. The seat is ent#498's address, read off the execution row, never sent. The ent#498 stamp already writes `source_channel='portal'` + `source_channel_client=<email>` after the roster and block checks; `services/schedule_seat_memory.seat_for_execution` reads it back for a `schedule`-triggered row and nothing else, and `routers/public_memory.py` accepts the write for exactly that case. `source_user_email` is deliberately not stamped — `client_portal/work` reads it as "work I started" and two stream-ownership checks key on it. No address → refused as before, now saying "names no one". The run reads before it writes: the tool is whole-blob replace, so the internal dispatch composes the seat's MEM-001 memory block plus a seat note into `execute_task(system_prompt=…)` on both branches, only after the stamp landed. The public persona prompt is not folded in. One write boundary, now with history: `db.write_public_user_memory_agent_notes` replaces the notes and records `public_user_memory_writes` (previous + new, execution, trigger, schedule) in one transaction — ent#419's screen lands there once, and its rollback layer is this table. The Workspace agent details gain "What it remembers about you" (`PortalAgentMemory.vue`, `GET /agents/{name}/memory`) listing the writes with schedule name and time, and Undo (`POST …/memory/writes/{id}/undo`) — latest-first, a named 409 for a later write, uniform 404 for a foreign id. Dual-track migration (SQLite `public_user_memory_writes_table` + Alembic `0065`), CASCADE in AGENT_REFS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(schedules): Run-now and webhook fires of an addressed schedule serve the same seat (Abilityai/trinity-enterprise#637) The manual trigger stamps triggered_by='manual' with the operator's own source_user_email (#1970); the brief is still addressed to the seat, so the seat resolver keys on a real schedule_id + the ent#498 portal stamp across all three fire paths and never consults source_user_email. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(workspace): a Run-now seat write is labelled as a scheduled run (Abilityai/trinity-enterprise#637) Found live: the Workspace projection keyed the write's kind on triggered_by == 'schedule', and a Run-now fire is 'manual', so the seat's own write rendered as "In a conversation". The boundary records schedule_id only for a seat run, so that is the key. Pinned with the projection test and the named-refusal test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(workspace): the memory change header wraps instead of truncating the time and the undone mark (Abilityai/trinity-enterprise#637) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * chore(migrations): chain 0066_public_user_memory_writes off #2920's 0065 — the three 2026-09-21 schema PRs are stacked (Abilityai/trinity-enterprise#637) Three open PRs each added a 0065_* off 0064, which alembic-heads reads as three heads and `upgrade head` would apply nothing. #2924 now stacks on #2920 (base branch fix/2914-skill-name-conflict) and its revision is 0066 off 0065_agent_skills_delivery_status. The migrations.py append collision is resolved by keeping both entries, #2920's first. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(workspace): the role card in Agent details — role, objectives with metric freshness, readiness (Abilityai/trinity-enterprise#527) When a companion has a role (Tandem, ent#497), the Info rail shows a Role card: the role it fills, the objectives it owns or supports with each metric's value / target / freshness, the viewer's relationship, and its readiness. Framework §8's organisation UI shrunk to one agent — files are truth, the card is a projection. The Role + Readiness half; the relationship line reads ent#500's assignment when it lands and states "no assignment recorded" until then. Files are truth, read through the platform, never a second store: `client_portal/role_card.py` reads template.yaml (`x-role`, `x-canon`), `<canon>/roles/<id>.yaml`, `<canon>/objectives/*.yaml` and the agent's own `/api/metrics` through the agent door on every request; ids and paths that reach a read are validated, text is bounded, and every failure is named (`role.error`, `unavailable`) — no `x-role` means no card at all. A metric is stale when its value is missing, unstamped, or older than the framework's 30-day bound, and stale renders as stale, never as current. Readiness is the agent owner's stamp (#663, ruled 2026-09-20). `x-role.status` is agent-writable, so `agent_role_readiness` (dual-track: SQLite + Alembic 0065, CASCADE in AGENT_REFS) holds the state, when it changed and who flipped it; a template that says `ready` with no stamp is shown as calibrating with the note that no owner stamped it. The flip is `POST …/role/readiness`, gated on the platform's owner of the agent record (named 403 for everyone else, no route for the agent), behind a confirm that says it does not switch any schedule on. While calibrating the card shows the viewer's own walkthrough count (asks in their Main, capped at ten, and their thumbs-down). `PortalAgentRole.vue` is mounted-tested (#2918); the backend card is driven through a fake agent door; the stamp against a real SQLite file. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * merge-train: mark the role card's 30-day freshness rule interim (#2927) — mechanical, per the merge-train note on the PR The PM ruling of 2026-09-21 (recorded on ent#476) allows shipping the card as-is only with the 30-day rule marked interim in the feature flow, pointing at the ent#479 shared metrics read that replaces it. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: sim <[email protected]>
7 of 8 tasks
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.
Closes #612
Summary
Subscription-mode agents authenticate via
CLAUDE_CODE_OAUTH_TOKENenv var (SUB-002) and have no.credentials.encfile. The agent-start path raninject_assigned_credentialsunconditionally, the encryption service raisedValueError("No .credentials.enc file found in agent workspace"), and the caller's"not found" in str(e).lower()substring check missed it (the actual message contains"file found", not"not found").The misleading
{"credentials_injection": "failed"}leaks to the agent-start response and prompts operators to re-assign subscriptions or recreate containers — disrupting running state for no reason. We hit this exact false alarm earlier today restartingagent-trinity-systemafter a subscription assignment.Fix
Two-part:
CredentialsFileNotFoundError(ValueErrorsubclass) inservices/credential_encryption.py.import_to_agentraises this specific type when.credentials.encis absent, so callers can catch it without fragile substring matching. SubclassingValueErrorpreserves the admin import endpoint's existing 400 behavior — that path should surface a real error when the operator explicitly asks for import.Subscription-mode short-circuit in
inject_assigned_credentials.db.get_agent_subscription_id()check fires before the import path runs; returns{"status": "skipped", "reason": "subscription_mode", "detail": "agent authenticates via CLAUDE_CODE_OAUTH_TOKEN; file-based credential injection is not used"}with explicit mention of the env-var path so operators see this is by design.The substring-match path is removed entirely — the explicit exception subclass replaces it.
Why two changes
Either alone would close the cosmetic bug, but together they're load-bearing:
import_to_agent(a no-op for them) and waste retry budget on the doomed path.Together they short-circuit the common case AND make the rare case (subscription agent that also has a
.credentials.encfor non-Anthropic creds) report cleanly if it ever fails.Tests
tests/unit/test_inject_assigned_credentials.py— 8 cases:CredentialsFileNotFoundErrorremains aValueError(admin path compat)ValueErrorshapes retry then surface as failedValueErrorrecovers on retryCREDENTIAL_ENCRYPTION_KEYreturns skippedTest plan
.env){"credentials_injection": "skipped", "credentials_result": {"reason": "subscription_mode", ...}}🤖 Generated with Claude Code