Editing State File Format - NiclasOlofsson/remember-mcp-vscode GitHub Wiki


title: Editing State File Format description: Structure and semantics of chat editing state timeline (linearHistory/stops/entries) with telemetryInfo correlations.

Editing State File Format (chatEditingSessions/<sessionId>/state.json)

This document explains the fine-grained editing timeline file that coexists with (but is separate from) the canonical chatSessions history. It captures incremental multi-file edit evolution, undo boundaries, and per-file telemetry request identifiers.

1. Purpose

Provide a replayable timeline of an editing turn's internal phases: which files changed, at which undo boundary, and under which underlying model request (telemetryInfo.requestId). Enables:

  • Accurate counting of model (HTTP) calls that led to persisted edits.
  • Distinguishing context (unchanged) files from actively modified ones.
  • Reconstructing per-file diff progression across "stops".

2. Hierarchical Structure

{
  version: number,
  sessionId: string,
  linearHistory: [ TurnTimeline, ... ]
}

TurnTimeline (conceptual turn): {
  requestId: string,          // turnId (high-level)
  stops: [ Stop, ... ]
}

Stop (undo boundary): {
  stopId?: string,            // absent for initial placeholder stop
  entries: [ FileEntry, ... ]
}

FileEntry: {
  resource: string,           // file URI
  languageId: string,
  originalHash: string,       // file content hash before this turn (empty sentinel possible)
  currentHash: string,        // hash after this stop
  state: number,              // small status flag (0/1 observed)
  snapshotUri: string,        // internal snapshot reference
  telemetryInfo: { requestId: string, agentId: string }
}

3. Semantics of Each Layer

Layer Role Cardinality
Turn (requestId) High-level editing/chat turn 1..N per session
Stop Undo/redo boundary (phase) inside a turn 1..M per turn
Entry Per-file snapshot at that boundary 1..K per stop

3.1 Turn vs Model Request

Turn (requestId) groups user-visible action; model request (telemetryInfo.requestId) is the underlying backend invocation that produced specific file modifications. A turn may reference multiple distinct model requestIds (retries, staged generations, refinement phases) or inherit untouched files from prior turns retaining their original telemetry IDs.

3.2 Stops (Undo Boundaries)

Each stop represents a cohesive batch of changes such that one editor undo would revert the group. Multiple stops appear as the agent refines output or files are sequentially updated.

3.3 Entries (File Snapshots)

An entry captures the file's state after applying changes for that stop. Re-emission across stops allows full reconstruction without computing cumulative diffs.

4. Hash & Change Detection

Change detection logic for enrichment:

changed = (
  firstAppearance && originalHash !== currentHash
) || (
  previousStopHash !== currentHash
)

Only entries producing changed = true should count toward model request attribution (to avoid inflating counts with carry-over context entries).

5. Telemetry Correlation

Field Meaning
telemetryInfo.requestId Backend model invocation ID (matches logs’ requestId field). Use this to correlate with log scanner output.
telemetryInfo.agentId Agent persona responsible for the edit (e.g., github.copilot.editsAgent).

5.1 Relationship Cardinalities

Model Request → File Entries: 1 → many (one model invocation can modify multiple files in a stop or across consecutive stops if the same invocation ID persists). Turn → Model Requests: 1 → many (retries, staged passes) BUT the file may retain older telemetry IDs for unchanged context.

6. Differentiating Context vs Active Edits

Context (carry-over) entry heuristics:

  • originalHash === currentHash on first appearance AND never changes in later stops.
  • All appearances of that resource share a telemetryInfo.requestId ≠ parent turnId and the file never changes → purely contextual.

Active edit entries are those where at least one stop yields changed = true.

7. Proposed Enrichment Output

For each turn (top-level requestId):

modelRequestIds: string[]                // unique telemetryInfo.requestIds for *changed* files only
allModelRequestIds?: string[]            // (optional) including context
modelRequestsCount: number               // modelRequestIds.length
contextOnlyRequestIds?: string[]         // telemetry IDs seen but no file changes
changedFiles: number                     // number of files with >=1 change
stops: number                            // total stops for this turn

8. Analytics & Debug Use Cases

Goal Fields Used Notes
True model call count per day Σ modelRequestsCount More accurate than counting turns.
Materialization rate modelRequestsCount vs log model requests Measures how many backend calls produce persisted edits.
Retry detection Multiple telemetry IDs within a single turn Distinguish sequential vs parallel attempts.
File churn changedFiles per turn / day Indicates scope of edits.

9. Pitfalls & Edge Cases

Pitfall Mitigation
Counting context telemetry IDs as active Filter by hash change.
Assuming stopId globally unique Treat stopId as turn-scoped helper only.
Over-attributing unchanged re-emissions Track last seen hash per resource.
Missing state file (deleted/rotated) Skip enrichment gracefully; keep base event.

10. Integration Strategy

  1. Implement EditStateScanner to locate and parse state files.
  2. Build per-turn summaries (hash tracking + telemetry sets).
  3. Enrich existing usage events post SessionDataTransformer using (sessionId, requestId) key.
  4. Add debug command to dump correlation vs logs.
  5. (Optional) Feature flag the enrichment initially.

11. Future Enhancements

Enhancement Description
Net-effect diff classification Classify changes as additive / refactor / revert using before/after hashes content inspection.
Latency attribution per model request Combine with log timing to produce phased latency breakdown within a turn.
Context utilization score Ratio of referenced but unchanged files to changed files.

Revision History:

  • v1 (initial extraction) – codifies observed semantics & enrichment strategy.
⚠️ **GitHub.com Fallback** ⚠️