Skip to content

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

Merged
vybe merged 9 commits into
devfrom
feature/1176-managed-hooks-skipped
Nov 24, 2026
Merged

vybe merged 9 commits into
devfrom
feature/1176-managed-hooks-skipped

Conversation

@webmixgamer

@webmixgamer webmixgamer commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The agent server now reports when Claude Code is not applying Trinity's managed hooks, and refuses the turns whose rule depends on those hooks. Claude Code's server-managed settings can take precedence over the image's file-based managed settings.
  • One Operations alert names every agent in that state. The Skills tab and the Permissions line say so too.
  • A turn the agent refuses for who it is for is no longer read as a credential failure. No push path walks the agent's subscriptions over it, and "could not ask the platform" is answered with 502, not 503.

Before you update: on an agent whose Claude Code is not applying Trinity's managed hooks, a turn by someone who is not the agent's owner or an admin (a person it is shared with, or a channel or public-link visitor the owner has limited) is refused after this update, where today it runs.

Changes

Agent server (docker/base-image/)

  • New agent_server/services/managed_hooks.py: reads Claude Code's cached server-managed settings (<config dir>/remote-settings.json, every config dir a spawn could use) and reports ok, skipped or unsupported_runtime.
    • A cache that is present but not a readable settings object counts as skipped.
    • The read never follows a link and never blocks.
  • services/claude_code.py: ClaudeCodeRuntime.execute / .execute_headless call the check before spawning. In the skipped state:
    • a shared person's turn and a visitor's turn with visitor_shell off get 403 turn_refused;
    • a schedule run rated below the owner gets its own words;
    • no answer from the platform is a 502.
  • services/headless_executor.py, services/_runtime_config.py: on an agent with skill gates in that state, both spawn sites add Skill, Agent and Task to --disallowedTools, so the turns that run there have no skills.
  • routers/info.py: /health reads skipped on guardrails_registration and skill_gate_hook. A missing or loosened file keeps its own value.
  • hooks/_skill_gate.py: one item in CLI_FACTS_TO_REAUDIT, so moving the Claude Code pin forces a re-check.

Backend (src/backend/)

  • New services/managed_hooks_check_service.py: one high alert, managed_hooks_skipped:fleet, naming every running agent that reads skipped. It runs inside the fleet-image cycle (fleet_image_service.run_cycle: same lease, same cadence) and its failure never breaks the image check.
  • services/platform_alerts.py, services/operator_queue_service/__init__.py: the new alert kind under a reserved prefix.
  • services/execution_classification.py: a typed turn_refused 403 is not a switch failure. Any other 403 still is.
  • services/public_chat_service.py: the public status read recognises the new refusal sentences.
  • services/skill_gate_map_service.py, models.py: the skipped hook state.

Frontend (src/frontend/)

  • components/skills/SkillsTab.vue, components/PeerSkillEnforcementLine.vue: words for skipped.

Docs

  • architecture/agent-runtime.md, architecture/security.md §5g, architecture/background-services.md.
  • Feature flows skill-gate.md, skills-tab.md, agent-lifecycle.md, subscription-auto-switch.md.
  • requirements/security.md, one learnings fragment, and docs/security-reports/cso-diff-2026-11-23-1176-managed-hooks.{md,json}.

No database migration. No change to the enterprise submodule pointer, the Dockerfile or compose.

How it was verified

  • Behaviour of the pinned CLI (2.1.322): the real CLI ran in a throwaway container on the base image, against a local stub API, with a simulated server-managed payload.
    • With a payload holding a policy key, the managed Bash hook did not run.
    • With "managedSourcesBehavior": "merge" added, with {}, or with no cache, it blocked.
  • Unit tests: tests/unit/test_ent1176_managed_hooks.py (detector, refusal, both runtime entries, the /api/chat and /api/task routes an MCP chat lands on, the async and pull terminals, the gated spawn command, /health) and tests/unit/test_ent1176_managed_hooks_fleet.py (alert, clear rule, /health read, cycle wiring, kind and prefix, classifier, refusal texts against is_auth_failure and the public markers). Two push-path tests added to test_3470_subscription_walk.py, with a subscription in the pool.
  • Localhost, rebuilt base image, one agent:
    • /health reads skipped; a shared person's Workspace turn and an operator account's own-key call are refused with the new words, with no subscription walk.
    • The Skills tab warns on a gated agent, and the owner's turn there has no Skill, Agent or Task in its tool list.
    • The alert appears, and ends by itself at the next cycle.
    • On a subscription login Claude Code fetched the organization's settings within about a second of the owner's turn starting, with the vendor-telemetry opt-out in place, rewrote the cache, and the managed Bash hook ran in that same turn.
  • Mutations: each fix was reverted from a scratch copy and its tests went red (22 mutations, including the review fixes); every file was restored byte-identical.
  • Full unit suite and the pinned-guard set (CI flags): no failure that is not also present at the merge-base.

Stated limits

  • The check reads Claude Code's cache, which holds the last fetch, so it is one fetch behind. On a login that fetches (a subscription), each session fetches within about a second, before its first tool call, and that result decides the session.
    • The first restricted turn after an organization adds a setting, or the first on a new agent, is not refused. After it, the cache holds the setting and restricted turns are refused.
    • After an organization removes its setting, restricted turns stay refused until the agent's owner runs one turn, which refreshes the cache.
  • While the alert stands, the owner's turns, a visitor's turn with visitor_shell on and the system agent's turns run without the managed hooks.
  • The agent's own code can change the input the check reads; the hooks are not a boundary against the agent user (documented).
  • An agent on an image built before this change reads ok until it is stopped and started. The existing base-image alert names those agents.
  • The peer-skill grant check lives in the same skipped hook. It holds only at dispatch, for skills a request names.
  • The gated-agent path (owner's turns without skills) is covered by unit tests and a localhost check. The Bash rule that refuses a nested coding-agent CLI on a gated agent lives in a skipped hook too, so a nested CLI started through Bash is not stopped in that state.
  • Not shown on a real organization with a policy key:
    • that its admin console accepts and delivers managedSourcesBehavior: "merge";
    • CLI 2.1.322 end to end.
  • The base image was built from this branch and run on one agent on localhost (the manual check above). No /verify-local ran; CI covers the build.

Test Plan

  • cd tests && pytest -p no:randomly unit/test_ent1176_managed_hooks.py unit/test_ent1176_managed_hooks_fleet.py unit/test_3470_subscription_walk.py unit/test_ent926_public_turn_refused.py unit/test_2372_platform_alert_ack.py unit/test_4483_fleet_base_image_check.py -q
  • Frontend: skillsTab.mount.spec.js, peerSkillEnforcementLine.spec.js
  • Manual (localhost):
    • with a simulated payload in a test agent's ~/.claude/remote-settings.json, /health reads skipped;
    • a shared person's Workspace or MCP chat is refused with the new words;
    • the owner's turn runs. On a subscription login its fetch rewrites the file within about a second (to {} for an account with no organization settings), so the managed hooks run and the state clears: place the file again before the next check;
    • the Skills tab warns on a gated agent;
    • one alert appears under Operations → Needs Response and ends after the file is removed.

Merge gate: this ships in the open-source core, so the merge needs the operator's yes for that.

Fixes abilityai/trinity-enterprise#1176

🤖 Generated with Claude Code

webmixgamer and others added 2 commits November 23, 2026 18:21
…inity's managed hooks, and restricted turns are refused then (Abilityai/trinity-enterprise#1176)

Trinity's guardrail hooks live in file-based managed settings in the agent
image. Claude Code composes its managed sources "first-wins": while it holds a
server-managed settings payload with any policy key, that payload is the
managed tier alone and none of the files' hooks run (only `env` still merges
per key).

Agent server
- services/managed_hooks.py reads the CLI's cached copy of that payload
  (`<config dir>/remote-settings.json`, every config dir a spawn could use)
  and reports ok / skipped / unsupported_runtime. A cache that is present but
  not a readable settings object counts as skipped (fail closed); the read
  never follows a link and never blocks.
- In the skipped state ClaudeCodeRuntime.execute / execute_headless refuse,
  before the CLI starts, a turn whose rule lives in a hook: a shared person's
  turn and a visitor's with visitor_shell off (403 turn_refused), a schedule
  run rated below the owner (its own words, no take-over remedy). No answer
  from the platform is a 502, never a 503. On an agent with skill gates both
  spawn sites drop Skill, Agent and Task, so the owner's turns run without
  skills.
