Skip to content

Stop null-padding turns.jsonl and recover poisoned resume loads - #480

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-5934-context-store-load-fails-hard-on-json-parse-during-resume
Aug 17, 2026
Merged

Stop null-padding turns.jsonl and recover poisoned resume loads#480
TheGreatAxios merged 2 commits into
mainfrom
cl-5934-context-store-load-fails-hard-on-json-parse-during-resume

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Segmented JSONL writer no longer calls truncate with a length past EOF when keepBytes is stale after an external shrink; rebuilds the segment from in-memory records instead (null-byte poison root cause).
  • Optimized context store load() recovers usable turns when the base isogit store hard-fails (null holes, corrupt metadata soft-defaults); unrecoverable parse errors name turns.jsonl.
  • Tests cover stale-keepBytes write path, mid-file null-hole resume, corrupt metadata soft-fail, and file-named unrecoverable errors.

Test plan

  • bun test src/session/incremental-jsonl.test.ts src/session/optimized-context-store.test.ts
  • bun run typecheck
  • bun run test (full suite)

Fixes CL-5934

@linear-code

linear-code Bot commented Aug 13, 2026

Copy link
Copy Markdown

CL-5934

When keepBytes exceeds on-disk size, rebuild the segment instead of
truncate-past-EOF (which pads null bytes). On load, if the base store
fails, recover usable turns with null-strip parse and soft-default
metadata; unrecoverable errors name the file.
Turn recovery after a hard base.load failure was always soft-emptying
metadata even when metadata.json parsed cleanly under the real schema.
That dropped pendingOperations, tokenUsage, and connectorState for
sessions whose turns.jsonl had null-byte holes but whose gates were
still parked — rehydrateGates then found nothing to re-arm and left
suspended agents wedged.

Prefer base.loadMetadata() on the recovery path so a good metadata
file survives; soft-empty only when that load itself fails. Regression
covers null-hole turns plus non-empty pendingOperations.
@TheGreatAxios
TheGreatAxios force-pushed the cl-5934-context-store-load-fails-hard-on-json-parse-during-resume branch from e7e617e to 7f88025 Compare August 17, 2026 17:13
@TheGreatAxios
TheGreatAxios merged commit 07c54ae into main Aug 17, 2026
2 checks passed
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