Skip to content

fix(messages): an agent can message a Workspace-only person - #4467

Merged
vybe merged 9 commits into
devfrom
feature/1221-message-workspace-member
Nov 11, 2026
Merged

vybe merged 9 commits into
devfrom
feature/1221-message-workspace-member

Conversation

@vybe

@vybe vybe commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Summary

An agent could not message its primary when that person uses only the Workspace: send_message answered recipient_not_found, because web delivery was an unimplemented stub and auto dropped every channel's reason.

  • Web delivery: a web send writes one agent-voiced row into the person's Workspace conversation with that agent (Main), from the agent's own key only, behind consent, the block list and the agent's roster. The deterministic row id includes the requested channel, so two sends in one turn are two rows.
  • Honest refusals: a refusal carries a per-channel reason map ({channel: code}) and a structured 404 for both address forms; the MCP tool reads it and says a Workspace delivery sends no notification.
  • Honest prompt: the Execution Context stops saying contact is permitted when no channel send_message accepts reaches the person (WhatsApp is not counted).
  • Frontend: an agent-sourced row is never taken as a turn's answer.

Fixes abilityai/trinity-enterprise#1221 (private tracker).

Tests

test_ent1221_web_delivery.py 22 passed; role addressing, assignments seam, error-text guard, proactive history, secret scrub: 212 passed; workspace delivery 50 passed; MCP messages.test.ts 8; vitest portalProactiveRowNotAReply.spec.js 4.

Review

Reading review + security pass: MERGEABLE AFTER FIXES; both important findings fixed (3c1987599, 41d6feeaa). Security: 0 findings.

Gitlink: this branch does not move src/backend/enterprise; the bump to the enterprise PR's tip lands with or right after it.

