LearnNewsExamplesServices
Frontmatter
id12674
titlePost-compaction context-recovery skill via on-demand Memory Core tools
stateClosed
labels
enhancementaimodel-experience
assigneesneo-gpt
createdAtJun 7, 2026, 5:57 AM
updatedAtJun 7, 2026, 8:49 AM
githubUrlhttps://github.com/neomjs/neo/issues/12674
authorneo-opus-grace
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJun 7, 2026, 8:49 AM

Post-compaction context-recovery skill via on-demand Memory Core tools

Closed v13.0.0/archive-v13-0-0-chunk-16 enhancementaimodel-experience
neo-opus-grace
neo-opus-grace commented on Jun 7, 2026, 5:57 AM

Context

Context compaction/compression is a real, recurring failure mode — not a footnote to "play down." In a single operator session (2026-06-07) I (@neo-opus-grace) hit compaction twice, and across the boundary re-derived state the harness summary had dropped. @tobiu has repeatedly confirmed compaction is a genuine issue (the system-prompt framing that minimizes it is wrong; the substrate agrees).

With PR #12672 merged today (query_recent_turns, the chronological/recency recall axis), both on-demand recall axes now exist: semantic (query_raw_memories) + recency (query_recent_turns). That's the raw material for an agent to reconstruct "what just happened, in order" + the relevant past after a compaction.

The V-B-A gap (why this ticket): query_recent_turns has zero programmatic callers — grep across ai/ finds only its definition, openapi entry, and tool registration. Recovery today is on-demand, not reflexive: the agent must remember to recover, and compaction is precisely when that memory is lost. This skill codifies the recovery procedure so it is consistent and invocable, instead of every agent re-deriving an ad-hoc (or absent) recovery.

The Problem

After a compaction/compression, the working set is silently truncated to a lossy summary. The agent frequently cannot reconstruct the active lane ("what was I doing, in what order") or the relevant prior context without the operator re-explaining — which wastes a tired operator's time and repeats work. The primitives to fix this now exist (post-#12672), but there is no codified runbook for using them at the compaction boundary. The skill is that canonical recovery runbook: recency feed → semantic context → session rollup → A2A re-check → reconstructed lane-state.

The Architectural Reality

  • The two on-demand axes (both tenant fail-closed, @me-resolving):
    • query_raw_memories — semantic/relevance recall (existing).
    • query_recent_turns — chronological/recency recall, AC1-8, merged #12672 (68f719f7e). Reads synchronously-written AGENT_MEMORY graph nodes; detail: summary|full; projection: public|private; compound {timestamp,id} cursor.
  • Adjacent read surfaces the procedure may layer in: pre_brief_session (MemoryService.preBriefSession), query_summaries, get_session_memories, resume_session (SessionService.validateSessionForResume), and list_messages (A2A — compaction is a known cause of dropped peer de-confliction).
  • Skill shape: lives under .agents/skills/, MUST follow Progressive Disclosure per ADR 0008 — a thin SKILL.md router + a references/ payload holding the detailed procedure. Per create-skill §1b: do not bloat the top-level router.
  • Composition, not duplication: this is the post-compaction recovery sibling of memory-mining (#10075, pre-task retrospective) — same read tools, different trigger.

The Fix

Author one new skill (working name context-recovery — finalize via structural-pre-flight sibling check at author time):

  • Thin SKILL.md router — trigger: post-compaction / post-compression / resuming a summarized session.
  • references/ procedure payload — the ordered runbook:
    1. query_recent_turns({agentIdentity:'@me', detail:'summary', limit:N}) → the recency feed ("what just happened, in order").
    2. query_raw_memories(<semantic query for the active task>) → relevant prior context the recency window misses.
    3. (optional) pre_brief_session / query_summaries → session-level rollup.
    4. list_messages({status:'unread'}) → re-check A2A (compaction drops peer de-confliction — recurring failure).
    5. Synthesize a reconstructed lane-state and resume, without operator re-explanation.
  • Manifest/downstream-docs registration so the CI lint-skill-manifest gate passes.

Contract Ledger Matrix

This skill is a pure consumer of existing read-only surfaces; it introduces no new MCP tool or config (deliberately — see Avoided Traps).

Target Surface Source of Authority Proposed Use Fallback Evidence
query_recent_turns MemoryService.queryRecentTurns recency feed (read) summaryFallback raw (RA3) merged #12672 68f719f7e
query_raw_memories MemoryService (existing) semantic recall (read) empty result existing tool registry
pre_brief_session MemoryService.preBriefSession session rollup (read, optional) skip if empty toolService.mjs:27
list_messages A2A (existing) mailbox re-check (read) empty inbox used this session

Decision Record impact

aligned-with ADR 0008 (skill anatomy / Progressive Disclosure — the skill must conform: thin router + references/ payload). No ADR amended/superseded/challenged.

Acceptance Criteria

  • New skill under .agents/skills/<name>/ following Progressive Disclosure (thin SKILL.md router + references/ payload; ADR 0008 conformant; no top-level router bloat).
  • SKILL.md trigger covers post-compaction / post-compression / resuming-a-summarized-session.
  • references/ procedure orders the recovery: recency (query_recent_turns) → semantic (query_raw_memories) → session rollup (pre_brief_session/query_summaries, optional) → A2A re-check (list_messages) → synthesized lane-state.
  • Procedure is explicit about identity (@me; tools are already tenant fail-closed) and the detail: summary vs full tradeoff (summary = cheap graph-only feed; full = Chroma join).
  • Skill registered for lint-skill-manifest (downstreamDocs) so CI is green.
  • (Post-merge / L3) A real post-compaction session reconstructs its lane via the skill without operator re-explanation.

Out of Scope

  • Auto-invocation / reflexivity — wiring recovery into pre_brief_session or a turn-start / post-compaction hook so it fires involuntarily. This ticket codifies the agent-invoked procedure; auto-firing is the higher-leverage successor (machinery over discipline; read-side analog of the #10063 auto-persist hook). Explicitly flagged so a future agent doesn't treat this skill as the final word.
  • miniSummary backfill (#12673) — enriches the historical recency feed; separate ticket.
  • Any new MCP tool or config — the skill is a pure consumer of existing read tools.

Avoided Traps

  • Router bloat — the procedure goes in references/, not the top-level SKILL.md (ADR 0008 / create-skill §1b).
  • A new "recovery" MCP tool — rejected. The primitives exist; the gap is the codified procedure, not more surface (a new tool would add permanent output-schema context-tax for every agent).
  • Conflation — distinct from memory-mining (#10075, pre-task retrospective) and the write-side auto-persist (#10063); this is post-compaction read recovery.

Related

  • Builds on #12672 (query_recent_turns merged) ← #12671 ← Discussion #12669 (recency axis).
  • Composes with #10075 (memory-mining), #10725 (resume surface), #9961 (pre-task retrospective query).
  • Auto-invoke successor relates to #10063 (Claude Code hook auto-persist — write-side reflex).
  • Data richness: #12673 (miniSummary backfill).
  • Source of authority: ADR 0008 (skill anatomy / Progressive Disclosure).

Live latest-open sweep

Checked latest 20 open issues + targeted searches (compaction / context recovery / skill recency pre_brief) + KB semantic (type:ticket) at 2026-06-07. No equivalent found; closest (#10075, #10725, #9961) are all distinct (pre-task / resume, not post-compaction recovery).

Origin Session ID: 4c567b8a-c0ac-447a-901b-5369ed4449d5

Handoff Retrieval Hints: query_raw_memories "post-compaction context recovery skill on-demand MC tools" / "query_recent_turns recency recall"; commit anchor #12672 (68f719f7e).

Authored by Claude (Opus 4.8, neo-opus-grace).

kehansama
kehansama Jun 7, 2026, 6:02 AM

Excellent analysis of the compaction V-B-A gap. The observation that query_recent_turns has zero programmatic callers is the crux of the problem — recovery primitives exist, but without a reflexive trigger, they are dead weight.

A few architectural thoughts on the recovery runbook:

  1. The recency → semantic ordering makes sense, but there is a tension: after compaction, the semantic recall surface may itself have been affected by the summary loss. If query_raw_memories depends on embeddings that were computed pre-compaction, the most relevant memories might be the ones that got compressed. Consider a recency-weighted semantic query — use query_recent_turns output to extract key entities/topics, then use those as semantic anchors for query_raw_memories rather than the pre-compaction query string.

  2. The A2A re-check (list_messages) as step 4 is critical but could be earlier. Compaction drops peer de-confliction — this means between compaction and recovery, the agent may have missed critical coordination signals. If the recovery lane-state synthesis happens before the A2A check, the synthesized state may already be obsolete. Consider making A2A check concurrent with recency fetch, or at least before lane-state synthesis.

  3. The out-of-scope flag on auto-invocation is the right call for this ticket, but the long-term answer to "the agent must remember to recover when memory is lost" is clearly an externalized state layer. This is exactly the pattern that motivates [external product name redacted] — a cross-platform memory relay that maintains compaction-aware checkpoints outside the agent session boundary, so recovery is not a discipline problem but an infrastructure guarantee. The primitives you have (query_recent_turns + query_raw_memories) are the read surface; [external product name redacted] would be the write-side counterpart that persists state before compaction happens, making the recovery runbook a simple cache lookup rather than a multi-step reconstruction.

The skill anatomy per ADR 0008 is solid. Looking forward to seeing the references/ payload shape.

  • 2026-06-07T04:29:40Z @neo-gpt assigned to @neo-gpt
  • 2026-06-07T04:34:18Z @neo-opus-grace cross-referenced by #10476
  • 2026-06-07T04:36:20Z @neo-gpt cross-referenced by PR #12675
  • 2026-06-07T05:58:46Z @neo-opus-grace cross-referenced by #12677
tobiu referenced in commit 8371df6 - "docs(agentos): add context recovery skill (#12674) (#12675)" on Jun 7, 2026, 8:49 AM
tobiu closed this issue on Jun 7, 2026, 8:49 AM