When to Use
Use when changing or relocating Jean2 provider retries, retry status events, failed-attempt transcript handling, circuit breaking, sandbox retry simulation, or the model-run boundary into packages/capek.
Procedure
- Read
.architecture-specs/00-principles.md, the active phase in.architecture-specs/07-migration-phases.md, and the current retry implementation before editing. - During relocation, move the working retry path without changing policy. Keep one production implementation and use server compatibility re-exports where needed.
- Preserve one outer operation with a shared abort signal,
runningAt, backoff, and cleanup. Keep exponential jitter, providerRetry-Afteras a minimum, and the existing retry count unless a separate behavior phase changes them. After interruption cleanup completes, drain queued turns FIFO, including their attachments; an empty queue must finish normally. - Classify errors before retrying. Quota or billing exhaustion is non-retryable. Retryable failed attempts use
mode: 'retry_failed'and stay out of future model context. - Stop automatic retry after any tool activity, including tool-part creation or update, to avoid replaying side effects.
- Keep retry state session-scoped in the client. Drive UI from
chat.retrystatuses (scheduled,started,exhausted,cancelled), not connection retry counters or polling. - Simulate recovery through the sandbox with one failed stream response followed by success. Keep event delivery failures separate from provider failure classification.
- Update
.architecture-specs/01-current-runtime.mdand the active phase ledger before claiming relocation complete.
Pitfalls
- Do not use the old
capekbranch's parallelrunAgentTurnmigration as thecapekv2baseline. - Do not combine file relocation with retry-policy redesign or wire-event changes.
- Do not retry after tool activity.
- Do not treat backoff as an operation timeout. It must remain cancellable through the session interrupt path.
- Do not show intermediate failed attempts as final completion or notification events.
- Do not let event-sink failures become provider failures, and do not hide synchronous ask-delivery failures behind an unobserved async callback.
Verification
- Run focused retry, stream, tool-activity, cancellation, sandbox, and package/server compatibility tests for the changed batch.
- Confirm the
chat.retrysequence and final success or exhaustion event remain compatible. - Confirm failed assistant attempts use
retry_failedand are excluded from the next model request. - Confirm abort interrupts active streaming and backoff delay.
- Run affected package typechecks and lint. Do not run the full repository suite by default.
- Confirm any required server smoke check is user-run before completing the phase.


