perf: move AgentBootstrapService to Phase.Background and parallelize init#14096
Draft
perf: move AgentBootstrapService to Phase.Background and parallelize init#14096
Conversation
…init AgentBootstrapService was blocking the WhenReady phase for ~4.4s with sequential operations that have no UI-critical dependency. This change: - Moves to Phase.Background (fire-and-forget, never blocks other phases) - Removes unnecessary @dependsOn(['ApiServerService']) - Parallelizes bootstrapBuiltinAgents, restoreSchedulers, and channelManager.start - Parallelizes channel adapter connections in ChannelManager.start() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: suyao <sy20010504@gmail.com>
Move registerSessionStreamIpc() from onReady() to onInit() to follow the lifecycle convention: infrastructure setup in onInit, async work in onReady. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: suyao <sy20010504@gmail.com>
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.
What this PR does
Before this PR:
AgentBootstrapServiceran inPhase.WhenReadywith a sequential initialization chain (~4.4s), blocking other WhenReady services and delaying UI startup.After this PR:
Phase.Background(fire-and-forget, never blocks other phases)@DependsOn(['ApiServerService'])— none of the bootstrap operations use ApiServerServicebootstrapBuiltinAgents,restoreSchedulers, andchannelManager.startviaPromise.allChannelManager.start()(was sequentialfor...await)Why we need it and why it was done in this way
The following tradeoffs were made:
Phase.Backgroundis the correct lifecycle phase per the Phase Selection Guide.The following alternatives were considered:
Phase.WhenReadywith manual fire-and-forget (this.initDone = Promise.all(...)withoutawait) — rejected because it reimplements whatPhase.Backgroundalready provides natively.initCherryClawandinitCherryAssistantinsidebootstrapBuiltinAgents— not done due to documented SQLITE_BUSY risk from concurrent writes.Breaking changes
None. All changes are internal to the main process startup sequence.
Special notes for your reviewer
registerSessionStreamIpc()is synchronous (just registersipcMain.handlecalls) — noawaitneeded.ipcMainregistration works inPhase.Backgroundsince it doesn't require Electron's app to be ready.connectChannelFromRow, soPromise.allwon't short-circuit on a single adapter failure.Checklist
/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note