Skip to content

fix(systems): create-mode deploy writes the platform prompt for an admin only (#4025) - #4247

Merged
vybe merged 8 commits into
devfrom
AndriiPasternak31/4025-deploy-prompt-admin
Nov 5, 2026
Merged

vybe merged 8 commits into
devfrom
AndriiPasternak31/4025-deploy-prompt-admin

Conversation

@AndriiPasternak31

@AndriiPasternak31 AndriiPasternak31 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

POST /api/systems/deploy admits require_role("creator") + capability_fence("agents.manage"). If at least one agent was created, it wrote a manifest's prompt: into the platform-wide trinity_prompt for anyone those two gates let through. So a creator, or an agent key holding agents.manage, could replace the instructions every agent on the instance receives at its next start. That includes an agent key whose owner is an admin, because the key carries its owner's role and so passes the role gate. The settings route reserves the same key for assert_admin.

Change

  • Deploy writes the prompt only for a caller who passes assert_admin, the settings route's own gate. That covers an admin JWT and an admin's user or system key. A creator, any agent key, a connector key and a portal-delegate key are refused.
  • Apply mode already gated the prompt the same way. Both modes now call one helper, _caller_passes_admin_gate, so they can't drift apart.
  • Anyone else still gets the fleet deployed, plus prompt_updated: false and a prompt_requires_admin: line in warnings[]. That is the same code apply's requires_admin verdict uses. SystemDeployResponse is unchanged: its contract is pinned by the create-mode golden, so the skip is reported in the warnings, as Apply and deploy results misstate what happened in five edge cases #4130 did for deploy: false.
  • Dry run (criterion 4): a non-admin preview flags it too. It returns prompt_updated: false with the same warning, so the preview predicts the write. Since the UI's consent gate reads prompt_updated, a non-admin is no longer asked to acknowledge a prompt change that will not happen. Enabled schedules still trigger the acknowledgement. No .vue change.
  • A non-admin whose manifest prompt already equals the stored one gets no warning: nothing is withheld (apply's unchanged).
  • The total-failure path is unchanged: 0 agents created means no prompt write for anyone and no warning. The first-run seeder deploys as the admin and is unaffected.

Golden

Regenerated by the procedure in its docstring (TRINITY_ENT695_REGENERATE_GOLDEN=abilityai/trinity#4025, serial). The fixture diff touches only deployed_by_creator_over_foreign_name: prompt_updated goes true → false, one prompt_requires_admin: warning is added, and the system_settings trinity_prompt row is no longer written. _meta.regenerated_by records the issue. Every other case is byte-identical, including the OpenAPI fragment.

Tests

  • tests/unit/test_4025_deploy_prompt_admin_only.py drives the real systems and settings routers with their real gates. Only the principal and the two Docker-bound create/start functions are stubbed. trinity_prompt is pre-seeded to a value no default could produce.
    • A creator JWT and an admin-owned agent key holding agents.manage get 200 deployed while the stored prompt stays unchanged. Before the fix, both overwrote it; that is the agent-key path the issue had not executed yet.
    • Control: the same agent key without the grant gets 403 at the fence.
    • Admin JWT and admin user key still write. Preview behaviour is covered for both a non-admin and an admin.
    • Parity across seven principals: deploy writes exactly when PUT /api/settings/trinity_prompt would accept the same caller. Connector and portal-delegate keys stop at the fence there, so a table test also pins the predicate itself to assert_admin across every MCP scope and both roles.
  • Mutating the helper to always allow turns 20 red in the new file (7 route-level, 13 in the scope table), plus the one shape the file does not cover, the golden's deployed_by_creator_over_foreign_name: a creator deploying with no stored prompt row; always deny turns 6 route-level red, 9 in the file.
  • src/frontend/tests/unit/manifestPreviewPromptRequiresAdmin.mount.spec.js: with the non-admin preview payload, the note renders, the prompt clause of the consent gate is absent, and a schedule still raises the gate.
  • 50 unit files that touch deploy, the system service or trinity_prompt: 2245 passed. The new file and the golden pass under random-order seeds 1–3.

Validation: the new test file fails on unfixed dev (creator and agent-key cases write the prompt) and passes after; golden 14/14 after regeneration; 2245 passed across the 50 related unit files; frontend spec 3/3; the one-line MCP tool-description change passes CI's MCP typecheck (Build (typecheck) + unit).
Mutation: helper forced to allow → 20 red in the file (7 route-level + 13 in the scope table), plus the golden's deployed_by_creator_over_foreign_name (a creator deploying with no stored prompt row); forced to deny → 6 route-level red, 9 in the file; role == "admin" and not agent_name → 4 red (the scope table); the matching-prompt check dropped → 2 red; the component's prompt clause forced on → the schedule case of the mount spec red.
Unverified: no live-stack deploy with real agent containers (create/start are stubbed, as in the golden).

Journey Impact: none: an authorization fix on the deploy route; an admin's deploy and every user journey through it are unchanged

Fixes #4025

)

`POST /api/systems/deploy` admits `require_role("creator")` plus
`capability_fence("agents.manage")`, and wrote a manifest's `prompt:` into
the platform-wide `trinity_prompt` for anyone it admitted. A creator, or an
agent key holding `agents.manage` (it carries its owner's role, so an
admin-owned one passes the role gate too), could replace the instructions
every agent receives at its next start. The settings route reserves that
key for `assert_admin`.

Deploy now writes the prompt only for a caller who passes `assert_admin`,
the same predicate apply already used; both modes share one helper. Anyone
else still gets the fleet, `prompt_updated: false`, and a
`prompt_requires_admin:` line in `warnings[]` (the response contract is
pinned, as #4130 did for `deploy: false`). A non-admin dry run says the
same, so the preview predicts the write and does not ask the caller to
acknowledge a prompt change that will not happen.

The create-mode golden is regenerated by its docstring procedure. Only the
creator case changes: `prompt_updated` flips to false, one warning is
added, and the `trinity_prompt` row is no longer written.

Fixes #4025
…the predicate per scope (#4025)

- A non-admin whose manifest prompt already equals the stored one gets no
  `prompt_requires_admin` warning, in the preview or the deploy: nothing is
  withheld, which apply reports as `unchanged`.
- `_caller_may_set_platform_prompt` is renamed `_caller_passes_admin_gate`,
  the name of what it is, which also matches apply's `caller_is_admin`.
- A table test pins the predicate to `assert_admin` across every MCP scope
  and both roles. Connector and portal-delegate keys stop at the deploy
  route's fence, so the route-level parity test never reached the predicate
  for them.
- Docs: the `sets_prompt` comment, the flow's parity wording and the user
  doc's "the result says so" (only once agents are created) now say what
  the code does.
- Say why the matching-prompt check may tell a non-admin whether a guess
  matches: apply's verdict already does, and their agents receive it.
- The guide lists the prompt write after agent creation, where the code
  has done it since trinity-enterprise#125.
- The golden's regenerated_by entry describes the change, like its siblings.
@AndriiPasternak31
AndriiPasternak31 marked this pull request as ready for review November 4, 2026 22:58
@AndriiPasternak31 AndriiPasternak31 self-assigned this Nov 4, 2026
…ty principals (#4025)

The feature flow said three. The fence refuses the connector key and the
portal-delegate key (403 agent_management_not_permitted); the creator, the
admin JWT, the admin's user and system keys and the agent key holding
agents.manage all reach deploy.
@AndriiPasternak31

Copy link
Copy Markdown
Contributor Author

Structural and security review, head 3676bc2

Both reviews ran against the diff from the merge-base with dev (0f97c0a): 11 files, +461/-33. One finding was a real defect. It is fixed in 5dc46d3 (docs only; not pushed yet). Nothing needed a new issue.

What the structural review checked

  • Scope. The diff matches bug(systems): create-mode deploy lets a creator or an agent key overwrite the platform-wide trinity_prompt #4025: deploy writes trinity_prompt for an admin only, the dry run predicts it, the golden is regenerated, and the docs follow. No changes outside that. Criteria 1–5 are each met in the diff: the gate is at system_service.py:2298-2303 and :2511-2520; the admin path is unchanged; the creator and agent-key tests are in test_4025_deploy_prompt_admin_only.py:131-166; the dry-run decision is at :2313 and :2412; and the golden diff touches only deployed_by_creator_over_foreign_name.

  • Is every changed path executed by a test? Yes. _caller_passes_admin_gate is called by deploy (:2298) and by apply (:3008). PROMPT_REQUIRES_ADMIN_WARNING is called by the preview (:2314) and the deploy (:2516). The mount spec renders the real ManifestPreview.vue and reads the real store (stores/systems.js:211). None of the new tests asserts on source text.

  • Fix evidence. I replaced system_service.py with dev's copy and ran the new test file: 23 red, 10 green. I also mutated the code and re-ran the new file, the golden and the apply-engine tests:

    Mutation New test file Golden Apply engine
    helper always allows 20 red (7 route-level, 13 in the scope table) 1 red: the creator case, a creator deploying with no stored prompt row 2 red
    helper always denies 9 red (6 route-level, 3 in the scope table) 4 red 3 red
    role == "admin" and not agent_name 4 red (scope table: connector, portal-delegate, ops, unknown scope) green green
    matching-prompt check dropped 2 red green green

    The worktree was clean again after each run.

  • Every writer of trinity_prompt. There are three: PUT /api/settings/{key} (routers/settings/generic.py:187, assert_admin), deploy (now gated) and apply (system_service.py:4473, written only on the update verdict at :4123). Each settings writer that takes a variable key writes only keys on its own allowlist (settings/ops.py:194, settings/agent_defaults.py:169, settings/integrations.py). None of them can reach this key. The first-run seeder (system_seed_service.py:443-455) deploys as the admin, and the bundled manifest has no prompt:.

  • Consumers of the new warning. Nothing matches deploy warnings by prefix, either in the UI (components/systems/*, stores/systems.js) or in the MCP tool. The warning shows up in the generic notes list.

  • Other checks. No SQL, no new concurrency, no new endpoints, and no credentials in the diff. The words the public-docs guard blocks for private features don't appear in any added doc line.

  • Tests run. The new file and the golden: 47 passed. Apply engine, resilient deploy, dry-run preview, first-run seed, and the auth guards (admin gate, human-only route census, auth wiring, enumeration uniformity, models location): 422 passed. Frontend mount spec: 3/3.

What the security review checked

  • Authorization (the issue's class). The prompt write now uses exactly the settings route's gate. The scope table in the test file pins it for every scope, including ops and an unknown one. A probe of the deploy route found that a creator JWT, an admin JWT, an admin's user and system keys, and an admin-owned agent key holding agents.manage all get through (200). Of these, only the three admin principals write the prompt. Connector and portal-delegate keys stop at the fence (403 agent_management_not_permitted).
  • Failure direction. The helper fails closed: any refusal from assert_admin means "may not". assert_admin has no side effects (dependencies.py:2994-3035). A principal with no scope field at all is refused, through assert_admin's own guard.
  • Logging. The refusal logs the system name and the username, and nothing secret.
  • Routes. No route was added and no route's gates changed. The route census and the admin-gate guards are green.
  • Not covered. The dependency, CI, container and infrastructure checks didn't run, because the diff touches no lockfile, workflow, Dockerfile or compose file. The private module tree isn't checked out in this worktree. I searched the copy in the main checkout instead, and it has no trinity_prompt writer. That copy may not be the exact pinned commit.

No security finding.

Findings

  1. docs/memory/feature-flows/system-manifest.md:2124: fixed in 5dc46d3. The flow said the deploy route's fence refuses "three" of the seven parity principals. Measured, it is two: the connector key and the portal-delegate key. The other five reach deploy.
  2. system_service.py:2299-2303: not a defect. Leaving out the warning when the prompt already matches lets a non-admin check whether a guessed prompt equals the stored one. Apply already answers the same question (unchanged is decided before the admin check, :4121). The stored prompt is also part of the instructions every agent receives, the caller's own agents included, so it is not secret from them.
  3. system_service.py:2302: not a defect. The stored prompt is read before the agents are created, so an admin changing it during a deploy could make the warning stale. The write decision doesn't depend on that read (:2511 checks only may_set_prompt), so nothing gets written that shouldn't be.
  4. src/frontend/src/components/systems/SystemInstallPanel.vue:129: not a defect. The bundled-manifest card shows "replaces global prompt" to a non-admin too. sets_prompt describes the manifest, not the caller (now stated at models.py:1432-1435). The preview gives the caller-specific answer and drives the consent gate (ManifestPreview.vue:229). The mount spec covers that.
  5. src/mcp-server/src/tools/systems.ts:249: not a defect. The description says the prompt is skipped with a warning for any non-admin caller. It doesn't mention the case where the prompt already matches. In that case nothing is withheld, so there is nothing to skip. The description holds for every case where something is withheld.
  6. docs/memory/requirements/roadmap.md:43: not a defect. The deploy requirement still says only "written when at least one agent was created", with no admin condition. The sentence is still true, because it names a necessary condition. A bug fix doesn't require a requirements edit, and the admin rule is stated for apply at :140 and in the feature flow.
  7. src/frontend/tests/unit/manifestPreviewPromptRequiresAdmin.mount.spec.js:21-23: not a defect. The spec keeps its own copy of the warning text, so a change to the backend text would not turn it red. The spec tests how the component treats prompt_updated, and it renders any warning text. The backend text is pinned by the golden fixture.

#4025)

Deploy now gates the prompt the same way apply does, so the requirement's
third stated difference is false. Mechanical, per the merge-train note on
the PR.

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

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-04): pushed one commit to this branch, 15c2145f5. It is documentation and code comments only.

docs/memory/requirements/roadmap.md P-F still listed "only an admin may change the platform-wide prompt (create lets any creator)" as a third difference, which this PR makes false. It now lists two differences and says both modes write the prompt for an admin only. The two system_service.py labels that cited "P-F exception 3" follow. The exception numbers 1 and 2 are unchanged.

Validated READY at 5dc46d3. Two notes ride with it and do not block:

  • People see the machine code prompt_requires_admin: in the preview and result text (system_service.py:2206, rendered by ManifestPreview.vue and DeployResult.vue:36). The code is shared with apply and pinned by the golden, so stripping it is a choice for a follow-up.
  • Nothing pins the result-side warning at DeployResult.vue:187. Forcing warnings to an empty list keeps the frontend suite green.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20261105-0424 (#4266), all gates green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants