Skip to content

screenshot silently falls back to tmp dir + prints success when target directory doesn't exist #1534

Description

@kpaytn

Summary

When the screenshot command is given a path whose parent directory does not exist (as resolved against the daemon's cwd), agent-browser silently saves to ~/.agent-browser/tmp/screenshots/screenshot-<epoch>.png and prints ✓ Screenshot saved to … with exit code 0. No warning, no error. The only signal that anything went wrong is that the returned path does not match the path the caller requested.

For an agent-driven tool, a false success on evidence capture is the worst-case failure mode: the agent records the check as PASS and moves on, and the screenshot is quietly lost to a temp dir the agent never inspects.

Environment

  • agent-browser 0.31.1
  • macOS arm64 (Darwin 25.5.0), system Chrome 150

Reproduction

agent-browser open https://example.com
agent-browser screenshot ./does-not-exist/page.png
# ✓ Screenshot saved to /Users/<user>/.agent-browser/tmp/screenshots/screenshot-<epoch>.png
# exit 0
#
# ./does-not-exist/ was never created. The file is NOT at ./does-not-exist/page.png.

This compounds with the daemon-cwd decoupling (#137): a relative path is resolved against the daemon's pinned cwd, not the caller's shell cwd, so even a directory that exists in the caller's cwd can trigger the fallback if it doesn't exist in the daemon's cwd.

Expected behavior

If the parent directory of the requested screenshot path does not exist (after path resolution), error with a clear message, e.g. ✗ Screenshot path parent directory does not exist: <resolved dir>. Do not fall back to the tmp dir when an explicit path was supplied. The tmp-dir fallback introduced in #247 is reasonable for the no-path-provided case; it should not fire for the path-provided-but-unwritable case.

Suggested fix

In cli/src/native/screenshot.rs (and any shared write path), before delegating to the tmp-dir fallback: if an explicit output path was provided, verify the parent directory exists (after resolving relative paths against the CLI cwd per #137). If it doesn't, return an error rather than falling back.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions