Skip to content

fix(agent-server): no exception text in API answers, snapshot path barrier and no-follow writes, dashboard error messages and no-follow read (abilityai/trinity-enterprise#1117) - #4293

Merged
vybe merged 15 commits into
devfrom
AndriiPasternak31/ent1117-s6-agent-server-error-text
Nov 6, 2026
Merged

vybe merged 15 commits into
devfrom
AndriiPasternak31/ent1117-s6-agent-server-error-text

Conversation

@AndriiPasternak31

@AndriiPasternak31 AndriiPasternak31 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of abilityai/trinity-enterprise#1117.
Also part of #4284.

Journey Impact: none: agent-server error answers name the exception class instead of its text; no user step changes

Problem

  • The agent server put the text of unforeseen exceptions into its 500 answers (bug: exception text in HTTPException detail across backend and agent-server routes (py/stack-trace-exposure siblings CodeQL does not flag) #4284). That text can hold paths, subprocess output, or a credential in a URL. The affected paths:
    • the file routes;
    • the Claude Code, Gemini and Codex chat and task paths;
    • the headless executor.
  • The dashboard endpoint did the same for a malformed or unreadable dashboard.yaml. It also carried an except yaml.YAMLError arm that can never run.
  • The dashboard endpoint read dashboard.yaml with read_text(), which follows a link. A link at that name, or a second name for another file, made it parse another file, and a parse error quotes the offending line.
  • The snapshot endpoint resolved the caller's backup_dir before checking it. The relative_to check was correct, but static analysis does not recognise a check that comes after the sink.
  • The snapshot endpoint then wrote snapshot.tar and files.txt into backup_dir with plain writes, which follow a link at either name and write through a hard link. A backup_dir that is not a string became a 500.

Fix

  • Snapshot:
    • A normalised, separator-terminated startswith barrier now runs before resolve(), comparing in unresolved space.
    • The resolve() + relative_to check is kept.
    • . and absolute paths inside the home are still accepted. ../home2 is refused.
    • The X-Snapshot-Path header is computed against the resolved home.
    • snapshot.tar and files.txt go in through files.write_bytes_nofollow (ent#822), the writer the restore path in the same module already uses. The directories are walked and created one component at a time without following a link. A link anywhere on the way, either file included, is a 403 resolved_path_mismatch, never a write that lands elsewhere.
    • A backup_dir that is not a path string (a number, a boolean, a list, a mapping, a string with a NUL) is a 400 before any work is done. An absent or empty backup_dir still means no disk copy.
  • Five snapshot behaviours change. Nothing calls this endpoint today, and every accepted write still lands inside the home.
    • .. is now applied lexically, before links are resolved. Example: deep links to home/a/b, and out links outside the home.
      • deep/.. now writes to the home itself; it used to write to home/a/.
      • deep/../.. is now refused; it used to be accepted.
      • out/../x is now accepted and writes to home/x/; it used to be refused.
      • The resolve() + relative_to check still refuses any path whose links lead out of the home.
      • No test pins the lexical .. cases.
    • backup_dir with exactly two leading slashes is now refused. For example //home/developer/x, which resolve() used to collapse.
      • POSIX normpath keeps exactly two leading slashes, so the barrier does not see the home prefix.
      • Refusing is the safe direction. Collapsing the slashes first would put a string operation between the normalisation and the barrier.
      • A test pins the refusal; one or three leading slashes stay accepted.
    • A link inside backup_dir is now refused even when it stays in the home. backups -> home/elsewhere with backup_dir: backups/run-1 used to write into home/elsewhere/run-1/; it is now a 403 and writes nothing.
    • false and 0 are now a 400. They used to be ignored like an absent backup_dir.
    • The files are replaced, not overwritten in place. Each is written to a temporary file and renamed over the old one, so a hard link at either name is replaced rather than written through. A new file is created 0644; an existing file keeps its mode.
  • Dashboard:
    • A fixed, actionable message for each known failure:
      • the top level is not a mapping;
      • a section or widget is not a mapping;
      • the file cannot be read (the message names the error class);
      • the bytes are not UTF-8.
    • Anything else gets the class name only.
    • The unreachable YAMLError arm and its import are removed.
    • dashboard.yaml is opened with O_NOFOLLOW | O_NONBLOCK, and its link count and modification time are taken from the same descriptor.
    • A link at that name (live or dangling), or a file with more than one name on disk, gets one fixed answer: Failed to read dashboard.yaml: it is a link, and links are not followed. So neither another file's text nor whether a link's target exists reaches the caller.
    • A FIFO at that name is answered at once instead of hanging the endpoint.
    • The refusal applies to every caller, the agent's owner included, because the agent server does not know the caller's tier. Nothing in the platform gives dashboard.yaml a second name: a git checkout, a template copy and a local deploy all produce a file with one name (a local deploy's copy breaks a hard link carried in its archive).
    • Kept on purpose: a parse error still names and quotes the offending line, with the same workspace_yaml_* codes. What is parsed is a file with no other name when it is checked, the same rule by which Files serves a file below the owner tier. So the quoted line is text the same caller receives whole on every successful read and through the Files routes. Dropping the quote would cost authors the pointer to their mistake and disclose nothing less.
    • The descriptor is closed when the open succeeds but the read cannot start (a directory at that name).
  • 5xx sites:
    • The answer keeps its prefix and names only the exception class.
    • The text is logged with its traceback after the credential sanitizer.
    • The original exception stays chained as __cause__.
    • A TimeoutError that reaches the Codex arms is foreign by construction, so it answers Codex execution timed out (<class>).
  • Kept on purpose: messages the agent server writes itself are unchanged. This includes Permission bypass failed, which the backend's container-fault classifier matches. No backend classifier reads the new fixed strings; a test that runs failure_classifier.py on them pins this.
  • Side effect: a foreign exception whose text merely mentions words like "credentials" or "401" no longer triggers a subscription switch.
  • Docs: the dashboard, file-browser and skills-on-agent-start feature flows now quote the new answers.

Evidence

  • tests/unit/test_ent1117_s6_agent_server_error_text.py has 70 tests:
    • 43 are red on the previous code and green now;
    • 27 are characterization tests, green on both.
  • Each changed site is driven through its real handler with an exception that carries an sk- key and a credential in a URL. Each test checks that:
    • the answer holds neither the secret nor the exception text;
    • the class name is present;
    • the log record holds the text with the secret redacted.
  • The dashboard's unreadable-file arm is checked the same way, with the credential in the error's filename.
  • The file routes are also driven once through the package import, the way the agent server loads them. This exercises the sanitizer import that production uses.
  • Snapshot coverage:
    • Refused: traversal, a sibling prefix, a link that leads out of the home, and the two-slash form.
    • Accepted: ., subdirectories, and absolute paths inside the home.
    • Under a home reached through a link: . and a subdirectory are accepted.
    • Refused with a 403 and nothing written through: a link at snapshot.tar to a file outside the home, a link at files.txt to another file in the home, and a linked directory inside the home. Each link's target keeps its content.
    • A 400 for each non-string backup_dir and for a NUL; a reused backup_dir replaces its files; no backup_dir writes nothing.
  • Dashboard link coverage: a link and a hard link to a stand-in credentials file are refused and none of its text is returned; a link to a valid dashboard elsewhere is not served; a dangling link gets the same answer as a live one. Also pinned: a FIFO at the path is answered at once, a missing file, a real file's own modification time, the quoted line of a real file's parse error, and no descriptor left open after an unreadable file.
  • Each of these behaviours was mutated back, and every mutation turns at least one of these tests red:
    • a following write for each snapshot file;
    • no type check; no NUL check;
    • a following dashboard open;
    • no link-count check, or a count limit of 2;
    • a blocking open;
    • an existence check before the open;
    • no descriptor close.
  • The two Agent runtime: process-ownership fix (#3308) covers Claude chat and headless only — Codex/Gemini keep a stale registry entry, and a failure before the reader starts leaks one #3408 test files used the leaked text as a control. Each control now checks the class-only detail plus the chained cause, so it still singles out the exception it was written for.
  • The existing tests for the touched modules pass:
    • test_1965_agent_server_safe_yaml.py and both test_3408_* files;
    • the snapshot and restore tests: test_ent822_shared_folder_links.py, test_reset_preserve_state_*, test_agent_data_export.py, test_ent183_skill_packages.py;
    • the dashboard tests: test_1265_*, test_2110_*, test_2198_*, test_ent479_*, test_ent730_*;
    • the Files policy tests: test_ent820_*.

Not covered

  • CodeQL. It is the only proof that the snapshot barrier closes the path-injection alert and that the dashboard alerts are gone; this PR's CodeQL run supplies it. The unit tests pin the barrier's shape and the behaviour around it. Removing only the trailing separator from the base path changes no observable behaviour, so only CodeQL can tell whether the barrier is recognised. The same run shows whether the snapshot's new route into the no-follow writer is reported.
  • A concurrent rename. A process that keeps renaming names in the home while the dashboard is read can race the link-count check. The Files read path has the same window, and an agent asked to copy a file to dashboard.yaml discloses it outright.
  • Lexical .. cases. The cases listed under Fix are described from a probe, not pinned by a test.
  • Snapshot partial write. When files.txt is the refused link, snapshot.tar has already been written into the same directory.
  • The Files open helper still answers an unexpected OSError from opening a path component with that error's text (files.py:124): the errno message and the component the caller sent. This predates this PR.
  • Built image and live agent. Behaviour there is not exercised here.
  • Running agents keep the old server until they are recreated on the new base image.

…up_dir (Abilityai/trinity-enterprise#1117)

The snapshot endpoint resolved the caller's backup_dir before checking it.
A normalised, separator-terminated comparison now runs first, in unresolved
space, so the sibling-prefix case (../home2) cannot pass and '.' (the home
itself) still does. The resolve() + relative_to check stays behind it for a
link inside the home that points out of it. The X-Snapshot-Path header is
computed against the resolved home, so a home reached through a link no
longer raises after the write.
…ption text (Abilityai/trinity-enterprise#1117)

A dashboard.yaml the validator could not walk (a list or string where a
mapping belongs) surfaced as the raw AttributeError text, and an unreadable
file as the OS error with its path. Each known failure now gets a fixed
sentence the author can act on: not a mapping at the top level, a section or
widget that is not a mapping, a file that could not be read (with the error
class), or bytes that are not UTF-8. Anything else answers with the class
name and is logged with its traceback, credential-scrubbed.

The except yaml.YAMLError arm is removed: load_hardened_yaml converts every
YAMLError into HardenedYamlError, so it could never run. Its import goes with
it.
…Abilityai/trinity-enterprise#1117, #4284)

The file routes (list, download, delete, update, mkdir) and the Claude Code,
Gemini, Codex and headless task runtimes rendered an unforeseen exception's
text into the 500 detail. That text can carry paths, subprocess output or a
credential. The answer now keeps its existing prefix and names only the
exception class; the text goes to the log with its traceback, passed through
the credential sanitizer first.

Codex's two TimeoutError arms are foreign by construction (every timeout the
path owns is already a 504 HTTPException), so they now answer
'Codex execution timed out (<class>)', keeping 'timed out' for the
backend's text checks.

Messages the agent server writes itself are unchanged, including
'Permission bypass failed', which the backend's container-fault classifier
matches.
…Error scrub and the two-slash backup_dir refusal (Abilityai/trinity-enterprise#1117, #4284)

- Drive one files-route 500 through `agent_server.routers.files`, the way
  the agent server loads it, so `_log_failure`'s package branch runs under
  test. Every other files test loads the router by path.
- The dashboard permission-denied test plants a credential in the
  PermissionError and checks the log record is scrubbed, so the OSError
  arm's sanitizer is held by a test.
- Pin that a `backup_dir` with exactly two leading slashes is refused
  (POSIX normpath keeps them, so the barrier does not see the home prefix),
  and that one or three leading slashes stay accepted.
…bilityai/trinity-enterprise#1117, #4284)

The class-only 500 detail let any UnicodeEncodeError or AttributeError pass
these controls. Every changed site raises `from e`, so the original text is
still on `__cause__`; checking it restores the controls' original
specificity.
…lass (Abilityai/trinity-enterprise#1117, #4284)

- agent-dashboard: the YAML parse answer is the hardened loader's named
  refusal (the old line/column form has been gone since #1965); add the
  not-a-mapping, unreadable, not-UTF-8 and unforeseen-failure answers.
- file-browser: the unforeseen-failure 500s name the class; the OS error
  arm of the no-follow walk keeps its text.
- skills-on-agent-start: the quoted update handler matches the code.

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

Reviewed (code review + /validate-pr, lane C). Approving.

  • No consumer in backend, frontend, MCP or scheduler parses the removed error strings; status codes unchanged; server-side tracebacks still logged via sanitize_text with from e. Vendored mirrors untouched.
  • Snapshot barrier is correct (normpath both sides, trailing separator, resolve() check retained).
  • Mutation: reverting the 7 agent_server files gives 27 failed / 20 passed; disabling only the snapshot startswith barrier gives 2 failed. Head 95/95 on 3.13.

Non-blocking:

  • tests/unit/test_ent1117_s6_agent_server_error_text.py:388 fails on Python 3.11: before 3.12 is_relative_to calls relative_to, so the patched raise fires in _refuse_outside_home outside the handler's try. CI and images are 3.13. Raising from inside the walk (e.g. the per-entry stat) makes it version-independent.
  • Follow-up: routers/snapshot.py:171-172 writes snapshot.tar / files.txt with symlink-following write_bytes; a planted symlink inside an accepted backup_dir redirects the write. restore already uses write_bytes_nofollow. Nothing sends backup_dir today.
  • Follow-up: the backend proxy still returns str(e) in its own 500s (services/agent_service/dashboard.py:322, files.py:631,769).

Merge-gate note: frontend-e2e skipped (no ui label); the changed strings surface in the dashboard and file browser.

…llowing a link (Abilityai/trinity-enterprise#1117)

The snapshot endpoint checked that `backup_dir` resolves inside the home,
then wrote `snapshot.tar` and `files.txt` into it with plain writes, which
follow a link at either name. Both files now go in through
`files.write_bytes_nofollow` (ent#822), the writer the restore path in the
same module already uses: the directories are walked and created one
component at a time without following a link, and a link anywhere on the
way, either file included, is a 403 `resolved_path_mismatch` instead of a
write that lands elsewhere. Reusing a `backup_dir` still replaces its files.

A `backup_dir` that is not a path string (a number, a boolean, a list, a
mapping, or a string carrying a NUL) is now a 400 before any work is done,
instead of a 500 from `os.path.join` or `resolve()`. An absent or empty
`backup_dir` still means no disk copy.
…ver through a link (Abilityai/trinity-enterprise#1117)

`GET /api/dashboard` read `/home/developer/dashboard.yaml` with
`read_text()`, which follows a link. A link at that name made the endpoint
parse another file, return it whole when it happened to be a valid
dashboard, and quote its offending line in a `workspace_yaml_yaml_invalid`
parse error otherwise.

The file is now opened with O_NOFOLLOW and its modification time taken from
the same descriptor. A link, live or dangling, gets one fixed answer ("it is
a link, and links are not followed"), so neither another file's text nor
whether a link's target exists reaches the caller. What is parsed is always
the file at the fixed path, so a parse error keeps naming and quoting the
offending line: that is the dashboard's own text, which the same caller
receives whole on every successful read. The refusal codes are unchanged.

A missing file, a non-UTF-8 file and an unreadable one keep their answers.
The descriptor is closed when the open succeeds but the read cannot start
(a directory at that name).
…me, and a FIFO test pins the non-blocking open (Abilityai/trinity-enterprise#1117)

O_NOFOLLOW does not see a hard link, so a second name for another file at
dashboard.yaml was still parsed, and a parse error quoted its line. The read
now refuses a file whose link count is above 1 with the same fixed answer as
a link, the rule Files already applies to hard-linked files below the owner
tier (ent#820). A FIFO at the path is answered at once; a test pins the
non-blocking open that keeps it from hanging the endpoint.
@AndriiPasternak31 AndriiPasternak31 changed the title fix(agent-server): no exception text in API answers, snapshot path barrier, dashboard error messages (abilityai/trinity-enterprise#1117) fix(agent-server): no exception text in API answers, snapshot path barrier and no-follow writes, dashboard error messages and no-follow read (abilityai/trinity-enterprise#1117) Nov 6, 2026
@AndriiPasternak31
AndriiPasternak31 marked this pull request as ready for review November 6, 2026 20:34
…ot the exception's (#4293)

Mechanical, per the merge-train note on the PR. The TimeoutError arm in
gemini_runtime.execute_headless returned str(e) in its 504 and logged it
unscrubbed, the one runtime arm this PR's sweep missed. The answer is now
built from timeout_seconds, which keeps the historical "Task execution timed
out after N seconds" shape task_execution_service reads, and the log goes
through sanitize_text.

Part of Abilityai/trinity-enterprise#1117.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vybe

vybe commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-06): one mechanical commit pushed to this branch, 0d49ac8dc.

The validator found one runtime arm this sweep missed. In gemini_runtime.execute_headless, the TimeoutError arm still answered 504 with detail=str(e) and logged the text unscrubbed.

  • The 504 is now built from timeout_seconds. It keeps the historical "Task execution timed out after N seconds" text, which task_execution_service reads. I did not switch to the class-name form, because that would have broken this text.
  • The log line goes through sanitize_text.
  • I added test_gemini_task_timeout_answers_with_its_own_text. It failed first with the planted secret in the answer, and passes now.

Nothing else changed. This PR is on the current merge train.

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.

4 participants