Skip to content

feat(session): crash recovery — auto-resume sessions after crash - #43489

Closed
AndyS77 wants to merge 8 commits into
anomalyco:devfrom
AndyS77:crash-recovery
Closed

AndyS77 wants to merge 8 commits into
anomalyco:devfrom
AndyS77:crash-recovery

Conversation

@AndyS77

@AndyS77 AndyS77 commented Aug 19, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #43488

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an opt-in config option (session.auto_resume) that persists active session IDs to a manifest file on disk. On next startup, if the manifest exists (previous process didn't shut down cleanly), opencode automatically resumes the most recently active session. The manifest is cleared on clean shutdown via process.on("exit"). Manifest writes are atomic and shape-validated; corrupt JSON degrades gracefully.

How did you verify your code works?

17 tests pass (13 unit + 4 e2e). Live-tested crash, partial-idle, clean-shutdown, corrupt-JSON, multi-session, and write-update scenarios against the real data directory.

bun test test/session/active-manifest.test.ts test/session/crash-recovery-e2e.test.ts --timeout 30000
# 17 pass, 0 fail

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, I found one highly related PR:

PR #39684: feat(core): recover interrupted sessions on startup

This PR appears to address a similar concern about recovering sessions on startup, which overlaps with the crash recovery auto-resume functionality in PR #43489. You may want to review that PR to ensure there's no duplication of effort and to understand any prior approaches to session recovery.

@AndyS77

AndyS77 commented Aug 19, 2026

Copy link
Copy Markdown
Author

Thanks for the heads up. I reviewed PR #39684 — it's complementary, not a duplicate:

  • feat(core): recover interrupted sessions on startup #39684 fixes database durability: SQLite WAL hardening and recovery of in-flight assistant messages (marks incomplete turns as interrupted).
  • This PR adds auto-resume: tracks which sessions were active in a manifest and automatically resumes the most recently active session on next startup, so the user doesn't need to manually find and pass --continue.

They solve different layers of the same problem: #39684 ensures session data survives the crash, this PR ensures the user gets back into their session automatically.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@AndyS77

AndyS77 commented Sep 21, 2026

Copy link
Copy Markdown
Author

This PR was closed by automated PR cleanup (older than 1 month, fewer than 2 reactions). I'd like to request reopening because:

The underlying issue (#43488) is still open. When opencode crashes, there is no mechanism to automatically resume the most recently active session on next startup. Users have to manually find and resume their session, which is particularly painful after an unexpected crash during long-running tasks.

The feature is opt-in. It's gated behind session.auto_resume in the config, so it doesn't change default behavior. It persists active session IDs to a manifest file and clears it on clean shutdown via process.on("exit").

No alternative exists. No other PR implements crash recovery. The feature has been requested by multiple users in the issue thread.

The PR was in a reviewable state. It includes tests for the manifest lifecycle (write, read, clear, crash detection) and was typecheck-clean.

I'm still actively maintaining this PR and would appreciate it being reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Crash recovery — auto-resume sessions after crash

1 participant