refactor(opencode): optimize doom loop detection, summary debounce, parallel plugin events#20303
refactor(opencode): optimize doom loop detection, summary debounce, parallel plugin events#20303AndresCdo wants to merge 3 commits intoanomalyco:devfrom
Conversation
…lel plugin events
Three targeted performance optimizations:
1. In-memory doom loop detection: Replace MessageV2.parts() DB call
with toolCallHistory array in ProcessorContext. Eliminates one
database query per tool call.
2. Summary debounce: Run SessionSummary.summarize() only on the first
step. Subsequent steps produce redundant summaries that overwrite
the first one with no additional value.
3. Parallel plugin event handlers: Replace sequential for loop with
Effect.forEach({ concurrency: "unbounded" }) so slow handlers
don't block the main event stream. Each handler runs in a forked
fiber with error isolation.
Closes anomalyco#20302
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #20288 - Why they're related:
Recommendation: Check PR #20288 to verify if it's addressing the same issue #20302 or if the changes overlap before merging. |
|
Re: duplicate flag from bot PR #20288 and this PR (#20303) are not duplicates — they target different code structures:
File overlap analysis:
The changes are complementary and non-conflicting. If both are merged, PR #20288 would need to be rebased onto current dev to apply the message/tool cache to the Effect-based code. |
Issue for this PR
Closes #20302
Type of change
What does this PR do?
Three targeted performance optimizations in the session processing loop:
1. In-memory doom loop detection (
session/processor.ts)Replaces
MessageV2.parts(ctx.assistantMessage.id)database call with an in-memorytoolCallHistoryarray tracked inProcessorContext. The doom loop check already has all the data it needs from the streaming event handler — no need to re-query the database on every tool call.2. Summary debounce (
session/processor.ts)Runs
SessionSummary.summarize()only on the first step of a session. Subsequent steps produce summaries that overwrite the first one with no additional value, wasting CPU and I/O on redundant summary computation.3. Parallel plugin event handlers (
plugin/index.ts)Replaces sequential
forloop withEffect.forEach({ concurrency: "unbounded" })so slow plugin event handlers don't block the main event stream. Each handler runs in a forked fiber with error isolation viaEffect.tryPromise.How did you verify your code works?
bun typecheckpasses (zero errors in changed files)Screenshots / recordings
Not a UI change.
Checklist