Skip to content

Survive malformed agent answers: reliability events, refresh snapshots, screenshots - #364

Open
t11z wants to merge 4 commits into
mainfrom
claude/hopeful-newton-j14ox4
Open

t11z wants to merge 4 commits into
mainfrom
claude/hopeful-newton-j14ox4

Conversation

@t11z

@t11z t11z commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

Scheduled crash-fuzzing run. This time the server was fuzzed with a connected mock agent that answers with mutated data (earlier runs stopped at "no agent connected" on those routes). Three crashes; the session may push to one branch only, so they share this PR. A fourth commit repairs an agent test that fails on the Linux CI runner regardless of this change.

1. A non-list reliability.events takes down the fleet overview

events is a section extra, so a valid telemetry frame may carry any JSON value there. event_categories.annotate_snapshots iterated whatever truthy value it found:

TypeError: 'float' object is not iterable
  webui/__init__.py  api_fleet_overview -> _annotate_reliability
  event_categories.py:716  annotate_snapshots

One host pushing "events": 3.7 made GET /api/agent/{id}, /api/fleet/overview and /api/today answer 500 for every host until that host pushed a different snapshot.

Fix: collect only a list, the same check the stamping loop a few lines below already makes.

2. A refresh stores a snapshot the push path would reject

POST /api/agent/{id}/refresh and the ticket-callback refresh stored the telemetry_collect result without the validation a pushed telemetry frame gets. A section that is not an object ("win_update": -5) was stored, and then:

AttributeError: 'int' object has no attribute 'get'
  webui/__init__.py  api_digest_preview -> digest.py build_digest -> _collect

Fix: new protocol.parse_snapshot validates the same dict[str, Section] map the frame uses. Both refresh paths run the result through it and do not store one that fails. The route still answers 200 with stored: false and a warning, as it does for a storage failure. docs/protocol.md gains one sentence saying so; no frame or tool shape changes.

3. An undecodable screenshot breaks every later GET .../screenshot

POST /api/agent/{id}/screenshot stored any image_b64; the GET base64-decodes the stored value, so a non-string or bad base64 raised TypeError / binascii.Error on every read until the next good capture.

Fix: ScreenshotStore.put keeps only a string that decodes and returns whether it did (this also covers the chat tool loop, the other writer). The route answers 502 for a rejected capture and the previous one stays.

4. CI: wait_times_out_while_another_process_runs_target fails on the Linux runner

The kenny-agent (Rust) job failed on this PR's first push and on its re-run, and identically on the unrelated dependency PR #361, so it is not caused by this diff. The test copied /bin/sleep to a file with another name and ran the copy; the child was gone before the wait looked for it. That is what a multi-call sleep does when run under a name that is not an applet. The copy now keeps the name sleep inside a private directory, and the job passes. Test-only; the runner's sleep was not inspected directly, so the cause is inferred from the fix working.

Fuzzing summary

Checklist

  • Tests pass: pytest -q (server, 4268 passed) and cargo test (agent, 588 passed). The three new regression tests fail without the fixes. CI is green on the current head.
  • Lint/format clean: ruff check . and cargo fmt --check pass locally; clippy ran in CI only.
  • If the wire contract changed: not applicable. The validation applies the existing snapshot shape to a second entry point.
  • If the change is architectural: not applicable, no boundary moved.
  • Docs updated where relevant: one sentence in docs/protocol.md.
  • Commits are signed off (DCO: git commit -s)

🤖 Generated with Claude Code

https://claude.ai/code/session_01QcqxZNqpHNGk5hJzgn6CWt

`events` is a section extra, so a telemetry frame may carry any JSON value
there. annotate_snapshots iterated whatever truthy value it found, so one
host reporting a number or a boolean raised TypeError and GET /api/agent/{id},
/api/fleet/overview and /api/today answered 500 for the whole fleet until
that host pushed a different snapshot. Found by crash fuzzing with a mock
agent that mutates its snapshots.

Only a list is collected now, matching the check the stamping loop below
already makes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QcqxZNqpHNGk5hJzgn6CWt
Signed-off-by: Claude <noreply@anthropic.com>
Found by crash fuzzing with a mock agent that answers tool calls with
mutated results. Two results were stored unchecked and broke later reads:

- POST /api/agent/{id}/refresh and the ticket-callback refresh stored a
  telemetry_collect result as a snapshot without the validation a pushed
  telemetry frame gets. A section that is not an object (`"win_update": -5`)
  then made GET /api/digest/preview answer 500. Both paths now run the
  result through protocol.parse_snapshot, the same map of section name to
  Section the frame uses, and do not store a result that fails it.
- POST /api/agent/{id}/screenshot stored any `image_b64`, and GET on the
  same route base64-decodes the stored value, so a non-string or undecodable
  payload turned every later GET into a 500. ScreenshotStore.put now keeps
  only a string that decodes and reports whether it did; the route answers
  502 for a rejected capture and the previous one stays.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QcqxZNqpHNGk5hJzgn6CWt
Signed-off-by: Claude <noreply@anthropic.com>
…fore storing

The server holds a telemetry_collect result to the same snapshot map as a
pushed telemetry frame before it stores one. The contract said the shape
is the same; it now also says what happens to a result that is not.

No frame or tool shape changes. The dashboard, tool and account references
need no update for this branch: they describe neither route's response to
a malformed agent answer, no tool or account capability is touched, and
nothing a healthy agent sends is handled differently. [skip-doc-drift]

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QcqxZNqpHNGk5hJzgn6CWt
Signed-off-by: Claude <noreply@anthropic.com>
wait_times_out_while_another_process_runs_target copied /bin/sleep to a
file named kenny-wait-test-<pid> and ran the copy. The Linux CI job fails
that test on every run that reaches it (also on an unrelated dependency
PR): the child is gone before the wait looks for it. Where sleep is an
applet of a multi-call binary, the binary picks the applet by the name it
is run as, so the renamed copy exits at once.

The copy now keeps the name `sleep` inside a private directory, which runs
the same on a standalone sleep and on a multi-call one. Test-only; no
agent behaviour changes. [skip-doc-drift]

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QcqxZNqpHNGk5hJzgn6CWt
Signed-off-by: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants