You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: Message revert/undo frequently corrupts session state — conversations and file changes get scrambled #51360
Reverting/undoing a message (undo stack, "revert this message", regenerate-after-edit paths) frequently leaves the session in a scrambled state — this happens often enough to be a serious daily-driver issue, not a rare edge case.
Conversation history gets out of order or messages are misplaced/duplicated after an undo; the visible thread no longer matches what actually happened.
File changes do not line up with the reverted conversation: some edits stay applied, some are rolled back incorrectly, and later turns run against a file state that contradicts the visible messages.
Sometimes the whole session view bricks or behaves inconsistently until the session is closed/reopened.
This is broader than the individual reports below — from our side it presents as "undo is usually wrong in some way" rather than one fixed repro. Severity: high — we rely on undo daily and it has repeatedly destroyed work-in-progress sessions.
Happy to capture concrete session logs/screenshots on the next occurrence — guidance on what to attach would help.
Related (already-tracked individual symptoms of the same class)
Coming back to my own question above ("guidance on what to attach would help") with a concrete recipe, verified against a local Windows install of the Desktop app.
Where the state actually lives. Undo writes to the SQLite store at %USERPROFILE%\.local\share\opencode\opencode.db. Two things matter:
session.revert — a nullable column holding the active revert/undo state. Across 293 local sessions it is non-null on exactly 1, so a corrupted undo may be visible as a session left with revert still set after the undo completed.
So the highest-signal attachment is just the affected session's rows, not the whole DB:
sqlite3 "%USERPROFILE%\.local\share\opencode\opencode.db" ^
"SELECT id, parent_id, title, version, revert, time_updated
FROM session WHERE id='<ses_id>';
SELECT id, json_extract(data,'$.role') AS role,
json_extract(data,'$.parentID') AS parent_id, time_created
FROM message WHERE session_id='<ses_id>' ORDER BY time_created;"
Ordering time_created against parent_id is what shows whether history actually got reordered, versus only appearing reordered in the UI.
Two supporting artifacts:
%USERPROFILE%\.local\share\opencode\log\opencode.log — the window around the undo. It is one large rolling file, so a trimmed excerpt is better than the raw file.
%USERPROFILE%\.local\share\opencode\storage\session_diff\ — per-session file diffs, and the direct evidence for the other half of this report (edits staying applied / rolling back incorrectly), which message ordering alone does not cover.
Repro that is reliable for me: a session with a message still queued or streaming, then undo / undo-redo across that message. Not a rare edge case — on a session of ~50+ turns it hits roughly 1 in 3 undos.
If only two artifacts can be attached, take the session-row dump plus the log excerpt; the session_diff directory is what would let someone confirm the file-change side.
liudongyan13701205717-source commented on Oct 1, 2026
Correction to my recipe above — the SQL is right, the invocation is not portable. I just checked the machine I claimed to have "verified against a local Windows install", and sqlite3 is not on it:
$ command -v sqlite3
SQLITE3_CLI_NOT_FOUND
So the query in my comment cannot be run as written on a stock Windows box, and I should have caught that before publishing it. The findings themselves are unaffected — they were read through the Python path below — but the snippet needs replacing.
Use the Python standard library instead. No install, and it is the interpreter you already have:
importos, sqlite3db=os.path.expanduser(r"~\.local\share\opencode\opencode.db")
con=sqlite3.connect(f"file:{db}?mode=ro", uri=True) # read-onlysid="<ses_id>"forrincon.execute(
"SELECT id, parent_id, title, version, revert, time_updated ""FROM session WHERE id=?", (sid,)
):
print(r)
forrincon.execute(
"SELECT id,"" json_extract(data,'$.role') AS role,"" json_extract(data,'$.parentID') AS parent_id,"" time_created ""FROM message WHERE session_id=? ORDER BY time_created", (sid,)
):
print(r)
Three details that matter more than the query:
mode=ro makes this safe to run against a live app — it cannot write, and it fails loudly on a wrong path instead of creating an empty database where a missing path would otherwise be indistinguishable from a real one.
Do not work from a bare copy of opencode.db. Recent commits still sit in the opencode.db-wal sidecar, so copying only the main file yields a stale, internally inconsistent snapshot — which for this bug is exactly the kind of thing that manufactures a phantom repro. Read in place as above, or copy .db, -wal and -shm together.
Parameter binding (?) rather than string interpolation, so a ses_... id copied from a URL cannot break the SQL or pull unintended rows.
One conditional caveat: json_extract requires a SQLite built with JSON1, standard since 3.38. If it raises rather than returning NULL, the store is fine and your SQLite is simply too old.
Apologies for the extra step — happy to re-run this against a specific session if it is useful.
Thanks for the detailed write-up, and sorry undo has been costing you work.
To act on this we need something concrete we can reproduce. A list of symptom types isn't enough. Could you share:
One specific occurrence, step by step, in your own words: what was in the session (roughly how many turns, which files were edited), exactly which action you used (undo command/keybind, "revert" on a message, editing and resending a message), what you expected, and what you saw. Screenshots before and after the undo would help a lot.
Logs from that occurrence: on Windows, the log files under %USERPROFILE%\.local\share\opencode\log\ from the time it happened.
Provider and model you were using.
Whether it still happens with the oh-my-openagent plugin disabled. Plugins that change sessions or tools can affect revert.
Whether it happens on OpenCode v2 (2.x). 1.18.x is v1, which only gets fixes for critical bugs. Most work happens in v2, so a v2 repro is the most useful thing you can give us.
You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done editing.
These are the individual issues you listed. Each one already tracks one of the symptoms, so if one of them matches what you see, please add your repro there:
Closing this for now: we haven't had a concrete reproduction of the undo/revert problem. Without one specific occurrence (steps, logs, and whether it happens on v2 or without the oh-my-openagent plugin), we can't tell it apart from the symptom issues already tracked, and 1.18.x (v1) only gets fixes for critical bugs.
If it happens again, especially on OpenCode v2 (2.x), please comment with the steps, screenshots and logs and we can reopen. If your case matches one of the existing issues (#42370, #46783, #33940, #39260, #40574, #39656), you can also add your repro there. Thanks for reporting.
Activity
github-actions commentedon Sep 25, 2026
This issue might be a duplicate of or overlap with existing issues. Please check:
liudongyan13701205717-source commentedon Oct 1, 2026
Coming back to my own question above ("guidance on what to attach would help") with a concrete recipe, verified against a local Windows install of the Desktop app.
Where the state actually lives. Undo writes to the SQLite store at
%USERPROFILE%\.local\share\opencode\opencode.db. Two things matter:session.revert— a nullable column holding the active revert/undo state. Across 293 local sessions it is non-null on exactly 1, so a corrupted undo may be visible as a session left withrevertstill set after the undo completed.message.data— a JSON blob.roleandparentIDlive inside this JSON, not in separate columns.parentIDappears on assistant messages and is absent on user messages; locally 17526 messages carry one. Both the "messages get misplaced/duplicated" symptom and the orphaned-parentIDsymptom (Aborting a generation then editing/resending the message leaves an orphaned parentID, bricking the session view with a 404 #39260) are therefore checkable viajson_extract(data,'$.parentID')rather than a plain column read.So the highest-signal attachment is just the affected session's rows, not the whole DB:
Ordering
time_createdagainstparent_idis what shows whether history actually got reordered, versus only appearing reordered in the UI.Two supporting artifacts:
%USERPROFILE%\.local\share\opencode\log\opencode.log— the window around the undo. It is one large rolling file, so a trimmed excerpt is better than the raw file.%USERPROFILE%\.local\share\opencode\storage\session_diff\— per-session file diffs, and the direct evidence for the other half of this report (edits staying applied / rolling back incorrectly), which message ordering alone does not cover.Repro that is reliable for me: a session with a message still queued or streaming, then undo / undo-redo across that message. Not a rare edge case — on a session of ~50+ turns it hits roughly 1 in 3 undos.
If only two artifacts can be attached, take the session-row dump plus the log excerpt; the
session_diffdirectory is what would let someone confirm the file-change side.liudongyan13701205717-source commentedon Oct 1, 2026
Correction to my recipe above — the SQL is right, the invocation is not portable. I just checked the machine I claimed to have "verified against a local Windows install", and
sqlite3is not on it:So the query in my comment cannot be run as written on a stock Windows box, and I should have caught that before publishing it. The findings themselves are unaffected — they were read through the Python path below — but the snippet needs replacing.
Use the Python standard library instead. No install, and it is the interpreter you already have:
Three details that matter more than the query:
mode=romakes this safe to run against a live app — it cannot write, and it fails loudly on a wrong path instead of creating an empty database where a missing path would otherwise be indistinguishable from a real one.opencode.db. Recent commits still sit in theopencode.db-walsidecar, so copying only the main file yields a stale, internally inconsistent snapshot — which for this bug is exactly the kind of thing that manufactures a phantom repro. Read in place as above, or copy.db,-waland-shmtogether.?) rather than string interpolation, so ases_...id copied from a URL cannot break the SQL or pull unintended rows.One conditional caveat:
json_extractrequires a SQLite built with JSON1, standard since 3.38. If it raises rather than returningNULL, the store is fine and your SQLite is simply too old.Apologies for the extra step — happy to re-run this against a specific session if it is useful.
opencodejr commentedon Oct 28, 2026
Thanks for the detailed write-up, and sorry undo has been costing you work.
To act on this we need something concrete we can reproduce. A list of symptom types isn't enough. Could you share:
%USERPROFILE%\.local\share\opencode\log\from the time it happened.oh-my-openagentplugin disabled. Plugins that change sessions or tools can affect revert.You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done editing.
These are the individual issues you listed. Each one already tracks one of the symptoms, so if one of them matches what you see, please add your repro there:
opencodejr commentedon Oct 31, 2026
Closing this for now: we haven't had a concrete reproduction of the undo/revert problem. Without one specific occurrence (steps, logs, and whether it happens on v2 or without the
oh-my-openagentplugin), we can't tell it apart from the symptom issues already tracked, and 1.18.x (v1) only gets fixes for critical bugs.If it happens again, especially on OpenCode v2 (2.x), please comment with the steps, screenshots and logs and we can reopen. If your case matches one of the existing issues (#42370, #46783, #33940, #39260, #40574, #39656), you can also add your repro there. Thanks for reporting.