Repository navigation
fix(schedules): a schedule says what tier its runs get, the owner can take it over, and a restricted run is named, marked, alerted and counted (#4281) - #4427
Draft
AndriiPasternak31 wants to merge 67 commits into
Draft
AndriiPasternak31 wants to merge 67 commits into
AndriiPasternak31 wants to merge 67 commits into
Conversation
…ead is never owner-capable (#4281) A turn backed by a schedule that can no longer be read has no known creator. It is rated a shared person with no account, so it gets no shell, no owner-tier routes and no standing work, whatever the visitor switch says.
…is never owner-capable (#4281) A schedule-backed run is rated by its schedule's creator. When the schedule cannot be read (gone, another agent's, or a failed read) there is no known creator, and the run used to rate as a visitor. A visitor has the shell, and the agent key's owner-tier routes and standing work, while the owner's `visitor_shell` switch is on, which is the default. So a run that could not be tied to an owner-tier creator could still act at owner capability, against the ent#926 ruling that only a known owner-tier creator's schedule runs that way. Such a run now rates as a shared person with no account: no shell, no Gemini/Codex turn, no owner-tier routes, no standing work, and reads narrowed to nothing, whatever `visitor_shell` says. Live, readable schedules are rated as before, and channel and public-link visitors keep their `visitor_shell` behaviour. Tests: test_ent926_turn_tier.py had two tests (a schedule that is gone, a schedule of another agent) that pinned the visitor rating as intended. They are replaced by tests asserting the shared-person rating, no shell and the standing-work fence, with `visitor_shell` explicitly on, over gone / another agent's / read error and every schedule trigger. The turn-tier route answers shell=false for those runs, while a channel turn on the same stub still gets the shell, so the stub is shown to reach the code. test_ent926_agent_key_turn_scope.py gains a test through the real `get_current_user`: the fence refuses the agent key with and without the turn header. With the fix reverted, all 20 new cases fail.
…rates a shared person (#4281) Describe the rule in the turn-tier section: such a run has no known creator, so it is a shared person with no account, never a visitor, and `visitor_shell` does not apply to it. State the cost to an owner whose own schedule disappears while it runs.
…d named to the hook (#4281)
…#4281) The schedule half of turn_actor is about to move into one run-tier function that every schedule read shares. The rule must not move with it, so this pins the full input matrix first: a user id (owner, admin, share, dangling, non-int), the Workspace branch, every owner-configured trigger plus `__manual__` and `""`, schedule-backed runs (live, soft-deleted, read error, another agent's, no recorded creator), each kind of creator, and an agent whose owner's user row is gone. Each row, with the visitor switch on and off, asserts the whole triple (no person id on an owner row), shell_allowed, restricts_standing_work and turn_person. The fake derives every answer from one table of users and one ownership map, with the real methods' semantics (get_agent_owner's INNER JOIN, get_schedule's soft-delete filter); any other method raises. A MagicMock cannot catch a refactor that reads the tier through a different lookup. Characterization test: 119 passed against the unmodified turn_tier_service.py at 35041e532 (a separate worktree).
…answer names the cause (#4281) `turn_tier_service.schedule_run_tier(db, agent, schedule) -> RunTier(tier, kind, cause, creator_id)` is now the one home of the creator rule. turn_actor's schedule branch reads its tier half and keeps the person id None on an owner row, so the rating does not change (the frozen matrix stays green). The cause (creator_owner_tier, no_recorded_creator, creator_not_owner_tier, creator_missing, agent_has_no_owner, schedule_unreadable) is a separate, total function: a failed lookup gives `unknown` and leaves the tier as it is. The fences never call it, so its lookups add no new way for an agent-key request to fail. RunTierLookups memoises the four lookups for one request, and its preload fills them with two bulk reads (new db.get_agent_owners, db.get_users_by_ids) for the fleet read. The hook's GET .../turn-tier answer adds cause, schedule (name, <=80 chars), creator (display name, else the username without any email domain, <=64 chars) and remedy for a schedule-backed shared turn, all null otherwise. Control and format characters are stripped, and the worst case is <=2048 bytes. Old hooks read only tier/kind/shell. Mutants, each red: leaking the creator on an owner row (14 matrix cases), PERSON->VISITOR on an unreadable schedule (8) or a non-owner creator (18), reading the tier through get_agent_owner (4), a non-total cause, an email-keeping label, and unbounded labels.
ScheduleResponse (list, get, create, PUT), the enable/disable bodies and the
admin fleet read GET /api/ops/schedules now carry:
- runs_as: owner | shared_person | null. Null means it was not computed;
it is never a guessed owner.
- runs_as_reason: {code, message}.
- created_by_you.
- created_by: display name, else username. Shown only to the agent's owner
tier and to an agent key that is not acting for a shared person.
The creator's id stays unexposed.
Each request computes the viewer's tier and a lookup memo once, so a 20-row
list costs the same queries as a 2-row one. The fleet read preloads creators
and owners in two bulk queries, so its cost is the same on 3 agents and on 30.
D1/D2: on Claude Code a shared-person schedule is created or enabled, and the
response says how it runs. On a Gemini or Codex agent it could never run, so
switching one on is refused with 409
`schedule_cannot_run_for_creator_on_runtime`. That covers create while
enabled, POST .../enable, and a PUT that turns a disabled schedule on. The
runtime read falls back to Claude Code, so a Docker fault warns instead of
refusing.
Mutants, each red: no preload on the fleet read, a view built per row, the
creator named to every viewer, no D2 check, and a failed rating read as
owner.
…s Claude Code (#4281) The check that refuses switching on a shared-person schedule where it could never run compared the runtime label to "claude-code" only. "claude" is an accepted spelling that selects Claude Code too (agent_service.helpers CLAUDE_RUNTIME_NAMES, and the agent's runtime factory), and Claude Code runs the turn-tier hook. On an agent labelled "claude" a share holder's schedule was refused with 409, naming "claude" as a runtime that cannot run it. The check now allows every name in CLAUDE_RUNTIME_NAMES. Test: the Claude Code case runs for both spellings, on create and on enable. Before the fix the "claude" case answered 409.
…le read (#4281) GET /api/ops/schedules preloads the run-tier memo with two bulk reads so its cost stays flat in the fleet size. When either bulk read raised, the error left the route and the whole fleet read failed, where every other schedule read answers `runs_as: null` for a rating it could not compute. The preload is an optimisation, so its failure is now logged and the rows are rated by the per-row lookups, showing `runs_as: null` when those fail too. Test: each bulk read failing still answers 200 with every row rated; the bulk and per-row owner reads failing together never rate a share holder's schedule as owner. Before the fix the route raised.
…ains (#4281) The turn-tier answer reads the schedule once for the tier and again for the detail. When the first read failed and the second succeeded, the turn was rated a shared person (fail closed, as intended), but the cause was then worked out against a readable schedule created by the agent's owner, and the answer named the owner as "not this agent's owner or an admin", with the recreate remedy. `schedule_run_cause` now answers `unknown` when the creator it finds is an admin or the agent's owner while the tier it was given is a shared person's. It reads nothing new: the user row and the owner row were read already. The tier is unchanged. Tests: the cause for an owner-tier creator given a shared-person tier is unknown (owner, admin, admin on an agent with no owner on record); a schedule read that fails once gives `share`, no shell, and no cause, creator or remedy. Before the fix all four answered creator_not_owner_tier or agent_has_no_owner. The fleet-reach guard lists the new role compare: it reads a schedule creator's user row, never the caller's.
…as the member's own turn does (#4281) Under the member rule (trinity-enterprise#1148) a person the registered provider rates the owner of one agent runs there at owner tier, kind `member`. The one home of the creator rule (`_schedule_tier`) rates the creator through the same `_person_tier`, so a schedule read and the turn agree for a member too. Pinned here: red when `_schedule_tier` rates the creator by role and ownership only. The security notes now say a member's owner row keeps the creator as the person, where they said every owner row names none.
…e schedule, not a chat (#4281)
…dule fields too (#4281) The turn-tier answer gained `cause`, `schedule`, `creator` and `remedy` (null on every turn that is not a schedule-backed shared one). The trinity-enterprise#1148 check that a member's and a delegated turn get the shell compared the whole answer, so it now expects those four nulls as every other answer check in this file does.
…the schedule, not a chat (#4281) A schedule's runs are rated by its creator. When the creator is not owner tier, every shell, MCP, owner-only path and search refusal in such a run said "This turn is for a person the agent is shared with", and a run whose schedule could not be read was told it came from "a channel or a public link". Neither is what happened. The turn-tier answer now carries `cause`, `schedule`, `creator` and `remedy` for a schedule-backed shared turn. The hook keys its text on `cause`, never on `kind`: a creator cause names the scheduled task, whose access it runs with and what it needs (from a fixed table keyed by the remedy code; an unknown code gets generic text), and `schedule_unreadable` gets its own text. The labels are bounded here as well as by the platform (control and format characters replaced, whitespace folded, 80/64 characters, an email's domain dropped). Each such deny is logged with its own code (`schedule_creator_tier`, `schedule_unreadable`) and the turn's kind as `turn_kind`, never `kind`. An answer with no cause (an older backend, or any other turn) keeps today's text byte for byte. Red before: 30 of the new hook cases fail on the unchanged hook (wrong text, no `code` in the record, three-element answer, an unhashable remedy); 17 skew guards are green on both by design. Mutants (no domain strip, any cause shape, `kind=` for `turn_kind=`, unbounded labels, unreadable logged as the creator code) each turn at least one case red.
…tor names the schedule (#4281) On Gemini CLI and Codex a run of a schedule whose creator is not owner tier already fails `turn_refused`, but its text called it a person the agent is shared with and told the owner to switch the agent to Claude Code, which would not give that run the shell either. `turn_scope.fetch_turn` now also returns the answer's schedule detail (a fourth element, None for any other turn), bounded as in the hook, and `require_owner_tier` keys the refusal on `cause`: the scheduled task, whose access it runs with, that the runtime cannot limit such a turn, and what the schedule needs; `schedule_unreadable` has its own text. No runtime switch is suggested. An answer with no cause keeps REFUSED / REFUSED_VISITOR as they are. The status code and `error_code` are unchanged. The six owner stubs of `fetch_turn` in other runtime test files gain the fourth element. A parity test pins the hook and the agent server to the same remedy table, creator sentence and label bounds. Red before: 16 of the new cases fail on the unchanged module; 5 skew guards are green on both by design.
…ule, its creator and the remedy (#4281)
…and raised once per creator (#4281)
…ds restricted_turn (#4281) A schedule's runs are rated by their creator. When the creator is neither an admin nor the agent's owner, every run is a shared person's turn, with no shell and no owner-added tools, and the run still ended a clean success. The terminal write now records restricted_turn in the existing turn_integrity JSON column, beside the #2467 keys: tier, kind, cause, schedule id, creator id and shell false, codes and ids only. Written by both branches of apply_result and by the pull-mode result writer. No status change and no migration. The rating is total: a lookup that raises writes no record and never changes the outcome, and an owner-tier run writes exactly what it wrote before.
… platform alert per agent (#4281) The agent's operator now hears of it on the one-row-per-subject seam: kind schedule_runs_restricted, subject per agent x creator. The text names the creator, the cause, the remedy and up to five schedules; the context carries ids and codes only. The row count is bounded by the agent's share list, so many schedules or many runs by one person stay one row. A person's ending is final for that cause; a new cause files again. schedule_tier_alerts.sync is the single owner of the observe/clear decision and reads the creator's live enabled schedules, so it is called after every write that can change the answer: the schedule routes, the admin pause, resume and emergency stop, the dispatch of a schedule-backed run (which also covers terminals that never reach apply_result) and the winning terminal write. A run that ends after its schedule was disabled therefore files nothing. No loop is added; two racing readings meet the seam's lock and its unique pending subject. The row names a person, so its reserved prefix is owner-only and about-a-person: a share holder and machine keys do not see it.
#4281) architecture/execution.md gains the Restricted Schedule Runs section (the stamp, its terminal-time and sticky semantics, the readers that pass the column through, the alert's callers). backend.md lists schedule_tier_alerts and the new kind; the scheduling, task-execution and operating-room flows describe the stamp, the per-creator alert and its bound.
…e wire codes, so it still loads once take-over replaces recreate (#4281) The take-over slice removes turn_tier_service.REMEDY_RECREATE. The two branches merge without a conflict on those lines, and the merged backend then failed to import services.schedule_tier_alerts, which the task applier and the internal router import.
…a failing alert never fails a schedule write (#4281) Both are stated contracts of schedule_tier_alerts.sync with no test: removing the unknown-cause guard, or the never-raise boundary, stayed green.
…nt still exists (#4281)
…'s schedule in place (#4281)
…edule in place (#4281) POST /api/agents/{name}/schedules/{schedule_id}/take-over makes the caller the schedule's creator, so its runs get owner tier from then on. A grant, so require_person plus OwnedAgent: agent, system and connector keys are refused, and there is no MCP tool. - The body echoes expected_updated_at (compared as an instant) and the reviewed prompt fields of the ScheduleResponse the person read. db.reassign_schedule_creator is one UPDATE pinned to the snapshot it compared, with NOT EXISTS a queued/running/pending_retry run, and it nulls the webhook columns (shared with revoke_webhook_token). - 409 schedule_changed_since_review / schedule_run_in_progress / schedule_not_restricted / schedule_delivers_to_another_person; a delivery to another person's Workspace is cleared, or kept only when the request repeats the address (D8). Taking over twice is a no-op. - A share holder's update, delete and webhook mint are bound to the creator they authorized against, so one authorized just before a take-over is 403 after it. An admin's writes keep their own rule. - An agent or other non-person key cannot Run now a schedule rated a shared person: 409 schedule_runs_as_shared_person (D9). - ScheduleResponse.can_take_over; audit authorization/schedule_taken_over; route census, agent-route tier and # mcp: header entries.
…over, not re-creating the schedule (#4281)
…talog, security notes, user guide and scheduling flow (#4281)
…tor account as a person the agent is shared with (#4281)
…ate reloads it, including the delivery refusal, a deleted schedule and a reload that fails (#4281)
…l text read only their own keys, so a malformed cause never throws in a list (#4281)
…issue-4281-schedule-run-tier # Conflicts: # docker/base-image/hooks/turn-tier-guard.py
…issue-4281-schedule-run-tier # Conflicts: # docs/memory/feature-flows.md # docs/memory/requirements/auth.md # tests/registry.json
…issue-4281-schedule-run-tier # Conflicts: # docs/memory/architecture/api-endpoints.md # docs/memory/architecture/backend.md # docs/memory/architecture/frontend.md # docs/memory/feature-flows/execution-detail-page.md # docs/memory/feature-flows/tasks-tab.md # docs/memory/requirements/auth.md # src/backend/models.py # src/backend/routers/schedules.py # tests/registry.json
…ail #4281 B added to ask_turn (Abilityai/trinity-enterprise#165) Integration of ent#165 S2 and #4281 B: whichever lands second carries this.
…asternak31/issue-4281-schedule-run-tier
…asternak31/issue-4281-schedule-run-tier
This was referenced Nov 10, 2026
Merged
…asternak31/issue-4281-schedule-run-tier Brings current dev (through the guardrail branch's merge of it) and the guardrail event store's revision renumbered to 0124. tests/registry.json keeps both sets of entries.
AndriiPasternak31
changed the base branch from
AndriiPasternak31/ent165-guardrail-events
to
dev
November 10, 2026 22:01
| path = os.path.join(tmp, "tool-results", "smoke.txt") | ||
| os.makedirs(os.path.dirname(path)) | ||
| with open(path, "w") as f: | ||
| f.write("build output\n" * 3000 + "token=" + SECRET + "\n") |
… four-element answer (#4281) `fetch_turn` answers (tier, owner_capable, kind, cause) since this change; the other runtime test files already stub four elements. The two #3408 files that reached dev meanwhile still returned three, so every headless Gemini case in them failed to unpack before it tested anything.
…er, not its first 4000 characters (#4281) The guard looked for the scheduler POST's `json=` in a fixed 4000-character prefix of `trigger_schedule`. On dev it sat at character 3934; the share-holder refusal this change adds in front of it moved it to 4013, so the guard reported the identity as dropped while the body was still sent. It now reads the handler's own source through `ast`, so a guard added in front cannot push the call out of view. Every assertion is unchanged, and replacing `json=source_payload` still fails it.
…asternak31/issue-4281-schedule-run-tier Brings dev's #4447 through the guardrail branch. No conflicts.
|
Resolve by running |
|
Resolve by merging |
AndriiPasternak31
changed the base branch from
dev
to
AndriiPasternak31/ent165-guardrail-events
November 11, 2026 20:20
…il-events' into AndriiPasternak31/issue-4281-schedule-run-tier
At 390px the run-tier reason box's "Created by <email>" line held the row's text column wider than the space beside the action icons: an email is one unbreakable word, so the page scrolled sideways and Delete sat past the screen edge (401px of 390). The creator line may now break anywhere, and below sm the box stacks the text above Take over; side by side the text was left a few pixels wide. From sm up the desktop box is unchanged. The new hermetic e2e measures it at 390px and 1280px in both themes; with the change reverted it fails on the page overflow, the icons past the row and the button beside the text.
6 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4281.
Draft until the manual UI sign-off is given. The Schedules tab's run-tier badge, the take-over review, the Run-now confirm and the restricted-run marker have not been visually accepted in a browser, in either theme or at phone width. This PR stays a draft until that sign-off.
Builds on #4425 (abilityai/trinity-enterprise#165). The refusal count on execution reads uses that PR's guardrail event store, its reporting state and the agent-side forwarder, so this branch contains #4425's branch. It targets #4425's branch, so its diff shows only the schedule change. The workflows that run only on PRs into
dev(backend unit tests, CodeQL, journey impact) do not run on it while it targets that branch; they run again once it is pointed back atdevafter #4425 merges. That is done by hand: this repository keeps merged branches, so GitHub does not retarget it on its own. Merge #4425 first.tests/registry.json; whichever merges second keeps both sets of entries (the only conflict, checked withgit merge-tree).0124_guardrail_events, from 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, ondev's0123_agent_ownership_default_model).dev's owner-by-rule answer tests until the commit that updates them (bb94e6773).Why
A schedule is rated by its creator. When the creator is neither an admin nor the agent's owner, every run is a shared person's turn — no shell, no owner-added MCP servers — and nothing said so: not the schedule, not the run, not the hook's message, which told the model the turn was "for a person the agent is shared with". The run still ended
success; the issue's case was 78 hook denials over about 25 hours with every execution readingsuccess. And a share holder's schedule could not be fixed in place: its runs kept the creator's access until someone re-created it.This PR gives one answer to "what tier will this schedule's runs get, and why", shows it on every schedule read and in every refusal, records it on the run, tells the owner once per creator, lets the owner (or an admin) take the schedule over after reading exactly what it does, and puts an honest refusal count on the run.
What changes
One run-tier rule, visible on every schedule read
services/turn_tier_service.turn_actorrates the turn as a shared person's turn with no person attached,(share, person, None). Through the existing functions:shell_allowedis False;restricts_standing_workis True, so the agent key's owner-tier, resource and standing-work routes are fenced for the rest of that run; the key's reads narrow to the no-rows id.(share, person, None)is already a value on the wire, so the turn-tier reply contract is unchanged. Live, readable schedules, the no-recorded-creator rule (the owner's) and channel and public-link visitors are unchanged. The stated cost: an owner whose own schedule disappears mid-run loses the shell for the rest of that run.schedule_run_tier(db, agent_name, schedule) -> RunTier(tier, kind, cause, creator_id).turn_actor's schedule branch calls the same tier half and projects it, so the rule does not move; a frozen matrix pinsturn_actor's output. A recorded creator is rated throughdev's_person_tier, so a registered member creator rates(owner, member, creator)exactly as the member's own turn does, andturn_actorreturns the creator as the person wheneverkindis set.creator_owner_tier,no_recorded_creator,creator_not_owner_tier,agent_has_no_owner,creator_missing,schedule_unreadable,unknown. The cause is total and never raises, is never on the fence path, and answersunknownrather than contradict the tier when two reads of the schedule disagree.creator_not_owner_tierandcreator_missing→take_over;agent_has_no_owner→repair_agent_owner; otherwise none.turn_tier_answer, moved into the service so the router does no execution read) addscause,schedule,creatorandremedyfor a schedule-backed shared turn, all null on any other turn. Labels have control and format characters stripped; the schedule name is cut to 80 characters and the creator label to 64 (display name, else username, anything after@dropped). Worst case ≤2048 bytes.ScheduleResponse(list, get, create, PUT), the enable and disable bodies, andGET /api/ops/schedules— carriesruns_as(owner|shared_person| null when it could not be computed),runs_as_reason {code, message},created_by_you,created_byandcan_take_over(a person at owner tier, not the creator,runs_as == shared_person, causecreator_not_owner_tierorcreator_missing).created_byis shown only to the owner tier and to the agent's own key (not while that key acts for a shared person); the creator's id is not exposed. No N+1: a per-requestRunTierLookupsmemo; the fleet read preloads it with two bulk reads (db.get_agent_owners,db.get_users_by_ids) and falls back to per-row reads if they fail.enabled,POST …/enable, a PUT that enables) on an agent whose runtime is not Claude Code is refused with 409schedule_cannot_run_for_creator_on_runtime({code, message, runtime, cause}), because such a run can never start there. Every Claude Code runtime spelling (claude-code,claude) is Claude Code; a Docker fault falls back to Claude Code, so it warns rather than refuses. On Claude Code the schedule is created and flagged.Scheduletype and thelist_agent_schedules/get_agent_scheduledescriptions cover the new fields (pass-through).A refusal caused by a schedule's creator names the schedule
hooks/turn-tier-guard.py).ask_turnreturns(tier, shell, kind, schedule);scheduleis the reply's detail for ashareanswer whosecausematches the event-code shape, withremedykept only if it is a known key. Labels are bounded again on the agent side (80 / 64 characters, non-printable characters replaced, an email's domain dropped).unreachablebranch and before today's branches, which are unchanged. The text keys oncause, never onkind.creator_not_owner_tier), "an account that no longer exists" (creator_missing), "This agent has no owner on record…" (agent_has_no_owner), or a generic line forunknownand any newer cause; what is not available; and "say in your answer that this schedule needs ".schedule_unreadablehas its own text.shell: truestill allows first.code="schedule_creator_tier"orcode="schedule_unreadable", pluscause=andturn_kind=, beside the codes the guardrail event record (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) gives every other deny.agent_server/services/turn_scope.py), the refusal path for runtimes other than Claude Code:fetch_turnreturns the same 4-tuple andrequire_owner_tieruses the schedule texts when there is a detail; neither mentions switching runtime. Status 403 anderror_code: turn_refusedare unchanged.take_over,recreate,repair_agent_owner, and a fallback.causegets today's four hook texts and today's refusals byte for byte (pinned literally). Six runtime test files that stubturn_scope.fetch_turngain the fourth element, and so does the turn stub intest_ent165_guardrail_spool.py.A restricted run is recorded on the run and raised to the owner once per creator
apply_resultrates the run once, before either branch, throughschedule_tier_alerts.run_restriction_by_id(which uses the newturn_tier_service.schedule_backed_run_tier: the same "schedule-backed" testturn_actorapplies, thenschedule_run_tier). A run whose tier is not owner writesturn_integrity.restricted_turn = {tier, kind, cause, schedule_id, creator_id, shell: false}into the existing Background task killed at CLI exit leaves no trace — execution records clean success while the work is lost #2467 column, merged beside the Background task killed at CLI exit leaves no trace — execution records clean success while the work is lost #2467 keys. The rating is total: a lookup that raises records nothing and never changes the outcome. Success and failure branches are both stamped (a refused run on another runtime is a failure), and so are the pull sink's two writes; the Background task killed at CLI exit leaves no trace — execution records clean success while the work is lost #2467 derivation and the stamp sit in separatetryblocks. Owner-tier and non-schedule runs write exactly what they wrote before; a manual "Run now" carries its clicker and is not stamped. No status change.schedule_runs_restricted(priority medium) on the existing seam: one operator-queue row per agent × creator, subjectschedule_runs_restricted:<creator id>. Its text names the creator (display name, else username; "an account that no longer exists" for a missing one), the cause, the remedy and up to 5 schedule names; its context carries ids and codes only (≤20 schedule ids plus a count).causeis the only material key, and a person's ending is final. The id prefix is reserved (an agent cannot pre-create the row), and the row is owner-only and about a person: the owner and admins see it; other share holders, the creator and every machine key do not.schedule_tier_alerts.sync(agent, creator_id): it reads that creator's live, enabled schedules on the agent and rates them in one memo; any shared-person schedule observes the row, none clears it. A rating that raises, or a set whose every cause isunknown, decides nothing, so a transient lookup failure never re-files a row a person ended. It never raises./api/internal/execute-taskafter the idempotency gate (so a replay does not sync); andapply_resulton the status-CAS-winning branch only. Re-reading the live schedules is what makes a run that ends after a disable file nothing. Rows go with the agent (operator_queueCASCADE) and follow a rename. No background loop, so one reading has one writer; racing readings meet the seam's per-agent lock and partial unique index.The owner takes a share holder's schedule over in place
POST /api/agents/{name}/schedules/{schedule_id}/take-over(take_over_schedule).require_person(agent, system and connector keys and the loopback get 403person_required) plusOwnedAgent(owner or admin, uniform 404); a Workspace-only person is refused at the operator floor.{expected_updated_at, reviewed: {message, allowed_tools, model, validation_enabled, validation_prompt}, delivery?: "clear"|"keep", keep_delivery_to?}; everyreviewedfield is required and echoed from the read.db.reassign_schedule_creatorcomparesowner_id,updated_at(as an instant), every reviewed field and the delivery, then makes one UPDATE whoseWHEREpins every one of those columns (IS NOT DISTINCT FROM),deleted_at IS NULLand the absence of aqueued/running/pending_retryrun of the schedule. Zero rows → 409schedule_run_in_progress,schedule_changed_since_reviewor 404schedule_not_found. The same UPDATE sets the new creator, revokes the schedule's webhook and clears the delivery when asked. Already the creator → 200, no write. Rated owner tier → 409schedule_not_restricted. A rating that raises propagates (500), so a schedule that cannot be rated is never changed.clear, orkeepwithkeep_delivery_torepeating the address (trimmed, case-insensitive); otherwise 409schedule_delivers_to_another_personnaming it.update_scheduleanddelete_scheduleaddowner_id = <caller>for a non-admin, and a share-tier webhook mint is bound to the creator (a 0-row mint is 403webhook_owner_or_creator), so a former creator's in-flight write cannot land after a take-over.schedule_runs_as_shared_personbefore the scheduler is called.trigger_agent_schedulereportsalready_runningonly for the real running-lock 409 ({"detail": "Schedule is already executing"}); any other 409 reaches the calling agent as{status: "refused", code, message, retryable: false}with the backend's code and message. The backend's scheduler relay likewise passes the lock text only for the scheduler'salready_runningand otherwise relays{code, message}(scheduler_conflictwhen the scheduler sent no code).schedule_taken_overwith the schedule, both creator ids, webhook revoked and delivery cleared.agent_route_tiers.jsonlists the route as owner tier with standing work;routers/schedules.pygains its first-line# mcp:header (take-over is a human-only grant, refused to agent keys);test_ent164_self_change_grants.pyclassifies the route as person-only.A schedule run reads its refusal count, honestly
services/execution_refusals.py(new).readings(agent, rows)makes onecount_by_executioncall (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 seam) per page, only over schedule-backed ids. The count is the sum ofturn_tier_guard:*refusals (credential events and Bash denies never count).Two fields on
ExecutionSummaryandExecutionResponse:guardrail_refusals: int | nullandguardrail_reporting, a marker that explains any doubt. In order, the most severe first:guardrail_refusalsguardrail_reportingnullunavailable(logged; the read still returns 200)null(or the refusals that did arrive)nevernif any, elsenullnot_claude_codenstalenpendingn(0 when none)null= completenullnullfirst_report_at: for the count to be complete every hook call of the run must come after coverage began, and the earliest one can fire is the start. Both times come from the backend clock.never, because the re-queue keeps no record of its first attempt's start.pendinglasts until the agent's next report after the run ended (each successful post carries the spool's backlog), at most one keepalive interval — up to 5 minutes, clean and refused runs alike.Routes: the executions list, the execution detail and a schedule's history each call
readingsonce, after the existing row narrowing, so a share holder gets readings for their own rows only. No new route.MCP:
get_execution_resultforwards both fields (??, so a complete 0 stays 0);list_recent_executionsandget_schedule_executionspass rows through and now describe the fields;ScheduleExecutionintypes.tsgains them.Stated limits (also in the requirement): coverage is a lower bound (a lost fast store moves the start later); a run started in the first seconds after boot reads
never; events are pruned after the retention window (90 days by receive time) while the coverage start is kept, so a run older than that can read a complete 0 once its events are gone; dropped spool records are not tied to runs, so a run a drop may cover still reads complete.The Schedules tab shows the run tier, offers take-over and marks a restricted run
runs_as === 'shared_person'(ownerandnullshow nothing;nullmeans "not computed" and never reads as owner), with the server's reason and a creator line (created_by, else "You created this schedule"). The title row wraps, so the badge does not push the action icons off a 390 px screen.can_take_over === true) opensScheduleTakeOverDialog.vueon a deep copy of the read, so a list refetch while it is open cannot change what is sent. It shows the full prompt, allowed tools, model, validation and its prompt, the Workspace delivery, the webhook state (live, none, or "couldn't read; taking over revokes any webhook URL either way") and what the creator loses.stores/schedules.js→utils/scheduleRunTier.js::takeOverBody) echoes the reviewed copy verbatim, withclearorkeep+ the address for another person's delivery; with no decision it throws rather than send an undecided request.can_take_over. Backdrop and Esc are blocked while the request is in flight.schedule_changed_since_review,schedule_not_restricted,schedule_delivers_to_another_person, or the schedule deleted — reloads the list and shows the current version (or disables Confirm when nothing is left to adopt); if that reload fails, the dialog says so instead of presenting the old version as current. Each code has words; a raw code is never shown. For a creator account that no longer exists, the review says so.apiErrorMessage) instead of the raw object.RestrictedRunMarker.vue, badge or line, each surface with its own requiredtestid) on the Schedules history and execution modal, the Tasks list and the execution page, read fromturn_integrity.restricted_turnwith a sentence by cause. A malformed record or an inherited key (toString,constructor) renders nothing rather than throwing in a list.ownerTierprop onSchedulesPanelfromagent.can_share(the flag the owner-only tabs use), defaulting to true so no false warning appears. Design-system tokens only; the ratchets are unchanged.Docs
requirements/auth.md§2.12 and §2.12.1 (the run tier, the refusal texts, the stamp and alert, take-over, the refusal reading and its limits, the UI) andrequirements/scheduling.md;architecture/security.md§5g,api-endpoints.md,backend.md,execution.md,frontend.mdandmcp-server.md; the operating-room, scheduling, task-execution, Tasks-tab, execution-detail and guardrails feature flows; the user docautomation/scheduling.md.Tests
test_ent926_turn_tier.pyreplaces the two tests that covered the unreadable-schedule rows withtest_a_schedule_backed_turn_whose_schedule_cannot_be_read_is_never_owner_capable(15 cases: gone / another agent's / read error × schedule, webhook, retry, validation and manual triggers) andtest_the_route_answers_no_shell_for_a_turn_whose_schedule_cannot_be_read(3, with a channel-visitor control);test_ent926_agent_key_turn_scope.pyaddstest_a_schedule_backed_turn_whose_schedule_cannot_be_read_is_fenced_through_auth(2: the realget_current_userand the standing-work fence; an owner-tier route andPOST /remindersget 403 while such a run is running, after a precondition that a channel visitor's run does not fence them). Newtest_4281_turn_actor_frozen_matrix.py(119: 58 rows ×visitor_shellon/off over a spec'd fake that mirrors the real joins, checking the triple,turn_tier,turn_actor(execution=),shell_allowed,restricts_standing_workandturn_person),test_4281_schedule_run_tier.pyandtest_4281_schedule_read_fields.py(real routers,get_current_user, JWTs and an agent key on the unit SQLite: the cause per row, the disclosure rules, the runtime refusal for both Claude spellings and two other runtimes, query counts — a 20-row list costs what a 2-row list does, the fleet read the same on 3 and 30 agents — andtest_a_member_creator_rates_as_the_members_turn_does).test_ent926_turn_tier_hook.pyandtest_ent926_runtime_turn_scope.pygain each cause (includingschedule_unreadablefed with bothkind: personandkind: visitor, proving the text keys oncause), the deny record'scodeandturn_kind, the shell-allowed guard, the label bounds and the hook/agent-server table parity.test_4281_restricted_run_stamp.py(the realapply_resultand the pull sink on the unit SQLite) andtest_4281_restricted_schedule_condition.py(the real schedules, ops and operator-queue routers, the internal handler, real JWTs and agent key, the real seam; four threads behind a barrier callingsync→ exactly one row; a failing alert never failing a committed write; the take-over casestest_taking_over_the_last_schedule_ends_the_former_creators_row,test_taking_over_one_of_two_keeps_the_row_for_the_other,test_a_refused_take_over_leaves_the_row,test_a_take_over_also_ends_the_takers_own_stale_row). Edited guards:test_2372_platform_alert_ack.py(the prefix is reserved) andtest_3254_unended_kinds.py(the final kinds).test_4281_schedule_take_over.py(61; only the scheduler hop and the audit sink replaced): the edited prompt after the review, a prompt changed without touchingupdated_at, each echoed field differing, and a write landing between the snapshot and the UPDATE (each 409, the new prompt not adopted); the delivery rules; the bound creator writes, each race test asserting that its hook fired inside the targeted DB method; Run now for agent and system keys; the relay's three conflict shapes; the lock detail pinned to the MCP server's constant. Newsrc/mcp-server/src/tools/schedules.trigger-conflict.test.ts(7).test_4281_execution_refusal_counts.py(38): events go in through the real ingest, the reporter state lives in fakeredis, reads go through the real schedules router over a real DB, so the wire JSON is asserted — late events, uncounted kinds, another agent's event naming this run ignored, every marker, the pending window, a count failure →unavailablewith 200, one count query per page, runs before/after/straddling the first report, a lost fast store, redelivered runs, the full precedence matrix. Newexecutions.refusals.test.ts(4).test_1474_read_boundary_zandtest_2467_turn_integritygainredelivery_countin their hand-written table DDL (real installs have the column on both tracks).scheduleRunTier4281.spec.js(33),schedulesPanelRunTier4281.mount.spec.js(29, mounts the realSchedulesPanel),restrictedRunMarker4281.mount.spec.js(5, the marker plus the realTasksPanelandExecutionDetail).get_agent_owner(17); a non-total cause (2); a failed rating shown as owner (1);created_byfor everyone (3); no fleet preload (the 3-vs-30 count); a view built per row (the 2-vs-20 count); no runtime check (4). Stamp and alert: subject per schedule;syncignoringenabled; no sync at any of its callers; the ending not final; no material key; the prefix not owner-only, not about-a-person or not reserved; owner runs stamped; a rating raise propagating; a manual run rated by its creator; the merge replacing the Background task killed at CLI exit leaves no trace — execution records clean success while the work is lost #2467 keys; the failure branch or the pull writer not stamped; anunknowncause counted;syncraising. Take-over: norequire_person;AuthorizedAgentforOwnedAgent;updated_atcompared as a string (24); no reviewed-field compare (6); no pinned predicate; no in-flight check (3); webhook kept; owner tier not refused; delivery never decided (5); the update, delete or mint unbound; no Run-now refusal or one narrowed to agent keys;can_take_overfor anyone; the remedy back torecreate; MCP every 409 the lock (6); relay every scheduler 409 the lock (3); no former-creator sync (3); no taker sync (1). Refusal reading: count every hook (2); no runtime rule (4);neverreads 0 (2); no pending window (3); stale read as complete (2); one query per row (1); no coverage check (8); the end compared instead of the start (5); no redelivery clause (3). UI: the badge onnull; the Run-now confirm removed or ignoring the owner tier; Take over withoutcan_take_over; the dialog reading the live list; the delivery defaultkeep;keepwithout the address; no reload on an out-of-date refusal; a failed webhook read shown as "none"; the raw save error; the marker ignoring the record or removed from a surface; Take over first in focus order;allowed_toolsnot echoed; no reset of the delivery choice between versions; Esc closing while in flight; an array accepted as the record.Validation: each area was re-run on
devat13d32e22fbefore the areas were merged into this branch — run tier:test_ent926_turn_tier.py+test_ent926_agent_key_turn_scope.py520 passed; the 24-file run-tier set (with the ent926 census, agent-key, runtime and Workspace scope, ent875 READ_SITES, ent629, ent872, 2996, models-centralized, facade delegation, 4284 ×2) 2231 passed;dev'stest_ent1148_*71 passed; seeds 11, 222 and 3333 over the #4281 files, ent926 turn-tier and ent1148 delegation 439 passed each; refusal texts: the runtime-scope, hook and six runtime files 417 passed with only the 39 macOS-only failures; stamp and alert 166 passed; take-over: the 13-file set 1203 passed, with the stamp and alert files 1295 passed; refusal reading 332 passed; MCPnpm test1378 passed andtsc --noEmitclean; UI: the three specs, the raw-colour, loading-gate and source-text ratchets and eight neighbour specs 169 passed,npm run check:tokensOK,vite buildrc 0. Wider sets earlier on the pre-devbase: 91 files (every #4281 file, ent926 except the hook file, ent875, 2372, 3246, 3254, 1310, 2996, ent164, ent872, ent629, ent866, ent715, 4053, 2467, 1482, 1474, 918, 1028, models-centralized, facade, cleanup parity, 1677, operator-queue edges, task execution, pull, schedules, ops, internal, 1823, 929, 2323, 293, 186) 3820 passed, with 21 failures and 21 errors identical on the untouched base (local APScheduler 3.11.0 vs the 3.11.3 pin intest_3940_cron_dst_fold, threetest_ent751paid A2A tests, PostgreSQL-only fixtures); 83 files around the execution reads 2755 passed, 0 failed; the full frontend unit run 504 files, 7705 tests passed.test_ent926_turn_tier_hook.pyfails 39 cases on macOS only (/homeresolves under/System/Volumes/Data), the same ids on untoucheddev; on Linux (Python 3.13, dash) it passed 163/163. On this branch, with #4425 underneath,test_ent165_guardrail_spool.pypasses 89/89 with the 4-tuple turn stub. The merges into this branch conflicted in docs,tests/registry.json,turn-tier-guard.py(the eventcode=on each deny kept beside the schedule branch),models.pyandrouters/schedules.py(both sides kept). After merging #4425's branch withdevat97a86f1dc(conflict only intests/registry.json, both sets kept): one Alembic head; this PR's test files (without the macOS-only hook file), every test using the route census or the turn-tier world, anddev's ent#1148, ent#1202 and schedule-status suites 3697 passed, 1 skipped. The first full unit run on this PR (it runs only for a PR intodev) found 11 failures in tests that reacheddevsince, each caused by this change and fixed here: the two #3408 Gemini files still stubbed the three-elementfetch_turnanswer (9 cases,4b9403ec1); the #1970 guard read a fixed 4000-character prefix oftrigger_schedule, and the share-holder refusal moved the scheduler POST'sjson=from character 3934 to 4013, so it now reads the whole handler throughastwith its assertions unchanged (d14cf6b62); and theschedule-restricted-comments tookoperator_queue_service/__init__.pyto 801 lines, over #3785's 800-line threshold, now 798 (bce82d4f9). Those files then passed with this PR's tests and every test that reads the operator queue's id prefixes: 1419 passed, 7 xfailed.devatb99c23f6e(#4447, tests only) came in afterwards through #4425's branch without conflicts.Mutation: each fix reverted on its own from a scratch copy, restored byte-identical. With
turn_tier_service.pyrestored todev's version, the 20 new run-tier cases go red:test_a_schedule_backed_turn_whose_schedule_cannot_be_read_is_never_owner_capable×15,test_the_route_answers_no_shell_for_a_turn_whose_schedule_cannot_be_read×3,test_a_schedule_backed_turn_whose_schedule_cannot_be_read_is_fenced_through_auth×2. With the hook andturn_scope.pyrestored todev's versions and the new tests kept, 44 fail on the behaviour acrosstest_ent926_turn_tier_hook.pyandtest_ent926_runtime_turn_scope.py(the "shared with" or channel text where the schedule text is expected, a missingcodein the deny record, a three-element answer); the 22 that pass are the skew guards (today's text byte for byte, a cause never refusing a shell-allowed turn). Refusal-text mutants: no domain strip (1), any cause shape accepted (6),kind=forturn_kind=(2), unbounded labels (2), the unreadable case logged as the creator code (8), the schedule shell branch removed (21), the cause checked before theshell: trueallow (3), theturn_scopeschedule text removed (14), no control-character strip (2). The stamp, alert, take-over, refusal-reading and UI tests are red on the base as listed under Tests.Unverified: the manual UI sign-off (pending, below); the member-creator rating resolved against
dev's member rule is newer than the live run (unit-tested only, includingtest_a_member_creator_rates_as_the_members_turn_does); the live run predates the merge ofdevat97a86f1dc(through #4425's branch); PostgreSQL-parametrized unit tests forget_agent_owners,get_users_by_ids,reassign_schedule_creatorand the bound creator writes (they ran live on PostgreSQL only); an agent image from this PR against a backend without the run-tier answer fields (the byte-for-byte skew is pinned by unit tests); a Slack or public-link visitor withvisitor_shellon, end to end; a no-path Grep live (the pinned CLI offers no Grep tool); a redelivered run on the pull pilot readingneverlive (unit-tested through the real requeue); blocking the forwarder's egress after a refused run (unit-tested); Python 3.13 and the full unit suite (CI).Verified on a live stack
Production images (backend, scheduler, MCP server, frontend and the agent image) built from one tree holding these changes together with the public ent#165 and ent#863 changes on the
devof that time, on the prod compose stack (PostgreSQL 16, Redis with ACL users, two backend workers), with real agent containers on Claude Code CLI 2.1.281. The first pass used a scripted model endpoint. The refusal texts were then read again with real model turns, through a pass-through logging proxy that recorded what the model received, and the MCP trigger and refusal-reading cases were re-run on rebuilt images:runs_as: shared_personandcreated_by: nullin their own view; the owner's view showedcreated_by;/api/ops/schedulesand MCPlist_agent_schedules(user key) carried the fields. During a share holder's cron run the turn-tier answer carriedcause: creator_not_owner_tier, the schedule name, the creator label and the remedy, in 142 bytes. For a schedule-backed run whose schedule could no longer be read, the turn-tier route answered{"tier":"share","kind":"person","shell":false,"cause":"schedule_unreadable",…}and the agent key got 403 on an owner-tier route during that run (200 with no such run). On a Gemini agent an enabled create and a switch-on were refused 409schedule_cannot_run_for_creator_on_runtime; the same create on a Claude Code agent was 201. The two bulk reads ran on PostgreSQL.Write ~/CLAUDE.mdwere refused with "This run is the scheduled task 'p-sched-1', not a chat …", naming the creator; none said "shared with"; the records carriedcode: schedule_creator_tierandturn_kind: person. The text as the model received it: "…It runs with the access of the person who created it, pshare, … say in your answer that this schedule needs the agent's owner or an admin to take it over." A schedule that could no longer be read mid-run gave its own text andcode: schedule_unreadable. A Gemini agent's share-rated cron run failed with the schedule, creator and take-over text, and no "switch to Claude Code". An owner chat or task kept the shell; a shared person's chat still got the "shared with" text.successwithturn_integrity.restricted_turn.cause = creator_not_owner_tier; the owner's own schedule run keptturn_integritynull. The owner disabling both schedules ended the row (cancelled, by the platform); re-enabling filed a new one; an admin's pause and resume did the same.can_take_over: truefor the owner; take-over → 200,runs_as: owner, webhook revoked; an agent key → 403person_required. REST Run now with the agent key and the system key → 409schedule_runs_as_shared_person; MCPtrigger_agent_schedulewith the agent key →{"status":"refused","code":"schedule_runs_as_shared_person",…,"retryable":false}, no poll text. With a real held lock, of four concurrent MCP triggers on the owner's schedule one wastriggeredand threealready_running.reassign_schedule_creatoroutcomestaken_over,in_progress,changedandgone, and the share holder's update, delete and webhook mint, ran on PostgreSQL. Take-over ended the alert row (auditschedule_taken_overandplatform_cleared); taking one of two schedules kept the row for the other. The API flows behind the dialog: an edit between open and confirm → 409schedule_changed_since_review; an in-flight run → 409schedule_run_in_progress; a deleted schedule → 404; a missing creator →creator_missing, take-over 200; a delivery to the share holder's Workspace → 409schedule_delivers_to_another_person, thenclear→ 200 and the delivery null.(0, pending)while running,(3, pending), then(3, null); an owner-tier run read(0, pending)and then(0, null)about 215 s after it ended. A Gemini agent's run read(null, not_claude_code); an agent on an older image(null, never). On an image with no forwarder, an owner Run now and a refused cron run both read(null, never); after the agent was recreated on the forwarder image, both older runs still read(null, never), and a run started after the first keepalive read(0, pending),(1, pending), then(1, null). MCPget_execution_resultandlist_recent_executionscarried both fields.Pending
Unfiled follow-ups
GET /api/executionsdoes not carry the refusal fields.never.never, closing the pruned-events case.not_claude_codeuntil the next keepalive.runs_as: ownerwith causecreator_owner_tier, whose message says "created by the agent's owner or an admin" — the tier is right, the text is not; acreator_membercause or a reworded message.turn_tier_answerreads the schedule twice per hook call — one read would save a query on every guarded tool call of a shared-person schedule run.contextis built and then dropped before the scheduler call (routers/webhooks.py).OWNER_ONLY/SEARCH_OWNER_ONLYsay "a person the agent is shared with" to a channel visitor whose path is denied — predates this PR; only the schedule variants change here.routers/admin_recovery.pyrecover_schedule) does not decide the alert — it heals at the next dispatch.syncthat read before a disable can file after the disable's clear — the row then stays until the next write for that creator; re-read after observe, or a per-agent × creator lock.person_ending_is_finalconsults only the newest person ending per subject, and retention prunes final endings — shared by every final kind on the seam.get_executionper terminal on every run, schedule or not (cost nit).already_runningonly fires inside the short dispatch window (observed live;src/scheduleris unchanged here).already_running(routers/webhooks.py) — accurate today, because the scheduler's only 409 is the lock.userkeys._is_personin the schedules router duplicates the person half ofdependencies.person_or_capability_admits— one shared predicate would keep one rule.SchedulesPanel.vuestill makes its other calls through raw axios (predates this PR).ScheduleAnalyticsCardthrows on a summary missingduration_ms(seen with a stubbed backend only).test_ent926_agent_key_turn_scope.pydefinestest_an_unreadable_ledger_fails_closedtwice (F811 ondev), so the first definition never runs — predates this PR.Journey Impact
Journey Impact: extends: J05