Repository navigation
feat(scope): worktrees of one repository share kept answers - #173
Merged
Merged
Conversation
Each git worktree kept its language-server answers only under its own .coherence/structure, so a new worktree's first Structure reading started a cold TypeScript server and asked every question again, though another worktree of the same repository had just answered them. On glimmervoid a new session worktree paid 99 s and a 1.7 GB tsserver for it (#170). Kept answers already carry no absolute path: they are keyed by relative path, each file's sha256 and a basis of Coherence's version, adapter code and config. So a worktree with none of its own now seeds from <git common dir>/coherence/structure/answers-<language>.json, and every save writes its own file and that shared one. A seed reuses only the answers whose hashes still hold in this tree; the rest are asked. writeAtomically moves to shared-structure.ts so gaps.ts and the kept answers share one. Rejected: sharing whole readings by fingerprint | answers alone remove the cold server, and a seeded reading of an unchanged tree asks nothing Rejected: a per-repository lock | the shared file is written atomically and a lost write only costs a later re-ask Confidence: high Scope-risk: narrow Ticket: coherence-worktree-readings/U3
The worktree seeding had a test but no bullet. "a new worktree starts from the repository's kept answers" now names it in Scope.spec.md, with a refutation recorded by refute (load reading only the worktree's own file turned the test red) and witnessed green batched and alone. Confidence: high Scope-risk: narrow
…share only from tracked folders, and ask git as any version answers - The shared copy is answers-<lang>-<project digest>-<basis digest>.json in the git common folder, the four most recent kept per project and language, so monorepo projects and branches whose manifests or lockfiles differ no longer overwrite each other; a worktree whose own file does not hold falls back to the copy its basis names. - Only a project folder the checked-out commit tracks shares: an untracked folder inside another repository writes nothing into its .git. - The common folder is asked without --path-format (which git before 2.31 echoes back), resolved against the root, with the git hook location variables stripped; mod-install's localSettingsPath uses the same helper. - writeAtomically uses a random temporary name and removes it on failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the basis digest alone after it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing and git-age resolution as invariants, each refuted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efused file by its project-relative path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Part of #170. Kept answers live in each worktree's own
.coherence/structure, so a new git worktree's first Structure reading cold-starts tsserver and asks everything again, even when another worktree of the same repo answered it all a minute ago. On my repo that's 99 s and a 1.7 GB tsserver for every new worktree, which hurts when an agent tool makes a worktree per session.Changes
KeptAnswers.load()reads the worktree's own file first, then the shared one when it has none. Answers are only reused where the hashes still hold in this tree; the rest get asked.save()writes its own file and the shared one. A failed shared write is ignored like a failed own write.shared-structure.ts:sharedStructureDir(root)(git rev-parse --git-common-dir, cached per root, undefined outside git) andwriteAtomically, moved fromgaps.tsso both use one.Scope.spec.md: new bullet "a new worktree starts from the repository's kept answers".How did you test this code?
refute(makingload()read only the worktree's own file): red on the test's own assertion, then green batched and alone withrun --invariant ... --each. The run records are in the PR..coherence/structurealone no longer empties the answers.component-interfaces.test.tsandgaps.test.tspass (19/19 with the kept-failures PR merged in too). Typecheck,lexicon:checkandspec:checkpass.The 3 at once each asked 15 because the shared file held the other commit's answers (last writer wins).