[Feature] Preserve source seq/turn references in compaction summaries

Aperta
#5,461 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start by locating the compaction request assembly and persistence paths in the Kimi Code TypeScript codebase, then read the related issues #1896, #3361, and #5127 for existing constraints. Trace how automatic and manual compaction receive history and return summaries. Done means trusted source references survive validation, readback, restart, and repeated compaction, with the listed fallback and diagnostics behavior verified on the real host.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What feature would you like to see?

Requested scope: Kimi Work and, where applicable, the shared Kimi Code compaction/plugin infrastructure.

I would like compaction summaries to preserve verifiable references to the source events that supported important conclusions. A reference should identify the original seq range and turnId, so that a continuity plugin or an existing readback tool can retrieve the evidence instead of treating the summary as an unverifiable endpoint.

For example, an important conclusion in a compacted summary could remain readable as:

The participants decided to adopt source-referenced compaction. [seq 32932-32935 | turn-032932]

The preferred implementation is native structured provenance rather than requiring every plugin to parse inline text:

{
  "text": "The participants decided to adopt source-referenced compaction. [ref:r1]",
  "references": [
    {
      "id": "r1",
      "seqStart": 32932,
      "seqEnd": 32935,
      "turnId": "turn-032932"
    }
  ]
}
Why this is needed

Long-session continuity currently has a gap between semantic summaries and raw history. A host summary may preserve a decision while losing the coordinates needed to inspect the original exchange. A retrieval hit against that summary therefore does not provide a reliable path back to the evidence.

A plugin can build a separate memory index, but it cannot reliably complete the following chain through a supported API in the Kimi Work build examined for this proposal:

  1. Obtain the trusted message-to-seq/turnId mapping for the exact history being compacted.
  2. Add a source-reference requirement to the actual request sent to the compaction model.
  3. Have returned references validated against the compaction input.
  4. Persist those references with the host summary for later readback.

Without this connection, a plugin must ask a model to generate a second, parallel set of summaries. That duplicates model calls and compute, and the two summaries can diverge. Reusing the host summary with source references would avoid that duplication.

Preferred option: native source-referenced compaction

The host would:

  • attach trusted source metadata to compaction inputs;
  • ask the compaction model to preserve references for important facts, decisions, promises, experimental results, and state;
  • accept only references actually present in that compaction input;
  • reject, remove, or retry invalid, resized, reordered, or fabricated coordinates;
  • persist a machine-readable reference table with the summary;
  • preserve references through subsequent compactions, either directly or through a resolvable compactionId lineage.

Messages with ambiguous or unavailable mappings should remain unannotated rather than receiving guessed coordinates. Text that merely resembles a reference inside user content must not become trusted provenance.

Alternative: a versioned compaction-request preparation hook

If native structured references are not currently practical, a narrower supported hook would still solve the plugin use case:

interface CompactionReferenceV1 {
  seqStart: number;
  seqEnd: number;
  turnId: string;
}

interface CompactionRequestPrepareInputV1 {
  apiVersion: 1;
  sessionId: string;
  compactionId: string;
  trigger: "auto" | "manual";
  references: Array<{
    messageId?: string;
    reference: CompactionReferenceV1;
  }>;
}

interface CompactionRequestPrepareResultV1 {
  additionalInstruction?: string;
}

The hook would run after compaction history and instructions have been assembled, but before the compaction model is called. The plugin only needs to read the trusted reference mapping and append an instruction. The host should still own coordinate generation, output validation, reference persistence, and fallback behavior.

This does not require arbitrary kernel execution, replacement of the model, access to provider secrets, or unrestricted mutation of internal requests.

Required safety and compatibility behavior
  • Versioned capability detection, so plugins can degrade cleanly.
  • Session-scoped references; no cross-session access by default.
  • Deterministic behavior when multiple plugins are installed.
  • A bounded hook timeout and deterministic instruction-merging rules.
  • Fallback to the original compaction request on mapping or plugin failure.
  • No behavior change or extra model call when the feature/plugin is disabled.
  • Invalid model references must never enter the trusted reference table.
  • References must remain resolvable after restart and repeated compaction.
Acceptance criteria
  1. Both automatic and manual real-host compaction can produce source-referenced summaries.
  2. Every persisted reference belongs to the actual compaction input and can read back supporting source events.
  3. Fabricated, resized, or wrong-turn references are removed, isolated, or retried before commit.
  4. Duplicate content and duplicate assistant steps are reported as ambiguous/unmapped rather than guessed.
  5. Long messages, tool calls, tool results, and split chunks do not shift coordinates.
  6. A second compaction preserves the original references or a resolvable source lineage.
  7. References survive client restart and remain session-scoped.
  8. Disabling the feature preserves existing behavior; mapping failure, plugin failure, and timeout do not block compaction.
  9. Diagnostics expose at least mapped, unmapped, ambiguous, valid, removed, and error counts.

Additional information

Authorship

This requirement was drafted by Kimi (AI) from runtime observations, experimental analysis, and iterative continuity testing. It is submitted through the GitHub account @theseus-whale; the feature request and its acceptance criteria were synthesized by Kimi rather than presented as a human-maintainer specification.

Reference implementation

The target behavior can be illustrated by:

@theseus-whale/[email protected]
https://github.com/theseus-whale/dsh-continuity/tree/v5.0.10

That project demonstrates host-generated turn summaries, unified folding, exact seq readback, semantic recall, and chronological/semantic neighbor navigation. It is a behavioral reference only. This request does not ask Kimi to adopt DSH's architecture, tool names, or full feature set.

Existing proof of concept and its limits

A workspace-only experimental patch against a copied Kimi kernel bundle verified the basic mapping, instruction, sanitization, and fallback logic:

  • Node syntax check passed.
  • Sample mapping: 3 mapped, 3 unmapped, and 2 ambiguous messages.
  • Reference sanitization: 2 valid references retained and 4 invalid references removed.
  • Custom compaction instructions and source-reference instructions rendered together.
  • Mapping-failure fallback and diagnostic fields passed offline assertions.
  • Patched bundle SHA-256: 9d9a376b118fd4562617009b6ea5001eb6019b5f6617766a1fd6d1bd8f3446ef.

This is not a claim of end-to-end product verification. The patch was not installed into the live client; no real-host automatic or manual compaction acceptance test was performed. I am requesting a supported kernel capability, not asking users to maintain a modified bundle.

Related issues
  • #1896 concerns post-compaction context restoration and hook output, but not source references inside compaction summaries.
  • #3361 concerns compaction transparency, pinned facts, and retention budgets, but not source-coordinate provenance.
  • #5127 concerns headless compaction and observability. Its proposed result metadata would complement, but not replace, source references.

I searched for existing requests covering source-referenced compaction and did not find one with this contract. This is a feature proposal only; no feature PR is being submitted.

Lingua principale
TypeScript
Stelle
8.3k
Fork
1.4k
Merge medio
12h 6m
PR unite (30g)
596

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MoonshotAI/kimi-code

Tutte le issue di MoonshotAI/kimi-code

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.