fix(agent): fail tainted fallback-only steps with POLICY_DENIED

Merged
OK
2mo ago
+112-22

After a secret fill the attempt is pixel-tainted, so the runner withholds pixelFallback. An agent step that could only read the screen from that fallback screenshot never got it: it failed with the engine's operation timed out (ACTION_FAILED), and act spent two operation budgets doing so (the cache's opening probe swallowed the first timeout and the executor's first look timed out again).

  • retryingObserve (packages/e2e/src/agent/phases.ts) now owns the pixelFallback decision: callers say whether the step wants fallback (act and executor observations in observation-feed.ts, vision: true judgments in invocation.ts), and the taint is read per capture. A capture whose fallback a secret fill withheld and that times out becomes POLICY_DENIED, naming the fill. The step clock still wins: a capture cut short by the step deadline stays STEP_TIMEOUT.
  • A vision: false judgment never asks for fallback and keeps its timeout. vision: 'only' was already denied before any capture.
  • The step cache's opening probe (step-cache.ts captureStart) propagates that denial instead of treating it as a miss, so act fails after one operation budget. Later probes still hand off to the executor, and a denied start is not an eviction.
  • Docs: reference/errors.mdx, reference/agent.mdx, security.mdx, and the skill's debugging table.
flowchart LR
  A[semantic capture times out] --> B{step clock out?}
  B -- yes --> T[STEP_TIMEOUT]
  B -- no --> C{fallback wanted and secret filled?}
  C -- yes --> P[POLICY_DENIED: a secret was filled]
  C -- no --> E[engine error, as before]

Follow-up: #821 moves these tests to agent-fallback-handoff.test.ts and still asserts 'timed out' for the two tainted cases. Once this lands, tighten that assertion to POLICY_DENIED (the cubic thread on its line 393).

Verified

Ran it locally: yes

  • tests/integration/agent-semantic-fallback.test.ts now asserts POLICY_DENIED for both tainted cases, one observation for the tainted act, and a timeout for a tree-only judgment after a fill. On main it fails with expected 'ACTION_FAILED' to be 'POLICY_DENIED'. Mutations checked: dropping the flag from the feed or from the judgment, setting it for tree-only judgments, or removing the opening-probe rethrow each fail it. Removing the guard-first order fails the new unit test in agent-phases.test.ts.
  • Built CLI, scratch project in /tmp on @e2e-dev/web: a page whose main thread hangs after the password field's input event, actionTimeout: 3000, then agent.act, agent.assert({ vision: true }), and agent.assert() after fill(credentials.user('admin').password). The secret appears nowhere under .e2e/.
stepmainthis branch
agent.actACTION_FAILED: operation timed out, 6.06sPOLICY_DENIED: agent.act could not read the semantic tree, and its screenshot fallback is denied: a secret was filled in this attempt, so no pixels leave the runner until it ends (PIXEL_TAINTED), 3.00s
agent.assert vision: trueACTION_FAILED: operation timed out, 3.00sPOLICY_DENIED: agent.assert could not read ... (PIXEL_TAINTED), 3.01s
agent.assert tree-onlyACTION_FAILED: operation timed out, 3.00sACTION_FAILED: operation timed out, 3.00s

A fresh-context review found three things, all fixed: the denial had overridden STEP_TIMEOUT at the deadline, the denying path had no unit test, and the JSDoc on begin() was stale.

web agent fails with REPLAY_STALE on main too (since chore: version packages (#774) moved the cache key); it is not from this change.