Repository navigation
fix(browser): tolerate stepping a torn-down event bus on warm-Lambda resume (ENG-5280) - #5086
Conversation
…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.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Agent Task Evaluation Results: 2/2 (100%)View detailed results
Check the evaluate-tasks job for detailed task execution logs. |
There was a problem hiding this comment.
💡 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".
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).
|
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. |
Problem
The V2 worker reuses a
keep_aliveBrowserSessionacross 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 anydispatch()restarts it. In that torn-down state, stockbubusEventBus.step()hits: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 nextdispatch()recreate a fresh queue and_start()the bus again (bubus_start()only recreates the queue whenevent_queue is None). So we can't simply stop nulling — but a nulled bus is exactly the state wherestep()/wait_until_idle()assert.Fix
Wrap the session's event bus in a small
ResilientEventBus(EventBus)subclass whosestep()andwait_until_idle()are safe no-ops when the bus has not been started, instead of asserting. Teardown is unchanged, so a laterdispatch()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:event_busis aResilientEventBusstep()/wait_until_idle()on a stopped + nulled bus returnNone(noAssertionError)dispatch()EventBusstill reproduces the original assertion (documents the upstream bug)All 4 pass;
pyrightandruffclean.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.ResilientEventBus(EventBus)that makesstep()andwait_until_idle()no-ops when_on_idleorevent_queueisNone.BrowserSession.event_bususeResilientEventBusby default and inkill()/stop(), and kept default bus names asEventBus_*(explicit names still honored).tests/ci/test_event_bus_resilience.pyto verify no-op behavior, restart ondispatch(), name prefix preservation, and to document the upstreambubus.EventBusassertion.ResilientEventBusdocstrings and comments (no behavior change).Written for commit 5123e4f. Summary will update on new commits.