Skip to content

fix(agent-device): clean up screenshots after cancelled captures - #206

Merged
okwasniewski merged 1 commit into
mainfrom
fix/device-screenshot-cleanup
Sep 8, 2026
Merged

okwasniewski merged 1 commit into
mainfrom
fix/device-screenshot-cleanup

Conversation

@okwasniewski

@okwasniewski okwasniewski commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What and why

  • A cancelled screenshot can finish later and recreate its raw temporary file after cleanup has already run.
  • Keep capture, reading, and deletion in one tracked command, with a separate temporary directory per screenshot. Cancellation still returns promptly; the next attempt waits for cleanup.
  • Deferred success and failure regressions reproduce the leak on main and verify cleanup before the next app launch.
flowchart LR
  C[Device capture] --> D[Read pixels and remove temporary directory] --> N[Next attempt]
  C -. cancellation .-> R[Caller receives CANCELLED]
Loading

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). Not applicable.
  • Docs updated in the same PR: the docs/src/content/docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures. Not applicable.
  • Engine contract change (@e2edev/e2e/engine): changesets for @e2edev/e2e, @e2edev/playwright, and @e2edev/agent-device. Not applicable.

Devin Review

@vercel

vercel Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
e2e-docs Ready Ready Preview Sep 8, 2026 5:48pm UTC

Request Review

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +607 to +614
return this.command('screenshot', async (client) => {
const directory = mkdtempSync(path.join(tmpdir(), 'e2e-agent-device-'));
const file = path.join(directory, 'screenshot.png');
try {
const shot = await client.capture.screenshot({ path: file });
return new Uint8Array(readFileSync(shot.path ?? file));
} finally {
rmSync(directory, { recursive: true, force: true });

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.

🟡 Final cancelled screenshot survives shutdown

When the final screenshot is cancelled, rawScreenshot can outlive disposal because worker shutdown never waits for tracked commands. The child worker exits before finally removes the temporary directory.

Prompt for agents
AgentDeviceSurface tracks cancelled screenshot work in inflight, but only startAttempt waits for that set. At worker shutdown, packages/agent-device/src/surface.ts dispose closes the session without waiting for inflight commands, and packages/e2e/src/run/worker/session.ts exits the child after dispose returns. A cancelled screenshot on the final attempt can therefore lose the rawScreenshot finally cleanup when the worker exits. Update disposal to give tracked commands a bounded chance to settle and clean their temporary directories before session closure and worker exit, while preserving cleanupTimeout behavior for commands that never settle. Add a regression covering cancellation followed directly by dispose rather than another startAttempt.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

This branch was successfully deployed

1 active deployment
Preview — 15ec617e Deployed Sep 8, 2026 by vercel[bot]
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.

1 participant