Skip to content

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

Merged
vybe merged 2 commits into
devfrom
feature/978-typed-refusals-and-owner-names
Nov 26, 2026

Conversation

@webmixgamer

Copy link
Copy Markdown
Contributor

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.

Item 3: TURN_REFUSED only from the typed body. The sync push and /chat coded every 403 as a turn refusal. They now read error_code: "turn_refused" from the body; a bare 403 falls to each path's existing default.

Item 4: visitor_shell fails 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 log event=visitor_shell_unreadable: the read raises, the stored value is not JSON (get_guardrails_config(strict=True), passed through the database.py facade), the value is not an object, or visitor_shell is 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.md and GEMINI.md are 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 needs instructions.manage for it, as for the top-level file. template.yaml stays 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

  • The path check is lexical, so a share holder can still delete a whole folder that holds a nested instruction file. Re-creating the file is a write, which is refused.
  • A nested .claude/ folder (docs/.claude/…) stays an ordinary folder; the ruling covers file names.
  • The shared-cause redelivery governor (off by default) no longer counts an older image's "could not check" 503 as auth. It was written for Claude API storms, not for this.

Changes

  • Agent server: services/turn_scope.py, services/managed_hooks.py, services/result_callback.py, file_path_policy.py, hooks/file_path_policy.py.
  • Backend: 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: 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 the response parameter, read for its typed code only, and a sixth site that answers fixed words), test fakes that now accept strict, tests/registry.json.
  • Docs: 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/ or src/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 real execute_task, the chat path the real _finalize_http_failure, the Workspace the real portal_chat, the DB reader a real SQLite table, and the database.py facade is tested itself.
  • Mutation proof, each file restored byte-identical: 22 single-line breaks each turned a test red (every call site above, the policy line, the facade, the DB reader, the three agent-side answers). Two that stayed green were dead branches and are removed.
  • test_ent926_turn_tier_hook.py cannot run on macOS (the hook's resolve() maps /home elsewhere; on the base too). Its new rows were checked with resolve stubbed: red with the old policy, green with the new. CI is the judge.
  • Full unit suite and the pinned guards with CI's flags, before and after merging 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, BSD sed, the mounted private submodule), none in a file this PR touches.
  • Checked by hand on a local stack: a share holder is refused writing a nested CLAUDE.md, AGENTS.md or CLAUDE.local.md and deleting a nested AGENTS.md (owner_tier_path), and the Files tab flags it; an ordinary file and a nested template.yaml are allowed; the owner may write. A visitor run's turn-tier answer reads shell: true, then shell: false with a broken guardrails row (and the log line), then shell: true after the row is restored.
  • CI: the agent-side 502 on a Gemini or Codex agent was not checked live (needs the new base image); the unit tests drive the real require_owner_tier and require_hooks_or_owner.

Fixes abilityai/trinity-enterprise#978
Part of #4778

🤖 Generated with Claude Code

webmixgamer and others added 2 commits November 25, 2026 15:16
…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]>

@obasilakis obasilakis 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.

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

@webmixgamer

Copy link
Copy Markdown
Contributor Author

Thanks for the review. This merged before I pushed the follow-ups, so they are in #4792:

  • I1: kept. A CLAUDE.md in a skill folder is an instruction file under the any-depth rule (Claude Code loads it when a turn works in that folder). A row in test_ent164_self_change_grants.py pins it; moving the name test inside the skills exclusion turns that row red.
  • I2: fixed. _PULL_STATUS_MAP has no 403 entry, so a refusal is read only from the typed body. The test covers bare, untyped-dict and typed 403s.
  • I3: no change. The diff has nothing under src/frontend/, which the train's frontend-e2e gate accepts.
  • I4: done, ent#978 is status-in-dev.
  • The /cso --diff pass found one more gap, fixed in fix(guardrails): Codex's override file is an instruction file, ~/.codex runs code, and the pull worker reads a refusal from its body (abilityai/trinity-enterprise#978) #4792. Codex also reads AGENTS.override.md, ahead of AGENTS.md, so it joins the instruction names. ~/.codex/ (unused in our layout, where Codex state lives in CODEX_HOME) is now owner-only, as files that run code. Report: docs/security-reports/cso-diff-2026-11-26-978-typed-refusals-and-owner-names.md.

Could you look at #4792?

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