Repository navigation
[Fix] Ollama tasks condense before their configured context limit - #2520
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
1 issue outstanding. See session
Reviewed a8bd7a0 |
Review statusThis PR was opened by an automated account. A human maintainer must verify the change intent, provenance, and validation before merging. Current step: Required CI passed. Waiting for automated review of the latest commit. If automated review does not start, a maintainer must restart it. Review-state labels are managed by this workflow; do not edit them manually. |
|
|
||
| if (!this.modelFetchPromise) { | ||
| const fetchOpts: [] | [{ signal: AbortSignal }] = signal ? [{ signal }] : [] | ||
| this.modelFetchPromise = getOllamaModels( |
There was a problem hiding this comment.
The shared promise is created with whichever request signal arrives first. If that caller is cancelled or its timeoutMs expires, getOllamaModels aborts and rejects this promise for every concurrent createMessage/completePrompt caller, including callers whose own signals remain active. Keep cancellation scoped to each waiter rather than letting one request cancel shared discovery, and add a cold-cache regression test where one concurrent caller aborts while the other still succeeds.
There was a problem hiding this comment.
Fixed in 0b75a51. fetchModel() now uses BaseProvider.ensureCatalogLoaded() for shared discovery. The fetch owns its timeout signal. Each caller's signal cancels only that caller's wait. Empty and failed loads remain retryable.
Added cold-cache property tests across fetchModel, ensureModelFetched, createMessage, and completePrompt, with both caller orders and cancellation before or after discovery settles. Added a concurrent prompt-timeout test where the streaming caller still succeeds. The original code failed 16 of the 64 cancellation schedules; the fix passes all 64.
The TLA+ model passes with independent cancellation and rejects the request-owned signal variant. Focused provider and Task suites pass (400 tests). Type checking and ESLint pass, with no increase in suppression counts.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Add a Task integration test asserting the fetched model context window reaches manageContext instead of the 128k fallback.
0b75a51 to
09411da
Compare
One conflict: src/api/providers/native-ollama.ts, where this branch's abort-hook refactor and Zoo-Code-Org#2520's shared-catalog rewrite touch the same lines. The merge base is 75a93a9. The merged tip is 2a082ce ("fix(vertex): prevent Gemini requests from ending with a model turn (Zoo-Code-Org#2641)"), not the 410e5ad the branch was one behind. Resolved for behaviour, not for text. Both sides must survive: - Zoo-Code-Org#2520's side: model discovery is a shared, bounded catalog load, so the caller's signal cancels only its own wait while the shared fetch keeps its own timeout. That means main's fetchModel (ensureCatalogLoaded(loader, signal) with AbortSignal.timeout(MODEL_CATALOG_FETCH_TIMEOUT_MS) on the loader and 'return Object.keys(this.models).length > 0'), main's ensureModelFetched body ('await this.fetchModel(signal)') and both of main's comments about cancelling the wait came over whole - including the comment above discoverySignal, which this branch's wording would have contradicted: after Zoo-Code-Org#2520 the per-request signal no longer reaches the discovery network fetch. - This branch's side: both bridges come from bridgeExternalAbortSignal, createMessage registers it with { onAbort } only because it needs bridge.controller.signal, and completePrompt registers it with { controller, onAbort } after the client exists so an already-aborted caller cancels through the hook. The method-local controller keeps that name here because the shared hook owns bridge.controller in createMessage; main's requestController is gone with the plumbing it named, as are the onExternalAbort / removeEventListener blocks it replaced. Nothing from either side was dropped: against main the merged file reads +36/-45 and against the branch +15/-25, which is exactly each side's own delta to the merge base, and no line either side added is missing.
Related GitHub Issue
Closes: #1151
Description
Supersedes #1174. This is the same fix, rebased onto current
main. The original PR cannot merge because its author is a deleted ghost account.Native Ollama now fetches model metadata before task context management reads the model limits. The fetch is single-flight, avoids repeat requests once metadata is populated, and can recover after a failed request.
Conflict resolution notes for the rebase:
mainhas changed since the original PR. PR feat(api): add ensureModelFetched to the six catalog providers #2191 addedNativeOllamaHandler.ensureModelFetched()andBaseProvider.ensureCatalogLoaded().Task.safeEnsureModelFetched()now runs before context management. The ordering part of the original fix is already onmain.NativeOllamaHandler.fetchModel()no longer refetches/api/tagsand/api/showon everycreateMessageandcompletePromptcall. It skips the fetch once the catalog is populated, shares one in-flight fetch between concurrent callers, and clears the in-flight promise after a failure so the next call retries. The optional abort signal still reaches the discovery fetch.fetchModelWithSingleFlighthelper intoBaseProviderand rewroteRouterProvider.fetchModel()to use it. That refactor was dropped.RouterProvider.fetchModel()onmainnow has negative caching and refresh logic that the simpler helper cannot express.Focused regression coverage verifies that a detected 1M context window replaces the 128k fallback before a model request, while preserving duplicate suppression and retry behavior.
Test Procedure
pnpm --dir src exec vitest run api/providers/__tests__/native-ollama.spec.ts— 102 tests pass. New tests cover: the detected 1M context window replacing the 128k fallback, skipping repeat fetches once models are populated, deduplication of concurrent fetches, and retry after a rejected request.pnpm --dir src exec vitest run core/task/__tests__/Task.spec.ts— 231 tests pass. The new integration test asserts that the fetched context window reachesmanageContextinstead of the 128k fallback.pnpm --dir src run check-typespasses.pnpm testpasses (13,899 tests).Pre-Submission Checklist
src/test-utils/,@/utils/test-utils) are used only for mechanical duplication; test intent and scenario-specific mocks remain visible.Documentation Updates
Zoo-Code-Docs: Zoo-Code-Org/Zoo-Code-Docs#23
Additional Notes
No visual proof is attached. The change is provider-side fetch behavior with no browser-renderable surface. The test results above are the primary evidence.