Skip to content

fix(daemon): rotate non-empty log on start to preserve previous crashes (#991) - #993

Open
yunusarda-sudo wants to merge 1 commit into
browser-use:mainfrom
yunusarda-sudo:fix/daemon-log-rotation-on-start
Open

yunusarda-sudo wants to merge 1 commit into
browser-use:mainfrom
yunusarda-sudo:fix/daemon-log-rotation-on-start

Conversation

@yunusarda-sudo

@yunusarda-sudo yunusarda-sudo commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary

In src/browser_harness/daemon.py, the daemon entry point called open(LOG, "w").close() on every startup, truncating the log file to 0 bytes. When ensure_daemon() respawned a dead or crashed daemon, the prior daemon's terminal output (WebSocket close code, fatal exceptions, or exit diagnostics) was destroyed before operators or debuggers could inspect it.

Changes

  • Added _rotate_log(log_path=None) to rotate any existing non-empty log file to {LOG}.1 using os.replace.
  • Replaced open(LOG, "w").close() in daemon.py:__main__ with _rotate_log(LOG) so previous run diagnostics are retained in {LOG}.1 and the active daemon starts fresh.
  • Added unit tests:
    • test_rotate_log_preserves_previous_run_output asserting non-empty log rotation to .1.
    • test_rotate_log_ignores_empty_or_missing_file asserting empty or missing log files do not produce spurious .1 backup files.

Closes #991.

Signed-off-by: Yunus Ardaguney [email protected]


Summary by cubic

Fixes the daemon truncating its log on startup so previous crash diagnostics survive respawns.

ensure_daemon() now rotates any non-empty log before opening the child's stderr sink instead of wiping it to 0 bytes, keeping three generations (.1–.3) so all start attempts in the retry loop survive. Remote spawns are now serialized under the same spawn lock as local ones, and rotation is skipped while another daemon is still starting so a concurrent caller cannot move a live child's log.

  • Reports rotation failures to stderr and the log instead of hiding them.
  • Adds tests for rotation, three-generation retention, empty or missing log files, failed-spawn rotation, and remote spawns with a starting sibling.

Written for commit fa2df68. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/browser_harness/daemon.py Resolved
Comment thread src/browser_harness/daemon.py Resolved
Comment thread src/browser_harness/daemon.py Resolved

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/browser_harness/admin.py Resolved
Comment thread tests/unit/test_admin.py Resolved
@yunusarda-sudo

Copy link
Copy Markdown
Author

Hi, this is green and ready for review whenever convenient. Thanks!

@yunusarda-sudo
yunusarda-sudo force-pushed the fix/daemon-log-rotation-on-start branch from 4bf4e0e to fa2df68 Compare November 25, 2026 23:17

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.

daemon truncates its own log on every start, erasing the previous daemon's output

1 participant