refactor: consolidate Provider's four generate paths (plan 017)#88
Open
DavertMik wants to merge 1 commit into
Open
refactor: consolidate Provider's four generate paths (plan 017)#88DavertMik wants to merge 1 commit into
DavertMik wants to merge 1 commit into
Conversation
Extract four shared helpers from chat/generateWithTools/generateObject/ processImage: recordUsage, recoverFromContextLength, buildGenerateConfig, raceWithIdleTimeout. Plan 005's per-attempt AbortController + combined idle-abort signal is folded into raceWithIdleTimeout, preserving one controller per retry attempt. Behavior-preserving: config spread order kept per site (defaults before config.config so user config can override maxOutputTokens; overrides after options). chat() still has no idle race; processImage() still skips context-length recovery and its minimal config path. processImage now records the cached token field like the other three paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Explorbot Self-RegressionCommit
Attempt details
Session analysis — basic (native): Session AnalysisThe Issues list feature was explored. Core flows for creating, viewing, searching, and filtering issues all function correctly. ET-2 had a verification retry that succeeded, and ET-5 required alternative selectors but achieved the goal. Coverage
What works
|
DenysKuchma
approved these changes
Jul 13, 2026
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.
Plan 017 — Consolidate the four duplicated generate paths in Provider
src/ai/provider.tshad four near-identical generate paths (chat,generateWithTools,generateObject,processImage) each re-implementing config assembly, usage recording, the idle-timeout race, and context-length recovery. This extracts four private helpers:recordUsage(agentName, modelName, usage)— singleStats.recordTokenscall site (was 4). Also adds thecachedtoken field toprocessImage(was the only path missing it).recoverFromContextLength(error, messages, options, retry)— single context-length reduce+retry, retry callback stays method-specific.buildGenerateConfig(defaults, overrides, options)— sharedmergeProviderOptions+finalizeConfigassembly.raceWithIdleTimeout(fn, timeoutMs)— singlePromise.raceagainst the idle abort.Drift reconciliation
This plan was written at
9e22b0d; since then plan 005 (abort in-flight request on idle timeout, PR #73) and plan 007 (PR #75) reshaped these methods. Per the plan's Step 4 guidance, plan 005's per-attemptAbortController+combinedAbortSignalis folded insideraceWithIdleTimeout— one controller per retry attempt (the helper is called inside thewithRetrycallback), signature(signal) => generateX({ ...config, abortSignal: signal }).Behavior-preserving
defaultsland before...(this.config.config)(so user config can still override themaxOutputTokens: 16384default),overrides(model/abortSignal/stopWhen) land after...options.generateWithToolsno longer stripsstopWhenfrom options —stopWhen: stopConditionsinoverridesalready wins over...options, andstopConditionsstill folds inoptions.stopWhenviaextraStop. Identical result.Deliberately NOT changed (behavior changes wanting their own review)
chat()still has no idle-timeout race.processImage()still skips context-length recovery and keeps its minimal config path (routing it throughbuildGenerateConfigwould change agent-level provider-option behavior).Verification
bun test tests/unit→ 765 pass / 0 fail (+1 new context-length-recovery-through-helper test).bun test tests/integration/→ 63 pass / 0 fail.bun run lint→ clean.tscerrors: 639 → 636 total (provider.ts 10 → 6) — refactor removed 4promptTokens/completionTokensTS2339s; no new errors.Stats.recordTokens×1,tryReduceMessages×2,abortAfterIdle×2,Promise.race×1.🤖 Generated with Claude Code