#6721·CodeWhale

Emergency compaction — the impact on the `save session` task

Author: ronoharaCreated Sep 29, 2026Updated Sep 30, 2026
Labelsneeds-triage

@Hmbown More of an FYI background information than a bug - but it does impact reliability and prompted an idea

I use a 'save session' command to a personalised context transfer as an adjunct to codewhale does. The agent was cut off while executing that command and it was impacted.

Details follow - from the new agents view on the other side of an Emergency Compaction

It has also prompted a though that I will expand on later. Perhaps we can avoid (by design) the need for emergency context compaction.

In essence, the agent is most effective when the context buffer is nearly full - lots of relevant recent experience to call on. /new destroys that and the agent only has its training to rely on. Emergency compact does much better by transferring context to the new agent.

But perhaps instead of codewhale directly doing the compaction (keep that for true emergencies) ...the agent could be given a tool to allow it to selectively prune its context.. . As long as the agent is given the state of the context buffer and the config parameters at each turn, it could then prune some of its older context by calling that tools if the parameters require it - but let the agent choose the scope of the context to prune

That should leave an agent with a ongoing mildly varying (almost full) context buffer and not suffer the drastic interruption that /compact implies. Continuity rather than disruption

Emergency compaction — the impact on the save session task

Recorded: 2026-09-29, by the session that resumed after the compaction. Subject: the emergency context compaction that interrupted the save session command, and what it cost the agent's ability to complete that task accurately. Evidence class: every number and path below was measured with a tool after the compaction, from the live filesystem and the runtime's own stores. Statements that come from the compaction's summary rather than from a measurement are marked [reported]. Statements that could not be explained are marked [unresolved] rather than given a cause.


1. What happened, in short

The user issued save session. That turn began, produced 3,908 characters of reasoning and nothing else, and was cut off by an emergency compaction before it called a single tool. The compaction took a 2.5 MB snapshot of the transcript, wrote an 8,608-byte relay summary, and handed that summary to a resumed turn — the one that wrote this file.

The consequence for accuracy is not that facts were lost. It is that the only continuity between the two turns was a model-written summary of a transcript that no longer exists. Everything inherited from it had to be re-measured before it could be written down; and of the four claims that failed that re-measurement, none was a small detail. What cost the agent its accuracy was not the gap in the transcript but the confidence of the summary that filled it.

Cost, measured: roughly ten gathering calls across three full-state probes, plus the re-measurement that the four failures forced. The delivered file is workbench-development/context-transfer-2026-09-29-11:36:26.md (24,229 bytes, 339 lines), written between 11:36:26 and 11:36:55, about three minutes after the resume.


2. The event, as far as it is observable

No tool records the compaction itself. What follows is the trace it left, and the timestamps agree to within half a minute.

  • Snapshot — ~/.codewhale/sessions/cc61cccd-9a41-4e00-ac24-6240e53d72a9/artifacts/context-transfer-4cf0b914-6eba-41da-b993-987d1e769a4a.json, 2,540,963 bytes, written 11:33:08.
  • Relay summary — the .md beside it, 8,608 bytes, written 11:33:38. Its first line is "Another language model started to solve this problem and produced a summary of its thinking process…" — and that is the text that appears in the resumed session's transcript as a user-role message.
  • Resumed turn — its first tool call ran at 11:33:08, its second at 11:33:41. The compaction's two writes therefore straddle the resume: the resolver handover and the disk write overlap by seconds.
  • The interrupted turn — one assistant message, index msg[57] in both stores, 3,908 characters of reasoning, no tool calls. Its closing lines are "Let me gather facts first.", then a blank line, then "Let me run." — so it died in the act of starting, not in the act of writing.
  • Nothing partial was left behind — verified, not assumed: the project root's newest transfer before the resumed one is context-transfer-2026-09-29-04:40:48.md (14,845 bytes), and nothing in the project root has a modification time between 11:25 and 11:36 except the file the resumed turn wrote.

This was not the session's first compaction. The session cc61cccd-9a41-4e00-ac24-6240e53d72a9 was created 2026-08-30, and its artifacts/ directory holds 46 compaction relays dated from 2026-09-15 onward — including two today (04:47 and 11:33). The transfer files at the project root are a separate, user-facing series written on request; the relays are the runtime's own. So the content of the delivered transfer file inherits from a chain of summaries, even though the file has exactly one compaction hop behind it.


3. What was lost, and what was not

Lost: the agent's side of the transcript for every turn before the compaction boundary. The live log and the checkpoint both retain assistant reasoning only from msg[57] onward — the interrupted turn's block and the resumed turn's segments. Everything the agent reasoned in the earlier turns of this session was replaced by summary text.

Not lost — the user's own words. All 57 of this session's user turns survive verbatim in the stores — msg[0] through msg[56], every one of them. (The 58th user-role message is the compaction relay itself, at msg[59].) Every instruction, every correction — "No point referencing line numbers", "try to avoid using invented shorthand", "Option B", "deploy this to a514" — is checkable word for word. The asymmetry is exact and worth stating plainly: the compaction destroyed the agent's reasoning and preserved the user's instructions.

Recoverable, and where: the interrupted turn's own 3,908 characters survive in both stores, and the resumed turn's reasoning survives in the checkpoint. The fuller record is the checkpoint beside the log — ~/.codewhale/sessions/checkpoints/cc61cccd-9a41-4e00-ac24-6240e53d72a9.json (22.7 MB, rewritten as the session turns) — which carries more messages and more reasoning segments than the live log at any moment:

  • live log, first sampled early in the resumed turn: 61 messages, 1 assistant block, 3,908 chars.
  • live log, sampled at the end of the resumed turn: 118 messages, 30 assistant blocks.
  • checkpoint, sampled at the end of the resumed turn: 125 messages, 33 assistant blocks.

So the stores do retain reasoning — progressively, and only from the last boundary. The live log simply lags within a turn, which is what made the first sample look like an empty store.


4. Impacts on the ability to complete the task accurately

4.1 Continuity arrived as a summary, and the summary was the only record

The resumed turn began with no transcript of the interrupted turn — no tool results, no partial deliverable, no working memory. The provenance chain for the file it produced is: full transcript (dropped) → relay summary → delivered transfer file. Each hop is lossy, neither is checkable against its source, and the second hop was written by an agent that had itself only the summary. The practical effect: the deliverable could be made true only by re-measuring the world, never by trusting its input.

4.2 The reasoning behind every decision was unavailable — only its conclusion survived

The summary states outcomes: decision 3 is Option B; the composer is PHP; the headline figures are read from each site's rendered report; the report links were dropped. It does not carry the argument for any of them. For conclusions that rest on a chain — why the five headline figures cannot come from the data file, for instance — the resumed turn could restate the conclusion with the summary's own one-line justification and nothing more. It could not re-derive it, and could not tell whether the justification was the real one. Errors of fact were catchable; errors of reasoning were not.

4.3 Four claims failed on contact with live state

All four were completion claims — the class of statement a summary compresses hardest and asserts most confidently. Each was found by measuring, not by reading:

  1. "The debian/changelog quirk is now recorded in docs/code-quirks.md." Measured false. That file's newest entries are dated 2026-09-27; it contains no 2026-09-28 or 2026-09-29 entry at all — so neither the build quirk nor any of the four composer defects reached the quirks backlog, though the project rule requires the append in the turn each is found. The summary reported a diligence that had not happened. [Reported, then refuted by measurement.]
  2. The .buildinfo.new. The summary and the user's own screenshot disagreed with each other; live state resolves neither: the file is absent from ~/Documents, from /tmp, and from a full-depth search beneath ~/Documents, and no command in the resumed turn removed it. [Unresolved — recorded as observed.]
  3. The reasoning-retention measurement. The summary's figure — 599 messages, 225 thinking blocks, 845,169 characters — matches neither store. Measured: the live log began the resumed turn with 61 messages and one 3,908-character block, and the checkpoint with 109 messages and 25 blocks. [Reported, then refuted.]
  4. Where the .deb goes. The summary's "published" implied the parent directory; the build script publishes it with mv to workbench-linux/website/workbench-linux.sentuny.com/dl/, where it verifies at 31,402,694 bytes dated 11:28. This one the resumed turn could settle by reading the code. [Reported, then corrected.]

Three of the four were caught only because the resumed turn re-measured the world rather than describing it. Had it written the file first and verified afterwards, all four would have been written down as fact.

4.4 A measurement that could not be reconciled at all

The 599/225/845,169 figure cannot be reproduced from either store now, and no third store was found. The resumed turn recorded the divergence as a divergence, inside the outstanding-questions section of the delivered file, rather than choosing a number. That is the honest handling — but it leaves the record with a figure that is known to be wrong and is not known to be replaced by a right one.

4.5 The boundary between the two turns was destroyed — including my ability to audit the loss

The resumed turn could not tell, from the stores alone, whose reasoning the one retained block was. It reasoned about it, concluded it was the resumed turn's own (streamed live), and wrote that conclusion into the delivered transfer file — where it is wrong. The block at msg[57] is the interrupted turn's; its closing lines ("Let me gather facts first.", then "Let me run.") show it died before its first tool call. The live log was simply lagging in persisting the resumed turn's own segments.

So the compaction did not merely remove information; it removed the marker by which the loss could be measured. Reconstructing the boundary took several probes of two stores and their timestamps. One reconstruction was committed to paper before it was checked, and it was false. This is the sharpest form of the impact: a summary that does not date itself makes its own errors unattributable.

4.6 No partial artefact existed to inspect or salvage

A real hazard for a task whose deliverable is a file is a half-written file that reads as complete. It did not materialise here: the interrupted turn made no tool calls, wrote nothing, and the project root's previous transfer file is untouched at 04:40:48. The resumed turn verified that instead of assuming it.

4.7 The session's own subject was demonstrated by its own ending

The session opened with the user noticing that the previous turn's reasoning cannot be reviewed after the fact, and it closed with the agent's reasoning being destroyed mid-task by the machinery that keeps the context window. Both are the same mechanism seen from two sides. The delivered transfer file records the first; this document records the second.


5. What the resumed turn had to re-establish before it could write anything

Every one of these was measured after the resume; none was inherited as fact.

  • The three deployed files' md5 sums against the box — acd494130580eba918449a48badd706d (/etc/draff.yaml), a0f074b5128f2d36d61ef142297ecbcc (/opt/draff/compose-daily-report.php), 1a9333e314a47bfe2545fb628498b548 (/opt/draff/run-daily.sh) — all three matching the repos.
  • The cron line (35 1 * * * /opt/draff/run-daily.sh >> /var/log/draff.log 2>&1) and the last line in /var/log/draff.log (04:25:34, the old draff job), which is what proves the composer has never run in production.
  • PHP 8.3.6 on the box.
  • The test suite, re-run live: 14 passed, 0 failed; message 119,836 bytes; longest line 657 bytes; 195 bar rows; 11 plain tables; three download detail blocks.
  • Seven repositories' branch and dirty state, and the one commit since the previous transfer (779354c).
  • The plan document: 882 lines, decision 3 settled as Option B, the nineteen categories listed, the Revisions section present.
  • ~/Documents free of build artefacts at any depth, and the .deb present in the website's dl/.
  • The session stores' own shape — which is what turned a hidden risk into a recorded one.

What could not be re-measured, and is therefore inherited in the delivered file: that the four composer defects were each "fixed and proved" (only their consequences were re-measured — the clean test suite, the line-length distribution, the -f sender in the source, the Postfix log line); the user's own in-conversation confirmation that the email "looks good"; the account of the earlier over-broad cleanup that deleted three /tmp artefacts; and every statement about why a decision was taken. These are written in the delivered file as they were reported, and they carry the summary's authority rather than a measurement's.


6. Defects this event exposed in the delivered file

Both are corrections the resumed turn found after writing the transfer file. Neither has been applied — an edit needs the user's word.

  1. A mis-attribution in the ### Session Log section. It says the live log's single retained thinking block is "the current turn's reasoning, streamed as it is produced." Measured after the fact, that block is msg[57], the interrupted turn's reasoning — and the claim's second half is wrong too: the live log does retain assistant reasoning, from the compaction boundary onward, and now holds 30 such blocks.
  2. A pointer that understates the record. The section directs a future reader to the live log, which at any moment is the thinner of the two stores. A fresh session following the delivered pointer would conclude that reasoning is barely retained and stop looking — the opposite of the truth. The checkpoint beside it, and the 46 relays in the session's artifacts/ directory, are the fuller record.

7. Structural risks for future save session turns, and proposed mitigations

Recorded as proposals; none is implemented.

  1. A summary's completion claims are its least trustworthy content. They are the most compressed and the most confidently asserted. A relay should mark each claim as verified by tool or reported, and the resumed turn must treat everything unmarked as a hypothesis to test. Here the four failures were all of this class.
  2. A summary must date and delimit itself. Without a statement of which turns it covers and when it was taken, the boundary is unreconstructable and its own errors become unattributable (§4.5). The compaction's own artifacts do carry timestamps; the relay text does not.
  3. Write the deliverable early, then verify. The interrupted turn gathered facts in no particular order and died with nothing on disk. Even a first-pass skeleton on disk would have made the resume cheap and the loss small. This is compatible with authoring the document in full — it changes the order, not the authorship.
  4. Layer the pointers. A transfer file's research section should name the live log, the checkpoint and the compaction relays, and say which is fuller — otherwise the next session reads the thinnest one and believes it.
  5. Record the provenance depth in the file itself. The delivered transfer file has one compaction hop behind it, but its content inherits a chain of 46 relays. A reader cannot tell the difference, and should be able to.
  6. State the boundary index. msg[57] is where retained reasoning begins. One line in the research section would tell the next session exactly which turns' reasoning is gone and need not be hunted for.

Appendix A — measurements cited

session id                 cc61cccd-9a41-4e00-ac24-6240e53d72a9
session created            2026-08-30
compaction relays in store 46, dated 2026-09-15 .. 2026-09-29 (two today: 04:47, 11:33)
snapshot (11:33 compaction)  artifacts/context-transfer-4cf0b914-….json  2,540,963 bytes  11:33:08
relay summary (same event)   artifacts/context-transfer-4cf0b914-….md       8,608 bytes  11:33:38
interrupted turn             msg[57], assistant, 3,908 chars of reasoning, no tool calls
resumed turn first tool call 11:33:08      second tool call 11:33:41
live log, early in resume    61 messages (60 user, 1 assistant), 1 thinking block (3,908)
live log, end of resume     118 messages (88 user, 30 assistant), 30 thinking blocks
checkpoint, end of resume   125 messages (92 user, 33 assistant), 33 thinking blocks
delivered transfer file      workbench-development/context-transfer-2026-09-29-11:36:26.md
                             24,229 bytes, 339 lines, written 11:36:26–11:36:55
previous transfer file       context-transfer-2026-09-29-04:40:48.md  14,845 bytes (untouched)
user turns retained         57 verbatim (msg[0] .. msg[56]); the 58th user-role message is the relay

Appendix B — the interrupted turn's surviving reasoning

Recoverable in full from both stores at msg[57]. Opening, verbatim:

The user says "save session". Per AGENTS.md, that means: generate a context-transfer file at the pro…

Execute this instruction exactly as written. Do not optimise, streamline, or deviate.

Steps:

  1. Get the current date/time for the filename. …

Closing, verbatim:

Let me gather facts first.

Let me run.

Those closing lines are the whole proof that the turn produced nothing: it was about to gather, and the compaction arrived first.

Appendix C — how to re-derive any of this

bash
# the two stores, and which is fuller
ls -t ~/.codewhale/sessions/*.json | head -1
ls -l ~/.codewhale/sessions/checkpoints/

# every compaction relay this session has had, with dates
ls -lt ~/.codewhale/sessions/<id>/artifacts/context-transfer-*.md

# the retained turns, roles and reasoning blocks, without reading 22 MB into a viewer
python3 -c "
import json,collections
d=json.load(open('<store>.json'))
print(len(d['messages']), dict(collections.Counter(m.get('role') for m in d['messages'])))"