Skip to content

feat(credentials): a credential ask can name a destination agent on another Trinity, delivered by merge under the asking agent's own key (abilityai/trinity-enterprise#1109) - #4262

Merged
vybe merged 7 commits into
devfrom
feature/ent1109-credential-handover
Nov 5, 2026
Merged

vybe merged 7 commits into
devfrom
feature/ent1109-credential-handover

Conversation

@vybe

@vybe vybe commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ent#1066's masked ask sinks the value into the asking agent's own .env and never shows it to the agent, so a hub Regent could not forward a secret to the agent it is building on another instance. This is the platform half.

  • Destination on the ask. ask_for_credential takes an optional destination {instance_url, agent_name, key_env} (services/credential_destination.py). A destination is limited to admin-registered instances: its origin (scheme + host + port, the A2A client's own _same_origin normalisation) must equal an endpoint in the outbound A2A endpoint registry — Settings → Integrations → Outbound A2A endpoints — read through the effective provider, so a module that scopes endpoints per agent counts. The registry entry is the approval only; key_env — the NAME of the variable in the asking agent's own .env that holds its key to that instance — stays the credential, and the entry's own credential is unused. The outbound A2A kill switch governs the path (a2a_outbound_enabled setting → A2A_OUTBOUND_ENABLED → default OFF). Both are checked at raise and again at delivery. No resolver runs at raise time (raise_ask is synchronous under an async route); delivery resolves off the loop via a2a_client.validate_endpoint. Named 422s: destination_not_approved, destination_outbound_disabled (each tells the agent where an admin registers the instance), destination_invalid, destination_url_invalid, destination_agent_invalid, destination_key_env_invalid, destination_on_non_credential. Stored normalised (canonical host, default port dropped, an IPv6 literal kept bracketed, a trusted-network http:// scheme kept). Receipt, Workspace projection and the wake say where in plain words — "the agent X on the Trinity at host", never "your" (nothing here ties the host to the person; the admin's registry ties it to the platform) — and never the key's variable name.
  • Delivery. The sink's _deliver_remote: switch + registry re-checked (nothing read, nothing sent on refusal), asking agent running, key read by name through its own read endpoint (destination_key_missing; destination_key_invalid when it cannot travel as a header value — whitespace, control or non-ASCII), URL resolved off the loop and the connection pinned to the resolved address (Host + SNI = the registered host), an audit row credential_delivery_attempt written BEFORE the request leaves, then one POST {instance}/api/agents/{agent}/credentials/inject with {mode: "merge", env: {NAME: value}} under that key through a2a_client._read_capped under _with_deadline (the client's byte cap, redirects refused, error bodies never read). After a 2xx the staged value is removed and credential_delivered is audited. Failures are plain retries: destination_unreachable (503; a connect failure unstages, a timeout after the request left says may_have_written), destination_unconfirmed (503; a 5xx or an unreadable answer — "may or may not have been stored", the value kept staged, since the receiving route's own 503 means exactly that), destination_key_refused (401/403), destination_agent_missing (404), destination_refused (other, or a redirect). Audit rows carry host, agent and name — never the value or the key. The ent#1066 AST guard covers the new branch; a test pins the transport (red if follow_redirects becomes True or verify becomes False).
  • Merge mode. POST /api/agents/{name}/credentials/inject gains mode: "merge" with env (default replace unchanged; require_person untouched — a user-scoped trinity_mcp_* key already satisfies it): the sink's read-patch-inject leaf, so a delivery sets one line in place instead of rewriting the file.
  • Manifest. SystemAgentConfig.credentials accepts a list of variable NAMES; the map form stays unknown so a value is never read from a manifest; a bad entry is refused by position, never echoed.
  • MCP tool, types and tests; Workspace secret field reads "for the agent X on the Trinity at host" and "Nothing is kept here after delivery".

key_env is a NAME stored on the ask row's context like the rest of the ask — an admin reading the raw operator-queue row sees it; it is withheld from the person's projection, the receipt, the logs and the audit rows.

Follow-up (not in this PR)

AC3 (the Regent's conversational wording) and AC6 (its pre-apply_system prompting for each credentials: name) are skill work outside this repo, tracked under abilityai/trinity-enterprise#1109 itself; no new issue is opened here.

Test plan

  • tests/unit/test_ent1109_credential_handover.py — 75 tests (registry approval at raise and delivery incl. the effective-provider path, the kill switch at both points, no resolver at raise, off-loop resolution at delivery, IPv6/http normalisation, the attempt audit, 5xx unconfirmed, redirect refused, oversized answer bounded, pinned transport, non-ASCII key, W7)
  • The six Tier 1 regressions (test_3247_replace_ask, test_ent611_native_ask, test_ent901_withdraw_ask): the frozen RECEIPT_KEYS literals gain credential_destination — 289 pass
  • ent1109 / ent1066 (sink + ask kind, AST guard) / 3247 / ent611 / ent901 / 2373 / 1310 / 2996 / models_centralized / 186 / ent1030 / ent695 / system_service / 736 / a2a*: 2185 passed; 1 failure + 2 errors are local-environment only (/data read-only for avatar.generate_default_avatars; opentelemetry.exporter missing for the route census)
  • MCP npm test: 1155 pass; the 2 failing tool-visibility.test.ts ops-scope subtests are untouched by this PR (operator_queue.test.ts 92 pass)
  • portalCredentialField.mount.spec.js + ratchets: 39 pass

Closes abilityai/trinity-enterprise#1109 (cross-repo: close manually at release)

🤖 Generated with Claude Code

vybe and others added 6 commits November 4, 2026 20:11
…nother Trinity, delivered by merge under the asking agent's own key (Abilityai/trinity-enterprise#1109)

ent#1066's masked ask sinks the value into the asking agent's own `.env` and
never shows it to the agent, so a hub Regent could not forward a secret to
the agent it is building on the person's own instance.

* `ask_for_credential` takes an optional `destination`
  `{instance_url, agent_name, key_env}` (`services/credential_destination.py`):
  the URL passes the outbound A2A gate (HTTPS, public or admin-trusted, no
  path) and is stored normalised; `key_env` is the NAME of the variable in
  the asking agent's own `.env` that holds its key to that instance — the key
  itself never travels through the ask or the tool call. Named 422s:
  `destination_invalid`, `destination_url_invalid`,
  `destination_agent_invalid`, `destination_key_env_invalid`,
  `destination_on_non_credential`. The receipt, the Workspace projection and
  the wake say where in plain words (agent + host, never the key name).
* The sink's `_deliver_remote`: asking agent running, key read by name
  through its own read endpoint (`destination_key_missing`), URL re-validated
  at delivery and the connection pinned to the resolved address, one
  `POST {instance}/api/agents/{agent}/credentials/inject` with
  `{mode: "merge", env: {NAME: value}}` under that key; after a 2xx the
  staged value is removed — nothing rests here. Failures are plain retries:
  `destination_unreachable` (503; a timeout after the request left says
  `may_have_written`), `destination_key_refused`,
  `destination_agent_missing`, `destination_refused`. Audit
  `credential_delivered` carries host, agent and name — never the value or
  the key. The ent#1066 AST guard covers the new branch.
* `POST /api/agents/{name}/credentials/inject` gains `mode: "merge"` with
  `env` (default `replace` unchanged): the sink's read-patch-inject leaf, so
  a delivery sets one line in place instead of rewriting the file.
* `SystemAgentConfig.credentials` accepts a list of variable NAMES (the
  manifest member declaring what it needs; the map form stays unknown so a
  value is never read from a manifest).
* MCP tool, types and tests; Workspace secret field reads "for your agent X
  on your Trinity at host" and "Nothing is kept here after delivery".

The Regent's conversational wording and its pre-apply_system prompting are
skill work outside this repo.

Red first: 51 of 53 tests in `test_ent1109_credential_handover.py` fail on
behaviour before the change; with the sink's destination branch removed, 11
delivery tests go red.

Closes Abilityai/trinity-enterprise#1109

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…bilityai/trinity-enterprise#1109)

The receipt gained one key, `credential_destination` ({agent_name, host} |
None), the way it gained `agent_ending` for ent#901. Three suites pin the
receipt shape as a frozen literal and went red on Tier 1 (test_3247_replace_ask,
test_ent611_native_ask, test_ent901_withdraw_ask — six tests). The shape change
is the feature; the pins move with it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…endpoint, under the outbound kill switch (Abilityai/trinity-enterprise#1109)

The operator's ruling on the review: a credential ask could name ANY public
HTTPS host as its destination, and delivery never consulted the outbound A2A
switch. Now:

* A destination's origin (scheme + host + port, the A2A client's own
  `_same_origin` normalisation) must equal that of an endpoint in the admin's
  outbound A2A endpoint registry (`a2a_outbound.list_endpoints`, through the
  EFFECTIVE provider so a module that scopes endpoints per agent counts) —
  at raise (`destination_not_approved`, 422, telling the agent an admin
  registers it under Settings → Integrations → Outbound A2A endpoints) and
  again at delivery (the same named 422; nothing read, nothing sent, the
  value unstaged). The registry entry is the approval only: `key_env` — the
  asking agent's own key — stays the credential; the entry's own is unused.
* The outbound A2A kill switch (`a2a_outbound_service.is_outbound_enabled`:
  setting, then env, default OFF) governs this path at both points
  (`destination_outbound_disabled`, 422).
* No resolver call at raise time (W4): `raise_ask` is synchronous under an
  async route. The registry entry was resolved when registered; delivery
  resolves off the loop through `a2a_client.validate_endpoint` and is the
  point that refuses a host that no longer passes (private address, DNS).
* Normalisation keeps an IPv6 literal bracketed and keeps a trusted-network
  `http://` endpoint's scheme (W8).
* The delivery transport (W1, W2, W3, W5, W6): an audit row
  `credential_delivery_attempt` is written BEFORE the request leaves; the
  request goes through the A2A client's capped reader (`_read_capped`,
  `A2A_ERROR_BODY_MAX_BYTES`, redirects refused, error bodies never read)
  under its total wall-clock deadline (`_with_deadline`); a 5xx from the
  destination is `destination_unconfirmed` — "may or may not have been
  stored", the value kept staged, like the timeout; a key that cannot travel
  as a header (whitespace, control or non-ASCII) is a named
  `destination_key_invalid` before any request; and the transport is pinned
  by a test that goes red if `follow_redirects` becomes True or `verify`
  becomes False.

The mock destination in the suite is now a real `httpx.AsyncClient` over a
`MockTransport`, so what the sink builds is what httpx would send.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ever echoed (Abilityai/trinity-enterprise#1109)

A value pasted where a variable name belongs came back verbatim in the
parse error (W7). The refusal now names the entry's position and the rule it
broke.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…st", never "your" (Abilityai/trinity-enterprise#1109)

Nothing on this instance ties the destination host to the person reading
the sentence — the admin's endpoint registry ties it to the platform — so
the card, the secret field's caption, the refusal copy, the wake and the
docs drop "your". A mount test pins the PortalAsks sentence (W13).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… the outbound switch; key_env is a stored name (Abilityai/trinity-enterprise#1109)

Requirements (§3.11, security §20.11), the feature flow, the backend catalog
entries, the sink's module docstring and the MCP tool's description now say
what the code does: a destination must match an admin-registered outbound A2A
endpoint, the outbound kill switch governs the path at raise and at delivery,
no resolver runs at raise time, the attempt is audited before the request,
and a 5xx is "may or may not have been stored".

W10: security.md overstated — `key_env` is a NAME stored on the ask row's
context like the rest of the ask (an admin reading the raw operator-queue row
sees it); it is withheld from the person's projection, the receipt, the logs
and the audit rows. The key's VALUE reaches nothing a reader sees.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vybe

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Pushed by the merge train (lane C, operator ruling applied) — head 18d0d30f7, five commits on top of e054a5789:

  1. f949c8169 test(asks): the three ask suites' frozen RECEIPT_KEYS literals gain credential_destination — the receipt gained one key, the way it gained agent_ending for ent#901; this is the cause of the six Tier 1 failures (test_3247_replace_ask, test_ent611_native_ask, test_ent901_withdraw_ask). Fixed in the tests: the shape change is the feature.
  2. b6effe6c7 feat(credentials): a destination is now limited to admin-registered instances — its origin (scheme + host + port) must match an endpoint in the outbound A2A endpoint registry (Settings → Integrations → Outbound A2A endpoints), read through the effective provider; the registry entry is the approval only and key_env stays the credential. The outbound A2A kill switch governs the path (default OFF): a destination is refused at raise (destination_outbound_disabled / destination_not_approved, 422, telling the agent where an admin registers it) and again at delivery (same names, nothing read, nothing sent, the value unstaged). No resolver runs at raise time (raise_ask is sync under an async route — W4); delivery resolves off the loop via a2a_client.validate_endpoint. Also in this commit, the transport warnings: W1 an audit row credential_delivery_attempt before the POST; W2 a 5xx is destination_unconfirmed "may or may not have been stored", kept staged; W3 the request goes through a2a_client._read_capped under _with_deadline; W5 a test pins follow_redirects=False and a verifying TLS context; W6 a non-header-safe key is a named destination_key_invalid; W8 IPv6 literals stay bracketed and a trusted http:// scheme is kept.
  3. 02718238d fix(system): W7 — a bad manifest credentials: entry is named by position, never echoed.
  4. b4d7a9ac5 fix(workspace): the copy reads "the agent X on the Trinity at host" / "Sent to the agent … at host" — never "your" — in both portal components, plain_words, the wake, the refusal copy and the docs; a mount test pins the PortalAsks sentence (W13).
  5. 18d0d30f7 docs: requirements, feature flow, backend catalog, sink docstring and the MCP tool description say the above; W10 — key_env is a stored name on the ask row (withheld from the projection, receipt, logs and audit rows), the sentence no longer claims more.

W12: AC3/AC6 (skill side) are stated as a follow-up in the PR body; no issue opened.

Verification: ent1109 suite 75 pass; the six Tier 1 tests + their suites 289 pass; the touched/neighbouring backend suites 2185 pass (1 failure + 2 errors are local-environment only — /data read-only, opentelemetry.exporter absent); MCP npm test 1155 pass (2 tool-visibility ops-scope subtests fail locally and are untouched by this PR); frontend mount spec + ratchets 39 pass. Not merged, not approved, not labelled.

…tial-handover

# Conflicts:
#	src/backend/client_portal/asks/models.py
#	src/backend/client_portal/asks/service.py
#	src/mcp-server/src/types.ts
#	tests/registry.json
#	tests/unit/test_3247_replace_ask.py
#	tests/unit/test_ent611_native_ask.py
#	tests/unit/test_ent901_withdraw_ask.py
@vybe

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

merge-train: merged dev into this branch after #4261 landed — both PRs add a field to the ask receipt/projection (wake_state there, credential_destination here), so the WorkspaceAsk model, the asks projection, the MCP receipt type, the three RECEIPT_KEYS pins and tests/registry.json were resolved keep-both. No logic change.

@trinity-ability trinity-ability 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.

merge-train: lane C (/validate-pr + /review + /cso --diff at e054a57); the critical and every warning fixed on the branch per the operator's ruling — a destination is limited to admin-registered outbound A2A endpoints, the outbound kill switch governs delivery, copy no longer vouches for the host. Tier 1 green on 2b47aa5.

@vybe
vybe merged commit 8df0445 into dev Nov 5, 2026
29 checks passed
@trinity-ability trinity-ability mentioned this pull request Nov 17, 2026
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.

2 participants