refactor(session): route safe recovery through retry policy#931
Conversation
📝 WalkthroughWalkthroughThis PR refactors the session processor's safe-recovery auto-replay retry mechanism from fixed backoff constants to effect-based scheduling. A new ChangesSafe Recovery Policy and Scheduling Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the safe recovery retry logic in the session processor to use a structured safeRecoveryPolicy schedule defined in retry.ts, replacing the previous inline status updates and backoff delays. It also adds corresponding unit tests. However, a critical runtime issue was identified in retry.ts where Cause.done is called; this method does not exist in the imported Cause namespace from the effect library, which will lead to a TypeError when the maximum retry attempts are exceeded.
125197a to
4b68c3b
Compare
4b68c3b to
d625a16
Compare
|
Temporarily closing and reopening to retrigger missing required GitHub Actions checks; no code change. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opencode/test/session/retry.test.ts (1)
131-207: ⚡ Quick winUse
testEffect(...)/it.effect(...)for these new Effect-based tests.These new cases run Effect workflows directly via
Effect.runPromise(...); please migrate them to the repo’s Effect test harness pattern (const it = testEffect(...)+it.effect(...)) to stay consistent with test runtime semantics.As per coding guidelines: “Use
testEffect(...)fromtest/lib/effect.tsfor tests that exercise Effect services or Effect-based workflows. Useit.effect(...)when the test should run withTestClockandTestConsole.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/opencode/test/session/retry.test.ts` around lines 131 - 207, Replace the plain Jest tests that call Effect.runPromise with the repository's Effect test harness: wrap the file with the testEffect helper (e.g., const it = testEffect(...)) and convert the two tests to it.effect(...) so they run under the Effect runtime/TestClock semantics; update the two test blocks ("safe recovery policy emits..." and "safe recovery policy stops...") to call SessionRetry.safeRecoveryPolicy and other Effect-based code inside the it.effect callback instead of calling Effect.runPromise directly, preserving the same assertions and references to SessionID, SessionStatus.Service.use, Schedule.toStepWithMetadata, and Exit/Pull checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/opencode/test/session/retry.test.ts`:
- Around line 131-207: Replace the plain Jest tests that call Effect.runPromise
with the repository's Effect test harness: wrap the file with the testEffect
helper (e.g., const it = testEffect(...)) and convert the two tests to
it.effect(...) so they run under the Effect runtime/TestClock semantics; update
the two test blocks ("safe recovery policy emits..." and "safe recovery policy
stops...") to call SessionRetry.safeRecoveryPolicy and other Effect-based code
inside the it.effect callback instead of calling Effect.runPromise directly,
preserving the same assertions and references to SessionID,
SessionStatus.Service.use, Schedule.toStepWithMetadata, and Exit/Pull checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: fbd15e1f-c92f-4df5-a7d7-44f338640fde
📒 Files selected for processing (3)
packages/opencode/src/session/processor.tspackages/opencode/src/session/retry.tspackages/opencode/test/session/retry.test.ts
Summary
Routes safe-recovery replay scheduling through the session retry policy path for #925 PR 3.
This adds a dedicated safe-recovery retry policy with its own one-replay budget metadata and lightweight retry presentation, then has
session.processoruse that policy instead of building the retry status and backoff timing locally.Why
#925 is consolidating model execution retry behavior so provider retry mechanics and PawWork safe-recovery checks share one retry pipeline. PR #928 added unified retry decision metadata, and PR #929 extracted the safety gate. This PR moves the remaining safe-recovery scheduling mechanics out of the processor-local branch while preserving the current #922 behavior.
Related Issue
Closes part of #925.
Human Review Status
Pending
Review Focus
Please check that
SessionRetry.safeRecoveryPolicykeeps safe-recovery replay metadata separate from ordinary provider retry attempts, and thatsession.processorstill preserves the existing lifecycle-close checks, reasoning retry timeout behavior, and safe-retry failure notice behavior.Risk Notes
Safe-recovery replay behavior is on the model execution path, so the main risk is accidentally broadening automatic replay. This PR keeps the existing safety gate and processor-level constraints in place, and only moves retry status/backoff scheduling to the retry policy layer.
Skipped conditional checklist items:
How To Verify
Screenshots or Recordings
Not applicable. This PR does not change visible UI.
Checklist
bug,enhancement,task,documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.app,ui,platform,harness,ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.P0,P1,P2,P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.Pending,Approved by @<reviewer>, orNot required: <reason>(default isPending; "not required" is restricted to bot-authored low-risk PRs).dev, and my PR title and commit messages use Conventional Commits in English.Summary by CodeRabbit
New Features
Refactor