- /health reports `skipped` on guardrails_registration and skill_gate_hook.
- CLI_FACTS_TO_REAUDIT records the fact, so moving the Claude Code pin forces
  a re-check.

Backend
- managed_hooks_check_service names every such agent in ONE high Operations
  alert (managed_hooks_skipped:fleet, reserved prefix), inside the leased
  fleet-image cycle.
- classify_switch_failure: a typed turn_refused 403 is not a credential
  failure, so neither push path walks the subscriptions over a refusal.
- The public status read recognises the new refusal sentences; the Skills tab
  and the Permissions line name the new state.

Tests: test_ent1176_managed_hooks.py, test_ent1176_managed_hooks_fleet.py,
and the push paths in test_3470_subscription_walk.py. Each fix was reverted
from a scratch copy and its tests went red (16 mutations), restored
byte-identical. Unit suite compared with the merge-base: no new failure.

Fixes Abilityai/trinity-enterprise#1176

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@webmixgamer webmixgamer added the ui PR touches the frontend UI — triggers Playwright e2e tests label Nov 23, 2026
…ooks-skipped

# Conflicts:
#	tests/registry.json
@webmixgamer
webmixgamer requested a review from vybe November 23, 2026 19:11
webmixgamer and others added 4 commits November 23, 2026 23:25
…trinity-enterprise#1176)

- task_execution_service: the except handler's legacy SUB-003 check read the
  refusal's TEXT for auth words, and a schedule run's refusal embeds the
  schedule's name, so a typed turn_refused 403 could still switch the agent's
  subscription. One predicate, execution_classification.is_turn_refusal, now
  exempts it in the walk's classifier and in the except handler.
- managed_hooks_check_service: an agent the last reading named that gives no
  answer stays named, so it cannot drop out of the alert without reading clean.
- managed_hooks: the memo keys on the file's change time too (a rewrite can
  restore the mtime, never the ctime); a `~` CLAUDE_CONFIG_DIR is read both
  expanded and as a literal relative dir; any non-empty disableAllHooks string
  counts as on.

Each fix was reverted from a scratch copy and its new test went red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the public text keeps the cache rule out (Abilityai/trinity-enterprise#1176)

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

# Conflicts:
#	tests/registry.json
…ooks-skipped

# Conflicts:
#	tests/registry.json
…ooks-skipped

# Conflicts:
#	tests/registry.json
@webmixgamer
webmixgamer requested a review from dolho November 24, 2026 16:08
@vybe

vybe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

merge-train note: validated at a599fbede (lane C: /validate-pr, /review, /cso --diff). No criticals; 17 of 17 single-line wiring mutations went red. Rides this train.

Operator rulings at Gate 1 (recorded on the linked issue): the refusal scope is accepted as is (only shell-restricted turns are refused while hooks are skipped), and this ships as OSS core.

For a follow-up, not blocking:

  • managed_hooks_check_service._run_once: _last_named is process-local and the could_not_check return never sets it, so after a backend restart or lease move a stale alert cannot clear while any running agent stays silent on /health (holding = unreadable if _last_named is None else held). Reading the named set from the pending alert row would fix it.
  • require_hooks_or_owner returns early for a turn with no execution id (voice tool at services/gemini_voice.py ~1490, public-link intro), which the stated limits do not list.
  • With subscriptions from different organizations in one pool, the "one fetch behind" gap may recur on every alternation (hypothesis, not reproduced).
  • The async path labels the "could not ask the platform" 502 as empty_result (result_callback.py ~207); the learnings fragment says 503 where the code ships 502.
  • In-container proof is one manual run; a /verify-local pass before the release cut would close that.

vybe pushed a commit that referenced this pull request Nov 24, 2026

@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: validated at a599fbe; batch gated on Tier 1 (and on train/20261124-1655 for the lane C members)

@vybe
vybe merged commit 621c40a into dev Nov 24, 2026
28 checks passed
@webmixgamer
webmixgamer deleted the feature/1176-managed-hooks-skipped branch November 25, 2026 13:03
vybe pushed a commit that referenced this pull request Nov 26, 2026
…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]>
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.

2 participants