Conversation
… fetcher - Introduced a semaphore to limit concurrent page renders, enhancing resource management. - Updated session handling to defer browser closure until all in-flight renders are complete. - Improved comments for clarity on the behavior of concurrent fetches and session lifecycle. - Cleaned up imports in alembic environment and migration flow scripts for consistency.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds concurrency control to the Google Search browser fetch module: a semaphore-based render gate limits concurrent page renders, and session drop logic defers closure until in-flight renders complete, with new unit tests. Two unrelated files have minor import statement reordering. ChangesRender Concurrency Fix
Unrelated Import Reordering
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant RenderOnLoop as _render_on_loop
participant Gate as Render Semaphore
participant Session as AsyncStealthySession
participant DropOnLoop as _drop_session_on_loop
Caller->>RenderOnLoop: request render
RenderOnLoop->>Gate: acquire
RenderOnLoop->>Session: increment _inflight
RenderOnLoop->>Session: fetch()
DropOnLoop->>Session: check _inflight
alt in-flight renders active
DropOnLoop->>Session: mark _doomed
else idle
DropOnLoop->>Session: close()
end
RenderOnLoop->>Session: decrement _inflight
alt session doomed and last in-flight
RenderOnLoop->>Session: close()
end
RenderOnLoop->>Gate: release
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR fixes a critical concurrency bug in the Google Search rendering system where concurrent SERP fetches would fail when one render encountered an error. The fix introduces a semaphore to limit concurrent page renders to 4, tracks in-flight renders per session, and defers browser session cleanup until all in-flight renders complete. This prevents the TargetClosedError cascade that previously occurred when a failing render closed the shared browser while sibling renders were still active. Additionally, the PR includes minor import ordering cleanup in unrelated files.
⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
surfsense_backend/tests/unit/platforms/google_search/test_fetch_concurrency.pysurfsense_backend/app/proprietary/platforms/google_search/fetch.pysurfsense_backend/alembic/env.pysurfsense_backend/scripts/check_migration_flow.pysurfsense_backend/alembic/env.pysurfsense_backend/scripts/check_migration_flow.pySummary by CodeRabbit
Bug Fixes
Tests