Skip to content

fix(asks): a credential ask goes to a person who can open its field — the primary, else the owner, else refused by name (#4579) - #4580

Merged
vybe merged 4 commits into
devfrom
feature/4579-credential-primary-reach
Nov 15, 2026
Merged

vybe merged 4 commits into
devfrom
feature/4579-credential-primary-reach

Conversation

@webmixgamer

@webmixgamer webmixgamer commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4579

Summary

Why not #4506's check

role_addressing.can_open_agent also counts an admin's access to any agent, because an approval can be decided in Operations. A credential cannot. An admin seated as primary on an agent they neither own nor were given would still have been recorded. The new predicate asks the field's own rule.

Changes

  • src/backend/services/role_addressing.py: on_workspace_roster (the field's rule: shared or owned, account active, fails closed) and resolve_credential_reader (the chain).
  • src/backend/services/ask_service.py: the agent's own credential raise reads the chain (_address_credential); readdress_role and admin_readdress re-address a pending credential row by the same rule (_fresh_credential_audience).
  • src/mcp-server/src/tools/operator_queue.ts: ask_for_credential names the refusal (description 1,820 of 2,048 characters).
  • Tests: tests/unit/test_4579_credential_primary_reach.py (new, 26), one MCP case and one description pin.
  • Docs: requirements (credentials, security), the credential-in-chat flow, the endpoint and backend catalogs, user docs (approvals, credential management, MCP server), and a learnings fragment for the class.
  • Security report: docs/security-reports/cso-diff-2026-11-14-4579-credential-primary-reach.{md,json}.

What does not change

  • Every other ask kind, including a question or approval to: primary: anyone with access can answer those in Operations.
  • no_person (nobody, or several people, fill primary).
  • The value path (credential_sink), the field's door, the answer refusal.
  • A replayed request_id still answers with its first receipt.

Limits

  • One consequence, decided on purpose: when the seated primary cannot open the agent, the owner fills the secret in their place. This is the one case where an ask to: primary reaches someone other than a message to: primary does.
  • Point in time. The check runs at the raise. A later unshare, deactivation or ownership transfer can leave a pending ask stuck again (the registered "unshare" debt). A credential ask has no deadline.
  • Session kind. The field unlocks owned agents only for a platform session. An owner signed in through an outside-client session still gets the field's 404 on their own agent.
  • readdress_role has no production caller yet, so the re-address arm is proven by unit test only. One corner for whoever adds the first caller: when the seat moves and neither the new primary nor the owner can open the field, the pending ask keeps its previous reader, who can still fill it while the agent is on their roster (the same class as credential ask: the addressee is frozen at raise time, not re-resolved as the agent's primary at answer time #4189). Ending such an ask instead is a separate decision.
  • Rows already stuck stay until the agent is shared with their reader or the ask is cancelled.
  • Not covered here: the queue-file channel ingests a credential entry addressed to anyone but the primary as unaddressed, by design, which is a credential row no field opens for; credential ask: the addressee is frozen at raise time, not re-resolved as the agent's primary at answer time #4189 (a former primary can still fill the field after a reassignment); the tool text says the ask reaches "the person of the current chat" while the platform asks the agent's primary.

Test Plan

  • New tests: cd tests && pytest unit/test_4579_credential_primary_reach.py -v — 26 passed. Before the fix: 12 of the first 23 failed (the rest are controls and unchanged cases); the three admin re-address tests were added after dev gained that path.
  • Mutations (scratch copy, restored byte-identical), each red in at least one test: the raise call site removed (10 red); on_workspace_roster swapped for can_open_agent (1: the admin primary); include_owned=False (3, incl. the owner on real rows); the suspended clause dropped (2); the owner step removed (4); no refusal (8); the roster lookup failing open (1); re-address ignoring the rule (2); the refusal naming the person (2); the admin's re-address reading the plain role (2).
  • Neighbouring suites: the 51 unit files that touch asks, credential asks or role addressing — 1,966 passed.
  • Pinned guards (305 files plus the new one, CI flags, seed 12345) on the final tree and at the merge-base b046b7af4: nothing is red only on the branch. The same 98 test ids are red on both (real-app, route-census and pin-parity tests my machine's environment cannot import); the merge-base has one more (test_3010_autosync_toggle, not touched here). 12,344 passed on the branch against 12,321: the 23 tests of that run. This run predates the second merge of dev and the admin re-address commit; after those, the new file, both bug: /api/telemetry/containers blocks ~6s on Docker stats (ThreadPool capped at 4, no cache) — stalls Dashboard/UI #1096 suites, the ask neighbours and the registry readers pass locally (280), and CI is the authority for the guards.
  • MCP server: src/operator_queue.test.ts 117 passed; tsc --noEmit clean.
  • /cso --diff: nothing at or above the gate; 746 guard tests pass across 22 auth, fence and credential files. Report: docs/security-reports/cso-diff-2026-11-14-4579-credential-primary-reach.md.
  • Re-test on the next RC by someone other than the author (release-matrix rule 1).

Journey Impact: none: an ask that could never be answered is now handed to a person who can answer it, or refused; no journey promise changes

🤖 Generated with Claude Code

webmixgamer and others added 2 commits November 14, 2026 17:42
… the primary, else the owner, else refused by name (#4579)

A credential ask is answered only through the Workspace secret field, and
that field opens for the ask's one reader only when the agent is on their
Workspace roster (shared with them, or their own). The raise picked the
reader with no such check, so a seated primary the agent was not shared
with became the only reader of an ask nobody could fill: 201,
resolved: true, no expiry.

The reader is now a chain with the field's reach checked at each step
(role_addressing.resolve_credential_reader): the agent's primary person,
else its owner, else the raise is refused 422 role_cannot_open_agent and
nothing is filed. The check is the field's own rule (on_workspace_roster:
shared or owned, account active, fails closed), not can_open_agent, which
also counts an admin's access through Operations, where a credential
cannot be filled. readdress_role moves a pending credential row by the
same rule.

Tests: tests/unit/test_4579_credential_primary_reach.py (23; 12 red
before the fix). Mutation: with the credential arm of raise_ask removed,
10 go red; swapping the predicate for can_open_agent turns the
admin-primary test red.

Fixes #4579

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
webmixgamer and others added 2 commits November 14, 2026 18:18
…a reader who can open its field (#4579)

dev gained admin_readdress (re-address a pending card "by its rule").
For an agent's credential ask it re-ran the plain primary role, which
would move the ask to a seated primary who cannot open the secret field:
the state this branch stops the raise from creating. It now reads the
same reader chain as the raise and readdress_role.

Tests: three more in tests/unit/test_4579_credential_primary_reach.py
(26 in total). Mutation: with the admin path reading the plain role
again, two of them go red.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@pavshulin pavshulin 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.

Reviewed as the B2 re-tester for v1.0.5 (release matrix rule 1: not the author). Ran /review, /validate-pr 4580 and /cso --diff against head 1844c84a0 (merge-base cb29afd5a), plus my own mutation runs in the backend image on a scratch copy.

Verdict: comment for now; I approve once the three points below are answered (any of them may change the diff, and an approval given before that would be stale on the next push). No critical finding in any of the three. The fix is right and proven: 26 new tests green; reverting the raise call site → 12 red, roster check failing open → 14 red, readdress_role ignoring the rule → 2 red, owner step removed → 6 red. Reader set only narrows and stays inside the field's door (_owned_ask); refusal names roles and the agent's own name only; no credential value path touched; enterprise-docs guard 0 hits on the added doc lines. The chain (primary → owner → refused by name) has the same shape as the project-ask chain (steward → creator → project_unreachable), which is the parity Eugene asked for.

Three things to fix in the description or decide; none requires code, but point 3 may add some:

  1. readdress_role now has a production caller on dev. The description says it has none. Since #4581 (18:24 UTC), the enterprise assignments write re-addresses the agent's pending asks through ask_service.readdress_role(agent, "primary", …) after every primary seat write. With this PR that re-address is reach-aware (your TestReaddress covers exactly that arm — good). Without it, a seat write would move a pending credential ask onto a primary who cannot open the agent, so this PR closes a path that dev opened today. Please update "Limits" and the Test Plan; the "corner for whoever adds the first caller" is live behaviour now.
  2. Second raise door, not covered: the queue-file channel (services/operator_queue_service/filechannel.py:178, _primary_addressee after _validated_addressee(include_owned=False)) files a credential entry for the primary only when that email is on the shared roster; otherwise the row is unaddressed, and a credential row with no reader can only be cancelled. Same state class through a different door. Fine to leave for a follow-up — say which in the description.
  3. Third door (from /cso, availability only): on_workspace_roster checks suspension (users.suspended_at) and the roster, not the ent#281 client block. A blocked outside client has no users row, block_client leaves agent_sharing rows, and _reject_if_blocked stops their sign-in — so a blocked outside-client primary with a share is recorded as the one reader and can never fill. One is_client_blocked(email) check plus a test closes it; can_open_agent (#4501) has the same gap. In-PR if quick, otherwise a follow-up issue.

Also: the attached CSO report predates the second commit (its merge-base is b046b7af4, no mention of admin_readdress). The arm was audited here and only tightens (audience_unchanged 409 / rule_refused 409 pinned), but please regenerate or annotate it.

Minor: a roster-lookup error is reported to the agent as role_cannot_open_agent with the "ask an admin to share" remedy; fail-closed is right, the wording misleads during an outage. Wording only.

Validation notes for the record: Tier 1 CI green; journey-smoke / e2e skip on this path set by design (Lane B mechanically; they run on dev after merge). Re-test of row B2 on rc3 is mine.

@dolho dolho 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.

Read the source diff at head 1844c84a0 against the code it relies on (client_portal/asks/service.py::_owned_ask / _on_roster, client_portal/service.py::agent_on_roster / email_account_suspended, raise_ask, both re-address arms). I did not run the suite locally; CI is green at this head.

No blocking finding. The fix is correct and I see no way it refuses a raise that could be filled before.

What I checked:

  • The new predicate matches the door. _owned_ask admits the addressee only when agent_on_roster(agent, email, include_owned=is_platform). on_workspace_roster asks the same function with include_owned=True, and the owned read joins users by email, so it can only differ from the door for an owner on an outside-client session (already listed under Limits).
  • Nothing that worked is now refused. A primary on the roster and an owner standing in on their own agent resolve exactly as before. Every case that now gets role_cannot_open_agent or goes to the owner was a row the field refused for its only reader.
  • Branch order in raise_ask is safe. The credential branch sits after named / pre / to: project, so platform-named rows and project asks keep their own rules, and _validated_ask already refuses a credential with to != primary (invalid_to), so ignoring norm["to"] in _address_credential cannot record a row under the wrong role.
  • Replay order holds. The request_id replay returns before addressing, so a retry of a row filed earlier gets its receipt, not the new refusal.
  • Re-address arms. readdress_role caches per (gate, own_credential), so a question row and a credential row on the same seat write no longer share one audience. admin_readdress reads the same helper. Both leave the row alone on a refusal.

Three small things, none of which needs to hold the merge:

  1. Client block (agree with Pavlo's point 3, confirmed in the code). The sign-in gate reads is_client_blocked (portal_auth.py:63, email_has_access), on_workspace_roster reads suspension only. A blocked outside client who still has the share row is recorded as the one reader and cannot sign in to fill it. One extra check next to email_account_suspended closes it. Fine as a follow-up if you want this PR to stay as tested.
  2. The refusal's remedy is wrong when nobody is seated. With no primary and an owner who cannot open the agent (a suspended owner, covered by test_nobody_seated_and_an_owner_off_the_roster_is_refused), the message still says "Ask an admin to share with its primary person". There is no primary person, and an agent cannot be shared with its own owner. Wording only.
  3. admin_readdress reports the wrong cause for this case. When the credential rule refuses, the admin reads "Nobody can be found for the primary role on this agent … end it with a reason instead". Someone is seated; they cannot open the agent, and the fix the admin has is to share it, not to end the ask. Wording only.

On the release question: this is safe to take into rc3 from the code side. The change only narrows who is recorded as a reader and adds one named refusal; no value path, door or schema is touched.

@dolho dolho 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.

Ran /validate-pr 4580 at head 1844c84a0 on top of my code read from this morning (comment above). Approve.

Check Result
Lane B (no auth, credential-store, schema or CI path touched)
Base, commits, closing keyword dev, conventional, Fixes #4579 (same repo, so the issue promotes on merge)
Docs requirements, the credential-in-chat flow, both catalogs and user docs updated; enterprise-docs guard: 0 hits on added lines
Secret / email / IP / mode / host-path scans nothing (one false hit: @pytest.fixture)
New env vars, new backend packages none
Tier 1 green, including regression diff, prod-image-smoke and the MCP build + unit job
dev before merge dev-ci green

Execution coverage. The new tests call ask_service.raise_ask, readdress_role and admin_readdress against a real database, and TestRealRoster runs the real agent_on_roster and owner lookup instead of the stubs. TestRaiseRoute goes through the HTTP route. None of it is source-text matching. The live consumers are raise_ask (the credential branch), readdress_role and admin_readdress. Mutation was done twice, by the author and independently by Pavlo: with the raise call site reverted, 12 tests go red. I did not repeat it.

Not blocking, and I would not hold the merge for them:

  1. Two doors this PR leaves open (Pavlo's points 2 and 3): the queue-file channel files a credential row with no reader when the primary is off the shared roster, and a blocked outside client with a share is still recorded as the reader. Both are the same dead end through a different door, both existed before this PR, and neither is made worse by it. They need a follow-up issue each so they are not lost.
  2. The description is out of date in one place. It says readdress_role has no production caller. Since #4581 the enterprise assignments write calls it after every primary seat write, so that arm is live. No committed file repeats the claim; it is the PR body only. Please fix the body before the squash so the commit message does not carry it.
  3. The committed CSO report predates the second commit (merge-base b046b7af4, no admin_readdress). Pavlo audited that arm in his review. A one-line note in the report is enough.
  4. The two wording notes from my earlier comment stand.

On the release: safe to take into rc3. It only narrows who is recorded as the reader and adds one named refusal. If it does not merge before the tag, B2 stays red on rc3 for the t#4579 leg and needs a release note.

@vybe

vybe commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-15): merging this into dev for rc3 at head 1844c84a0, the head both reviews above read. Answers to the three points, by Eugene's ruling at the train's gate:

  1. readdress_role has a production caller. Correct, and the description's "Limits" line is out of date: since chore(enterprise): bump the submodule pointer to dd84ab4 (abilityai/trinity-enterprise#1098) #4581 the assignments write re-addresses pending asks through it after every primary seat write. TestReaddress covers that arm, so this PR is what makes that path reach-aware. Recorded here; the description is left as the author wrote it.
  2. Queue-file channel door and 3. blocked-client gap (also in can_open_agent, bug(asks): an ask to: approver is filed for a seated approver who cannot open the agent, and then nobody can answer it #4501): not in this PR. Filed as bug(asks): a credential ask can still be recorded for a reader who cannot fill it — queue-file channel and blocked clients (follow-up to #4579) #4599, together with the three wording items and the CSO report that predates the second commit.

On the merged tree (this PR on top of dev) the 26 new tests pass.

@webmixgamer nothing was pushed to your branch. @pavshulin row B2 is yours to re-test on rc3.

@vybe vybe 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: validated at 1844c84 (two prior reviews at this head; member tests green on the simulated batch). Remaining points filed as #4599.

@vybe
vybe merged commit 847e4a4 into dev Nov 15, 2026
34 of 35 checks passed
vybe added a commit that referenced this pull request Nov 15, 2026
One conflict, in docs/user-docs/credentials/credential-management.md: #4580's
bullet on who the secret field opens for and this branch's bullet on a
credential for an agent on another Trinity. Both kept, #4580's first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

4 participants