Implement graceful crawl abort via AbortController#55
Merged
YusukeHirao merged 3 commits intomainfrom Mar 11, 2026
Merged
Conversation
Crawler の独自 #aborted フラグを AbortController/AbortSignal に置換し、 @d-zero/dealer の deal() に signal オプションとして渡すようにした。 これにより abort 後は dealer が新しいワーカーの起動を停止し、 実行中のワーカーの完了を待ってから正常に終了する。 - Crawler: #aborted フラグ → #abortController + signal getter - deal() 呼び出しに signal オプションを追加 - CrawlerOrchestrator.abort(): archive.abort() → crawler.abort() - CLI シグナルハンドラ: orchestrator.abort() を呼ぶよう統一 - abort 動作を検証するテストを追加 Closes #19 https://claude.ai/code/session_015YfPBKbEv53mMTkgPxGCm5
- Replace duplicate signal-aborted assertion with crawlEnd-on-resolve test that verifies the normal completion path (deal resolves → crawlEnd emits) - Add double-abort safety test to ensure calling abort() twice doesn't throw https://claude.ai/code/session_015YfPBKbEv53mMTkgPxGCm5
Document the AbortController-based crawl cancellation flow (CLI signal handler → Orchestrator → Crawler → deal signal) and fix missing blank line in crawler.ts signal getter. https://claude.ai/code/session_015YfPBKbEv53mMTkgPxGCm5
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
Refactored the crawl abort mechanism to use the standard
AbortControllerAPI instead of a simple boolean flag. This allows the dealer to stop launching new workers when abort is signaled, while allowing in-progress workers to complete naturally.Key Changes
Crawler abort mechanism: Replaced
#abortedboolean flag with#abortController(AbortController instance)signalgetter to expose the AbortSignal for external useabort()method to callabortController.abort()instead of setting a flag and immediately emittingcrawlEnd#abortedflagDealer integration: Pass the AbortSignal to the
deal()function via thesignaloptiondeal()resolves andcrawlEndis emittedCrawlerOrchestrator: Updated
abort()method to delegate tocrawler.abort()instead ofarchive.abort()CLI signal handlers: Updated the
killed()handler to callorchestrator.abort()before garbage collection and process exitDocumentation: Updated ARCHITECTURE.md to document the new abort flow and mechanism
Implementation Details
The new abort flow is:
CrawlerOrchestrator.abort()CrawlerOrchestrator.abort()→ callsCrawler.abort()Crawler.abort()→ callsAbortController.abort()deal(), which stops launching new workersdeal()resolves →crawlEndevent is emitted via normal completion pathThis is more robust than the previous approach because:
crawlEndevent is emitted through the normal completion path, not immediately on abortTests Added
Four new test cases verify the abort behavior:
abort()is calledcrawlEndevent is emitted on normal deal completionabort()calls don't throw errorssignalgetter returns an AbortSignal instancehttps://claude.ai/code/session_015YfPBKbEv53mMTkgPxGCm5