Repository navigation
fix(guardrails): a turn check that could not ask the platform is typed, an unreadable visitor_shell is off, and instruction file names count at any depth (abilityai/trinity-enterprise#978) - #4782
Conversation
…d, an unreadable visitor_shell is off, and instruction file names count at any depth (Abilityai/trinity-enterprise#978) 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]>
…sals-and-owner-names
obasilakis
left a comment
There was a problem hiding this comment.
Review + validation: approve
Head e7addc9a1, merge-base 7ce8eb1d2. 44 files, +937/-82. Lane C (touches docker/).
Scope: clean. Items 2 to 5 of trinity-enterprise#978 are all in the diff; items 4 and 5 follow the option-1 ruling recorded on the issue, and CLAUDE.local.md is in the name list as the ruling asked.
Execution coverage
| Changed path | Executed by | Live consumer | Verdict |
|---|---|---|---|
is_turn_check_unavailable_response / task path |
test_ent978…::test_the_task_path_codes_it_and_never_switches (real execute_task) |
task_execution_service.py:3340 |
executed |
classify_switch_failure new branch |
test_ent978… |
execution_classification.py:267 |
executed |
_classify_agent_http_failure typed 403 |
test_ent978… (real _finalize_http_failure) |
chat_execution_service.py:793 |
executed |
pull sink _switch_failure_kind / _recode_credential_independent_auth |
test_ent978… |
pull_coordination_service.py:615 |
executed |
visitor_shell_allowed(strict=True) + database.py facade |
test_ent978… (real SQLite row, real DatabaseManager) |
turn_tier_service.py:850 |
executed |
INSTRUCTION_FILE_NAMES at any depth (3 copies) |
test_ent820_files_tier_census, test_ent164_self_change_grants, test_ent978… |
file_path_policy.classes |
executed |
agent-side typed 502 (turn_scope, managed_hooks) |
test_ent978…, test_ent926_runtime_turn_scope, test_ent1176_managed_hooks |
require_owner_tier, require_hooks_or_owner |
executed |
scheduler failure_classifier.py read_text() |
parity pin against the backend copy | CI | guard |
Mutations run here (each file restored after): 8 single-line reverts, 8 red.
| Reverted line | Result |
|---|---|
and not turn_unchecked (task path switch gate) |
1 failed |
classify_switch_failure turn-check branch |
2 failed |
strict=True in visitor_shell_allowed |
9 failed |
basename(rel) in INSTRUCTION_FILE_NAMES |
18 failed |
chat path back to agent_status_code == 403 |
1 failed |
pull _switch_failure_kind turn-check branch |
1 failed |
database.py facade dropping strict |
1 failed |
turn_scope back to the untyped 503 |
4 failed |
Local runs with -p no:randomly: test_ent978… 69 passed, test_ent820… 174, test_ent164… 52, test_ent926_turn_tier 82, test_ent1176… 67, test_ent926_runtime_turn_scope 47, test_ent1108… 55, test_4284… 118.
Critical findings
None.
Informational (none blocks)
I1. A skill folder's CLAUDE.md / AGENTS.md / GEMINI.md now carries the instructions class as well as the skills class (confidence 6/10)
file_path_policy.py:307: or posixpath.basename(rel) in INSTRUCTION_FILE_NAMES sits outside the not _under(rel, SKILLS_DIR) exclusion on the next line. classes(".claude/skills/x/CLAUDE.md") returns {hidden, instructions, skills}; SKILL.md in the same folder stays {hidden, skills}. The share tier is refused both classes already, so nothing changes there. For an agent key, the decided rule in test_ent164_self_change_grants.py is "skills.manage alone" for skill files, and a skill package that ships one of these names would now also need instructions.manage. No table row covers this path. Either add the row to state the intended answer, or move the basename test inside the skills exclusion.
I2. The agent's pull worker still maps a bare 403 to turn_refused by status (confidence 7/10)
docker/base-image/agent_server/services/pull_worker.py:230: 403: "turn_refused". The typed body wins when present (line 264), so the turn-check 502 is coded correctly on the pull path. A 403 with no error_code is still reported as a turn refusal there, which is the item-3 rule the push and /chat paths now follow. Worth a one-line follow-up or a note on #4778.
I3. Merge gate, lane C
Tier 1 is green (pytest (head, seed 12345), regression diff, the four required contexts, gitleaks, prod-image-smoke). journey-smoke ran green on the PR. frontend-e2e was skipped: the diff has nothing under src/frontend/ and the PR carries no ui label. Add the label before merging if the lane-C rule is applied strictly. dev-ci on dev is currently success. /cso --diff was not run as part of this review.
I4. After merge
Fixes abilityai/trinity-enterprise#978 is cross-tracker, so the issue needs status-in-dev set by hand, and the close is manual at release.
Validation summary
| Category | Status | Notes |
|---|---|---|
| Base branch | ✅ | dev |
| PR size | ✅ | 44 files |
| Commit messages | ✅ | conventional fix(guardrails): … |
| Issue link | ✅ | closing keyword, cross-tracker; priority-p3, type-bug |
| Requirements | ✅ | requirements/auth.md updated |
| Architecture | ✅ | architecture/security.md, agent-runtime.md |
| Feature flows | ✅ | file-browser.md, subscription-auto-switch.md |
| Security greps (keys, emails, IPs, secrets, env files, credential files) | ✅ | no hits |
| Enterprise disclosure | ✅ | enterprise-docs-guard green; no private module named |
| Infrastructure / build packaging | ➖ | no Dockerfile, compose or new top-level package |
| Config packaging | ➖ | no new env var |
| File modes / host paths | ✅ | only /home/developer/ (the container home) in tests |
| Schema | ➖ | no migration |
| Vendored mirrors | ✅ | three file_path_policy.py copies and both failure_classifier.py copies change identically |
| Enum completeness | ✅ | new code added to _PULL_ERROR_CODES, NO_TURN_ERROR_CODES, the callback normaliser, Workspace copy, /chat and /task mapping |
| Structural review | ✅ | this report |
| Test adequacy | ✅ | named regression file, controls beside each behaviour test, mutations above |
| Learnings | ✅ | two fragments under docs/memory/learnings/ |
| Tests-only deletions | ✅ | 22 deleted test lines, each a pin of the old rule replaced by the new one |
|
Thanks for the review. This merged before I pushed the follow-ups, so they are in #4792:
Could you look at #4792? |
Summary
Items 2–5 of the issue, the last four follow-ups of the turn-tier fence. Items 1 and 6 landed in #4760. Items 4 and 5 follow the operator's ruling of 2026-11-25, recorded on the issue.
Item 2: "could not check whose turn this is" is not a credential failure. When a Gemini CLI or Codex agent could not ask the platform whose turn it was, it answered 503, and every backend path reads a 503 as an auth failure: the subscription walk ran, and the AUTH dispatch breaker counted it. Claude Code's check (#4743) already answered 502, but with no code, so the async record called it an empty result.
error_code: "turn_check_unavailable"(turn_scope.could_not_check).TaskExecutionErrorCode.TURN_CHECK_UNAVAILABLE, accepted on the pull result. The sync push,/chatand the/tasktranslation (both answer 502 with fixed words andX-Trinity-Error-Code),classify_switch_failure, the async callback normaliser and the pull sink each name it, and none of them switches.failure_classifier.TURN_CHECK_UNAVAILABLE_MARKERSrecognises it (anchored at the start, pinned against the agent's constant, mirrored in the scheduler copy) at each place the prompt-length 503 is recognised (bug: a prompt-length rejection is classified as an auth failure and walks every subscription (SUB-003) #3849).terminal_reason, notempty_result, and the learnings note says 502 (bug(guardrails): after a backend restart the managed-hooks alert cannot clear while any agent is silent, and an async "could not check" is recorded as an empty result (follow-ups of #4743) #4778 items 2 and 3).operator_resume_service.NO_TURN_ERROR_CODES), as it did while this answer read asauth.Item 3:
TURN_REFUSEDonly from the typed body. The sync push and/chatcoded every 403 as a turn refusal. They now readerror_code: "turn_refused"from the body; a bare 403 falls to each path's existing default.Item 4:
visitor_shellfails closed while the setting cannot be read. It read as on when the guardrails read raised, and when the stored value was broken JSON (the DB reader returned{}). Now these all turn the shell off for that turn and logevent=visitor_shell_unreadable: the read raises, the stored value is not JSON (get_guardrails_config(strict=True), passed through thedatabase.pyfacade), the value is not an object, orvisitor_shellis not true or false (the route writes booleans only). A setting that is simply not there keeps the default (on).Item 5: instruction file names count at any depth.
CLAUDE.md,CLAUDE.local.md,AGENTS.mdandGEMINI.mdare in the instructions class in any folder (file_path_policy.INSTRUCTION_FILE_NAMES, all three byte-identical copies). The runtimes load a nested one when a turn works in that folder. The share tier may not write or delete one, the Files tab flags it, a shared person's file tools are refused it, and an agent key needsinstructions.managefor it, as for the top-level file.template.yamlstays top-level only.Gating
OSS-core: a fix of code that already shipped publicly (the turn-tier fence, the path policy, the execution classifiers). No private module is edited and the submodule pointer does not move. Same Gate 1 ruling as #4760 (OSS core, recorded on the linked issue).
Stated limits
.claude/folder (docs/.claude/…) stays an ordinary folder; the ruling covers file names.auth. It was written for Claude API storms, not for this.Changes
services/turn_scope.py,services/managed_hooks.py,services/result_callback.py,file_path_policy.py,hooks/file_path_policy.py.services/execution_envelope.py,services/execution_classification.py,services/failure_classifier.py(+src/scheduler/failure_classifier.py, byte-identical),services/task_execution_service.py,services/chat_execution_service.py,services/pull_coordination_service.py,services/operator_resume_service.py,services/turn_tier_service.py,services/file_path_policy.py,client_portal/service.py,models.py,database.py,db/agent_settings/security.py.tests/unit/test_ent978_typed_refusals_and_owner_names.py(new). Updated: the tests that pinned the old rules (test_ent926_runtime_turn_scope.py,test_ent926_turn_tier.py,test_ent1176_managed_hooks.py,test_ent820_files_tier_census.py,test_ent164_self_change_grants.py,test_ent926_turn_tier_hook.py,test_ent1108_deferred_wake.py), the bug: exception text in HTTPException detail across backend and agent-server routes (py/stack-trace-exposure siblings CodeQL does not flag) #4284 allowlist entry for_apply_sub003_autoswitch(gains theresponseparameter, read for its typed code only, and a sixth site that answers fixed words), test fakes that now acceptstrict,tests/registry.json.requirements/auth.md,architecture/security.md,architecture/agent-runtime.md,feature-flows/file-browser.md,feature-flows/subscription-auto-switch.md,user-docs/agents/agent-files.md,user-docs/agents/agent-guardrails.md, and two learnings fragments.No migration. No change under
src/frontend/orsrc/mcp-server/. No submodule pointer moves.docker/base-image/changes, so agents pick the agent-side part up when recreated on the new image; until then the backend recognises the older 503.Test plan
cd tests && pytest unit/test_ent978_typed_refusals_and_owner_names.py: 69 tests. Each behaviour test was red before the change; the controls beside them (a genuine 503 still walks, a real empty result keeps its label, a readable setting reads as before, lookalike file names stay ordinary) were green, as they should be. The task path runs the realexecute_task, the chat path the real_finalize_http_failure, the Workspace the realportal_chat, the DB reader a real SQLite table, and thedatabase.pyfacade is tested itself.test_ent926_turn_tier_hook.pycannot run on macOS (the hook'sresolve()maps/homeelsewhere; on the base too). Its new rows were checked withresolvestubbed: red with the old policy, green with the new. CI is the judge.dev(7ce8eb1d2, which includes fix(access): a read narrowed by a running turn says so, and the route census checks every tier's gate (abilityai/trinity-enterprise#978) #4760): every failure is a local-environment one (a missing package in the venv, BSDsed, the mounted private submodule), none in a file this PR touches.CLAUDE.md,AGENTS.mdorCLAUDE.local.mdand deleting a nestedAGENTS.md(owner_tier_path), and the Files tab flags it; an ordinary file and a nestedtemplate.yamlare allowed; the owner may write. A visitor run's turn-tier answer readsshell: true, thenshell: falsewith a broken guardrails row (and the log line), thenshell: trueafter the row is restored.require_owner_tierandrequire_hooks_or_owner.Fixes abilityai/trinity-enterprise#978
Part of #4778
🤖 Generated with Claude Code