feat(model+mem): retry with backoff for transient errors + fix in-memory map leaks#80
Closed
dyyz1993 wants to merge 3 commits into
Closed
feat(model+mem): retry with backoff for transient errors + fix in-memory map leaks#80dyyz1993 wants to merge 3 commits into
dyyz1993 wants to merge 3 commits into
Conversation
added 3 commits
June 8, 2026 12:21
The DeepSeek-compatible model client previously failed the entire turn on the first transient error (rate limit, server hiccup, network blip). This adds exponential backoff with jitter, honors the Retry-After header, and aborts cleanly if the turn is cancelled mid-backoff. Retries only happen before any streaming chunk is yielded, so consumers never see partial-then-retried output. Adds 5 tests covering: 429 retry success, Retry-After header, non-retryable errors, network error retry, and abort during backoff.
…ak, clean telemetry on thread delete
…thod Move resolvers.delete() into cleanupEntry so all state (approvals, timers, resolvers) is cleaned in one place. Adjust decide and expire to grab the resolver reference before calling cleanupEntry.
Collaborator
|
这条 PR 当前目标分支是 |
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
Two independent improvements bundled in one PR (separate commits for easy cherry-picking).
Commit 1:
feat(model): add retry with backoff for 429/5xx and network errorsThe DeepSeek-compatible model client previously failed the entire turn on the first transient error (rate limit, server hiccup, network blip).
Changes (
src/adapters/model/deepseek-compat-model-client.ts):Retry-Afterheader (both seconds and HTTP-date formats)DeepseekCompatConfig.retry(maxAttempts,baseDelayMs,maxDelayMs)New config option:
Commit 2:
fix(mem): bound in-memory maps with TtlLruCache, fix approval gate leak, clean telemetry on thread deleteFour memory-safety fixes for long-running
kun serveinstances:toolCatalogSnapshots(agent-loop.ts):Map→TtlLruCache(limit=64, ttl=30min). The old Map was written to on every modelStep but never had entries deleted.promptTokenPressure(agent-loop.ts):Map→TtlLruCache(limit=128, ttl=10min). The only delete point was incompactIfNeeded; failed/aborted turns would leak entries.InMemoryApprovalGate(in-memory-approval-gate.ts):decide()now deletes the entry instead of overwriting with a resolved value (was leaking resolved approvals forever)drainAllPending()method for startup/shutdown cleanupThread deletion (
routes/index.ts):DELETE /v1/threads/:idnow callsusageService.reset()to clean up per-thread telemetry (usage counter + cache telemetry).Both TtlLruCache replacements are API-compatible with Map (verified all 6 call sites). TTL expiry degrades gracefully — a miss simply means "rebuild the snapshot" or "skip compaction this round", never data corruption.
Testing
model-client.test.ts): 429 retry success, Retry-After header honored, non-retryable errors (400), network error retry, abort during backoffports.test.ts): post-decide entry cleanup, TTL auto-expiry rejects promise,drainAllPendingclears alltsc --noEmit)TtlLruCachefromsrc/cache/Files changed