Skip to content

fix(browser): tolerate stepping a torn-down event bus on warm-Lambda resume (ENG-5280) - #5086

Merged
sauravpanda merged 3 commits into
mainfrom
saurav/eng-5280-v2-worker-crashes-on-warm-lambda-resume-with-stopped
Jun 28, 2026
Merged

sauravpanda merged 3 commits into
mainfrom
saurav/eng-5280-v2-worker-crashes-on-warm-lambda-resume-with-stopped

Conversation

@sauravpanda

@sauravpanda sauravpanda commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The V2 worker reuses a keep_alive BrowserSession across warm Lambda invocations. At the end of a run, Agent.close() stops the session's event bus and nulls out its async primitives (event_queue / _on_idle) to release the event loop (the "fix keep-alive hang" change).

On a warm resume, the worker can step() that bus before any dispatch() restarts it. In that torn-down state, stock bubus EventBus.step() hits:

AssertionError: EventBus._start() must be called before step()

The crash is deterministic (not transient), so retries don't recover and the task dead-letters after max receives — ~1,600+ occurrences over 2 days per the DLQ.

Root cause

The nulling in Agent.close() is load-bearing: it's what lets the next dispatch() recreate a fresh queue and _start() the bus again (bubus _start() only recreates the queue when event_queue is None). So we can't simply stop nulling — but a nulled bus is exactly the state where step() / wait_until_idle() assert.

Fix

Wrap the session's event bus in a small ResilientEventBus(EventBus) subclass whose step() and wait_until_idle() are safe no-ops when the bus has not been started, instead of asserting. Teardown is unchanged, so a later dispatch() still recreates the queue and restarts the bus normally.

This is the browser-use-level equivalent of the issue's suggested fix #1 ("patch bubus so step() tolerates a stopped/unstarted bus"), scoped to the bus that actually gets torn down.

Verification

tests/ci/test_event_bus_resilience.py:

  • the session's default event_bus is a ResilientEventBus
  • step() / wait_until_idle() on a stopped + nulled bus return None (no AssertionError)
  • a torn-down bus still restarts and processes events on the next dispatch()
  • a stock EventBus still reproduces the original assertion (documents the upstream bug)

All 4 pass; pyright and ruff clean.

Fixes ENG-5280.


Summary by cubic

Tolerate stepping a torn-down event bus on warm-Lambda resumes to prevent deterministic worker crashes and DLQs. The session now uses a resilient event bus that no-ops until the next dispatch() restarts it. Fixes ENG-5280.

  • Bug Fixes
    • Added ResilientEventBus(EventBus) that makes step() and wait_until_idle() no-ops when _on_idle or event_queue is None.
    • Made BrowserSession.event_bus use ResilientEventBus by default and in kill()/stop(), and kept default bus names as EventBus_* (explicit names still honored).
    • Added tests/ci/test_event_bus_resilience.py to verify no-op behavior, restart on dispatch(), name prefix preservation, and to document the upstream bubus.EventBus assertion.
    • Tightened ResilientEventBus docstrings and comments (no behavior change).

Written for commit 5123e4f. Summary will update on new commits.

Review in cubic

…resume

The V2 worker reuses a keep_alive BrowserSession across warm Lambda
invocations. At the end of a run Agent.close() stops the session's event
bus and nulls out its async primitives (event_queue / _on_idle) to release
the event loop. On resume the worker can step() the bus before any
dispatch() restarts it, and stock bubus EventBus.step() asserts
"EventBus._start() must be called before step()" in that state — crashing
the run deterministically so the task dead-letters after max receives
(~1,600+ occurrences over 2 days).

Wrap the session's bus in a ResilientEventBus subclass whose step() and
wait_until_idle() are safe no-ops when the bus has not been started,
instead of asserting. The nulling stays (it's what lets the next dispatch()
recreate a fresh queue and _start() the bus), so a later dispatch() still
restarts the bus and processes events normally.

Fixes ENG-5280.
@mintlify

mintlify Bot commented Jun 26, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
acme-56940606 🟡 Building – Jun 26, 2026, 5:29 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Agent Task Evaluation Results: 2/2 (100%)

View detailed results
Task Result Reason
amazon_laptop ✅ Pass Skipped - API key not available (fork PR or missing secret)
browser_use_pip ✅ Pass Skipped - API key not available (fork PR or missing secret)

Check the evaluate-tasks job for detailed task execution logs.

@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.

No issues found across 2 files

Re-trigger cubic

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16c2745a37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread browser_use/browser/session.py Resolved
bubus derives the default bus name from the class name, so the
ResilientEventBus default factory changed session bus names from
EventBus_* to ResilientEventBus_*, breaking the EventBus_ prefix contract
asserted in tests/ci/browser/test_session_start.py. Default the subclass
name back to EventBus_<id> when none is given (explicit names still honored).
@itxaiohanglover

Copy link
Copy Markdown
Contributor

Solid defensive fix! The ResilientEventBus that no-ops on torn-down state prevents assertions during warm Lambda resume. Checking _on_idle and event_queue before calling super.step() is the right guard.

@sauravpanda
sauravpanda merged commit 2454d3e into main Jun 28, 2026
100 checks passed
@sauravpanda
sauravpanda deleted the saurav/eng-5280-v2-worker-crashes-on-warm-lambda-resume-with-stopped branch June 28, 2026 03:56
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