Skip to content

fix(asks): an ask to a role several people fill reaches every one of them (abilityai/trinity-enterprise#816) - #3513

Merged
vybe merged 4 commits into
devfrom
feature/ent816-multi-person-ask
Oct 11, 2026
Merged

vybe merged 4 commits into
devfrom
feature/ent816-multi-person-ask

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Summary

An ask addressed to a role that two or more people fill was stored with no Workspace addressee, so it showed up in nobody's Inbox. Its receipt still said resolved: true. After this change the one ask reaches every person the role resolves to. The first answer wins, and the others see who answered.

Root cause

role_addressing.resolve sets a single addressee (Resolution.single) only when exactly one person resolved. For 2+ people, ask_service._address stored addressed_to_email = NULL, with every person kept in resolved_to. The Workspace asks list and every per-ask door (_owned_ask) matched only addressed_to_email = viewer, so no viewer could ever match. The receipt computes resolved as bool(resolved_to), so it reported true in exactly that case.

The fix (operator ruling, 2026-10-07)

This builds what the operator ruled in the issue thread: deliver the one ask to everyone the role resolves to. The first answer wins and the others see that someone else answered. Dismiss and Discuss are refused on a shared ask for now. Refusing the raise with role_resolves_to_several was rejected, because it would block two-approver gated skills.

  • Fan-out on read, no duplicate rows. In db/operator_queue._list_conditions, "addressed to this person" now means addressed_to_email = viewer OR viewer ∈ resolved_to. The membership check (_resolved_to_contains) runs in SQL: it matches the JSON-quoted email with LIKE escaping, ignores case, and works the same on SQLite and PostgreSQL. The list, its count and the agent prefilter therefore cover exactly what is shown (bug: Workspace asks read silently stops at 200 rows with no total #3059). No schema change.
  • One rule for every door. client_portal/asks/service._is_addressed_to is the Python twin of that check. It is used by answer, dismiss, discuss, the context read and the replace-link projection. Someone the role does not resolve to still gets the uniform 404 (Invariant security: implement safe tar extraction with symlink/hardlink validation #8).
  • First answer wins. The existing compare-and-set in the ask sink already lets only one answer land. A later answer is refused with already_resolved. The projection now carries shared, and when a co-addressee answered first it carries ended_by = someone_else plus answered_by, which is that person's account name, or their address if they have no name. An operator's ending is unchanged: still operator, still unnamed.
  • Dismiss and Discuss are refused on a shared ask with 422 shared_ask, and PortalAsks hides both buttons. Answering is unaffected.
  • Receipt. resolved: true for a multi-person role is now accurate, because each person's Workspace Inbox shows the ask. The operator role still goes to the Operating Room only (unchanged).
  • Expiry and counts. Each person's Inbox and pending count come from the same SQL, so a shared ask that expires reads as expired in every one of their Inboxes.
  • The MCP ask_operator description now explains resolved and the multi-person delivery. Docs updated: architecture/workspace.md, architecture/backend.md, feature-flows/operating-room.md.

Tests

  • tests/unit/test_ent816_shared_asks.py: 18 new tests, run through the real raise_ask with a two-person assignment provider. They check that the ask is in both Inboxes, each person's count, that there is one row, the uniform 404 for a non-addressee at every door, shared, the receipt, expiry in each Inbox, that the second answer is refused, the someone-else ending plus answered_by, that an operator stays unnamed, the Dismiss/Discuss shared_ask refusals, and exact membership (lookalike addresses, _/% wildcards, case).
    • Mutation check: with the db/operator_queue.py change reverted, 13 of 18 fail, including test_an_ask_to_a_role_two_people_fill_lands_in_both_inboxes (assert [] == [<ask id>]).
  • src/frontend/tests/unit/portalSharedAsk.mount.spec.js: 3 mounted tests. With PortalAsks.vue and utils/operatorQueue.js reverted, all 3 fail.
  • Regression runs: every operator_queue|ent751|3246|ask|ent815|workspace unit file passed (2031 passed, 7 xfailed). npm run test:unit passed 333 files and 5453 tests. MCP src/operator_queue.test.ts passed 46 of 46.

Deferred (not in this PR)

  • Per-person Dismiss and Discuss on a shared ask (the ruling's follow-up).
  • The issue's other ACs: when the provider answers "nobody" for primary, re-recording to_role as operator; a separate receipt and get_my_ask field for "a Workspace will show this"; reporting unaddressed non-operator rows to the operator. With fan-out, resolved is already accurate for the multi-person case. The primary→[] case already reports resolved: false.
  • A shared ask has no single addressee, so it isn't attached to a chat thread. It lives in the Inbox only, like a background ask.

Implements abilityai/trinity-enterprise#816

🤖 Generated with Claude Code

trinity-ability and others added 3 commits October 10, 2026 15:13
…them (Abilityai/trinity-enterprise#816)

role_addressing.resolve names a single Workspace addressee only when exactly
one person resolved, so an ask to a role two people fill was stored with
addressed_to_email NULL. The Workspace list filtered on addressed_to_email =
viewer, so the ask rendered in nobody's Inbox while the receipt said
resolved: true.

Per the operator ruling of 2026-10-07 in the issue thread: the ONE ask is
delivered to every person the role resolves to (fan-out on read, no
duplicate rows), the first answer wins, and Dismiss/Discuss are refused on a
shared ask for now.

- db/operator_queue: "addressed to this person" is addressed_to_email =
  viewer OR viewer in resolved_to, as a SQL condition (JSON-quoted,
  LIKE-escaped, case-insensitive; same on SQLite and PostgreSQL), so the
  list and its count page over exactly what is shown (#3059).
- client_portal/asks/service: _is_addressed_to is the Python twin used by
  every per-ask door (answer, dismiss, discuss, context), so a non-addressee
  still gets the uniform 404 (Invariant #8). The projection carries
  `shared`; a co-addressee's answer reads ended_by=someone_else with
  answered_by; Dismiss and Discuss on a shared ask are 422 `shared_ask`.
- The receipt's `resolved` is now truthful for the multi-person case: a
  person's Workspace shows the ask.

Tests: tests/unit/test_ent816_shared_asks.py (18). Mutation check: with the
db/operator_queue.py change reverted, 13 of 18 go red, including
test_an_ask_to_a_role_two_people_fill_lands_in_both_inboxes
(assert [] == [<ask id>]).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…answered it (Abilityai/trinity-enterprise#816)

PortalAsks hides Dismiss and Discuss on a shared ask (the server refuses both
with `shared_ask`); queueEnding reads ended_by=someone_else as the
projection's answered_by, and the Inbox list's badge says "Answered · <name>".

Tests: tests/unit/portalSharedAsk.mount.spec.js (3, mounted). Mutation check:
with PortalAsks.vue and utils/operatorQueue.js reverted, all 3 go red,
including "offers neither Dismiss nor Discuss, but can still be answered".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…em (Abilityai/trinity-enterprise#816)

ask_operator's description now says what `resolved` means and that a
multi-person role reaches every person; operating-room flow, workspace and
backend area files record the fan-out-on-read rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vybe
vybe force-pushed the feature/ent816-multi-person-ask branch from d3dc52c to 1e9bab3 Compare October 10, 2026 14:14
…he shared replace link (Abilityai/trinity-enterprise#816)

Pre-landing review of #3513:

- `_ending_of` mapped ANY ending by a person in `resolved_to` to
  `someone_else` and `_answered_by` then named them. A co-addressee who is
  also an operator and cancels the shared ask from the Operating Room is an
  operator's ending: it read "Cancelled by <name>" in the other person's
  Inbox and carried `answered_by` on a cancel, against the projection's own
  contract (operator endings stay coarse and unnamed). Now only an answer
  reads `someone_else`.
- The `_linked_request_id` widening (replace links on a shared ask) had no
  test; a mutation reverting it stayed green. Two tests now pin it, including
  the withheld case (the replaced ask was never the viewer's).

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

Copy link
Copy Markdown
Contributor Author

/review Report

Branch: feature/ent816-multi-person-ask → dev (diffed against the merge-base)
Files Changed: 14 (+600/-23), plus review fix commit f7c766c (+55/-3)

Tests run after the fix: pytest unit/test_ent816_shared_asks.py = 21 passed; the 41 related ask / operator-queue / role-addressing unit files (*ask*, *operator_queue*, *3246*, *3247*, *ent364*, *ent606*, *ent610*, *ent611*, *ent661*, *ent747_748*) = 1343 passed, 7 xfailed. No frontend change in the fix commit.
Scope: CLEAN. Delivers the 2026-10-07 operator ruling in abilityai/trinity-enterprise#816: deliver to everyone, first answer wins, Dismiss/Discuss refused on a shared ask. The issue's other ACs (primary→[] re-recorded as operator, a separate "a Workspace will show this" receipt/get_my_ask field, reporting unaddressed non-operator rows) are explicitly deferred in the PR body.
Plan Completion: AC1 DONE (db/operator_queue.py::_list_conditions + _resolved_to_contains, asks/service.py::_is_addressed_to). AC5 PARTIAL: the 2+ people row is tested, the other rows already had coverage. AC2/3/4/6 NOT DONE, by scope cut and named in the PR body (LOW impact now that resolved is accurate for the multi-person case).

Execution coverage (Step 2.5)

changed symbol / test file executed by live consumer verdict
OperatorQueueOperations._resolved_to_contains / _list_conditions test_ent816_shared_asks.py (list, count, membership exactness) asks/service.list_asks_page, _discussed_in, _recent_answers ✅ executed
asks/service._is_addressed_to / _owned_ask non-addressee 404 at all 4 doors; answer by co-addressee answer/dismiss/discuss/context routes ✅ executed
_is_shared → shared, shared_ask refusals TestSharedAskRefusals, projection tests PortalAsks.vue canDismiss/canDiscuss ✅ executed
_ending_of someone_else + _answered_by TestFirstAnswerWins, plus the new cancel test PortalAsks ending text, PortalInboxList.askStatusLabel ✅ executed
_linked_request_id(viewer_email) none before review (a mutation reverting it stayed 18/18 green). Now TestReplaceLinkOnASharedAsk _project replaces/replaced_by ✅ executed (after fix)
portalSharedAsk.mount.spec.js mounted PortalAsks (jsdom) n/a ✅ executed (not source-text)

Fix mutation: reverting db/operator_queue.py turns 13/18 red (the author's figure; I confirmed the suite is green on the branch). Reverting the _linked_request_id branch turns test_a_shared_ask_that_replaces_a_shared_ask_links_both_ways red (I checked this one myself). Reverting the _ending_of guard turns test_a_co_addressee_who_cancels_from_the_operating_room_stays_the_operator red.

Critical Findings (block merge)

None.

Findings fixed in this review: commit f7c766c

[F1] Data disclosure / contract: a co-addressee's CANCEL was named as someone_else + answered_by (Confidence: 9/10). FIXED in f7c766c.
File: src/backend/client_portal/asks/service.py (_ending_of)
Evidence: if who == "operator" and _answered_by_co_addressee(item, by): who = "someone_else". This did not check the verb, so it also fired when by was a disposed_by_email from a cancel.
Issue: some person the role resolves to may also be an operator. If they cancel the shared ask from the Operating Room, the other co-addressees read "Cancelled by <name/email>", and the projection carries answered_by on a cancel. That contradicts the model's own contract ("Set ONLY for a co-addressee's answer: an operator's ending stays the coarse operator, unnamed").
Fix: someone_else now applies only when status == "answered". Regression test: TestOnlyAnAnswerNamesTheCoAddressee (red before the fix: ('someone_else', '<alice email>') != ('operator', None)).

[F2] Test gap: the _linked_request_id widening had no executing test (Confidence: 9/10). FIXED in f7c766c.
The PR changed the replace-link projection to use the shared addressing rule, but no test covered it. Added two tests: links both ways across two shared asks, and the link is withheld when the replaced ask was never the viewer's (Alice's single-person ask replaced by a shared one, viewed by Bob).

Informational Findings (review required)

[I1] Performance: _answered_by does one get_user_by_email per projected row (Confidence: 7/10)
File: src/backend/client_portal/asks/service.py (_answered_by)
It only runs for shared asks ended by someone_else, so a full page (≤PAGE_MAX) is at worst N lookups. Suggestion: memoise per list_asks_page call if shared asks become common.

[I2] Product: a co-addressee's email crosses to the other co-addressees when they have no account name (Confidence: 6/10)
This follows the ruling ("the others see that someone else answered") and is bounded to people the same role resolved to. Still, for external clients this is the first place one Workspace principal sees another's address. It's a product call, so I left it as is.

[I3] Casing rule drift: .lower() (new code) vs .casefold() (ask_service.may_end, skill_gate_service._approved_by_addressee) (Confidence: 5/10, appendix-grade)
The two only differ for non-ASCII addresses (ß). Today it has no effect because shared asks are never gate rows (gates name one addressee each).

[I4] Requirements doc not updated (Confidence: 6/10). The ruling changes ask-addressing behaviour, but there is no docs/memory/requirements/ edit. The architecture and feature-flow docs are updated.

Clean Categories

  • SQL safety: the LIKE pattern is a bound parameter, JSON-quoted and LIKE-escaped (\, %, _). ESCAPE '\' follows the existing context_contains precedent at db/operator_queue.py:1148. resolved_to is TEXT on both tracks (schema.py, Alembic 0076). No schema change, so no migration was needed.
  • Auth / Invariant security: implement safe tar extraction with symlink/hardlink validation #8: every per-ask door goes through _owned_ask → _is_addressed_to. A non-addressee gets the uniform 404 at answer, dismiss, discuss and context (tested). resolved_to is platform-written only (create_native_item is its only writer, and ingest never sets it).
  • Races: first answer wins through the sink's existing compare-and-set (respond_to_operator_queue_item). The loser gets already_resolved (tested), with no second write or dispatch.
  • Resume destination: operator_resume_service._workspace_destination requires addressed_to_email == responder. A shared ask has none (and no discussion chat, since Discuss is refused), so a co-addressee's answer never widens a run's audience.
  • Enterprise-docs guard: the guard pattern finds no hits in the added doc lines.
  • Credentials: none touched.
  • Frontend: no v-html. The gates are template branches covered by mounted tests.

Summary

  • Critical: 0 open. Fixed during review: 2 (F1 contract/disclosure bug, F2 test gap), commit f7c766c.
  • Informational: 4 (no change needed for merge).
  • Scope: clean. The deferred ACs are named in the PR body.

Deferred debt (not pushed to trinity-dev in this run): I1 (memoise answered_by lookups), I3 (one casing rule for addressee comparisons), and the PR's own deferrals (per-person Dismiss/Discuss; AC2/3/4/6 of ent#816).

🤖 Generated with Claude Code

@trinity-ability
trinity-ability marked this pull request as ready for review October 10, 2026 20:55

@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: batch validated on train/20261011-0752 (#3528)

@vybe
vybe merged commit 60f5333 into dev Oct 11, 2026
28 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.

2 participants