Repository navigation
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
Conversation
…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]>
…ooks-skipped # Conflicts: # tests/registry.json
…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
6 of 7 tasks
…ooks-skipped # Conflicts: # tests/registry.json
…ooks-skipped # Conflicts: # tests/registry.json
Contributor
|
merge-train note: validated at 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:
|
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]>
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.
Summary
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/)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 reportsok,skippedorunsupported_runtime.skipped.services/claude_code.py:ClaudeCodeRuntime.execute/.execute_headlesscall the check before spawning. In the skipped state:visitor_shelloff get 403turn_refused;services/headless_executor.py,services/_runtime_config.py: on an agent with skill gates in that state, both spawn sites addSkill,AgentandTaskto--disallowedTools, so the turns that run there have no skills.routers/info.py:/healthreadsskippedonguardrails_registrationandskill_gate_hook. A missing or loosened file keeps its own value.hooks/_skill_gate.py: one item inCLI_FACTS_TO_REAUDIT, so moving the Claude Code pin forces a re-check.Backend (
src/backend/)services/managed_hooks_check_service.py: one high alert,managed_hooks_skipped:fleet, naming every running agent that readsskipped. 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 typedturn_refused403 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: theskippedhook state.Frontend (
src/frontend/)components/skills/SkillsTab.vue,components/PeerSkillEnforcementLine.vue: words forskipped.Docs
architecture/agent-runtime.md,architecture/security.md§5g,architecture/background-services.md.skill-gate.md,skills-tab.md,agent-lifecycle.md,subscription-auto-switch.md.requirements/security.md, one learnings fragment, anddocs/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
"managedSourcesBehavior": "merge"added, with{}, or with no cache, it blocked.tests/unit/test_ent1176_managed_hooks.py(detector, refusal, both runtime entries, the/api/chatand/api/taskroutes an MCP chat lands on, the async and pull terminals, the gated spawn command,/health) andtests/unit/test_ent1176_managed_hooks_fleet.py(alert, clear rule,/healthread, cycle wiring, kind and prefix, classifier, refusal texts againstis_auth_failureand the public markers). Two push-path tests added totest_3470_subscription_walk.py, with a subscription in the pool./healthreadsskipped; a shared person's Workspace turn and an operator account's own-key call are refused with the new words, with no subscription walk.Skill,AgentorTaskin its tool list.Stated limits
visitor_shellon and the system agent's turns run without the managed hooks.okuntil it is stopped and started. The existing base-image alert names those agents.managedSourcesBehavior: "merge";/verify-localran; 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 -qskillsTab.mount.spec.js,peerSkillEnforcementLine.spec.js~/.claude/remote-settings.json,/healthreadsskipped;{}for an account with no organization settings), so the managed hooks run and the state clears: place the file again before the next check;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