Skip to content

Institutional memory from externally-initiated coding-agent sessions (hook ingestion) #11137

Open
5 of 8 issues completed

Description

@mrveiss

Summary / PRD

AutoBot already captures rich institutional memory from coding-agent sessions that it spawns itself as an execution backend, and exposes that memory back to agents over MCP. This epic closes the one remaining capture gap: externally-initiated developer sessions — a person running Claude Code / Codex / Cursor on their own machine, outside AutoBot's execution loop — currently leave no trace in AutoBot memory. Their transcripts, tool calls, and decisions are lost, so a later agent (or the same developer) re-derives context AutoBot never learned.

The goal is a zero-friction, opt-in path that streams an externally-initiated coding session into AutoBot memory using the existing event → memory → MCP pipeline, so past external work becomes searchable via the tools we already ship.

What already exists (reuse, do not rebuild)

  • Coding-session capture → memory: services/execution/claude_code_backend.py (Issue feat(llm): Claude Code / Claude Agent SDK as an execution provider #10550) streams ACTION / OBSERVATION / MESSAGE events into the event bus, which persists to memory.
  • Transcript parsing: _parse_cli_line (claude_code_backend.py:123) decodes Anthropic content blocks (text / tool_use / tool_result). Anthropic-only today.
  • Event → memory persistence: events/stream_manager.py, events/bus.py, events/types.py (AgentEvent, ActionContent, ObservationContent, MessageContent).
  • Cross-session memory: memory/agent_diary.py, AutoBotMemoryGraph, VerbatimStore.
  • MCP read surface (query side is DONE): mcp/autobot_server.py — memory.verbatim_search (supports session_filter), memory.timeline, memory.related, agents.diary_summary, kb.search.
  • Embed reconcile: background_vectorization.py vectorize_pending_facts self-heals failed embeds (retry until vectorization_status=completed).

The gap

  1. No ingestion path for a completed transcript produced outside AutoBot's execution loop (hook-driven, from a developer's own CLI session).
  2. _parse_cli_line handles a live Anthropic JSONL stream only — no Codex / OpenAI response-item format, and no batch/file (optionally gzipped) parsing.
  3. No session read/list MCP tools to pull a full external session back (only verbatim chunk search exists).

Proposed solution (thin, reuses the pipeline)

  • Extract the block-decoding logic from _parse_cli_line into a shared transcript_normalizer that accepts a whole transcript (JSONL, optionally gzipped) and yields the same event shapes, adding a Codex response-item branch. claude_code_backend then imports the shared normalizer instead of its private copy (no behaviour change for spawned runs).
  • Add an authenticated POST /api/sessions/ingest endpoint (owner-scoped) that accepts a transcript, runs it through the normalizer, and publishes the events through the existing bus so they persist to memory exactly like a spawned run.
  • Ship opt-in hook scripts (on_session_end, etc.) that POST the just-finished transcript to that endpoint. Governed by an explicit env/config opt-in — off by default.
  • Add memory.session_list / memory.session_read MCP tools over the existing session store so ingested sessions are retrievable, not just chunk-searchable.

Non-goals

  • No new vector DB, embedder, or search stack — reuse ChromaDB + the existing RAG/rerank pipeline.
  • No change to spawned-run behaviour beyond swapping the private parser for the shared one.
  • No always-on capture — ingestion is opt-in per developer.

Tasks

  • Task 1: Shared transcript normalizer → PR
    • 1.1 Extract block decoding from claude_code_backend._parse_cli_line into services/execution/transcript_normalizer.py (pure, unit-tested against fixtures)
    • 1.2 Add Codex/OpenAI response-item branch + gzip/batch file support
    • 1.3 Repoint claude_code_backend at the shared normalizer; assert no behaviour change for spawned runs
  • Task 2: Owner-scoped ingestion endpoint → PR
    • 2.1 POST /api/sessions/ingest (auth + owner scoping + size limits + SSRF/path safety); publish via existing bus
    • 2.2 Idempotency by session id (re-ingest is a no-op / update, mirror session_service.upsert semantics)
  • Task 3: Opt-in hook scripts → PR
    • 3.1 on_session_end hook that POSTs the finished transcript; env/config opt-in, off by default
    • 3.2 Docs: enabling capture + privacy note (local-only framing)
  • Task 4: Session read/list MCP tools → PR
    • 4.1 memory.session_list + memory.session_read over existing session store, behind the memory scope

Acceptance criteria

  • An externally-initiated Claude Code and Codex session, once ended, appears in AutoBot memory and is returned by memory.verbatim_search and the new memory.session_read.
  • Spawned-run behaviour is byte-for-byte unchanged (normalizer swap is transparent).
  • Capture is opt-in and off by default; endpoint rejects unauthenticated / oversized / cross-owner payloads.

Open decisions (owner input needed before Task 2+)

  • Retention & privacy: how long are ingested external transcripts kept, and are they per-user private by default? (Affects endpoint + storage.)
  • Redaction: do we scrub secrets/paths from external transcripts on ingest, and to what depth?
  • Scope of formats for v1: Claude Code + Codex only, or also Cursor / Gemini CLI?

Task 1 (shared normalizer) and Task 4 (read tools) are safe to start immediately — they reuse existing seams and carry no product/privacy decision. Tasks 2–3 are gated on the decisions above.

Activity

  1. mrveiss commented on Jul 7, 2026

    @mrveiss
    OwnerAuthor

    Owner decisions resolved (un-gates Tasks 2–3, sizes Task 1)

    1. Retention & privacy → private-per-user, indefinite.
    Ingested external transcripts are owner-scoped and not shared by default; no auto-purge. Storage growth + stale-content pruning is a follow-up, not v1 (file a discovery issue if growth becomes real). Sharing to a team is explicit opt-in via the existing share/publish path — never a default.

    2. Redaction → route secrets through the existing secrets manager, do not scrub-and-drop.
    On ingest, detected secret-like spans are stored in the envelope vault and replaced in the transcript with a secret reference placeholder, so plaintext secrets never land in memory or embeddings, while the vault manages user/team sharing. This reuses:

    • services/secrets_service.py (SecretsService, get_secrets_service()) + autobot_shared/secrets_vault.py (envelope vault, team-shareable VaultAccess) for storage.
    • services/workflow_secret_service.py:240 resolve_secrets(text, owner_id) already does reference → value; Task 1 adds the inverse capture (value → vault ref) so the same reference format round-trips.
    • services/secrets_access_audit.py for access logging.
      This replaces the old "aggressive scrub" line item — no lossy redaction; content stays intact via references.

    3. Formats → all four: Claude Code, Codex, Cursor, Gemini CLI.
    Task 1 sizes to 4 parser branches + 4 fixture sets in the shared transcript_normalizer, each yielding the canonical AgentEvent shapes. _parse_cli_line (Anthropic) is the seed for the Claude Code branch.

    Revised task tree

    • Task 1: Shared multi-format transcript normalizer → PR
      • 1.1 Extract Anthropic block decoding from claude_code_backend._parse_cli_line into services/execution/transcript_normalizer.py; repoint the backend at it (no behaviour change for spawned runs)
      • 1.2 Add Codex (OpenAI response-item), Cursor, and Gemini CLI branches + gzip/batch-file support; one fixture set per format
      • 1.3 Secret-capture pass: detect secret spans → store via SecretsService (envelope vault) → replace with reference placeholder compatible with workflow_secret_service.resolve_secrets; unit-test round-trip + audit log
    • Task 2: Owner-scoped ingestion endpoint → PR
      • 2.1 POST /api/sessions/ingest (auth + owner scoping + size limits + path safety); runs normalizer → secret-capture → existing event bus → memory
      • 2.2 Idempotency by session id (mirror session_service.upsert semantics)
    • Task 3: Opt-in hook scripts (4 agents) → PR
      • 3.1 on_session_end hooks for Claude Code / Codex / Cursor / Gemini that POST the finished transcript; env/config opt-in, off by default
      • 3.2 Docs: enabling capture + privacy note (secrets go to the vault, transcript stays private-per-user)
    • Task 4: Session read/list MCP tools → PR
      • 4.1 memory.session_list + memory.session_read over the existing session store, behind the memory scope

    Status: Tasks 1 & 4 unblocked and buildable now; 2 & 3 unblocked by the decisions above. No new vector/embedding/secrets infrastructure — all four tasks reuse existing modules.

  2. mrveiss commented on Jul 8, 2026

    @mrveiss
    OwnerAuthor

    Correction — wire secret-capture to the canonical secrets store (#10088)

    Follow-up audit note on the redaction decision above. The earlier comment named SecretsService / autobot_shared/secrets_vault.py as the storage target. The canonical entry point is services/secrets_coordinator.py SecretsCoordinator — the RBAC-governed façade being standardised under umbrella #10088 ("unify AutoBot secrets — replaces 11 stores, 5 keys, 2 UIs"). Task 1.3 must target it, not the legacy service classes:

    • Store a captured secret: SecretsCoordinator.create(...) (:78)
    • Team/user sharing (satisfies the "shared among users and teams" requirement directly): SecretsCoordinator.share(...) (:135)

    Net-new scope clarified: existing helpers only handle known, registered secret names — workflow_secret_service.resolve_secrets (ref→value, :240) and redact_secrets (:281). Task 1.3's new work is auto-detecting unregistered secret spans in an external transcript (pattern-based: API keys, bearer tokens, export KEY=…) → SecretsCoordinator.create → replace with a ${secrets.NAME} reference that round-trips through the existing resolver. Reuse the detection patterns, add the capture direction.

    Cross-link: secrets-store consolidation itself is out of scope here and owned by #10088 — this epic consumes the canonical coordinator, it does not modify the secrets architecture.

  3. ajdelaguila commented on Jul 9, 2026

    @ajdelaguila

    Full disclosure: I maintain Data Olympus, a governed project-knowledge MCP server for coding agents: https://github.com/knaisoma/data-olympus

    This external-session ingestion path is a strong fit for an authority/lifecycle split. Transcript capture can make institutional memory much richer, but raw transcript-derived facts should probably not become governing knowledge automatically.

    A pattern that has worked well for us is:

    • ingest external sessions as evidence with provenance, source session, timestamps, and privacy scope;
    • distill candidate learnings from that evidence;
    • keep candidates in a proposed state until reviewed or otherwise promoted;
    • expose only accepted/current guidance by default when an agent is making decisions;
    • keep superseded or expired guidance searchable for audit, but out of normal ranking.

    Data Olympus focuses on that governed layer: markdown in git, MCP retrieval, proposed writes, accepted/in-force filtering, validity windows, and supersession chains. It may be useful as a reference for the part of this epic where transcript events become durable project knowledge rather than just searchable history.

    The secret-capture correction in the latest comment also reinforces the same point: capture and retrieval need provenance and policy metadata close to the memory, otherwise it becomes hard to answer “why did the agent remember this?” or “is this allowed to influence this user/project?”

  4. hegu-1 commented on Jul 10, 2026

    @hegu-1

    The hook-ingestion gap is real, but I would avoid making external sessions write directly into institutional memory.

    A safer pipeline is four layers:

    1. raw_hook_event: append-only capture from Claude/Codex/etc. with source, cwd, repo, branch, tool name, timestamp, and redaction state.
    2. normalized_session_trace: grouped run with goal, files touched, commands, test results, decisions, failed paths, and final outcome.
    3. candidate_memory: proposed reusable facts such as conventions, architectural decisions, recurring fixes, or environment gotchas.
    4. promoted_institutional_memory: reviewed memory that agents can trust in future sessions.

    That distinction matters because externally initiated sessions have mixed authority. Some traces are useful evidence; not all of them should become durable instructions. The ingestion boundary should preserve provenance, but promotion should be explicit and reviewable.

    I have been working on a similar memory-vault pattern for personal and project AI continuity: trace is cheap to capture, but durable memory needs a promotion gate. This repo may be useful as a concrete reference: https://github.com/hegu-1/personal-ai-os

  5. added this to the v0.10.0 milestone on Sep 12, 2026
  6. mrveiss commented on Oct 17, 2026

    @mrveiss
    OwnerAuthor

    @hegu-1 @ajdelaguila your design input is answered in #18657. The review step is now a requirement on this epic: #18656.

  7. mrveiss commented on Oct 25, 2026

    @mrveiss
    OwnerAuthor

    Owner decisions, 2026-10-25: ingest our Claude Code history about AutoBot into the local AutoBot install, so historical decisions are searchable. Nothing leaves this machine. Build this issue now; run the actual ingest only after the KB read-path leak fix (#16665) is deployed, because session history is private.

    Sources found (local only):

    source coverage format
    full session transcripts (this repo's project) 49 sessions, 5.0 GB, since 2026-09-25 Claude Code session JSONL
    AutoBot's own agent runs (the service user's Claude Code project) 47 transcripts session JSONL
    prompt history (current) 6,482 prompts, 2026-03-17 → now history.jsonl (prompt, project, timestamp)
    prompt history (previous dev machine, rescued) 7,441 prompts, 2025-09-27 → 2026-04-17, 6,880 mention AutoBot history.jsonl
    Windows-side sessions 2 session JSONL

    Loss to note: the previous dev machine's 837 full sessions (Jan–Apr 2026) were copied over on 2026-09-05 with their original timestamps, and Claude Code's default 30-day transcript cleanup deleted them. Retention is now 10 years (cleanupPeriodDays: 3650), so nothing more expires. For that period, only the prompt histories remain.

    Scope additions to this issue:

  8. 13 remaining items

  9. mrveiss commented on Oct 30, 2026

    @mrveiss
    OwnerAuthor

    Findings from review of merge train PR #20083, recorded here as follow-ups:

    • autobot-backend/memory/verbatim_sessions.py:69: Real: Chroma get() with a limit is not documented to return newest-first, so past the scan cap the newest session can fall outside the scanned rows. The response does set truncated=true when the scan is cut, so the partial view is declared, not silent. Needs an ordering-safe scan (page through all owner rows, or keep a per-session index); tracked as a follow-up.
    • autobot-backend/memory/verbatim_sessions.py:93: Real but narrow: if a later turn is stored before turn 0 and the session exceeds the chunk cap, the capped page can start mid-conversation. truncated=true is returned in that case, and chunks arrive in insertion order, so it needs out-of-order writes plus an oversize session. Tracked together with the session_list scan cap.
    • autobot-backend/mcp_server/memory_session_tools.py:101: Accurate: the byte budget is charged on the redacted body, but the frame (warning text plus delimiters, a few hundred bytes per chunk) is added on top, so the response can exceed SESSION_READ_MAX_BYTES by a bounded amount (at most chunk-cap times frame size). Not unbounded; count the framed text instead of the body when charging.
    • autobot-backend/mcp_server/memory_session_tools.py:100: Partly accurate: only the text is redacted and framed; metadata is copied as stored. The stored keys are session_id, turn, role, timestamp and user_id (verbatim_store.py:243-250), all written by or for the same owner, so the exposure is the owner's own session id and principal id echoed back, with session_id as caller-chosen text outside the frame. Low severity; return an allowlist (turn, role, timestamp) and drop user_id.
    • autobot-backend/mcp_server/memory_session_tools.py:117: The mismatch is real by construction: reads are filtered on exact user_id, an MCP bearer resolves to a token-derived id (principal.py:40) and a run JWT to agent_id, while chat writes store the human user id. Binding principals to a writer identity is a design and authorization decision (it widens who can read whose history), so it needs a maintainer decision rather than a patch here. The fail-closed behaviour is the safe default meanwhile.
    • autobot-backend/services/execution/transcript_normalizer.py:221: Confirmed inconsistency: _codex_item_event handles custom_tool_call and custom_tool_call_output, but the bare-record dispatch in normalize_codex_record lists only message, function_call and function_call_output, so a bare custom-tool line yields no event (wrapped response_item lines are fine). I could not confirm that bare custom-tool lines occur in real rollouts. Adding both types to the tuple is safe.
    • autobot-backend/services/execution/transcript_normalizer.py:244: Partly inaccurate: a boolean timestamp already yields an empty value (_iso_from_epoch_ms returns "" for non-numeric, non-string input), so true is not retained. A present string is passed through unchanged by design, so "not-a-date" is kept as the entry's timestamp. Validating that string as ISO is optional hardening; low impact since the value is the user's own history.

    The item on which stored user_id an MCP principal reads as is an authorization decision for the maintainer.

  10. github-actions commented on Oct 30, 2026

    @github-actions
    Contributor

    Landed via the merge train (#20083, merge f69c6a7d46) via #20033

  11. mrveiss commented on Oct 30, 2026

    @mrveiss
    OwnerAuthor

    The merge train (PR #20083), main f69c6a7, via #20033. 6 of 12 boxes ticked: Tasks 1 and 4.

    • 1.1 and 1.2: services/execution/transcript_normalizer.py has parse_cli_line, normalize_codex_record, gzip in iter_lines, and read_transcripts for batches.
    • 1.3: claude_code_backend.py _parse_cli_line = parse_cli_line. transcript_normalizer_test.py::TestSpawnedRunOutputUnchanged pins the decode results.
    • 4.1: mcp_server/memory_session_tools.py, mixed into AutoBotMCPServer. Test: test_behind_the_memory_scope_only.

    Open: Tasks 2 and 3 (no sessions/ingest route on main) and their open decisions. The issue's acceptance criteria need those, so it stays open.

  12. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision (2026-11-02): an admin binds each tool-server login to a named person, and that login reads only that person's history. Until a login is bound, reads stay refused. The authorization design follows here.

  13. removed
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 1, 2026
  14. mrveiss commented on Nov 20, 2026

    @mrveiss
    OwnerAuthor

    Branch issue-11137-session-normalizer (PR #20033, head 7ad4ed1) was deleted as a zero-change branch: its content is already on main. Tasks 1 and 4 were already ticked. Task 2 (owner-scoped POST /api/sessions/ingest) and Task 3 (opt-in on_session_end hook plus docs) stay unticked: I found no ingest route or session-end hook script on main (searched autobot-backend/api, scripts, docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions