Skip to content

Persist streaming deltas for crash recovery #135

Description

@louismorgner

Summary

If the process dies mid-stream, partial content (text and tool call arguments) is lost. The runtime should persist streaming deltas as they arrive so interrupted streams can be recovered.

What OpenCode does

OpenCode persists text deltas, reasoning deltas, and tool input to the database in real-time as stream events arrive. If the process crashes mid-stream, partial content is recoverable.

Proposed implementation

In ChatStream() / the stream consumer in native_runner.go:

  • Write partial assistant content to a scratch file (e.g., .toc/sessions/<id>/stream_buffer.json) as deltas arrive
  • On successful stream completion, discard the buffer (the full message is saved normally)
  • On crash recovery (PendingTurn exists + stream_buffer present), reconstruct the partial message from the buffer
  • This complements the existing PendingTurn checkpoint which tracks tool execution but not partial LLM output

Priority

P1 — improves resilience for long-running sessions where a crash mid-stream loses significant work

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions