Skip to content

fix(opencode): preserve pending messages on session error#2094

Merged
qin-ctx merged 3 commits into
volcengine:mainfrom
CuSO41108:fix/opencode-session-error-pending-messages
May 18, 2026
Merged

fix(opencode): preserve pending messages on session error#2094
qin-ctx merged 3 commits into
volcengine:mainfrom
CuSO41108:fix/opencode-session-error-pending-messages

Conversation

@CuSO41108
Copy link
Copy Markdown
Contributor

@CuSO41108 CuSO41108 commented May 17, 2026

Description

Preserve pending OpenCode messages when a session.error event occurs.

Before this change, the session.error handler only treated capturedMessages and commitInFlight as unsaved work. If a session had messages in pendingMessages but no captured messages yet, the session mapping could be cleaned up and those pending messages could be lost.

This change includes pendingMessages.size > 0 in the unsaved-work check so the plugin triggers a best-effort background commit instead of deleting the session mapping.

Related Issue

Fixes #2093

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Updated the session.error handler in examples/opencode-memory-plugin/openviking-memory.ts
  • Treat pendingMessages as unsaved work before session cleanup
  • Preserve pending messages by triggering the existing background commit path

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Manual verification:

  • Ran git diff --check
  • Verified the change is scoped to the session.error handler
  • Verified the existing session.deleted behavior is unchanged

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A

Additional Notes

No tests were added because this example plugin does not appear to have a dedicated test harness in this directory. The change is intentionally scoped to the existing session.error recovery condition.

@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

2093 - PR Code Verified

Compliant requirements:

  • Added pendingMessages.size > 0 to the condition check in the session.error handler
  • Maintains existing logic for capturedMessages and commitInFlight

Requires further human verification:

  • Manual testing to verify pending messages are preserved on session.error
⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🏅 Score: 92
🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an OpenCode session lifecycle edge case in the example OpenViking memory plugin so that pending (not-yet-captured) messages aren’t dropped when a session.error event occurs, by treating pendingMessages as unsaved work and triggering the existing commit/cleanup path.

Changes:

  • Updated the session.error handler to consider pendingMessages.size > 0 as unsaved work (in addition to capturedMessages and commitInFlight).
  • Ensures the plugin takes the “best-effort background commit” path instead of deleting the session mapping when only pending messages exist.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CuSO41108
Copy link
Copy Markdown
Contributor Author

Thanks for expanding the recovery path. I’ll keep an eye on the checks.

@qin-ctx qin-ctx merged commit 1071b8b into volcengine:main May 18, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug] session.error handler loses pending messages when no captured messages exist

3 participants