Skip to content

context-refresh --once and charter_context serve a stale snapshot as fresh after a branch, HEAD or working-tree change #440

Done

Description

@stackbilt-admin

Problem

shouldSkipRefresh (context-refresh.ts:431) compares only generatedAt against the TTL. loadCharterContextSnapshot (serve.ts:656) returns the file as-is. After a branch switch, a new commit, or an edited file, the hook reports fresh_snapshot and MCP charter_context serves the old branch and dirty state with no staleness signal.

A resuming agent, the exact case this surface exists for, gets a wrong answer stated with confidence, while git status is right in one call.

Reproduction (pinned 5412100; both reviewers reproduced it independently)

charter context-refresh --sources git            # snapshot on main, clean
git checkout -b scratch/x HEAD~5; echo "// wip" >> some/file.ts
charter context-refresh --once --format json     # "status":"skipped","reason":"fresh_snapshot"
# .ai/context.snapshot.json still shows the old branch, dirty:false, the old top commit

Expected

  • --once skips only when the stored git fingerprint (branch, full HEAD SHA, dirty-file set) matches the live repo. Expensive non-git sources may keep the TTL.
  • charter_context (and the snapshot JSON) adds stale: boolean and staleReasons: string[]. Additive fields only; existing keys unchanged.
  • Snapshot stores the full HEAD SHA.
  • Generated snapshot and telemetry files don't count as dirty, so refreshing never invalidates itself.

Acceptance (one TTL window, one test each)

Branch switch at the same SHA, a commit on the same branch, a dirty-file edit: each refreshes, or reports stale:true with a reason. An unchanged repo still takes the cheap skip path.

Works on its own. Part of #437 (the preflight freshness stamp depends on it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugepic:preflightpriority:p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions