Skip to content

Capture core: read ended sessions' transcripts and store failed-then-fixed commands (#59 Phase 2, S2) #134

Closed

Description

@gosha70

Why

#59 Phase 2 plans capture: memory written from what a session did, not only from what the agent chose to retain. Its first slice, S1 (#128), shipped the hook-path collapse; S2 is the capture core. The owner's decisions on #59 (2026-11-15, recorded in the slicing plan) set the frame:

  • D2: the transcript reader lives in memkernel, behind a port;
  • D3: capture extracted signals only, no transcript excerpts;
  • D4: no model-written distillation;
  • D5: one issue per slice.

The first extractor is failed-then-fixed commands, which also gives the #120 count something to measure: errors captured, and repeats after capture.

Checked facts (main at 7f26012, memkernel 0.9.0)

  • The spool drains every ended session but reports only some. session_spool.drain() removes every ended session from the spool. It returns only the windows with no checkpoint (DrainResult.unsaved), which the session-start block lists. The other ended sessions are deleted without being returned.
  • The spool already records the transcript. The SessionEnd hook writes the session's transcript_path into its ended line (templates/hooks/session-end.py), but SessionWindow does not carry it.
  • The drain runs at normal startup only (MemoryLifecycle.on_session_start, source == "startup"), inside the SessionStart hook.
  • A transcript reader exists, temporary, in eval/repeat-mistakes/transcripts.py (Make repeated mistakes countable: a recall log and a counting script #120). It reads Claude Code's JSONL by sessionId, with each session's window, its own Bash outputs, and its recall calls.
  • memkernel has no redaction code in src/.

Requirements (the owner's, 2026-11-15)

  1. Expose all ended windows. The spool exposes every ended session's window, including its transcript_path, not only the unsaved ones. The unsaved report keeps working.
  2. Commit only after a durable store. An ended session leaves the spool, or a cursor advances past it, only after its extracted records are durably stored. A capture that fails or is interrupted leaves the session to be captured again.
  3. Idempotent. Each extracted record is keyed by (session, record UUID, extractor version), where the record UUID is the failing command's transcript record (its tool_result entry's uuid). Capturing the same session twice, or retrying after a failure, neither loses nor duplicates a signal.
    • An extractor-version bump changes the key, so a session captured again under the new version gets new records. The new record supersedes the old-version record for the same session and failing record UUID, so there is never one record per version. Sessions already gone from the spool are not re-scanned; a bump affects only sessions captured after it.
  4. The transcript reader is behind a port. A TranscriptReaderPort in core/ports.py, with a Claude Code adapter that graduates the Make repeated mistakes countable: a recall log and a counting script #120 reader into src/. The Make repeated mistakes countable: a recall log and a counting script #120 count then uses the adapter instead of its own copy.

Proposed (for a spec)

  • Opt-in. Capture is off by default, behind a setting (for example MEMKERNEL_CAPTURE), because it reads transcripts and stores their text. If the spec prefers another default, that is its first decision.

  • Extractor: failed-then-fixed commands. A Bash command whose output shows an error, followed later in the same session by a run of the same command, or the same tool target, that succeeds. It is stored as a short-term observation, with:

    • the error text and the fixing command;
    • origin: tags (the session, the extractor and its version);
    • the idempotency key.

    Only command output and structured fields are used, never free text from tool or web results (Context rescue: fix the compaction hooks, then capture session knowledge before it is lost (0.5.1 → 0.6) #59's prompt-injection rules).

  • Redaction of secrets in what is stored, before writing.

  • Caps: records per session and per run.

  • When capture runs: at normal startup, after the drain, within a time budget. Sessions it doesn't reach stay for the next start (requirement 2). Whether a detached worker is needed is for the spec.

  • A missing or unreadable transcript is retried at a bounded number of startups (the spec sets the number). After that, the session leaves the spool with one logged warning and a count in the startup report, so a deleted transcript never blocks the spool.

  • At session start:

  • How captured records feed the Make repeated mistakes countable: a recall log and a counting script #120 count:

    • A captured record quotes the error in backticks, so it is a stored error under the count's rule.
    • Its origin: tags let the count report captured errors apart from errors the agent stored itself.
    • The report then shows how often a captured error came back after capture, and whether a recall or hook block showed it first: shown, missed, other store or unknown.

Out of scope

Acceptance (sketch)

  • Every ended session in the spool is offered to capture, not only the unsaved ones, and the unsaved report is unchanged.
  • A capture killed after extraction but before the store, or after the store but before the spool commit, loses no signal and duplicates none on the next start.
  • Capturing the same session twice stores each signal once. After an extractor-version bump, a newly captured session holds one record per failing command, under the new version.
  • A session whose transcript is missing leaves the spool after the bounded retries, and the startup report counts it.
  • With capture off (the default), nothing is read or stored.
  • At session start, captured records are left out of, or capped in, the promotion candidates, and quoted as stored memory wherever they are shown.
  • The Make repeated mistakes countable: a recall log and a counting script #120 count reports captured errors separately from agent-stored ones.
  • A fixture transcript with a failed-then-fixed command yields one record; one with a failure and no fix yields none.
  • The Make repeated mistakes countable: a recall log and a counting script #120 count runs on the adapter, and its fixture test still passes.

Related: #59 (Phase 2, slicing plan), #128 (S1), #120 (the reader and the count), #107 (other tools).

Activity

  1. gosha70 commented on Nov 17, 2026

    @gosha70
    OwnerAuthor

    Key change (the owner's decision, 2026-11-16). Requirement 3's key becomes (session, record UUID, extractor), where extractor is the extractor's name, not its version. The extractor version is kept as a tag on each record.

    The supersede rule for version bumps is dropped. A session leaves the spool once its records are stored, so it is captured again only when a capture is interrupted, possibly across an upgrade. With the version out of the key, that retry skips the records already stored, whatever version wrote them. So a session is captured once, under the version installed at the time, and nothing is superseded or re-scanned.

    The spec also records the owner's other decisions for this issue: capture is off by default; it runs in the startup hook within a time budget and a per-run record cap; redaction is best-effort; and captured records stay out of the promotion candidates.

  2. gosha70 commented on Nov 18, 2026

    @gosha70
    OwnerAuthor

    Built in #137 (spec #135, specs/memkernel-0-12-capture-core/spec.md). Two points differ from this issue's text, by decisions recorded in the spec:

    • The key uses the failing result's tool_use_id, not the entry's uuid, because one transcript entry can hold several results (R2).
    • No version supersede: a session is captured once, under the extractor version installed at the time, and the version is a tag (D1).
  3. added a commit that references this issue on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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