Skip to content

fix(gateway): rewrite transcripts atomically - #4985

Closed
binhnt92 wants to merge 1 commit into
NousResearch:mainfrom
binhnt92:fix/atomic-transcript-and-channel-directory-writes
Closed

fix(gateway): rewrite transcripts atomically#4985
binhnt92 wants to merge 1 commit into
NousResearch:mainfrom
binhnt92:fix/atomic-transcript-and-channel-directory-writes

Conversation

@binhnt92

@binhnt92 binhnt92 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

rewrite_transcript() still overwrites the legacy JSONL transcript with a bare
open(path, "w"). If the gateway dies mid-write during /retry, /undo, or
/compress, the transcript file can be left empty or partially rewritten.

This refresh trims the PR down to the still-reproducible bug on current main.
channel_directory already uses atomic_json_write(), so it is no longer part
of the fix.

Changes Made

  • Rewrite transcripts through a temp file in the same directory
  • fsync() the temp file before replacing the original transcript
  • Remove the temp file on failure so aborted rewrites do not leave garbage behind
  • Add a regression test proving a mid-rewrite failure leaves the old transcript intact

How to Test

python3 -m pytest tests/gateway/test_session.py -k rewrite -v
python3 -m pytest tests/gateway/test_session.py -v

Checklist

  • Tests added
  • Existing session test file passes
  • Tested on Linux (Ubuntu 22.04)

@binhnt92

Copy link
Copy Markdown
Contributor Author

channel_directory looks fixed on main already. rewrite_transcript() still reproduces, so I'd keep this open but trim it to that part.

@binhnt92
binhnt92 force-pushed the fix/atomic-transcript-and-channel-directory-writes branch 2 times, most recently from 9819658 to 391afaf Compare April 15, 2026 14:24
@binhnt92 binhnt92 changed the title fix(gateway): use atomic writes for transcript and channel directory fix(gateway): rewrite transcripts atomically Apr 15, 2026
@binhnt92
binhnt92 force-pushed the fix/atomic-transcript-and-channel-directory-writes branch from 391afaf to ea1e879 Compare April 17, 2026 11:47
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15085 and #8065 — same atomic rewrite_transcript() fix for JSONL corruption on crash. Multiple competing PRs exist for this issue.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15085 and #8065 — same atomic rewrite_transcript() fix for JSONL corruption on crash.

@binhnt92

binhnt92 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing this to reduce duplicate PR noise. There are multiple competing PRs for the same atomic rewrite_transcript() issue (#8065, #8077, #15085, #20012), and a collaborator already flagged this one as likely duplicate.

@binhnt92 binhnt92 closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants