Skip to content

V0.5+: compact memory pruning in continuous fold (daemon settled + iOS reducer) #16

Description

@yyq1025

Context

V0 maintains each session's cold-path snapshot (SessionRuntime.settled) via a continuous in-memory fold of EventDeltas (packages/daemon/src/messages/fold.ts, foldEventDelta). This is the daemon-side mirror of the iOS transcript reducer (transcript-collection-factory onEvent) — both apply the same deltas the same way, so the daemon's cold snapshot equals what iOS shows live, with no JSONL re-read (no dependency on the SDK's async flush timing, no live/settled divergence).

The deferred bit

compact_started / compact_applied are a deliberate no-op on both sides in V0:

  • iOS reducer no-ops compact (divider + prune deferred).
  • foldEventDelta mirrors that no-op so settled == live.

Re-reading the compacted JSONL on compact_applied would instead prune settled (filter to the post-compaction surviving UUIDs) and thus diverge from iOS's still-unpruned live state — which is why we don't do it today.

Consequence: after a compaction, both the daemon's settled and the iOS transcript keep the full pre-compaction timeline in memory (correct for rendering, but not pruned). No divider is shown.

V0.5+ work

Teach both reducers to prune on compact_applied, kept mirrored so cold == live:

  1. iOS reducer: on compact_applied, filter the transcript to preservedUuids and append a compact divider item.
  2. foldEventDelta: apply the same prune + divider — still purely in-memory, still no re-read.

Both must land together to preserve the cold==live invariant. This pairs with the surviving-UUID metadata work in #13 (own getSessionMessages that preserves compactMetadata / subtype / isCompactSummary off the raw JSONL) — the prune needs that metadata to know which UUIDs survived.

Pointers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions