Skip to content

[Bug]: Reopening a conversation fails if one event file is corrupt or empty #6649

Closed

Description

@enyst

I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.

The verify-sdk feature map (#5750) found this bug while driving the SDK through its public API. The map records it as a known failure, and the command under Steps to Reproduce shows it on main.

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

If one saved event file of a finished conversation is corrupted (bad JSON) or empty, as after a crash or a bad copy, reopening the conversation fails: a pydantic ValidationError ("Invalid JSON") for the corrupt file, and FileNotFoundError: Missing event file for the empty one. A deleted file has recovered since #6197. The unit tests cover an EventLog read in isolation, not a conversation resumed over it.

Expected Behavior

The conversation reopens with every readable event (lost_beyond_damaged 0), and the damaged file is reported in the log.

Actual Behavior

reopen_error is the ValidationError above.

Steps to Reproduce

From a checkout of main (uv sync), with the verify-sdk tools on the path:

export PATH="$PWD/.agents/skills/verify-sdk/scripts:$PATH"
sdk-map run --file S05 --only S05.event-log-recovery

That runs this recipe from the map (each control-sdk call runs in its own HOME, persistence and workspace; the first block fails, the second, a deleted file, passes since #6197):

export SDK_VERIFY_RUN=$(control-sdk new --field run)
CID=$(control-sdk conversation new --script S05/write_and_read.json --field id)
control-sdk conversation send "$CID" --text "Write notes.txt" --run --check execution_status eq finished
control-sdk program S05/damaged_log --arg "$CID" --arg corrupt \
  --check reopen_error missing --check lost_beyond_damaged eq 0
export SDK_VERIFY_RUN=$(control-sdk new --field run)
CID=$(control-sdk conversation new --script S05/write_and_read.json --field id)
control-sdk conversation send "$CID" --text "Write notes.txt" --run --check execution_status eq finished
control-sdk program S05/damaged_log --arg "$CID" --arg delete \
  --check reopen_error missing --check lost_beyond_damaged eq 0

Acceptance Criteria

  • A conversation reopens over a corrupt or empty event file, keeping every readable event.
  • Tests cover both cases through Conversation(...) resume.
  • The S05.event-log-recovery bullet in .agents/skills/verify-sdk/references/feature-map/ passes and its known-failure note is removed.

Installation Method

uv sync in a checkout of main


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Verified against main: EventLog._get_single_item() raises pydantic ValidationError for invalid JSON and FileNotFoundError for an empty file (openhands-sdk/openhands/sdk/conversation/event_store.py), so a resumed conversation is unloadable — the same failure class #6197 fixed for missing files. tests/sdk/conversation/local/test_state_serialization.py::test_conversation_state_corrupted_event_handling currently asserts this failure, and the S05.event-log-recovery recipe reproduces it through the public API (reproduced 2026-10-13 and 2026-11-03).

Bounded scope: treat an unreadable event file (invalid JSON or empty) the way #6197 treats a missing file — skip it, log a warning naming the damaged file and the reason, and reopen with every readable event, reusing the existing recovery mechanisms (bridged ancestors, HEAD falling back to the last readable event when the damaged file held the leaf, system prompt preserved).

Non-goals: no deletion, rewrite, quarantine, or re-synthesis of the damaged file or its content; no repair tooling or UI; no change to the agent-server REST surface or event serialization; no changes outside the SDK local-conversation persistence path and its tests.

Priority stays medium: a reproduced failure in the actual SDK workflow, twice on main, filed by a maintainer; not evidence of a broad production outage.

Acceptance Criteria

  • Reopening a finished conversation whose persisted event log contains one corrupt (invalid JSON) event file succeeds: the reopened state contains every readable event and none are lost beyond the damaged one (lost_beyond_damaged == 0 in the S05 recipe).
  • The same holds for an empty (0-byte) event file.
  • On reopen, a warning naming the damaged file and the reason is logged, and the damaged file is left on disk unchanged.
  • Recovery holds wherever the damaged file sits: mid-log (events on both sides stay readable) and at the leaf (HEAD falls back to the last readable event, per the fix(sdk): keep a conversation loadable when an event file is missing #6197 behavior).
  • After recovery the conversation is usable: a new event can be appended, and a subsequent reopen succeeds without further repair.
  • Unit tests cover corrupt and empty files through Conversation(...) resume (not only an isolated EventLog read), and test_conversation_state_corrupted_event_handling no longer asserts the ValidationError failure.
  • The fix(sdk): keep a conversation loadable when an event file is missing #6197 lost-file recovery tests (tests/sdk/conversation/test_state_damaged_event_log.py) still pass unchanged.
  • sdk-map run --file S05 --only S05.event-log-recovery passes both recipe blocks (corrupt and delete), and the S05.event-log-recovery bullet in .agents/skills/verify-sdk/references/feature-map/S05-events.md no longer carries a known-failure note.

Activity

  1. added
    bug
    priority:medium
    ready-for-dev
    on Nov 9, 2026
  2. enyst commented on Nov 9, 2026

    @enyst
    MemberAuthor

    I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.

    #6669 fixes this, with one choice a maintainer should confirm. An unreadable event file now reads as a ConversationErrorEvent stand-in (code UnreadableEventFile) with the lost event's id and place, so indexes, seqs and the event tree are unchanged and nothing reaches the LLM for it. The alternative is to drop the file from the index the way a deleted file is dropped since #6197; that keeps the event list free of placeholders but shifts indexes under readers that are walking the log. The PR's "Decision needed" section has the details.


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:mediumready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions