Skip to content

fix(export): read JSONL from one snapshot - #134

Merged
samzong merged 4 commits into
mainfrom
feature/release-0.5-ng07
Aug 14, 2026
Merged

fix(export): read JSONL from one snapshot#134
samzong merged 4 commits into
mainfrom
feature/release-0.5-ng07

Conversation

@samzong

@samzong samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • read JSONL session metadata and child records from one SQLite snapshot
  • prevent concurrent sync writes from producing mixed-version exports
  • cover the race with a WAL-backed concurrent writer regression

Verification

  • cargo test export_jsonl_reads_every_record_from_one_snapshot
  • cargo test export_jsonl
  • make check

Closes release blocker NG-07.

Signed-off-by: samzong <samzong.lu@gmail.com>
@samzong

samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b917e56ff8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/export.rs
options: &ExportOptions,
mut writer: W,
) -> Result<()> {
let snapshot = store.conn.unchecked_transaction()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Decouple the snapshot from output backpressure

When recall export writes to a slow or stalled pipe while a concurrent sync keeps committing—the concurrency this change targets—this transaction remains open across every Write call. In WAL mode, that reader snapshot prevents checkpoints from advancing beyond its end mark, so sustained writes can grow the WAL until the consumer drains and may eventually exhaust disk space. Spool or materialize the export while the snapshot is open, commit it, and only then copy the completed JSONL to the caller's writer.

Useful? React with 👍 / 👎.

Signed-off-by: samzong <samzong.lu@gmail.com>
@samzong

samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e58e7b2097

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/export.rs Outdated
};

write_jsonl_for_sessions(store, sessions, options.includes, &mut writer)
let records = collect_session_records(store, sessions, options.includes)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep export memory bounded

With the default --limit 0, this now retains every session’s messages, usage events, and events until the entire export has been read, so an index whose contents exceed available RAM will be OOM-killed instead of streaming successfully as before. Preserve the snapshot without accumulating all ExportSessionRecords in memory—for example, serialize into a temporary spool while the snapshot is open, commit it, and then copy the spool to the requested writer.

Useful? React with 👍 / 👎.

Signed-off-by: samzong <samzong.lu@gmail.com>
@samzong

samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13013ac48c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/export.rs Outdated
Comment on lines +240 to +242
let mut spool = (page_count.saturating_mul(page_size) > EXPORT_IN_MEMORY_DB_LIMIT)
.then(|| tempfile::tempfile().map(BufWriter::new))
.transpose()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound buffering by the selected export size

When recall session export --ids-file contains repeated IDs, a database below 8 MiB stays on this in-memory path even though the selected output is unbounded: each duplicate is loaded into a separate ExportSessionRecord, so repeating one 7 MiB session 100 times retains roughly 700 MiB before writing anything. The new page-count threshold therefore does not fully resolve the earlier memory issue; switch to the spool based on accumulated record size, or always spool selected-session exports.

Useful? React with 👍 / 👎.

Signed-off-by: samzong <samzong.lu@gmail.com>
@samzong

samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: e698fc20e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@samzong

samzong commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: e698fc20e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@samzong
samzong merged commit 2c56a42 into main Aug 14, 2026
3 checks passed
@samzong
samzong deleted the feature/release-0.5-ng07 branch August 14, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant