Skip to main content

5. Time Machine & Incremental Patching

5.1 Snapshot Format

Snapshots capture the complete state of the code graph at a point in time:

{
"snapshot_id": "batho_<uuid>_<timestamp>",
"schema_version": "snapshot.v1",
"root": "/path/to/repo",
"created_at": "2026-05-17T12:00:00Z",
"graph": { /* InMemoryGraph serialized */ },
"bsg": { /* BSGMap serialized */ },
"metadata": {
"git_commit": "abc123",
"entity_count": 15420,
"relationship_count": 48230
}
}

5.2 Incremental Patch Lifecycle

The patch lifecycle ensures atomic updates with proper validation:

Figure 8: Incremental Patch Lifecycle - State diagram showing the atomic update process with validation and rollback support.

Patch States

StateDescriptionNext Possible States
DetectedFile changes identified via hash scanValidated, RolledBack
ValidatedChange limits checked, within boundsApplied, RolledBack
AppliedChanges applied to base snapshotConsistencyCheck, RolledBack
ConsistencyCheckGraph validation runningSnapshotted, Warning
WarningNon-fatal issues detectedSnapshotted
SnapshottedNew snapshot persisted[*]
RolledBackFailure occurred, changes reverted[*]

5.3 Patch Operation Record

Each patch operation is recorded with full audit trail:

FieldTypeDescription
operation_idUUIDUnique patch identifier
base_snapshot_idstringSource snapshot
new_snapshot_idstringResult snapshot
changes_appliedFileChange[]Ordered change list
patch_chainstring[]Lineage chain
metricsobjectTiming, token size, file counts
checksumSHA-256Integrity hash

FileChange Structure

{
"file_path": "src/services/user.py",
"change_type": "modified",
"entity_changes": [
{
"entity_id": "UserService.create",
"change_type": "updated"
}
]
}

5.4 CLI Commands

Snapshot Management

CommandPurpose
batho index --root . --snapshotCreate snapshot
batho snapshots --root .List snapshots
batho diff-snapshots --root . A BCompare two snapshots

Patch Operations

CommandPurpose
batho patch --root . --scanAuto-detect and apply changes
batho patches --root . --format timelineList patch history
batho patch-info --root . --patch-id IDShow patch details
batho apply-patch --root . --base-snapshot ID --diff-file changes.diffApply from diff
batho cherry-pick --root . --patch-id ID --target-snapshot IDCross-snapshot cherry-pick