Skip to content

Checkpoints record git state and warn on drift (stacked on #50) - #51

Open
jbwinters wants to merge 6 commits into
feat/hot-injection-dedupfrom
feat/checkpoint-git-state
Open

jbwinters wants to merge 6 commits into
feat/hot-injection-dedupfrom
feat/checkpoint-git-state

Conversation

@jbwinters

@jbwinters jbwinters commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Task Master 164. Stacked on #50; review the top two commits.

Problem. Hot checkpoints carried no HEAD, branch, dirty or untracked-file state, and captured command output had no revision. A session in another checkout, on another machine, or after the tree moved on trusted results observed on different bytes.

Changes

  • Capture. Evidence captured at Stop, PreCompact and PostToolUse records the workspace's git state:

    • one git status --porcelain=v2 --branch -unormal call, with a 1.5 s timeout and no optional locks;
    • up to 10 untracked files with content hashes; names that look private are left out.

    Command output is stamped with the commit it ran at.

  • Render. The saved state is compared with the reader's tree:

    • one Workspace drift line (at most 320 characters) when HEAD, branch, uncommitted changes or untracked files differ;
    • file excerpts that are gone or changed on disk are marked;
    • command output run at another commit is marked;
    • in the same checkout, nothing is shown.
  • Dropped sources keep their name and digest and are listed as "not kept".

  • Compatibility. The new field is optional and travels inside the opaque evidence, so older clients drop it. Metadata is bounded and is dropped before any excerpt when a checkpoint is over the 30,000-character sync budget.

  • Warning only. Nothing is restored or rewritten.

Handoff capsules (070d3f4, narrowed in the next commit). The Claude Code and Codex handoff export records the exporting workspace's commit, branch and dirty state in continuityIr.provenance.workspace. No untracked file names or hashes are included, and deal handoffs to another party never carry it. The field is optional and signed with the capsule, and older importers ignore it. Import attaches it to the imported checkpoint, so a handoff opened in a different tree shows the drift line. Further tests cover a hanging git (null within the timeout) and a synced document carrying git state passing the unchanged wire validator.

Verification

  • vitest run on Node 22.23.4 passes: 81 files, 713 tests.
  • New tests are in tests/runtime/workspace-state.test.ts. They cover:
    • a temp git repo;
    • a moved tree;
    • the same checkout, including a symlink, a large file and sed-named sources;
    • traversal and absolute synced paths;
    • a symlink escape;
    • a FIFO;
    • git missing from PATH;
    • the sync budget with maximum metadata.
  • An independent review found seven defects. All are fixed in the top commit.

Hot checkpoints carried no HEAD, branch, dirty or untracked-file state,
and captured command output carried no revision, so a session in another
checkout or after the tree moved trusted results observed on other bytes.

- Evidence captured at Stop, PreCompact and PostToolUse records the
  workspace's git state (one 'git status --porcelain=v2', 1.5 s timeout,
  no optional locks; untracked files hashed, at most 20, private names
  skipped). Command output is stamped with the commit it ran at.
- Rendering compares with the reader's tree: one 'Workspace drift' line
  when HEAD, branch, uncommitted state or untracked files differ; file
  excerpts no longer on disk or changed are marked; command output run
  at another commit is marked. Same checkout: nothing.
- Sources dropped to fit a bound keep their name and digest and are
  listed as not kept.
- The field is optional inside the opaque evidence: older clients drop
  it, sync budget unchanged. Warning only; nothing is restored.

Handoff capsules do not carry git state yet. Task Master 164.
… and latency

From an independent review:
- Only sources that plainly name a file (a path, or one cat/head/tail/sed
  read) are checked on disk; command-named reads were always 'missing'.
- An untracked entry captured without a hash (symlink, large or
  unreadable file) is checked for presence only.
- Synced untracked paths must be workspace-relative (no '..', absolute
  or NUL); reads lstat first, open with O_NOFOLLOW|O_NONBLOCK, require a
  regular file and check realpath containment, so a FIFO cannot block a
  hook and a symlink cannot read outside the workspace.
- Metadata is bounded (10 untracked, 8 dropped names, 160-char paths) and
  is dropped before any excerpt when a checkpoint is over budget.
- git status uses -unormal; drift and file checks are computed once per
  prompt; the drift line is capped at 320 characters.
- The private-name filter covers more secret-like names.
# Conflicts:
#	src/runtime/host-adapter-base.ts
…and round-trip tests

- Export records continuityIr.provenance.workspace (head, branch, dirty,
  filtered untracked names) for the exporting workspace. The field is
  optional and signed with the capsule; older importers ignore it.
- Import attaches it as evidence on the imported checkpoint, so opening
  the handoff in a different tree shows the drift line.
- Tests: export and import through the lifecycle engine, a git that
  hangs (null within the timeout), and a synced document with git state
  that the wire validator accepts unchanged.
From a fresh review: every capsule, including deal handoffs uploaded to
a counterparty, carried branch, HEAD, dirty state and untracked file
names with content hashes.

- Only the Claude Code and Codex handoff export opts in; deal handoffs
  and other callers never carry it.
- A capsule carries commit, branch and dirty state only: no untracked
  names or hashes leave the machine. Hot sync (own devices) is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant