perf(session): write saved sessions as compact JSON

Saved sessions and crash checkpoints were written with to_string_pretty.
Indentation alone took a document the reporter measured from 6.50 MB to
8.96 MB, over the 8 MiB resume bound, and costs 16-27% on the two measured
large sessions. serialize_saved_session now writes compact JSON; every
reader parses JSON either way, and the existing over-bound projection now
measures the compact form, so a document over the bound only because of
indentation is rewritten compact and resumes. /save with no path,
which rewrites the live session file in place, is compact too; /save to an
explicit path stays indented for reading.

Verification: checked once on the final batch tree (parent db89057d84):
cargo fmt --check clean; tui lib nextest across route_budget,
provider_catalog_live, provider_lake, mounted_history_tests,
session_manager, client, core::engine, compaction, tools::subagent,
runtime_api, purge, commands::contract, tui::model_picker and whats_new
2757 passed, 0 failed; tui integration exec_turn_usage 11 passed, 0
failed; feature_registry 2 passed, 0 failed; clippy -p codewhale-tui
--lib --tests -D warnings with the CI allow-list clean; check-blocking-
calls-budget 540 sites, within budget. Not run: hosted CI and the
loopback product captures (those follow on the release build).

Refs #6955
Thanks @7jrxt42BxFZo4iAnN4CX for the measurements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
CodeWhale BotandClaude Opus 5.5 committed 2026-10-21 17:07:05 -07:00
1 parent 77535c2f61
commit d1df47061c
4 files changed
+19 -2

No files matched your search

+6
View File
@@ -106,6 +106,12 @@ guidance.
counted, instead of rewriting the file and then reporting that nothing
changed. Refs #6955. Thanks @7jrxt42BxFZo4iAnN4CX.
- Saved sessions and crash checkpoints are now written as compact JSON
instead of indented JSON. Files are smaller (16–27% on the two measured
sessions from the report), and a session that was over the 8 MiB resume
limit only because of indentation resumes again. Refs #6955. Thanks
@7jrxt42BxFZo4iAnN4CX.
- A `codewhale resume` or `codewhale fork` that is refused before it
reserves anything no longer tells you to recover it with an operation key.
Refs #6954.
+6
View File
@@ -106,6 +106,12 @@ guidance.
counted, instead of rewriting the file and then reporting that nothing
changed. Refs #6955. Thanks @7jrxt42BxFZo4iAnN4CX.
- Saved sessions and crash checkpoints are now written as compact JSON
instead of indented JSON. Files are smaller (16–27% on the two measured
sessions from the report), and a session that was over the 8 MiB resume
limit only because of indentation resumes again. Refs #6955. Thanks
@7jrxt42BxFZo4iAnN4CX.
- A `codewhale resume` or `codewhale fork` that is refused before it
reserves anything no longer tells you to recover it with an operation key.
Refs #6954.
+6 -1
View File
@@ -506,6 +506,7 @@ impl CommandSessionLifecycleContext for SessionLifecycleAdapter<'_> {
path.display()
));
}
let in_place = explicit_save_path.is_none();
let save_path = explicit_save_path.unwrap_or_else(|| {
let dir = crate::session_manager::default_sessions_dir()
.unwrap_or_else(|_| app.workspace.clone());
@@ -519,7 +520,11 @@ impl CommandSessionLifecycleContext for SessionLifecycleAdapter<'_> {
match std::fs::create_dir_all(&sessions_dir) {
Ok(()) => {
let json = match serde_json::to_string_pretty(&session) {
let json = match if in_place {
serde_json::to_string(&session)
} else {
serde_json::to_string_pretty(&session)
} {
Ok(j) => j,
Err(e) => return Err(format!("Failed to serialize session: {e}")),
};
+1 -1
View File
@@ -1524,7 +1524,7 @@ fn serialize_saved_session(mut session: SavedSession) -> io::Result<String> {
validate_saved_journal(journal)?;
}
session.make_storage_compatible();
serde_json::to_string_pretty(&session)
serde_json::to_string(&session)
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))
}