Skip to content

DO NOT MERGE — merge train: 4246,4247,4251 - #4266

Closed
trinity-ability wants to merge 16 commits into
devfrom
train/20261105-0424
Closed

trinity-ability wants to merge 16 commits into
devfrom
train/20261105-0424

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Integration surface for #4246, #4247, #4251. Never merged. Members merge individually once this is green.

🤖 Generated with Claude Code

AndriiPasternak31 and others added 16 commits November 4, 2026 21:59
…ccess (#4026)

The MCP audit wrapper labels a tool call by throw / no-throw plus one
out-of-band stamp, and the only stamp was `denied` (#2807). A tool that
RETURNS a failure instead of throwing it was therefore audited
`success: true`: apply_system's 409 refusal report, its 503/500 reports and
not_available, and every teardown_system refusal.

- ToolOutcome gains a `failed` kind. audit.ts::toolFailed stamps it on the
  per-call context and serialises the envelope exactly as before, so the
  caller's JSON is unchanged. The row reads `success: false` with a short
  `error` and no `denied` key. A `denied` stamp is never overwritten, and the
  reason is never empty (an empty `error` is dropped from the row).
- apply_system: every non-403 failure (404/405 not_available, JSON object
  bodies 400/401/409/422/503/500, non-object bodies, missing key, lost
  connection) is stamped `failed`. The 403 stays `denied`, byte-identical.
- teardown_system: the 403 (unlicensed, human-only, or every member
  not_authorized) is stamped `denied` through accessDenied; every other
  returned failure, the 500 `failed` report included, `failed`.
- 2xx results (a dry-run `invalid`, a `partial` apply or teardown) stay
  `success: true`.

Tests drive both tools through the registered, audit-wrapped server and pin
the caller's text byte-for-byte as it was before this change.
system-manifest.md's apply_system table said a non-403 failure is audited
success: true; audit-trail.md described only the denied stamp. Both now name
the failed kind and toolFailed.
)

`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
…#4026)

Review follow-ups on the returned-failure stamp:

- An apply failure's reason copied the backend `detail` unbounded (a 5,000-
  character manifest error became a 5,000-character row reason). Reasons now
  come from one helper, httpAuditReason, which caps a detail at 200
  characters. The caller still receives the full detail.
- A teardown 403 recorded the caller's licensing / human-only paragraph as its
  reason, including when the real cause was every member being refused
  (`skipped: not_authorized`). The row now names the backend's own cause.
- Teardown's other failure reasons carry the backend detail before the flags,
  so an absent route ("Not Found") and a serving route that found no such
  system read differently on the row, even though the caller's message does
  not yet tell them apart (trinity-enterprise#1100).
- types.ts no longer claims a denial's reason is never empty; that guarantee
  is toolFailed's only.
- Tests pin three cases that were right but unguarded: an array-valued
  error, an empty report status, and a write to any other session key.

The caller-facing JSON of both tools is unchanged; the byte-for-byte pins
still pass.
…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.
…script (#4028)

refresh_if_owned / release_if_owned were GET-then-EXPIRE and GET-then-DELETE:
a holder whose lease lapsed between the two commands extended or deleted the
successor's lease, and two holders ran at once. The atomic bodies added for
the apply lock now carry the plain names; the non-atomic ones are gone.

- refresh_if_owned(retake_lapsed=True) renews, or re-takes an absent key with
  SET NX, in one script. Only the fleet restart passes it, keeping its #1919
  re-take; by default a lapsed lease is LOST, as system apply relies on.
- One home for the lease scripts (LEASE_*_LUA, KEYS[1] form); the canary
  leader lease uses them and is pinned to never re-take. Registered on the
  client per call, no process-wide cache.
- A reply that is not one of the script's ASCII integers is DEGRADED, never
  OWNED, and never raised.
- The KEYS/SCAN guard refuses the scan command as an attribute call, as a
  string literal in any case, and as the bare words, and admits a script's
  KEYS[n]; 14 spellings are pinned.
- tests/unit/_ent695_lua.py is the one executing emulator (race hooks on
  client commands only, SET NX EX, byte compare, Lua truth, non-positive TTLs,
  with_lua for fakeredis); every lock client in the caller tests runs the real
  script text, and the memory retain lease gets a release test.
…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.
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants