refactor(agent): typed codes for Agent.continue precondition failures - #1588
Merged
Conversation
Classifying continuation-start failures by error message text
(includes("already processing"), includes("continue from")) breaks
silently when wording changes. Agent.continue() now throws
AgentContinueError with a stable code — busy or nothing-to-continue —
and the post-compaction classifier switches on the code. Unknown errors
still reject headless idle waiters.
The queue characterization suite also reaches the reschedule path with a plain Error; it now throws the typed busy error like the compaction suite.
sethkarten
self-requested a review
August 20, 2026 19:01
sethkarten
approved these changes
Aug 21, 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.
Follow-up to #1583, which classified
Agent.continue()precondition failures by error message text (includes("already processing"),includes("continue from")) — flagged in review as brittle: a rewording in packages/agent silently breaks the classification, and the failure mode is the bad one (a benign nothing-to-continue race would start rejecting headless idle waiters).Linear: ENG-5407 — https://linear.app/primeintellect/issue/ENG-5407/typed-error-codes-for-agentcontinue-precondition-failures
Change
Agent.continue()throwsAgentContinueErrorwith a stable code at its three precondition sites:busy(a run is active — retryable) andnothing-to-continue(no messages, or trailing assistant message — the turn already completed).busy→ reschedule,nothing-to-continue→ settle clean, anything else → reject headless idle waiters. Messages are unchanged; only the classification contract moved from wording to a type the owning layer exports.prompt()'s "already processing" error is intentionally untouched — nothing classifies it.Tests
No new tests: the three existing precondition assertions in packages/agent now pin the code alongside the message (
rejects.toMatchObject), and the one coding-agent test that mocked a plainError("already processing")to reach the reschedule path is retargeted to throwAgentContinueError("busy", ...)— which also proves plain errors no longer take that path.Validation
+47/−21 across 8 files.
Note
Low Risk
Small error-type change with tests updated; classification is more robust, not a behavior change for the intended paths. External callers that still string-match continue() messages would need to switch to the new class/code.
Overview
Callers can classify
Agent.continue()precondition failures by stable codes instead of matching error message text.continue()now throws exportedAgentContinueErrorwithbusy(active run, retryable) ornothing-to-continue(empty history or trailing assistant turn). Post-compaction continuation in coding-agent branches on those codes: reschedule onbusy, ignorenothing-to-continue, reject other errors.prompt()still throws a generic Error.Reviewed by Cursor Bugbot for commit 91856c1. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Replace generic errors with typed
AgentContinueErrorinAgent.continueAgentContinueErrorclass andAgentContinueErrorCodeunion ("busy"|"nothing-to-continue") in agent.ts;Agent.continuenow throws these instead of genericError.error.code— reschedules on"busy", swallows on"nothing-to-continue", and settles any other error.Error.messageforAgent.continueprecondition failures will no longer match; they must checkerror instanceof AgentContinueErroranderror.codeinstead.Changes since #1588 opened
Agent.continueprecondition failures [91856c1]📊 Macroscope summarized 8c542c0. 1 file reviewed, 1 issue evaluated, 1 issue filtered, 0 comments posted
🗂️ Filtered Issues
packages/ai/.changes/fix-typed-continue-preconditions.md — 0 comments posted, 1 evaluated, 1 filtered
scripts/release.mjsintopackages/ai's publishedCHANGELOG.md, but this PR contains no model-catalog/pricing/context-window change inpackages/ai; it will therefore publish a false AI release note (and leaves the actual typed-continue change undocumented for that package). Remove this unrelated fragment or replace it with an accurate AI-package change. [ Failed validation ]