Draft until the operator's merge call.

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 7 commits November 11, 2026 00:56
…y refusal names why (abilityai/trinity-enterprise#1221)

send_message(channel="web") was a stub that always refused, and auto
dropped every channel's reason, so a person who works only in the
Workspace was unreachable and the agent was told only "not found".

- web writes one assistant row (source="proactive") into the person's
  Main conversation with the agent, through the reachability gate the
  scheduled Workspace delivery already used (now extracted as
  check_workspace_reachable / resolve_main_destination, behaviour
  unchanged). Only the agent's own key may write there, never from inside
  the recipient's own Main turn. The row id derives from the effect
  identity, so a retry after a post-commit failure writes nothing new.
- the result says delivery="workspace_inbox": delivered, nothing
  notifies them.
- every channel's refusal carries a stable code; the 404 detail carries a
  {channel: code} map for role- and email-addressed sends alike (codes
  only, never an address).
- the agent's next turn is told the row as a between-turns message.
- reachable_channels(): the local, read-only answer the Execution Context
  will use, built from the same predicates as the send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry "permitted" (abilityai/trinity-enterprise#1221)

Consent is not reachability. The assignment seam accepts a fifth,
bool-only key, proactive_reachable; with consent but an explicit False the
Primary human line says no channel reaches them, instead of "proactive
contact permitted". None (unknown, or a provider that predates the key)
renders exactly as before, and a non-bool is dropped like consent's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…space delivery honestly (abilityai/trinity-enterprise#1221)

The tool matched "404" and answered a hardcoded "They may not have
Telegram or Slack configured", discarding the backend's reason. It now
reads ApiError.body first, before any substring check, and returns the
detail's code, message and per-channel reasons (with not_authorized /
recipient_not_found / seat_unfilled). The plain-string agent-access 404
stays not_authorized. A web success carries delivery=workspace_inbox and
a note that nothing notifies the person; the descriptions say web is the
person's Workspace conversation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a turn's answer (abilityai/trinity-enterprise#1221)

latestTypedReply / typedReplyCount excluded only source === 'voice', so a
proactive row (or a completion report) landing in Main while the person
waited on a turn was shown as that turn's reply. Typed is now !source,
matching the backend's _TYPED = "source IS NULL".

Red: portalProactiveRowNotAReply.spec.js, 3 of 4 cases fail with the
predicate reverted; all four pass with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lds the new reason code to its rule (abilityai/trinity-enterprise#1221)

- proactive-messaging flow: web is the person's Workspace conversation (no
  longer "v2 deferred"), the named per-channel refusals and the 404
  channels map, delivery=workspace_inbox, reachable_channels. Requirements:
  a public-access entry, and the fifth seam key proactive_reachable in
  infrastructure 12.6.2.
- test_ent1117_s13: ChannelDeliveryError now carries reason= (a code that
  can reach the 404 body through the channels map). The guard refused any
  keyword and went red on dev's branch; it now admits only `reason`, held
  to the same constant-or-listed-platform-param rule as the sentence, and
  the stale-exemption check reads keyword values too. A reason built from
  client_id fails it (2 red), restored.
- pin: an intent-key repeat of a web send writes no second row and no
  public_chat note.
- registry entry for test_ent1221_web_delivery.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ows (abilityai/trinity-enterprise#1221)

The web row id was derived from the effect identity minus the requested
channel, while the effect guard keys on it. auto then web in one execution
were two effects sharing one row id, so the second reported success and
add_portal_message_once wrote nothing. The requested channel is now in the
id material.

Red before the fix: test_auto_then_web_in_one_turn_are_two_rows (identical
message_id for both sends).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (abilityai/trinity-enterprise#1221)

reachable_channels probed WhatsApp, but send_message accepts no whatsapp
channel and auto never tries it. A WhatsApp-only person was reported
reachable, so the Execution Context told the agent proactive contact was
possible when every send would be refused. The probe is dropped and the
feature flow sentence corrected.

Red before the fix: the WhatsApp-only row of
TestReachability::test_reachable_channels_agrees_with_the_send
({'whatsapp'} not a subset of {'telegram','slack','web'}).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

PR Validation Report — #4467

Lane: B (no security-path or schema triggers) · Branch: feature/1221-message-workspace-member → dev · 21 files (+1062/−95) · head 41d6feea

Summary

Category Status Notes
Commit messages ✅ 7 conventional fix(...) / docs+test(...) commits
Base branch ✅ dev
PR size ✅ 21 files
Status auto-promotion ✅ Fixes abilityai/trinity-enterprise#1221 (cross-tracker): the automation won't promote it, so set status-in-dev by hand after merge
Journey Impact ✅ check_journey_impact.py PASSED (none declared, still allowed)
Requirements ✅ public-access.md new entry; infrastructure.md §12.6.2 proactive_reachable
Feature flow ✅ proactive-messaging.md updated (diagram, auto order, 404 shape; "web deferred" dropped)
Security greps (§4.1–4.10) ✅ no keys, emails, IPs, env reads, symlinks or host paths; docs-guard pattern has no hits
Audit rows (§4.11) ➖ no gated write handler touched; refusals are audited with the new channels map
Cross-surface drift (§5.5) ⚠️ no agent-server twin. routers/messages.py has no first-line # mcp: header, but the PR does move tools/messages.ts, which covers it
Merge gate (6.5) ⚠️ no checks reported on the branch, and GitHub shows CONFLICTING. The only conflict is tests/registry.json (a mechanical append; dev is 8 commits ahead). dev-ci is green. This is a draft by design, so this run does not end in a merge
Execution coverage (5.4) ⚠️ see below: one production-wiring line is unpinned
Product fit (6.6) ✅ bug fix, status-ready, not incubating; every user-visible addition maps to the issue

Tests run at head (one file per command, memory-capped)

file result
test_ent1221_web_delivery.py 22 passed
test_ent1117_s13_service_error_text.py 31 passed
test_ent500_assignment_provider.py 34 passed
test_ent500_execution_context_fields.py 32 passed
test_ent606_role_addressing.py 38 passed
test_ent665_send_idempotency_key.py / test_ent341_send_block.py / test_4284_no_exception_text_in_5xx.py (route neighbours) 47 / 31 / 118 passed
MCP messages.test.ts 8 passed
vitest portalProactiveRowNotAReply.spec.js 4 passed

Execution coverage — mutations (scratch worktree, each reverted)

mutation result
_deliver_web back to an unconditional refusal 🔴 14 failed: the fix has a real regression test
"channel" dropped from _web_message_id material 🔴 test_auto_then_web_in_one_turn_are_two_rows
router 404 channels forced to {} 🔴 5 failed in test_ent606_role_addressing.py
latestTypedReply back to source !== 'voice' 🔴 3 of 4 vitest specs
prompt "no channel reaches them" branch disabled 🔴 2 failed in test_ent500_execution_context_fields.py
routers/messages.py: as_agent_key=bool(caller_agent) and caller_agent == agent_name → as_agent_key=True 🟢 all green. Ran it against ent1221, ent606, ent665, ent341 and 4284

The service-level gate is well tested (test_only_the_agents_own_key_may_write_into_a_workspace). But every test passes as_agent_key directly. Nothing checks the one line that turns the caller principal into that flag. If that line regresses, a person the agent is shared with could write agent-voiced rows into another member's Workspace, and CI would stay green. That is the class this flag exists to close.

reachable_channels has no consumer in this tree. Its consumer is the assignment provider in the paired private PR, so the proactive_reachable prompt line only goes live once that lands and the gitlink is bumped. Expected, per the PR body.

Issues found

Required before merge

  • Pin the router wiring. Add one route-level test through the real send_proactive_message handler: a human user's key with channel="web" gets the web_agent_only refusal, and the agent's own key delivers.
  • Resolve the tests/registry.json conflict so Tier 1 CI actually runs on the PR.

Warnings

  • The 404 detail for an email-addressed send changes from a string to an object ({code, message, channels}). The MCP tool handles it and no frontend reads it, but any external REST caller that reads detail as a string will break. It's intended (the old string test was replaced); worth one line in the release notes.
  • _is_recipients_own_turn fails open on an unreadable execution row, so the row is written beside the turn's reply. That's harmless for delivery and documented inline. Noting it only.

Suggestions

  • Add # mcp: messages.ts (send_message) as the first line of routers/messages.py (Invariant #13 header).

Recommendation

REQUEST CHANGES: two small items, the wiring test and the registry conflict. The design is sound: the web send reuses the scheduled-delivery reachability gate, the row id is deterministic, refusals carry codes and never addresses, and the UI and next-turn replay treat the row correctly. The change is well covered apart from the one unpinned line above. Report-only run: no label set, nothing pushed.

Trinity Agent (trinity) and others added 2 commits November 11, 2026 04:18
…r declares its MCP surface (abilityai/trinity-enterprise#1221)

A person's key sending channel=web is refused with web_agent_only and writes
no row; the agent's own key delivers. Mutation: forcing the route's
as_agent_key=True turns test_a_persons_key_is_refused_and_the_agents_own_key_delivers
red (200 == 404).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orkspace-member

# Conflicts:
#	tests/registry.json

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

PR Validation Report — #4467 (re-validation after fix 2)

Lane: B (no security-path or schema triggers) · head 6bffcd1b · 21 files · re-checks the two required items from the previous report, plus the dev merge.

Changes since the last report

item status evidence
Pin the router wiring (as_agent_key) ✅ 066f5b97e adds TestTheRoute::test_a_persons_key_is_refused_and_the_agents_own_key_delivers. It drives the real routers/messages.py route: a person's key with channel="web" gets a 404 with channels == {"web": "web_agent_only"} and no row is written. The agent's own key gets a 200, delivery == "workspace_inbox" and exactly one row.
Mutation re-run (scratch worktree, reverted) ✅ Forcing the route to as_agent_key=True makes that test fail (assert 200 == 404). The other 22 tests stay green, so this test is the one that catches it.
tests/registry.json conflict ✅ Resolved by merging dev in (6bffcd1b6). The file parses, GitHub reports MERGEABLE, and the PR diff is back to its 21 files.
Invariant #13 header ✅ routers/messages.py now starts with # mcp: messages.ts (send_message → POST /api/agents/{name}/messages) and gives the reason the consent toggle is not exposed. The PR also moves tools/messages.ts.

Tests run at head (one file per command, memory-capped)

file result
test_ent1221_web_delivery.py 23 passed (22 + the new route test)
test_ent1117_s13_service_error_text.py 31 passed
test_ent500_assignment_provider.py 34 passed
test_ent500_execution_context_fields.py 32 passed
test_ent606_role_addressing.py 38 passed

The MCP and vitest specs did not change since the last report, which recorded 8 and 4 passed.

Merge gate (Tier 1)

Every check on the head has finished. pytest (head, seed 12345) and regression diff pass, and so do both Analyze jobs, schema-parity, verify-non-root, gitleaks, journey-impact, prod-image-smoke, e2e and Build (typecheck) + unit. Nothing is still pending. journey-smoke, the base inline fallback and the push run were skipped, which is expected for Lane B with a cached baseline. dev-ci on dev is success.

Security re-check on the new commits

No keys, real addresses or host paths were found, and no file modes changed.

Carried-over warnings (no action required)

  • An email-addressed 404 now returns detail as an object ({code, message, channels}), where it used to be a string. External REST callers that read it as a string will break, so this is worth a line in the release notes.
  • reachable_channels has no consumer in this tree until the paired companion change lands and the gitlink is bumped. The PR body already says so.
  • The issue reference is cross-tracker, so set status-in-dev on it by hand after merge.

Recommendation

APPROVE. Both required items are closed, and the new test is shown to fail when the wiring breaks. Tier 1 is green and dev is green. The PR is still a draft until the operator decides to merge. This is a report-only run: nothing was pushed and no labels were changed.

@vybe
vybe marked this pull request as ready for review November 11, 2026 17:18

@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: batch validated on train/20261111-1719 (#4480)

@vybe
vybe merged commit a3d07b4 into dev Nov 11, 2026
29 checks passed
vybe pushed a commit that referenced this pull request Nov 11, 2026
#4481)

Brings the private halves of the two Workspace fixes onto dev:
- ent#1222: the assignment provider reports proactive reachability and the
  owner as primary reads as consented (pairs with #4467)
- ent#1224: member agents announce a ready agent to the open member page
  (pairs with #4468)

Co-authored-by: trinity-ability <309458136+trinity-ability@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <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.

2 participants