Skip to content

last-save.json is single-slot — interleaved sessions clobber each other's saved positions, producing duplicate memory entries #140

Closed

Description

@bonyohana

Observed (production, 0.8.3 via marketplace; mechanism re-verified on main @ 7db7866)

The same span of one session ("99 exchanges (11 human)" in the extract log) was summarized twice, ~2.5h apart (06:06 and 08:33), yielding a near-identical triplet of entries in the daily file.

Mechanism

pipeline/shell.py:cmd_save_position writes a single-slot store:

json.dump({"session": session_id, "line": position}, f)

and pipeline/extract.py:get_last_save_line returns 0 whenever the stored session differs:

Returns 0 if the file is missing, corrupt, or belongs to a different session.

So with two live sessions A and B alternating saves (multiple terminals, or a background/worktree session sharing the store): A saves (slot=A), B saves (slot=B), A's next save finds slot=B → resumes from 0 → re-extracts and re-summarizes A's entire span → duplicates. The dedup context (last memory entry) doesn't catch it when other entries landed in between.

Suggested fix

Key positions by session: either last-save-<session>.json files, or one JSON object {"<session_id>": line, ...} with a small LRU cap (sessions are UUIDs; a dozen entries suffice). Read path change is one lookup; write path merges instead of replacing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions