Repository navigation
fix(access): a read narrowed by a running turn says so, and the route census checks every tier's gate (abilityai/trinity-enterprise#978) - #4760
Conversation
… census checks every tier's gate (Abilityai/trinity-enterprise#978) Items 1 and 6 of the issue. Items 2 to 5 are not in this change. Item 6. While a shared person's or a visitor's turn runs on an agent, every request made with the agent's key reads executions narrowed to that person and is refused owner-tier routes: the platform cannot tell which process sent a request, so it fails closed. The behaviour is accepted (operator ruling 2026-11-23), but for reads it was silent: an owner-started run on the same agent read list_recent_executions as 0 rows instead of 10, with no error and no marker, and get_execution_result for a finished run answered 404. - A response computed under the narrowed view carries X-Trinity-Read-Narrowed: turn_person | running_turn | unverified. The seam that decides the view (acting_turn_user_id) notes the code; a pure-ASGI middleware (utils/read_narrowing.py, mounted in main.py) puts it on the response, so every reader that narrows through the seam is marked without a per-route edit, 404s and streams included. - The marker is decided from the principal, never from a row. get_execution and get_execution_log compute the scope before the row lookup, so a run that exists and one that does not answer the same status, body, headers and query count. The code does not vary with the turn id a caller sends, and a handler cannot set the header itself. Only an agent key is marked. - The MCP read tools show it as narrowed: {code, message} (list_recent_executions, get_execution_result, get_fan_out_result, get_agent_activity_summary, get_schedule_executions, list_project_executions). Under a narrowed view a 404 from get_execution_result / get_fan_out_result is returned with the reason instead of thrown; an unmarked 404 still throws. - A route refused because ANOTHER turn is running says that, at the fence and in assert_agent_owner, instead of telling the owner's run that its own turn is a shared person's. Same 403, same string shape; an unreadable ledger keeps the old text. - get_execution_result also shows restricted_turn when a run carries the #4281 stamp. Item 1. The census checked the code gate for owner and accessor rows only. It now holds self, internal, public and resource rows to the code too, through one function: a self row shows a self gate and no owner gate (and assert_own_agent only beside an access check), an internal row sits on a router that requires the internal secret, a resource row shows its predicate, a public row shows no gate and is on a reviewed list. A tier with no rule fails. No row of the table changes. Tests: tests/unit/test_ent978_narrowed_read_marker.py (real routers, real get_current_user, real agent key and rows on SQLite), src/mcp-server/src/read-narrowing.test.ts (real HTTP through withAudit), the census file, and the main.py middleware pin in test_3127_pull_chat.py. Mutation proof, each restored byte-identical: 24 single-line breaks (the seam note, each scope-first reorder, the header append, the main.py mount, the code mapping, the text picker at both sites, each MCP spread, each census rule and two re-declared live rows) each turned a named test red. No migration. No change under docker/ or src/frontend. Part of Abilityai/trinity-enterprise#978 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ityai/trinity-enterprise#978) Nothing open. Three low findings from the pre-commit review are fixed on the branch, each with a regression test named in the report. Part of Abilityai/trinity-enterprise#978 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ai/trinity-enterprise#978) CI's regression diff reported 9 new errors in test_public_folder_mount_match.py. That test loads services/agent_service/file_sharing.py, and through it dependencies.py, against a stubbed `models` that provides only `User`. The narrowed-read marker had added `TaskExecutionStatus` to the module-level `from models import`, which that stub cannot satisfy. The enum is now imported where it is used, beside the function-level `turn_tier_service` import. Reproduced outside the suite (real fastapi imported first, `models` stubbed, file_sharing.py loaded by path): ImportError before, loads after. Part of Abilityai/trinity-enterprise#978 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
merge-train note: validated at Operator ruling at Gate 1 (recorded on the linked issue): ships as OSS core. For a follow-up, not blocking:
This will conflict with #4743 in |
|
merge-train: left the train after its first run; rides the next one once fixed. Nothing is wrong with this PR against
#4425 adds How the rule should treat a gate reached through a wrapper is this PR's call (follow one level of local helper, or name |
|
Resolve by running |
|
Resolve by merging |
…ead-marker # Conflicts: # docs/memory/architecture/security.md
…ator check in the DB writer; review notes on the narrowed-read marker (Abilityai/trinity-enterprise#978) After merging dev, the census failed on a route that landed there meanwhile: POST /api/agents/{agent_name}/guardrail-events (#4425) is declared self and reaches authorize_heartbeat through a helper of its own file run on a worker thread, which the new self rule did not see. Census: - The self rule reads the handler one level into a helper of the same file that the handler names, never further. A gate behind asyncio.to_thread(helper, ...) is seen, and a helper cannot hide an owner gate. No row of the table changes. - The resource rule no longer accepts a DB writer's name as the gate: three of the eight resource rows passed because the handler called the writer. The writer's own body is read for the creator check (a comparison on owner_id, or the owner predicate). Narrowed-read marker, from the PR review: - The running-executions read computes its scope before it looks at the container, so "no executions" for a missing, stopped or unreachable agent is marked like any other answer. - The refusal text for a route refused while a share-tier turn runs says "A turn is running on this agent ...", not "Another turn ...": a request that sends no turn id may come from the restricted turn itself. - The claim that the code "does not vary with the turn id sent" was too strong. Docstring and security.md now say what holds: while a share turn runs, every id that is not a running share turn reads the same; turn_person confirms only that an id the caller already holds is a share turn running on its own agent; with nothing running the view differed before the marker existed. Tests pin each case, the running share id included. Mutation proof on the merged tree, files restored byte-identical: 29 single-line breaks each turned a named test red, among them "helpers are not followed", "a helper may hide an owner gate", "calling the writer is enough", the writer losing its creator check in both places, the scope moved back after the container, and the old wording. Removing one of the writer's two creator checks stays green, as it should: the UPDATE's WHERE still checks. Part of Abilityai/trinity-enterprise#978 Co-Authored-By: Claude Fable 5.2 <[email protected]>
obasilakis
left a comment
There was a problem hiding this comment.
/review + /validate-pr at f9244f948
Verdict: approve. No critical findings. Lane C (dependencies.py).
Execution coverage
810 Python tests and 18 MCP tests pass locally at head. 17 single-line mutations, each restored afterwards; all 17 turned a test red.
| Mutation | Red test |
|---|---|
read_narrowing.note(code) removed from acting_turn_user_id |
test_a_run_that_exists_and_one_that_does_not_answer_the_same[] |
header append disabled in ReadNarrowedMiddleware |
same |
app.add_middleware(ReadNarrowedMiddleware) removed from main.py |
test_main_mounts_the_middleware_inside_the_host_guard |
get_execution scope computed after the row |
..._answer_the_same[] |
get_execution_log scope computed after the row |
..._answer_the_same[/log] |
| running list scope moved back after the container lookup | test_the_running_list_is_marked_whatever_the_container_says[None-404] |
_turn_refusal_detail always picks the old text |
test_the_owners_concurrent_run_is_told_a_shared_turn_is_running |
turn_person returned for a finished share turn |
test_an_id_that_is_not_a_running_share_turn_reads_the_same_while_one_runs |
ledger path returns unverified in place of running_turn |
..._answer_the_same[] |
| handler-set header no longer stripped | test_a_handler_cannot_set_the_header_itself |
| non-agent principal gets a code | test_a_signed_in_person_is_never_marked[owner] |
turnFetch stops recording the header |
read-narrowing.test.ts |
narrowedField() spread removed: list_recent_executions, get_schedule_executions, list_project_executions (3 mutations) |
read-narrowing.test.ts |
| narrowed 404 thrown | read-narrowing.test.ts |
| unmarked 404 swallowed | read-narrowing.test.ts |
The census file is a guard whose live consumer is CI. The owner and accessor rules carry the same three assertions as before the move into TIER_RULES; the 17 deleted test lines are that move plus the middleware count going 3 → 4.
Pass 1 (critical): clean
- SQL / data: no query, schema or migration change.
- Concurrency: the holder is created per request by the outermost-but-two ASGI layer and mutated in place, so the threadpool and
BaseHTTPMiddlewarecontext copies share it.finally: _holder.reset(token)runs on every exit. - Auth boundary:
_acting_turn_narrowingreturns the same person as before on every branch; only the second tuple element is new._turn_refusal_detailruns afterrestricted_agent_turnhas already refused and falls back to the original text on any exception. Status stays 403 at both sites. - Enumeration (Invariant #8): the code is noted before any row lookup in
get_execution,get_execution_logand the running list. Mutations 4–6 above pin it. - Disclosure: the header carries one of three codes, shape-checked on both sides (
^[a-z_]{1,64}$). Onlymcp_scope == "agent"is marked. - Enterprise docs guard: no hit on added doc lines.
- Secrets / emails / IPs / host paths / file modes / new env vars / new backend directories: none.
Follow-ups from the 2026-11-24 merge-train note
All four are addressed on this head: the turn-id claim is restated with a test per case, _resource_rule reads the DB writer's body for the creator check, the refusal text says "A turn is running", and the running-executions read computes its scope before the container lookup.
Informational (non-blocking)
get_execution,get_execution_logand the running list now callviewer_row_scopeon every request, including ones that end in 404 for a missing row or container. For an agent key that is one ledger read per call. Acceptable for the enumeration guarantee; worth knowing if these routes get polled.ReadNarrowedMiddlewarelogs one info line per marked response. A monitoring run that polls history during a long shared turn will write one line per poll.- The body links the issue with "Part of", so nothing auto-promotes. That matches the issue: items 2–5 stay open. The issue's
status-in-progresslabel needs no change after merge.
Merge gate
Tier 1 green on this head (pytest (head, seed 12345), regression diff, the four required contexts). journey-smoke and e2e green on the PR. dev-ci on dev: success. Branch is 1 commit behind dev, mergeable.
…d, an unreadable visitor_shell is off, and instruction file names count at any depth (Abilityai/trinity-enterprise#978) (#4782) The last four follow-ups of the turn-tier fence (items 2-5 of the issue; items 1 and 6 are in #4760). Rulings on items 4 and 5: 2026-11-25. Item 2 - "could not check" is not a credential failure: - Gemini CLI and Codex answered 503 when the agent could not ask the platform whose turn it is, and every backend path read a 503 as auth: the subscription walk ran and the AUTH breaker counted it. All three runtimes now answer 502 with error_code "turn_check_unavailable" (Claude Code's check from #4743 answered 502 untyped). - New TaskExecutionErrorCode.TURN_CHECK_UNAVAILABLE, accepted on the pull result. The sync push, /chat and the /task translation (both answer 502 with fixed words and the code header, #4284), classify_switch_failure, the async callback normaliser and the pull sink each name it and never switch. - An agent on the older image answers 503 with the same sentence; failure_classifier.TURN_CHECK_UNAVAILABLE_MARKERS (anchored, pinned against the producer, mirrored in the scheduler copy) recognises it at each place the prompt-length 503 is recognised. - The async record gets its own terminal_reason, not empty_result (#4778 AC 2), and the learnings note says 502 (#4778 AC 3). - Workspace: retryable, fixed words (agent_unavailable). An owed resume wake stays owed (operator_resume NO_TURN_ERROR_CODES), as it did when the 503 read as auth. - The #4284 allowlist entry for _apply_sub003_autoswitch gains the `response` parameter (read for its typed code, never rendered) and the sixth site. Item 3 - TURN_REFUSED only from a typed turn_refused body, on the sync push and /chat. A bare 403 falls to each path's existing default. Item 4 - visitor_shell fails closed while the setting cannot be read: the read raises, the stored value is not JSON (get_guardrails_config(strict=True), passed through the database facade, which has its own test) or not an object, or the value is not a boolean. Logged as event=visitor_shell_unreadable. A missing setting keeps the default (on). Item 5 - CLAUDE.md, CLAUDE.local.md, AGENTS.md and GEMINI.md are instructions at any depth (file_path_policy.INSTRUCTION_FILE_NAMES, in all three byte-identical copies): owner tier to write or delete, flagged in the Files tab, refused to a shared person's file tools, and an agent key needs instructions.manage. template.yaml stays top-level only. Stated limits: deleting a folder that holds one (the check is lexical); a nested .claude/ folder. Two learnings fragments: a retyped failure leaves every set its old code was in; a new DB keyword must pass through the database.py facade. Part of Abilityai/trinity-enterprise#978 Part of #4778 Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Items 1 and 6 of the issue. Items 2 and 3 wait for #4743 (same classifiers); items 4 and 5 wait for an operator decision.
Item 6: a read narrowed by a running turn says so. While a shared person's or a visitor's turn runs on an agent, every request made with the agent's key reads executions narrowed to that person, and is refused owner-tier routes. The platform cannot tell which process sent a request, so it fails closed. That behaviour is accepted (operator ruling 2026-11-23). For reads it was silent: while a shared person's turn ran on an agent, an owner-started run on the same agent read
list_recent_executionsas 0 rows instead of 10, with no error and no marker, andget_execution_resultfor a finished run answered 404.X-Trinity-Read-Narrowed:turn_person(the key's own turn is a person's or a visitor's),running_turn(another running turn narrows this request) orunverified(the turn or the running turns could not be checked).narrowed: {code, message}:list_recent_executions,get_execution_result,get_fan_out_result,get_agent_activity_summary,get_schedule_executions,list_project_executions. Under a narrowed view, a 404 fromget_execution_result/get_fan_out_resultis returned with the reason instead of thrown. An unmarked 404 still throws.get_execution_resultalso showsrestricted_turnwhen a run carries the A schedule created by a non-owner-tier person silently loses the shell on every run, and the run still reports success #4281 stamp.Item 1: the route census checks every tier's gate. It checked
ownerandaccessorrows only. The runtime fence leavesself,publicandinternalrows open to an agent's key in a restricted turn, so a row that claims one of those without enforcing it is a hole. All six tiers now go through one rule function; a tier with no rule fails. No row of the table changes.Gating
OSS-core: a fix of code that already shipped publicly (the turn-tier fence, the viewer tier, the route census, the public MCP server). No private module is edited and the submodule pointer does not move. Ruled OSS core by the operator at the merge train's Gate 1 (2026-11-24, recorded on the linked issue).
How it works
dependencies.acting_turn_user_iddecides the view. It now also notes why (utils/read_narrowing.note), andReadNarrowedMiddleware(pure ASGI, mounted inmain.py) puts the first code of the request on the response. Every reader that narrows through the seam is marked with no per-route edit: lists, by-id reads, 404s, the stream.get_executionandget_execution_lognow compute the scope before the row lookup, so a run that exists and one that does not answer the same status, body, headers and query count. What the code can tell a caller about a turn id it sends is bounded: while a share turn runs, every id that is not itself a running share turn (unknown, an owner turn's, a finished share turn's, none) readsrunning_turn;turn_personconfirms only that an id the caller already holds is a share turn running on its own agent. With nothing running, an owner turn's id reads the full view and an unknown id reads narrowed, as before the marker existed. A handler cannot set the header itself. Only an agent key is ever marked.turnFetchrecords the header for the tool call in progress (with or without a turn id). The wording lives insrc/mcp-server/src/read-narrowing.ts; the backend sends codes only, and a parity test fails when a code has no wording._turn_refusal_detail) for the fence and forassert_agent_owner. An unreadable ledger keeps the old text.self: a self gate and no owner gate, read in the handler and one level into a helper of the same file that it names (a gate run on a worker thread sits in such a helper); novia;assert_own_agent(a no-op for a person) counts only beside an access check.internal: the route's router requires the internal secret.resource: the handler shows its resource predicate, or calls a DB writer whose own body carries the creator check. Calling the writer is not enough; the writer is what is read.public: no owner, accessor, signed-in-user or internal-secret gate, and the route is on a reviewed list in the test.Changes
src/backend/utils/read_narrowing.py(new),dependencies.py,services/turn_tier_service.py(codes),routers/schedules.py(scope before the row, two handlers),routers/chat.py(scope before the container, the running list),main.py(mount).turn-context.ts,read-narrowing.ts(new),tools/executions.ts,tools/schedules.ts,tools/projects.ts,types.ts.client.tsis not touched.tests/unit/test_ent978_narrowed_read_marker.py(new),tests/unit/test_ent926_agent_route_census.py,tests/unit/test_3127_pull_chat.py(themain.pymiddleware pin and its disconnect model),src/mcp-server/src/read-narrowing.test.ts(new),tests/registry.json.docs/security-reports/cso-diff-2026-11-24-978-narrowed-read-marker.{md,json}(/cso --diff: nothing open; three low findings from the pre-commit review are fixed on the branch).requirements/auth.md§2.12,architecture/security.md§5d / §5f / §5g,architecture/api-endpoints.md,architecture/mcp-server.md,feature-flows/executions-dashboard.md,user-docs/collaboration/agent-network.md.No migration. No change under
docker/orsrc/frontend/. No submodule pointer moves.Test plan
cd tests && pytest unit/test_ent978_narrowed_read_marker.py unit/test_ent926_agent_route_census.py unit/test_3127_pull_chat.py— real routers, the realget_current_user, a real agent key and real execution rows on SQLite.cd src/mcp-server && node --import tsx --test src/read-narrowing.test.ts(18 tests, real HTTP throughwithAudit) andtsc --noEmit.-n 6 --dist loadfile -p randomly --randomly-seed=12345): no failure that a clean copy of the merge-base does not also have on the same machine. The pinned guards were run again on the final tree.dev(173e58cca, which includes feat(guardrails): guardrail events reach the platform with fleet counts, and credentials in tool output are hidden from the model (abilityai/trinity-enterprise#165) #4425 and fix(guardrails): an agent reports when Claude Code is not applying Trinity's managed hooks, and restricted turns are refused then (abilityai/trinity-enterprise#1176) #4743): the pinned guards anddev's new tests show no failure that was not there before the merge./logreads carry the header (the same 404 for a real hidden run and a made-up id), the MCP tools shownarrowed, and the header is gone when the turn ends.main.pymount, the code mapping, the text picker at both sites, each MCP spread, each census rule (helpers not followed, a helper hiding an owner gate, calling the writer being enough, the writer losing its creator check), two live rows re-declared to a tier they do not enforce, the running list's scope moved back, and the old refusal wording.test_2996_route_census_runtime.py,test_3180_ops_write_route_census.py) could not run on the development machine (a missing package in its environment, on the base too).Review round (2026-11-25)
After the merge-train notes on this PR:
dev. The census failed on feat(guardrails): guardrail events reach the platform with fleet counts, and credentials in tool output are hidden from the model (abilityai/trinity-enterprise#165) #4425'sguardrail-eventsroute (aselfgate reached through a local helper on a worker thread); theselfrule now follows one level of same-file helper. No row changes.resourcerule reads the DB writer's body for the creator check instead of accepting the writer's name.Stated limits
chat_with_agent.narrowedfield for their field-level narrowing./logs,/chat/history,/activity) and the Files routes keep their current text for the owner's concurrent run.Overlap
restricted_agent_turnand the fence'sdetailline. This PR does not editrestricted_agent_turn; the fence's text selection will conflict by a few lines with whichever lands second.security.mdkeeps both paragraphs; the census passes on feat(guardrails): guardrail events reach the platform with fleet counts, and credentials in tool output are hidden from the model (abilityai/trinity-enterprise#165) #4425's route).tests/registry.json,tests/unit/test_3127_pull_chat.py(different lines) anddocs/user-docs/collaboration/agent-network.md(neighbouring lines).Part of abilityai/trinity-enterprise#978
🤖 Generated with Claude Code