Fix session deletion bug when quitting with incomplete tasks#266
Conversation
Identifies root cause of session file deletion bug: the completion check at run.tsx:1975-1976 incorrectly uses engine status 'idle' which is always true after execution finishes, regardless of why it stopped. Also documents why "No task loaded" occurs after manual recovery - tasks are loaded from tracker, not session.json. https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
Fixes #247 - Session resume failures The bug was in the session completion check at run.tsx:1975-1976. The condition `finalState.status === 'idle'` was always true after the engine finished (set in finally block), regardless of WHY it stopped. This caused sessions to be incorrectly deleted even when the user quit normally with incomplete tasks. Changes: - Remove buggy `|| finalState.status === 'idle'` from completion check - Add helpful warning when resume finds no tasks but session has history - Add regression tests for the completion condition The fix ensures session.json is only deleted when all tasks are actually complete (tasksCompleted >= totalTasks). https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughAdds an investigation doc for Issue Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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 |
Resolved conflict in src/commands/run.tsx: - Main added parallel mode support with `parallelAllComplete` variable - My fix removed the buggy `|| finalState.status === 'idle'` condition - Merged both: kept parallel mode support AND applied the bug fix https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (31.42%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #266 +/- ##
==========================================
- Coverage 43.70% 43.69% -0.01%
==========================================
Files 94 94
Lines 28978 29009 +31
==========================================
+ Hits 12665 12676 +11
- Misses 16313 16333 +20
🚀 New features to boost your workflow:
|
Add tests covering: - Tracker validation warning logic in resume command - Parallel mode completion condition (from merged main) - Sequential mode fallback with fix verification - Edge cases: empty projects, partial completion, task count mismatches All tests verify that the old buggy logic would have failed, documenting the fix for future reference. https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@tests/commands/resume.test.ts`:
- Around line 35-37: The test comment uses time‑bound phrasing ("This was the
user's scenario - session showed 108/130 but tracker returned nothing") which
should be made evergreen; update the comment in the test around the
expect(shouldWarnAboutTrackerMismatch(0, 130)) to describe the scenario
neutrally (e.g., "Scenario: session reports 108/130 but tracker reports 0
tasks") without referencing time or "user" language so it remains relevant
long-term and clearly documents the intent for the
shouldWarnAboutTrackerMismatch test.
In `@tests/commands/run.test.ts`:
- Around line 454-588: Update comments in the tests so they avoid temporal
phrasing (e.g., "was", "previously", "old", "would have been", "This was the
bug!") and instead use evergreen wording; specifically edit the commentary
inside the describe blocks for session completion and parallel mode (the
comments around the describe titles and inside the tests that explain the bug)
as well as inline comments near the helper functions isAllComplete and
computeAllComplete and the two tests named "completion does NOT depend on engine
status" and "sequential fallback does NOT use engine status" to describe the bug
and fixed logic in present-tense, timeless language.
Extract helper functions for better testability and coverage: - isSessionComplete() in run.tsx for completion logic - shouldWarnAboutTrackerMismatch() in resume.tsx for validation Update tests to: - Import and test actual exported functions (improves coverage) - Use evergreen comments without temporal language - Document invariants in present tense Addresses PR feedback on test comments. https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
Expand test coverage for isSessionComplete() and shouldWarnAboutTrackerMismatch(): - Reorganize tests into logical groups (mismatch detection, no mismatch, boundary conditions) - Add edge cases: large task counts, zero scenarios, minimal mismatches - Add explicit tests for nullish coalescing behavior in parallel mode - Add tests demonstrating parallel mode completely overrides task count logic - Document key invariants for both functions https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
…Jviz6 Fix session deletion bug when quitting with incomplete tasks
Summary
Fixes a critical bug (#247) where session files were incorrectly deleted when users quit the application with incomplete tasks. The bug was caused by checking
engine.status === 'idle'as a completion condition, which is always true after the engine finishes regardless of why it stopped.Changes
Fixed completion logic (
src/commands/run.tsx): Removed thefinalState.status === 'idle'condition that was always evaluating to true. Now only checks iftasksCompleted >= totalTasksto determine if a session should be deleted.Added validation warning (
src/commands/resume.tsx): When resuming a session, now detects and warns users if the tracker returns no tasks while the session has task history. Provides helpful guidance on how to recover by explicitly specifying the tracker source.Added regression tests (
tests/commands/run.test.ts): Comprehensive test suite covering the completion logic, including the exact scenario from the bug report (108/130 tasks completed).Added investigation documentation (
docs/investigations/issue-247-session-resume-failures.md): Detailed analysis of the root cause, affected code paths, and recommendations for future improvements.Root Cause
The engine's
runLoop()setsstatus = 'idle'in a finally block that executes regardless of why the loop exits (user quit, max iterations, no tasks, or actual completion). The completion check incorrectly used this status as an indicator of task completion, causing sessions to be deleted even when tasks were incomplete.Impact
https://claude.ai/code/session_01E6dQhS1es6Tdm3p5Y2XxaK
Summary by CodeRabbit
Bug Fixes
Documentation
Tests