Skip to content

Capture core: failed-then-fixed commands, and the count fixes (#134, #136) - #137

Merged
gosha70 merged 5 commits into
mainfrom
feat/134-capture-core
Nov 18, 2026
Merged

gosha70 merged 5 commits into
mainfrom
feat/134-capture-core

Conversation

@gosha70

@gosha70 gosha70 commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Builds the S2 spec, specs/memkernel-0-12-capture-core (#135): D1–D8 and amendments R1–R15.

Fixes #136. Refs #134.

Capture (opt-in, MEMKERNEL_CAPTURE, off by default)

  • Reader: a TranscriptReaderPort (core/ports.py), with a Claude Code reader (transcripts/claude_code.py). It handles batched results under one entry uuid, sidechain lines, agent_id, recursive subagent files (journal.jsonl skipped) and the 50 MB limit.
  • Spool: every ended window carries its transcript_path. With capture on, ended sessions stay until commit(), and unsaved ones are still reported once (via a reported line). Misses are counted with capture_missed lines. Ended sessions older than 7 days are dropped and counted.
  • capture.py:
    • the D7 rerun and exit-code rules and the FR-005 extractor;
    • FR-006 redaction, applied before the record is composed;
    • the key (session, tool_use_id, extractor), with the version as a tag;
    • a non-blocking capture.lock (R3), the 3 s budget, the 20-record and 5-per-session caps, 3 misses, and the oversize rule;
    • Windows stays off with one warning (R6).
  • Store: captured records are stored with retain(content_dedup=False) (R1), and consolidate() never returns them as candidates (D5).

The count (#136, DIADE's report on #112)

  • Reading: it now reads through the new reader, subagent and workflow-agent files included. Their repeats count toward the parent session, on a (subagent) line.
  • Repeats: a repeat needs a Bash run that failed with its own exit code, and its evidence names the command (R8).
  • Stored errors: single-word stored errors are dropped (R9).
  • Threads: recalls stay with their thread (R12). A subagent repeat is shown only when that subagent recalled the memory; otherwise not shown, never missed. "Other store" and "unknown" still apply there (R14, plus the owner's build note).
  • Captured errors are reported apart (FR-011).

Checks

  • Tests: 1180 passed, coverage 94.8% (capture 96%, reader 99%, spool 96%).
  • Lint and types: ruff and strict mypy are clean, including CI's own mypy command for the eval tools.
  • Origin gate: passes.
  • DeepSeek: not run (owner's decision, 2026-11-17).

For review

  1. Redaction mangles file paths with digits. FR-006's long-string rule counts / as part of a string, so it redacts paths such as …/tests/test_zz_us1_scratch.py. The real fixture shows it. Treating / as a separator would fix it, at the cost of missing base64 secrets that contain /.
  2. eval/repeat-mistakes/transcripts.py is kept as a re-export, because ci.yml's mypy step names it. Deleting it needs a one-line CI change.
  3. The count's existing fixture test now marks its failing runs as real failures (is_error and an Exit code prefix), as R8 requires. Its expected outcomes are unchanged.
  4. The key lookup uses list_memories(session_id=…): filtered by the store, but it reads content, not only metadata.
  5. DIADE's fixtures can land as a PR against this branch (the order note).

…ipts (#134, #136)

Builds specs/memkernel-0-12-capture-core (D1-D8, R1-R15). With MEMKERNEL_CAPTURE
on, normal startup reads ended sessions' Claude Code transcripts through a new
TranscriptReaderPort and stores each failed-then-fixed command as a redacted,
short-term observation keyed by (session, tool_use_id, extractor). The spool keeps
ended sessions until their records are stored; one capture runs at a time within
3 seconds and 20 records; captured records are never promotion candidates.

The repeated-mistake count moves onto the same reader: it reads subagent
transcripts and reports their repeats apart, counts only Bash runs that failed with
their own exit code, names the command, drops single-word stored errors, and
reports captured errors apart. DIADE reported these on #112.
Only recalls before a failure decide its outcome, on both threads; captured
errors repeated by a subagent are counted apart; the key lookup is store-filtered
and metadata-only (MemoryService.list_metadata); sessions a budget stop leaves add
to the misses already counted; a sidechain entry with no agent identity is skipped
rather than joining any thread. The spec is marked approved and its tasks ticked.
…thout it

From the review of #137 at 6c0072e: capture.run was unguarded, so a lock, spool or
store error inside it cost the session its whole startup block. A session leaves
the spool only after its records are stored, so the next start retries it.
The owner's amendment from the review of #137 at 6c0072e: the slash-inclusive
long-string rule redacted paths with a digit, in file paths and inside error lines,
so a captured error naming such a path could never match later output. A token is
now redacted when a /-separated piece is 32+ characters mixing letters and digits
(not all hexadecimal) or 16+ mixing uppercase, lowercase and digits.
…is a test

From the owner's review of #137 at cb362cf: splitting every token on / let AWS's
documented sample secret key through (pieces of 13, 7 and 18 characters). A token
is split only when it starts with / or a file extension follows it; any other token
is judged whole by the 32-character rule, as before R16.
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.

Repeated-mistake count: read subagent transcripts, count only failed runs, drop single-word signatures (DIADE's report)

1 participant