Skip to content

fix(access): scope per-user views of agent activity (ent#875) - #3777

Merged
dolho merged 9 commits into
devfrom
feature/ent875-exec-control-tier
Oct 28, 2026
Merged

dolho merged 9 commits into
devfrom
feature/ent875-exec-control-tier

Conversation

@dolho

@dolho dolho commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Scopes per-user access on the agent execution and control routes to operator rulings recorded on abilityai/trinity-enterprise#875 (private tracker; rationale, probes and release-note items live there).

Post-1.0 item: do not merge before the 1.0 cut (operator ruling 2026-10-13). Kept as a draft until then.

No schema change, no migration, no dependency, CI or Docker change.

Verification

  • New unit tests (viewer tier, real-SQLite narrowing, route census plus an AST guard over read-helper call sites) and mount specs; mutation battery red as expected; PostgreSQL narrowing cases pass.
  • Existing suites: only 3 failures, all in test_ent751_gate_callers.py::TestPaidA2A, which fail identically on the base (stale payments_py in the local venv).
  • Frontend ratchets pass.
  • Live check on a real agent, base vs this branch: details on the private issue.

Related to abilityai/trinity-enterprise#875

🤖 Generated with Claude Code

@dolho dolho added the ui PR touches the frontend UI — triggers Playwright e2e tests label Oct 16, 2026
@dolho
dolho marked this pull request as draft October 16, 2026 12:41
@dolho dolho changed the title fix(executions): share holders see and steer only their own turns (ent#875) fix(access): scope per-user views of agent activity (ent#875) Oct 16, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Nightly unit-suite clean when this PR is merged into dev, all 3 seeds (head_sha: 4e6691c1422b1dff7989f0355bf1e26cddde7a8b).

dolho added a commit that referenced this pull request Oct 19, 2026
…nsus (ent#926)

With #3777 and #3776 merged in, 36 of the 152 legacy accessor rows already
have a ruling: the five shared-state reads and the model write are owner
tier, the execution reads narrow to the caller's own rows, the five webhook
routes are creator-or-owner, start/stop/model read stay open by ruling, and
the six Files routes are tiered per verb and path. Each row now carries that
reason; the legacy baseline drops to 116. The ent#875 census rules the new
turn-tier route (the agent's own key only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dolho
dolho marked this pull request as ready for review October 22, 2026 07:56
@dolho
dolho requested a review from obasilakis October 22, 2026 09:04

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

The share-holder narrowing on the routes ent#875 lists is correct and well tested: uniform 404 on execution detail/log/stream/terminate, webhook 403 only after the access check, unknown MCP scopes fail closed, SQL parameterized. Three things block it.

Major

  • src/backend/client_portal/work/service.py:372-374 — Workspace /work calls get_fleet_executions(agents, …) without the own-rows narrowing. roster_agent_names(include_owned=True) includes shared agents and _project returns title=clean_title(message), so a share holder still sees the first 120 chars of other people's prompts. Pass the viewer narrowing into the three calls and get_fleet_execution_stats, and add the route to the census test.
  • src/backend/services/turn_tier_service.py:27-40 — runs with no source_user_id (schedule/webhook/manual) are rated OWNER. A share holder can create a schedule (create_schedule uses assert_agent_access), mint its webhook, and have their own prompt run as an owner-tier turn with the full execution view. For runs carrying a schedule_id, rate the schedule's owner_id.
  • src/backend/dependencies.py:2695-2716 — the agent-key narrowing applies only when X-Trinity-Execution-Id is sent; missing or manual gets the full view. The docstring relies on a turn-tier hook that is absent on this branch (it ships in #3778). Either move these commits into the ent#926 PR so they land with the hook, or fail closed, and correct the docstring.

Minor

  • src/backend/db/schedules/executions.py:549 — a share holder's history for a schedule they created hides every cron run (no source_user_id). Treat the schedule creator as owner tier on that history, or note it as intended.
  • src/backend/models.py:4116 — can_manage_webhook: bool = True defaults permissive. Default to False.
  • routers/schedules.py analytics / analytics-summary — whole-agent aggregates stay visible to share holders. List them in the census test as ruled open.

dolho added a commit that referenced this pull request Oct 22, 2026
- Workspace /work and /work/activity narrow every agent the viewer does
  not own to their own rows (user id, or email as requester / spawned-for
  client), in the WHERE before each LIMIT and in the window count; no other
  person's prompt reaches a card title.
- turn_tier rates a schedule or webhook run by the schedule's creator, so a
  share holder's own schedule runs at share tier; a missing schedule fails
  closed. Its creator's history also shows its unattributed runs.
- An agent key's narrowing no longer trusts X-Trinity-Execution-Id: it
  starts from the agent's running share-tier turns in the ledger, and the
  header can only narrow. Fails closed on a ledger error. Docstrings no
  longer lean on the turn-tier hook.
- ScheduleResponse.can_manage_webhook defaults to False; the census covers
  the Work routes and rules the schedule analytics routes open.

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

dolho commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@obasilakis thanks. All three blockers and the three minors are addressed in 6424f75 (it also merges origin/dev, 73d99ce). For each fix I wrote the test first and then confirmed it goes red when the fix is reverted.

Major 1: Workspace /work showed other people's prompts. client_portal/work/service._own_rows now narrows every rostered agent the viewer does not own. This is an exemption list, so an agent missing from the owned roster gets narrowed. A row counts as the viewer's when it carries their user id, or their email as source_user_email / source_channel_client. Workspace turns are stamped with the email and not the id, so filtering on the id alone would have hidden the viewer's own turns. The narrowing is applied in the WHERE of all three get_fleet_executions calls and in get_fleet_execution_stats, which now takes the same own_rows_* arguments. I also found that /work/activity returned the live tool-activity lines of every running turn on a shared agent, so it is filtered to the same rows.

  • Tests: test_ent875_workspace_work_own_rows.py runs against a real SQLite with the caller's rows oldest. It covers the narrowing applying before the LIMIT, owned agents unaffected, the count matching the list, and no title from another person reaching the response. The census now includes the Work routes, and an AST guard checks that all four ledger calls in get_work carry **own.
  • Mutation: removing **own turns the e2e test and the guard red. Removing the activity filter turns the activity test red.

Major 2: a share holder's own schedule ran at owner tier. turn_tier now rates a run that has no source_user_id but a real schedule_id as the schedule's creator (owner_id), the same way it rates any person. A missing schedule, or one belonging to another agent, rates share. A schedule with no recorded creator stays the owner's, matching the webhook rule. turn_person returns the creator, so an agent key in that run reads the creator's rows.

  • Tests: in test_ent926_agent_key_turn_scope.py, the creator's cron and webhook runs are share and narrowed to the creator, the owner's schedule stays owner, a missing schedule fails closed, and a foreign agent's schedule is not used.
  • Mutation: reverting to rating by trigger turns 4 tests red.

Major 3: the agent-key narrowing could be bypassed. This is closed in this PR alone and does not depend on #3778. acting_turn_user_id no longer trusts X-Trinity-Execution-Id. It starts from the ledger: a new accessor, db.get_running_turn_attribution(agent), returns the agent's RUNNING rows, and each one is rated with turn_tier.

  • No share-tier turn running: full view, as the ruling says.
  • Exactly one person's share turn running: that person's rows.
  • Several people's share turns, or one with no platform user: no rows.

The header can only narrow further:

  • An unknown id gives no rows.
  • A share-turn id gives that person's rows, but only if no other person's share turn is running.
  • An owner-tier id widens nothing.

So leaving the header out, sending manual, or naming the owner's run no longer widens the view. A ledger read error also fails closed. I rewrote the docstrings (and security.md §5d) so they no longer rely on the turn-tier hook. The trade-off: while a shared person's turn is running, the owner's own concurrent runs also read narrowed.

Minors

  • Schedule history: on a schedule the share holder created, they also see its runs with no user (get_schedule_executions(..., include_unattributed=True), set only when schedule.owner_id equals the caller). Other people's runs stay hidden. Tested in SQL and at the route. Mutation: red.
  • can_manage_webhook now defaults to False, with a test. Mutation: red.
  • Schedule analytics / analytics-summary: analytics is now a census word, and both routes are listed as ruled open (counts and durations only, no text).

Targeted unit tests: 532 passed. Those are the ent875/ent926 suites, the ent629/ent872 reach guards, the portal Work suites, fleet executions and the models guard.

🤖 Generated with Claude Code

dolho added a commit that referenced this pull request Oct 22, 2026
…te-census

Keeps both PRs' guarantees: the agent key's execution reads start from the
ledger (#3777: the header only narrows), and the turn-tier hook, the
census-driven owner-route fence and turn_actor's visitor/person split stay
(#3778). turn_actor now takes a row, rates a schedule on another agent as
share and one with no recorded creator as the owner's (#3777 rules).

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

@obasilakis obasilakis 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. Every point from my review is fixed, and each fix has a test that fails when the fix is reverted (checked one at a time: /work list filter, stats filter, activity filter, email match, schedule-creator rating, running-turn narrowing, include_unattributed, can_manage_webhook default).

This must land together with #3778.

Two points to settle, here or in a follow-up:

  1. dependencies.py:2730-2756: while any share-tier turn runs on an agent (a Slack, Telegram or public-link chat has no user id, so it rates share tier), every request with that agent's key is narrowed to no rows, including the owner's own concurrent and scheduled runs, and gets 403 on /chat/history, /activity and /logs. The docstring states this; requirements/auth.md §2.11 does not. Please record it there as a known limit.
  2. turn_tier_service.py:35-39 with chat_execution_service.py (~2181): a reminder or self-task the agent starts during a share turn rates as owner tier (reminder has no user id and triggered_by="reminder"; a self-task is stamped with the owner's id). The running-turn check narrows it only while the parent turn runs, so a delayed one fires with the full view. This is the schedule-laundering path through a different trigger. Either carry the originating person onto the new turn and rate it share tier, or list reminders and self-tasks as a known limit next to loops. (Traced in code, not reproduced.)

dolho and others added 8 commits October 27, 2026 11:40
…t#875)

A person an agent is merely shared with sat at the accessor tier for
execution reads and for the verbs that steer the agent: they listed,
opened and streamed every other person's turns, read the activity
timeline and the container log, terminated the owner's running turn,
changed the model, forced a git pull and minted or read webhook URLs.

Operator rulings (2026-10-15): one flat share grant, no schema change.
Share holders see only executions they started (lists, detail, live
stream, queued-prompt routes, fleet list narrowed in SQL before the
limit). Terminate needs owner/admin or the execution's own requester.
Webhook management is the schedule's creator or the agent owner. Model
change and git force-pull are owner tier; start/stop stay open.

- dependencies: viewer tier as an allowlist (owner / share / key), row
  scope helpers, assert_not_share_viewer (403 owner_tier_path)
- db: keyword-only source_user_id / own_rows_user_id with an exemption
  list for agents the caller provably owns; NULL never matches
- routers: schedules, chat, agents, git, executions, activities,
  fan_out, agent_config (capacity prompt previews)
- frontend: webhook controls hidden when can_manage_webhook is false;
  own-rows note on the Tasks panel
- scripts/management/list_webhook_rotation_candidates.py: read-only list
  of webhook schedules on currently shared agents, for rotation

Tests: 241 new/updated unit tests, route census + AST guard over the
read-helper call sites, real-SQLite narrowing proof, 18/18 mutations red.

Related to Abilityai/trinity-enterprise#875

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- CodeQL: the rotation script prints token / signing-secret presence as
  constant text, so no credential-column value reaches the output.
- regression diff: test_the_fleet_route_passes_the_narrowing_to_the_query
  failed only under CI's test order. The fleet router binds viewer_own_rows at
  import, and another test reloads the helpers module, so the test patched one
  module copy and the route called another. The helper now patches the globals
  of every copy the code under test can reach.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…s output path (ent#875)

CodeQL classifies by name: a dict key called has_secret was treated as secret
data even though only constant yes/no text reached the print. The fields are now
url_minted and hmac_on. Output unchanged apart from the labels (url / signing).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…n it is (ent#926)

ent#875 left an agent key at the full view of executions. An agent acts for
whoever chats with it, so the auth dependency now records an agent key's
X-Trinity-Execution-Id (#2392) privately on the principal, and the viewer
helpers rate that turn with turn_tier_service: an owner-tier turn or no
platform turn keeps the full view; a share-tier turn reads that person's
rows (none with no platform user); an id that is not one of the key's
agent's executions reads none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uard (ent#926)

turn_tier_service rates the person who started a turn, read from the
execution row, not the requesting principal, so no agent-key reach applies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g a fake roster (ent#875)

- viewer_own_rows asks is_fleet_admin instead of comparing the role; agent
  keys already return before that line, so behaviour is unchanged.
- turn_tier joins the guard's allowlist: the role it reads is the turn
  starter's user row, never the caller's, and it selects no roster.
- _own_rows patched one module dict with both setattr and setitem. pytest
  undoes every setattr before any setitem, so the fake roster survived the
  test and broke ent#872's accessor tests under random order. Each dict is
  now patched once, with setitem.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Workspace /work and /work/activity narrow every agent the viewer does
  not own to their own rows (user id, or email as requester / spawned-for
  client), in the WHERE before each LIMIT and in the window count; no other
  person's prompt reaches a card title.
- turn_tier rates a schedule or webhook run by the schedule's creator, so a
  share holder's own schedule runs at share tier; a missing schedule fails
  closed. Its creator's history also shows its unattributed runs.
- An agent key's narrowing no longer trusts X-Trinity-Execution-Id: it
  starts from the agent's running share-tier turns in the ledger, and the
  header can only narrow. Fails closed on a ledger error. Docstrings no
  longer lean on the turn-tier hook.
- ScheduleResponse.can_manage_webhook defaults to False; the census covers
  the Work routes and rules the schedule analytics routes open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve tests/registry.json as a union of both sides' new entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dolho
dolho merged commit 91a2cef into dev Oct 28, 2026
28 checks passed
dolho added a commit that referenced this pull request Oct 28, 2026
#3777 merged into dev (91a2cef). Its branch was rewritten before
landing, so its commits arrive again under new ids; the content equals
the 6424f75 tip this branch had already absorbed (b76b99a is the
same review-blocker fix). Every conflicted file therefore resolves to
this branch's version, which is #3777's final text plus #3778's own
extensions:

- turn_tier_service.py, executions.py, dependencies.py: #3778 extends
  #3777's code (Workspace channel/email columns, the standing-work
  fence for every agent key); no #3777 line is dropped.
- test_ent629/ent872 reach guards: the exemption follows the role check
  into _user_tier, where #3778 moved it.
- auth.md: #3778's new section 2.12 and the renumbered 2.13 self-gate.
- models.py: drop the duplicate _acting_execution_id PrivateAttr the
  auto-merge added (#3778 keeps it beside _acting_turn_cache).
- registry.json: dev's file plus this PR's six ent926 entries; drop the
  duplicated ent875 entries the auto-merge produced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AndriiPasternak31 added a commit that referenced this pull request Oct 29, 2026
…hook call would pass

The field applied only #3777's share-tier rule, so an agent key without
`schedules.manage`, and the system key, read `can_manage_webhook: true` and
then got 403 on every webhook route (trinity-enterprise#719 gates them with
`require_person_or_capability("schedules.manage")`). The response now ANDs
that rule, answered by a new non-raising `person_or_capability_admits` that
shares the decorator's agent-key test and writes no audit row, with the share
tier. The two lines #3777 left false once both landed are corrected: the
"capability fence" sentence in webhook-triggers.md and the
`_can_manage_webhook` docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw
vybe pushed a commit that referenced this pull request Nov 1, 2026
…schedule webhooks a person or schedules.manage (#4041)

* fix(auth): sharing, public links and channel bindings take a person; schedule webhooks a person or schedules.manage

Forty-nine owner- and access-tier routes decide who may reach an agent, who
outside the platform sees it, or what a channel or webhook may do in its name.
Each is a grant, so each now takes its rule as a decorator dependency, which
FastAPI runs before the ownership or access check, so the refusal is the same
whether or not the agent exists.

- Schedule webhooks: a person or a schedules.manage holder; the own-agent
  exemption no longer covers them, since a webhook run is not bounded by
  autonomy.
- Sharing, agent files, the operator's Workspace client management, public
  links and canvas share links: a person. Sharing and approving an access
  request write a Workspace sign-in, so they take a signed-in session.
- Telegram, Slack, WhatsApp and VoIP bindings and exposure: a person; the
  three credential binds take a signed-in session. The agent-settable Telegram
  group fields stay agent-callable.

FROZEN_BASELINE_COUNT is the baseline length.

Part of Abilityai/trinity-enterprise#719

* fix(auth): the inline second layer on sharing, channel toggles and Workspace client control is the route's own allowlist

Seven handlers carry a human-only rule in their decorator and keep an inline
check "for direct callers": share and unshare, the Telegram progress-indicator
toggle, the Slack proactive-consent toggle, and the Workspace client log out,
block and unblock. The inline check was still `reject_agent_principal`, a
denylist that refuses only an agent key, so a direct caller holding the
system, ops, portal-delegate or an unknown-scope key, or a principal with no
`mcp_scope`, got a weaker gate than the route has.

Each first statement is now the allowlist its decorator applies:
`reject_non_interactive_principal` on the INTERACTIVE share route,
`assert_person` on the six PERSON routes. No HTTP caller sees a change: the
decorator already refuses every one of those principals first.

Tests: test_ent719_inline_layer_matches_route_rule.py calls each handler
directly, with its first side effect replaced by a sentinel; 36 rows go red
with the old denylist. Two direct-call pins (test_1310, test_223) now expect
the PERSON detail, and test_837's sharing stand-in declares the session's
`mcp_scope=None`, which the allowlist needs (the #2323 sentinel rule).

Answers dolho's informational thread on client_portal/router.py:495.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw

* docs(grants): name the census, not a route list, for owner-tier writes outside the grants

The "stay agent-reachable without a grant" bullet listed eight routes. This
branch rules three of them (folders, file-sharing, access-policy) and the
settings branch of trinity-enterprise#719 rules the other five, and every line
of the list names routes from both, so the two branches could not edit it
without conflicting. Both now replace the list with the same sentence, true
before, between and after the two land: what stays agent-reachable is what the
route census lists as agent-callable or still holds in its baseline, and no
grant lifts a route that takes a person.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw

* docs(auth): the #1710 note on the Slack consent toggle names its current inline check

requirements/auth.md said the toggle's inline `reject_agent_principal` was
kept by #1710. The inline check is now `assert_person`, the allowlist the
route decorator applies (trinity-enterprise#719), so the note says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw

* fix(schedules): can_manage_webhook is true only when the caller's webhook call would pass

The field applied only #3777's share-tier rule, so an agent key without
`schedules.manage`, and the system key, read `can_manage_webhook: true` and
then got 403 on every webhook route (trinity-enterprise#719 gates them with
`require_person_or_capability("schedules.manage")`). The response now ANDs
that rule, answered by a new non-raising `person_or_capability_admits` that
shares the decorator's agent-key test and writes no audit row, with the share
tier. The two lines #3777 left false once both landed are corrected: the
"capability fence" sentence in webhook-triggers.md and the
`_can_manage_webhook` docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: trinity-ability <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants