Skip to content

refactor(agent): typed codes for Agent.continue precondition failures - #1588

Merged
sethkarten merged 5 commits into
mainfrom
fix/typed-continue-preconditions
Aug 21, 2026
Merged

refactor(agent): typed codes for Agent.continue precondition failures#1588
sethkarten merged 5 commits into
mainfrom
fix/typed-continue-preconditions

Conversation

@snimu

@snimu snimu commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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() throws AgentContinueError with a stable code at its three precondition sites: busy (a run is active — retryable) and nothing-to-continue (no messages, or trailing assistant message — the turn already completed).
  • The post-compaction classifier in agent-session switches on the code: 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.
  • No fallback text-matching kept: the packages move together in this workspace, and a fallback would keep the brittleness alive silently.

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 plain Error("already processing") to reach the reschedule path is retargeted to throw AgentContinueError("busy", ...) — which also proves plain errors no longer take that path.

Validation

  • check/build green
  • packages/agent suite 70/70; compaction, compaction-continuation, print-mode, acp-mode suites 91/91

+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 exported AgentContinueError with busy (active run, retryable) or nothing-to-continue (empty history or trailing assistant turn). Post-compaction continuation in coding-agent branches on those codes: reschedule on busy, ignore nothing-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 AgentContinueError in Agent.continue

  • Adds exported AgentContinueError class and AgentContinueErrorCode union ("busy" | "nothing-to-continue") in agent.ts; Agent.continue now throws these instead of generic Error.
  • Updates agent-session.ts post-compaction handler to branch on error.code — reschedules on "busy", swallows on "nothing-to-continue", and settles any other error.
  • Updates unit, e2e, and compaction tests to assert the new error shape.
  • Risk: callers that string-match on the old generic Error.message for Agent.continue precondition failures will no longer match; they must check error instanceof AgentContinueError and error.code instead.

Changes since #1588 opened

  • Introduced typed error codes for Agent.continue precondition 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
  • line 1: This fragment is consumed by scripts/release.mjs into packages/ai's published CHANGELOG.md, but this PR contains no model-catalog/pricing/context-window change in packages/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 ]

snimu added 4 commits August 20, 2026 16:04
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
sethkarten self-requested a review August 20, 2026 19:01
@sethkarten
sethkarten merged commit 35103cb into main Aug 21, 2026
22 checks passed
@sethkarten
sethkarten deleted the fix/typed-continue-preconditions branch August 21, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants