Repository navigation
fix(batch): stop timed-out places, handle SIGTERM, keep collection fast - #34
Merged
Merged
Conversation
Issue #33: `revcli batch` could not finish long lists unattended. - A location timeout now really stops the scrape: runWithTimeout() aborts a signal that withRetry and scrapeLocation honour, closes the browser, and waits until it is closed before the next place starts. A late result is never saved. If a stopped browser does not close within 15 s, the batch stops with exit 1 (resume with --resume). - revcli owns SIGHUP/SIGINT/SIGTERM: Playwright's own handlers (whose SIGTERM handler closed browsers without exiting) are turned off; a signal aborts running work, closes every browser and exits 129/130/143. - Collected review cards are marked with their review id and skipped, so a collect cycle reads only new cards (last/first 10 cycles at 2,000 reviews: 970/177 ms before, ~140/85 ms after). A reused card is read again. - Output and state files are written atomically (temp file + rename). Also includes `revcli scrape --time-limit <minutes>`: stop collecting after the given time and save the reviews collected so far, with a warning. Closes #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #33:
revcli batchcan now finish long lists unattended.--location-timeoutis really stopped, its browser is closed, and only then does the next place start.kill <pid>(SIGTERM) closes the browser and ends revcli with exit 143 (SIGHUP 129 when attached to a terminal, Ctrl+C 130).This PR also contains
revcli scrape --time-limit <minutes>(stop collecting after N minutes and save the partial result), which was developed in the same working tree.Root causes (verified)
batch.tsusedPromise.race(scrape, timer): the losing scrape kept running and its persistent Chromium kept~/.revcli/chrome-profilelocked, so the next place failed. The timer was never cleared either.playwright-core/lib/coreBundle.js,sigtermHandler): they close browsers but never exit, and their presence turns off Node's default exit on SIGTERM. That is whykillleft revcli running.Approach and assumptions
AbortSignal:runWithTimeout()(src/core/timeout.ts) aborts the signal;withRetrystops retrying;withBrowserSession()closes the browser on abort, so every pending Playwright call rejects. The batch waits for the stopped scrape to settle (15 s grace). If it does not settle, the batch stops (BROWSER_NOT_CLOSED, exit 1) instead of starting a second browser on the same profile.closeBrowser()shares one close per browser: a secondcontext.close()returns at once while the first is still running, which would let the next place start too early.handleSIGINT/handleSIGTERM/handleSIGHUP: falseand installs its own handlers fromsrc/index.ts(SIGHUP only when attached to a terminal, sonohupkeeps working).data-revcli-collected="<review id>"; a card is skipped only while the mark equals its current review id, so an element Google reuses for another review is read again. Nothing that was collected before is skipped (the 2,000-review test asserts all 2,000 are collected).--location-timeout(documented in CHANGELOG/AGENTS.md).Acceptance criteria
tests/batch-run.test.ts(event order "Slow started → Slow browser closed → Fast started");tests/browser/abort.test.ts(real persistent browser on a temp profile: abort mid-scroll rejects < 5 s, a second browser then opens the same profile); live run belowtests/batch-run.test.ts(files written for places 2 and 3, none for place 1, state lists them); live run belowtests/browser/shutdown.test.ts(real child process + Chromium on a temp profile: exit 143 < 10 s,pgrepfinds no Chromium); live run belowtests/browser/scroll.test.ts: beforefirst 10 = 177ms, last 10 = 970ms(5.5×); afterfirst 10 = 86ms, last 10 = 138ms. Also a timing-free check: every cycle reads ≤ 100 cardsexpected [ 'Slow started', 'Fast started' ] to deeply equal [ 'Slow started', …(2) ]; SIGTERMexpected 'timeout' to be 143; AC4expected 970 to be less than or equal to 354; retry/shutdown tests failed against stubs. All pass after the fixChecks run
Baseline before the change: 25 files, 420 tests, all passing. No existing test was changed, skipped or weakened (
tests/retry.test.tsandtests/browser/scroll.test.tsonly gained tests).Live run (macOS, headless, signed-in profile)
Batch with a 1,673-review place first and a 27-review place second,
--headless --delay 1000 --location-timeout 60000 --location-delay 1000:kill <revcli pid>during scrolling:Note: the issue's step 3 uses
-o <dir>;batchtakes-d, --output-dir.Not done / follow-ups
--delay 3000, the end-of-list detection (6 stale scrolls with back-off) takes ~60 s per place, so a small place cannot finish within a 60 s location timeout. Pre-existing, related to Improve stale scroll detection with backoff and loading spinner awareness #2; not changed here. The live run above used--delay 1000.--resumescrapes that place again; a collected card that Google re-renders as a new element may get a stuck "More" button clicked again (≤ 2 clicks per cycle);launchBrowser's close-on-partial-launch path has no test.npm auditfindings (2 critical / 5 high, mostly in the vitest/vite dev chain;zodhigh in production deps, fix needs a major upgrade). No dependency changed in this PR.Reused code
None from outside the repo. The atomic write follows the existing state-file pattern in
batch.ts; the test child reusesbrowserLaunchOptions().