Skip to content

[BUG] Foreign key constraint failure in part table during session cleanup #37450

Closed as not planned

Description

@ByteTora

Description

When a session is interrupted during response generation, cleanup writes a part record but the parent message/session no longer exists — SQLite FK constraint fails.

Steps to reproduce

  1. Trigger a long response
  2. Interrupt during generation (Escape / abort)
  3. Check ~/.local/share/opencode/log/opencode.log

Error

EffectDrizzleQueryError: Failed query: insert into "part" ... on conflict ("part"."id") do update ...
cause: SQLiteError: FOREIGN KEY constraint failed
Stack: Session.updatePart → SessionProcessor.cleanup → process → SessionPrompt.run → loop

Context

  • OpenCode version: 1.18.3
  • OS: macOS
  • DB: SQLite (opencode.db, ~1GB)
  • Race condition: abort deletes session/message while cleanup still writes parts

Suggested fix

Guard Session.updatePart with existence check on parent message/session, or catch FK error gracefully during cleanup.

Activity

  1. github-actions commented on Jul 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. github-actions commented on Sep 17, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions