Skip to content

fix(messages): the owner stands in for an unseated primary (ent#904) - #3754

Merged
vybe merged 1 commit into
devfrom
fix/ent904-primary-unseated
Oct 17, 2026
Merged

vybe merged 1 commit into
devfrom
fix/ent904-primary-unseated

Conversation

@dolho

@dolho dolho commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On an install where the assignments module is entitled, an agent with no rows answers "nobody fills primary" (people_for → []), which overrides the owner fallback. That's the default state of a fresh enterprise install. send_message(to: "primary") then returned 422 role_unassigned, so the agent had no sanctioned way to message a person. Only the deprecated recipient_email delivered.
  • Ruling (2026-10-15): on the message surface only, primary with no seat now goes to the agent's owner. The owner is always allowed proactive messages (proactive_message_service), so it delivers.
  • The resolver is unchanged on purpose. role_addressing.resolve also decides who may approve a gated skill (skill_gate_service._approvers, where primary is the default approver). An owner fallback there would silently make the owner every unseated agent's approver, and an owner requesting a skill would approve themselves. So asks still go to the operators (the ent#606 rule), and a gate approved by primary still fails closed. Both are pinned by tests.
  • An owner with no email gets a 422 that names the remedy: assign a primary in the agent's Access tab.
  • The send_message tool text no longer tells the agent to "raise an ask of type alert" to reach someone. That advice lands in the Operating Room, not with a person.

Changes

  • src/backend/routers/messages.py: the owner stand-in in _recipient, for primary only.
  • src/mcp-server/src/tools/messages.ts: the send_message description.
  • tests/unit/test_ent904_primary_unseated.py (new): covers
    • the resolver is unchanged;
    • a gate approved by primary still refuses;
    • an owner with no email gets a 422 with the remedy;
    • the stand-in applies to primary only;
    • a seated primary still wins over the owner;
    • the tool text no longer sends a person to an alert.
  • tests/unit/test_ent606_role_addressing.py: the "message to an unseated primary is refused" test becomes "goes to the owner".
  • Docs: requirements/security.md (the Messages bullet) and feature-flows/proactive-messaging.md.

Not in this PR (from the issue's suggestions)

Test Plan

  • New and updated tests: 44 passed. Before the fix, the 3 behaviour tests fail.
  • 22 related unit files (messages, role addressing, proactive, gates): 705 passed, 3 failed. The 3 are TestPaidA2A in test_ent751_gate_callers.py, which also fail on unchanged dev (f5fc04fb0).
  • Manual, on an enterprise install with no seats: send_message(to="primary") reaches the owner; a gated skill approved by primary still refuses.

Fixes abilityai/trinity-enterprise#904 (cross-repo, so it won't auto-close; close it at release)

🤖 Generated with Claude Code

With the assignments module entitled, an agent with no rows answers
"nobody fills primary", which overrides the owner fallback. That is the
default state of a fresh enterprise install, and send_message(to:
primary) then refused with 422 role_unassigned: the agent had no
sanctioned way to message a person. The tool text sent it to an alert,
which lands in the Operating Room and reaches no person.

On the message surface only, primary with no seat now goes to the
agent's owner, who is always allowed proactive messages. The resolver
is unchanged on purpose: it also decides who may approve a gated skill,
so asks still go to the operators and a primary-approved gate still
refuses. An owner with no email gets a 422 naming the remedy (assign a
primary in the agent's Access tab). The send_message description says
so instead of pointing at an alert.

Fixes Abilityai/trinity-enterprise#904

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 (rc4 backend f6a998f69, enterprise pin 6501fb1, PostgreSQL, assignments entitled). This PR's messages.py was hot-swapped into the bind-mounted backend, then restored. proj-alpha has assignments active, no primary seat, and owner admin (who has an email).

Check Before (unchanged code) After (this PR)
POST /api/agents/proj-alpha/messages with to: primary 422 role_unassigned, the reported bug gets past addressing and resolves to the owner
sales-companion, to: primary (seated primary) — still the seated person, not the owner
proj-alpha, to: approver (nobody fills it) — still 422 role_unassigned
role_addressing.resolve(proj-alpha, primary) — unchanged: people=[], resolved=False (asks still go to the operators)
Gate: _approvers(proj-alpha, primary) / approver_people — still refused role_unassigned / []; the owner doesn't become an approver

The addressing rows were checked inside the running backend container against the instance's database, with the assignments provider registered exactly as app startup does.

Not covered: delivery itself. After the fix the HTTP call returns 404 role_no_channel, because proactive web delivery isn't implemented (_deliver_web always refuses) and this instance has no Telegram or Slack binding. The owner now receives the same address the issue's working recipient_email=<owner> call used. Delivery still needs a check on an instance with a channel.

@webmixgamer

Copy link
Copy Markdown
Contributor

/review + /validate-pr

Verdict: APPROVE on head 60d784c06. No critical findings. Five informational findings, none blocking.

/review (structural)

Scope: clean. On the message route only, the owner stands in for a primary that resolves to nobody. The resolver is unchanged, so asks, reports and gate approvals behave as before.

Execution coverage

Changed symbol Executed by Live consumer Verdict
_recipient stand-in (routers/messages.py:162-165) test_a_message_to_primary_when_nobody_is_primary_goes_to_the_owner, test_a_seated_primary_still_wins_over_the_owner send_proactive_message → _recipient(...) (routers/messages.py:58), its only caller ✅
Owner with no email → 422 with a remedy (routers/messages.py:166-170) test_an_owner_with_no_email_is_refused_with_the_remedy the same route ✅
The request.to == "primary" clause test_the_stand_in_is_only_for_primary, which stays green without the clause (informational 2) the same route ⚠️ defence in depth, not pinned
send_message description (messages.ts:68-71) test_the_tool_text_no_longer_sends_a_person_to_an_alert (a source-text slice); delegation-contract.test.ts reads the published text through the real registration and checks the cap server.ts:669 registers the tool; agents receive the text as written 🛡 text pin. Fine here, because the string is the behaviour
Resolver unchanged (asks → operators, gates fail closed) test_the_resolver_still_says_nobody_fills_primary, test_a_gated_skill_approved_by_primary_still_refuses, and ent606 test_a_provider_saying_nobody_is_primary_falls_back_to_the_operators skill_gate_service.py:326 (_approvers), ask_service.py:1203, reports.py:145 ✅
Rewritten ent606 test (4 lines) itself — ✅ It changes the refusal to the ruled behaviour, with a stronger assertion (== OWNER). It does not loosen the test.
  • Tests (local):
    • The new file and test_ent606_role_addressing.py: 44 passed.
    • 35 related unit files (messages, role addressing, proactive messages, gates, asks, reports, channels): 1203 passed, 5 skipped.
    • MCP: the messages, intent_key and execution_id tests pass 21/21, and delegation-contract passes 23/23.
  • Mutation: I restored each file byte-identical afterwards, and the worktree was clean.
    • Stand-in deleted (the fix reverted at its call site) → 2 red: ent606 …goes_to_the_owner and …owner_with_no_email….
    • Owner-with-no-email refusal dropped → 1 red.
    • Tool text reverted → 1 red.
    • Owner fallback moved into the resolver (the shape the ruling rejects) → 3 red: the resolver pin, the gate pin, and ent606's fallback to the operators. A later "fix" that makes the owner an approver fails CI.
    • request.to == "primary" dropped → 0 red (informational 2).
    • Stand-in moved above the several-people check → 0 red (low confidence).
  • Safe by construction (read in code):
    • This is an address, not a grant. The consent rule already lets the owner receive any proactive message (db/agent_settings/sharing.py:332-337). Who may call the route is unchanged (AuthorizedAgentByName + get_current_user, routers/messages.py:43-47).
    • The agent never sees the owner's address. A role-addressed failure names only the role (_role_only), and the MCP tool echoes to. The 429, 409 and 502 texts carry no address.
    • Several people still refuse before the stand-in runs (routers/messages.py:157-161). I confirmed this with a throwaway probe: two primaries → role_resolves_to_several.

Informational

  1. The no-email refusal names a control that some installs don't have (8/10).
    • The new 422 says: "An admin can assign a primary in the agent's Access tab" (routers/messages.py:166-170).
    • With no assignments provider (OSS, or not entitled), resolve returns nobody for primary when the owner has no email (role_addressing.py:136-137). The request then lands in this branch.
    • On those installs the "People this agent serves" section does not render (AgentAssignmentsSection.vue:5, <section v-if="entitled">). A probe with no provider and an owner with no email got exactly this text.
    • PostgreSQL installs seed the admin without a real email address (PostgreSQL installs seed the admin with email = username, so the first-run "Sign-in email" step never appears #3554), so this path is common there.
    • Suggest naming both remedies, for example: "Give the agent's owner an email address, or assign a primary in the agent's Access tab." The existing test still passes with that text.
  2. test_the_stand_in_is_only_for_primary cannot fail (9/10).
    • With the request.to == "primary" clause removed, all 44 tests stay green.
    • The reason: resolve() already raises role_unassigned for an unfilled approver or viewer (role_addressing.py:140-143), so _recipient returns the 422 at line 154 before it reaches the stand-in.
    • The clause is defence in depth. Either stub role_addressing.resolve in that test to return an empty resolution for approver, so the clause is reached, or reword the test's claim.
  3. The stand-in covers more than "no seat written" (7/10).
    • It runs whenever the provider names nobody.
    • The seam drops an answer that is not an email address (services/assignment_provider.py:242). So a seat whose holder has no email also sends the message to the owner. A probe confirmed this.
    • The agent sees only to: primary, and the owner can already read the agent, so the outcome is probably right.
    • But the tool text says "when nobody holds the primary seat", and the flow doc says "no seat written". Suggest "nobody the platform can address holds the primary seat", or one test that pins the case.
  4. The public FAQ still says that an unfilled role is refused (8/10).
    • docs/user-docs/faq/collaboration.md:152 reads: "a role nobody fills, or several people fill, is refused by name."
    • The flow doc and requirements/security.md are updated; this user doc is not.
    • One sentence would align it: "If nobody holds the primary seat, the agent's owner receives the message."
  5. The two deferred suggestions are tracked only in the abilityai/trinity-enterprise#904 thread (7/10).

Low confidence

  • Several primaries is not pinned on this path (5/10). Only statement order stops the stand-in from catching two primaries, because not r.single is also true for several people. The current code is correct. if not r.people and request.to == "primary", or one test, would make the order irrelevant.
  • Not covered: delivery end to end. The address now resolves to the owner. Delivery still needs a Telegram or Slack binding for the owner, because proactive web delivery is not implemented. The author's instance test covers addressing, and the PR's manual Test Plan item is still open.

/validate-pr

Lane B (no schema), 6 files (+106/−9), 1 commit, head 60d784c06.

Category Status Notes
Commit / base / size ✅ fix(messages); targets dev; 6 files
Status auto-promotion ✅ (manual step) Fixes abilityai/trinity-enterprise#904 is cross-tracker, so the workflow will not move it. Set status-in-dev on that issue by hand after the merge.
Issue ✅ abilityai/trinity-enterprise#904: P1, type-bug, status-in-progress
Requirements / architecture ✅ / ➖ the Messages bullet in requirements/security.md is updated; no endpoint or schema change
Feature flow ✅ ⚠️ proactive-messaging.md "Addressed by role" is updated. The file predates the standard section layout, which is not this PR's doing.
MCP third surface ✅ the tool passes to through unchanged; only its description changed, and it matches the route
Security §4.1–4.10 ✅ no keys, real emails (placeholders only), IPs, env files, secrets, credential files, infra, file mode or host-path changes
Disclosure guard ✅ 0 hits over the 2 added doc lines
Test adequacy / execution coverage ✅ named regression file test_ent904_primary_unseated.py; the fix mutation turns 2 tests red
Merge gate ✅ Tier 1 green: regression diff, pytest (head, seed 12345), the 4 required contexts, gitleaks, both lints. journey-smoke, prod-image-smoke and the MCP build + unit are green too (21 pass, 5 skipping). dev-ci is a success on the dev tip f5fc04fb0.

Release: this P1 correction is not in rc4. If it lands for 1.0, it goes into the next RC, and the open manual item is that RC's re-test: a to: primary message from an unseated agent reaches an owner who has a Telegram or Slack binding.

@webmixgamer webmixgamer 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 60d784c06: no critical findings. The /review + /validate-pr report is in the comment above. The five informational items can be follow-ups. After the merge, set status-in-dev on abilityai/trinity-enterprise#904 by hand, because the reference is cross-tracker.

@vybe
vybe merged commit ac3f0ff into dev Oct 17, 2026
26 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