Repository navigation
fix(computer): classify local model KV pool and context overflow failures - #669
oldwinter53 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Request changes (1 P1, 1 P2, 1 P3)
Scope: base main, merge base 94ada676. Reviewed 1 commit (400981e0) touching 21 files. I followed the rules from the coderbook (sections 2, 3 and 5), ponytail-review (sections 1–3) and karpathy-guidelines (sections 2–3) skills from memory; I did not load them in this session. The review ran in a separate session.
Findings
P1
apps/computer/local-daemon/internal/provider/execution_failure.go:44 — the provider error-code classification now exists in two copies, and they already disagree
diagnosticFailureCodenow contains the full llama.cpp/OpenAI/Anthropic code lists: context overflow, auth, rate limit, server/unavailable, and POSIX errnos.- The same lists also live in
isContextTooLongErrorCode,isAuthErrorCodeandisUnavailableErrorCode(internal/provider/model_invoke.go:922-944). This PR extends both copies in parallel. classifyPiModelInvokeFailure(internal/provider/pi_model_invoke.go:75-88) adds a third copy of the status rules: 401/403 → auth, 413 → context, 429/≥500 → unavailable.diagnosticFailureCodealready encodes those rules.- The copies already diverge.
rate_limit_exceeded,rate_limit_errorandrate_limitbecomerate_limitedin one place and "unavailable" in the other.model_not_foundis a branch in one and a list entry in the other. - The POSIX errno regex is also duplicated:
posixNetworkErrnoPatternexists inmodel_invoke.go:916and again innative/diagnostics.go:139.parseStructuredAPIError(model_invoke.go:918) is a one-line passthrough tonative.ParseStructuredAPIError. - Failure scenario: the next code anyone adds (say a new llama.cpp
type) goes into one list. Interactive Runs and backgroundmodel_invokethen report different outcomes for the same gateway response, and the Agent Service either backs off or retries depending on the path. - Fix:
- Have
classifyPiModelInvokeFailurebuildnative.APIErrorDiagnostics(answer.Error)and send it throughClassifyExecutionFailure. It can then reuse the sameswitch classified.CodethatclassifyModelInvokeFailureWithDiagnostics(model_invoke.go:972-984) already uses, mappingrate_limitedtoModelInvokeRuntimeUnavailablethere. - Then delete the code lists that become redundant, use the native errno pattern in one place, and drop the passthrough wrapper.
- Have
P2
apps/computer/local-daemon/internal/provider/pi_local_error_test.go:72 — KV-pool exhaustion during decode is still unclassified, and the test name says otherwise
- The PR body lists "
server_error(503/500 shared KV pool full)" among the codes it now classifies. - But the mid-stream SSE case (
{"error":{"code":500,"type":"server_error","message":"shared KV pool full during decode"}}) assertswantFailureCode: "execution_failed", an emptywantDiagnosticCode, andModelInvokeFailed. - The case is named "mid-stream SSE error preserves server diagnostics", yet it asserts that no diagnostics are kept.
- During long sessions with concurrent slots, this is a likely way for the shared KV pool to run out. Such failures still reach users as generic
execution_failedand send no overload signal toModelQueue. Background calls are classifiedfailedand retried. - Fix either way:
- classify the mid-stream error (find out what Pi puts in
errorMessagefor it), or - rename the case and state in the PR description that mid-stream errors stay out of scope.
- classify the mid-stream error (find out what Pi puts in
P3
apps/web/src/features/rooms/runtime-status/runtime-status.messages.ts:149 — runtime-agnostic copy now carries local-model-only advice
failureContextTooLongandfailureModelServiceErrorare shown for every runtime. A cloud Codex or Claudecontext_too_longwould now also say the problem may be "available memory" and suggest "reduce concurrent runs". Neither applies to a hosted model.- Fix: put the memory/concurrency wording behind a local-model condition, or keep it generic.
Verified as fine
- Pi 1.2.0 event shape: in the pinned
@earendil-works/pi-coding-agent@1.2.0,dist/core/agent-session.js:2420-2425and:2596-2602emitcompaction_endwithreason,result: undefined,aborted,willRetry: falseanderrorMessagewhen overflow recovery fails.auto_retry_start(:3073-3078) carriesattempt,maxAttemptsanderrorMessage. These match the newpiEventFramefields and theoverflowFailedbranch innative/pi_events.go:113-129. overflowFailedlocking: it is written undert.muinpi_events.go, reset atapplyMessageEnd(pi_events.go:181), and read undert.muinpi_finish.go:204-206. The new and touched native tests passed with-race -count=2.pi_finish.go:203-214: exit code and signal are still added only when the Daemon did not cause the failure. The structured API diagnostics are added next to them instead of being overwritten byprocessExitDiagnostics.codexFailureDiagnostics(native/codex_events.go:308-322): it falls back to message parsing only for an empty code,other, orhttpConnectionFailedwith status 400. A Codex 400 with no embedded code keepshttpConnectionFailed+ 400, so it still classifies as before.ParseStructuredAPIError(native/diagnostics.go:146):- Numeric
codevalues are read as an HTTP status only within 400–599. String codes still pass through. - Codes that reach
Sanitized()are limited bydiagnosticCodePattern, so free-form text cannot get into diagnostics.
- Numeric
- Breaker impact of 503/429 →
runtime_unavailablefor background calls: these now count toward the breaker (isAvailabilityRuntimeFailure,apps/node-services/src/runtime-model-call.ts:449; threshold 2, 30 s doubling up to 30 min). This matches the PR's stated "fail fast" intent. - Language checks: the commit message contains no CJK, and outside
zh-CN.jsonno added line contains CJK.
Unverified: whether TestPiLocalGatewayCapacityAndContextErrors actually ran in CI rather than skipping. CI installs with --ignore-scripts and does not run Go tests with -v, so the log cannot tell. Pi is not installed in my worktree, so I did not run it.
Process notes
- One conventional commit; no merge commits and no fixup commits.
- Merge state is
BLOCKED, waiting on required review.
CI
- All checks that ran passed: computer-go, computer-go-windows, web, web tests, web-static, desktop, repository-gate and CodeQL. No
check (node-services)job appears in the PR's checks, so the newrunner-operations-public.test.tscase was not exercised by CI. - I ran
go test -race -count=2onTestPiStructuredFailureDiagnosticsAndCompactionEvents,TestAPIErrorDiagnosticsParsingandTestCodexFailedTurnExtractsStructuredAPIErrorOnHTTP400in./internal/provider/native. They passed.
Automated review by Claude Code
Automated review of 400981e by Claude Code.
…ures Extract structured HTTP status and JSON API error codes from Pi and Codex local-model failures (including llama.cpp numeric error codes and unwrapped OpenAI SDK bodies), deduplicate interactive and background failure classification through ClassifyExecutionFailure, track Pi overflow compaction failures, and preserve structured diagnostics in logs and wire frames.
400981e to
efcf3b9
Compare
|
Rebased onto latest
|
There was a problem hiding this comment.
Approve (0 findings)
Follow-up on 400981e. The PR was force-pushed and rebased, so I compared the two versions with git range-diff and then re-reviewed the full merge-base diff (6a511c15, 1 commit, 19 files).
Previous findings
- Resolved: duplicated failure-code rules.
classifyModelInvokeFailureWithDiagnosticsandclassifyPiModelInvokeFailurenow both go throughClassifyExecutionFailure→modelInvokeResultForFailureCode(internal/provider/model_invoke.go:930,internal/provider/pi_model_invoke.go:71). The single code list is indiagnosticFailureCode(internal/provider/execution_failure.go:53). - Resolved: mid-stream SSE KV-pool-full errors. The PR body and the test comment now say these are out of scope, and the test case is renamed to match (
internal/provider/pi_local_error_test.go). - Resolved: local-only advice in the generic Web copy. The Web change is no longer part of the PR.
Verified as fine
rate_limitednow maps toruntime_unavailable(model_invoke.go:938). In Node,runtime_unavailableis not retried and counts toward the background breaker (apps/node-services/src/runtime-model-call.ts:456,471,882). Repeated 429s or full-KV-pool failures therefore back off instead of being retried. The PR body declares this change.- Pi failed turns now keep the structured
CodeandStatusCode, keepExitCodeandSignalonly on a real process exit, and setcontext_too_longonly after a failed overflow compaction.overflowFailedis guarded byt.muand cleared on eachmessage_end(native/pi_finish.go:206-218,native/pi_events.go:119-135,234). - The Codex 400
httpConnectionFailedwrapper is enriched only when Codex's own info is generic (native/codex_events.go:308).
CI: desktop, computer-go-windows, web, repository-gate and CodeQL passed; check (computer-go) was still pending. I ran go test -race -count=1 with focused -run filters on ./internal/provider and ./internal/daemon, and both passed. The pinned-Pi gateway test skipped because Pi is not installed locally. The focused ./internal/provider/native run with -race produced no output within its 300 s limit, so I have no result for that package.
Automated review by Claude Code
Automated review of efcf3b9 by Claude Code.
Summary
Hardens product error classification and diagnostics preservation when a local model (
llama-serverbehind Bifrost) exhausts its shared KV pool or context window during a long Agent session or concurrent multi-slot load.Root Cause
piTurnonly stored raw error text and overwroteOutcome.DiagnosticswithprocessExitDiagnostics(exitCode: 0), never extracting structured HTTP status codes or JSON errorcode/typefields. As a result,ClassifyExecutionFailurereported genericexecution_failedforllama.cppexceed_context_size_error(400),request_too_large(413),unavailable_error/server_error(503/500 non-SSE shared KV pool full), andrate_limit_exceeded(429). This also preventedRunnerOperationsfrom emitting anoverloadsignal toModelQueueto back off concurrency.compaction_endevents were ignored: Pi emitscompaction_endrather thanauto_compaction_end, so overflow compaction failures were not mapped tocontext_too_longand successful compactions were not counted.llama.cppnumeric codes and unwrapped OpenAI SDK bodies: API error parsing expected string-only JSONcodefields and requiredbody.Code != ""on top-level objects, failing on realllama-serverresponses formatted by@earendil-works/pi-ai(400: {"code":400,"type":"exceed_context_size_error",...},503: {"code":503,"type":"unavailable_error",...}). Backgroundmodel_invokecalls fell back to genericfailed, whichruntime-model-call.tstreated as retryable instead of failing fast.codexErrorDiagnosticskepthttpConnectionFailed(400) without inspecting embedded structured API error codes such asexceed_context_size_error.What Changed
apps/computer/local-daemon/internal/provider/native/diagnostics.go): AddedParseStructuredAPIErrorandAPIErrorDiagnosticsparsing only structured signals (HTTP status prefixes, JSON errorcode/typefields accepting numeric 4xx/5xx status codes and top-level unwrapped bodies, and POSIX network errnos).pi_events.go,pi_run.go,pi_finish.go,codex_events.go): Handle bothcompaction_endandauto_compaction_end, mark failed overflow recovery ascontext_too_long, logauto_retry_start/auto_retry_end/failedcompaction_end, preserve structuredDiagnostics(Code,StatusCode) alongsideExitCode/Signal, and enrich Codex HTTP 400httpConnectionFailedwith embedded structured API error codes.execution_failure.go,model_invoke.go,pi_model_invoke.go,executor.go,daemon/operations.go): Map structured context-overflow, capacity/server, rate-limit, auth, model-not-found, and POSIX network codes (plus HTTP 413) inClassifyExecutionFailure; route bothclassifyModelInvokeFailureWithDiagnosticsandclassifyPiModelInvokeFailurethroughClassifyExecutionFailureand a shared failure-code switch (rate_limited->ModelInvokeRuntimeUnavailable); log classifiedfailure_code,diagnostic_code, andhttp_statusin Daemon and local diagnostic logs.pi_local_error_test.go, covering HTTP 400exceed_context_size_error, HTTP 503unavailable_error, HTTP 500server_error, and bounded settlement for mid-stream HTTP 200 SSE errors), deterministic Pi/Codex/Daemon/failure-classification unit tests, and a Node ServicesRunnerOperationsoverload-backoff + diagnostics preservation test.Scope Note on Mid-Stream HTTP 200 SSE Errors
data: {"error":{"code":500,"type":"server_error","message":"..."}}) remain out of scope for structured classification in this PR and continue to settle boundedly asexecution_failed/ModelInvokeFailed.@earendil-works/pi-coding-agent@1.5.2/@earendil-works/pi-aiandopenai@6.49.0:openai/core/streaming.mjsthrowsnew APIError(undefined, data.error, undefined, response.headers)(leavingstatus === undefined), and@earendil-works/pi-ai/dist/utils/error-body.js(formatProviderError) dropsnorm.bodywhenevernorm.status === undefined, forwarding only raw error prose inerrorMessage. Because Linger never classifies failures by matching natural-language prose, structured classification of mid-stream SSE errors requires upstreampi-aito preservenorm.bodywhenstatusis absent.Verification
go test -v -race -count=2on all touched/new tests in./internal/provider,./internal/provider/native, and./internal/daemon(including real pinned Pi 1.5.2 local gateway tests)make -C apps/teamhub lint-go-daemon BASE=origin/main(0 issues)GOOS=windows GOARCH=amd64 go build ./...(apps/computer/local-daemon)pnpm --filter @linger/node-services typecheck && pnpm --filter @linger/node-services lintpnpm --filter @linger/node-services exec vitest run tests/agent/runner-gateway/runner-operations-public.test.ts(63/63 passed)pnpm --filter @linger/web test src/features/rooms/runtime-status/runtime-failure-message.test.ts(22/22 passed)make check-repository && make check-repository-gate BASE=origin/main