Skip to content

fix(write): advance the cached branch after publishing - #33

Merged
yuezengwu merged 1 commit into
mainfrom
fix/publish-advances-cache-ref
Nov 4, 2026
Merged

yuezengwu merged 1 commit into
mainfrom
fix/publish-advances-cache-ref

Conversation

@liuchao-001

Copy link
Copy Markdown
Contributor

Problem

In 1.1.0, write finish --publish pushes to origin but leaves the repository cache's refs/remotes/origin/<ref> and its fetch record unchanged. A sync on the same machine within the 60-second fetch window then reuses the cached ref and returns the pre-publish snapshot. An agent, or another project on the same cache, cannot read a write it just published. This breaks OpenTag's Context Tree integration tests when it is bumped to 1.1.0.

Fix

  • recordPublished (src/sources/resolve.ts) runs after a successful push. Under the repository cache lock it moves refs/remotes/origin/<ref> from the session's base commit to the published commit with git update-ref <ref> <new> <old>, then records a fetch for that ref. The push proves the remote held that commit at that moment.
  • If the ref already holds the published commit, only the fetch time is recorded.
  • If the ref holds anything else, or the compare-and-swap loses a race, that ref's fetch record is dropped and the next sync fetches.
  • docs/specification.md describes this under write completion.

Tests

In tests/fetch-freshness.test.ts:

  • Connect two projects to the same cache, publish from one, then sync both inside the window. Both resolve the published commit and its file, with no extra fetch. This test fails without the fix.
  • When the cached ref no longer holds the base commit, the ref is left unchanged, the fetch record is dropped, and the next sync fetches.

Validation

Command Result
pnpm check passed
pnpm typecheck passed
pnpm test 14 files, 128 tests passed
pnpm check:package passed

After merge: release 1.1.1, then bump OpenTag and First Tree (first-tree-ai/first-tree#2431) to 1.1.1.

🤖 Generated with Claude Code

A publish pushed to origin but left the repository cache's remote-tracking
ref and fetch record unchanged, so a sync on the same machine within the
60-second fetch window resolved the pre-publish commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@yuezengwu yuezengwu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 65609201e8198ba4dcd38c21f09ffce900bb65a2 on current main 32f0c180ef1c297f025a6645cee017d2e4d67330. After a successful nonforce push, the shared repository-cache lock and compare-and-swap update preserve branch identity while making the published commit visible inside the fetch window. A mismatched or raced ref is left intact and only its freshness record is evicted, so the next sync fetches; unrelated ref records and failed write sessions are preserved. The existing cached-object repository is shared with the publishing worktree, so the published commit is available to update-ref.

Independent validation: pnpm check, pnpm typecheck, the complete test suite, and pnpm check:package all pass, including two projects sharing the cache and the mismatched-ref fallback. No remaining code finding. No live remote write, global skill installation, release tag or npm publication was performed; current CI and repository merge gates still apply.

@yuezengwu
yuezengwu merged commit a089f69 into main Nov 4, 2026
3 checks passed
@yuezengwu
yuezengwu deleted the fix/publish-advances-cache-ref branch November 4, 2026 18:56
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.

2 participants