fix: resolve graph freshness from repos nested under the project root - #640
Open
pgm-serdkara wants to merge 1 commit into
Open
fix: resolve graph freshness from repos nested under the project root#640pgm-serdkara wants to merge 1 commit into
pgm-serdkara wants to merge 1 commit into
Conversation
A parent directory holding several checkouts (e.g. `~/Code/Acme/{api,web}`)
is a valid analysis root, but it has no HEAD of its own. `getGraphFreshnessBatch`
built a single snapshot with `git rev-parse` in the project directory, so every
graph analyzed from such a root reported `git-head-unavailable` and the dashboard
showed a permanent "freshness could not be verified" banner. Re-running
`/understand` could not clear it, because the failure depends on where the
dashboard is pointed rather than on the age of the data.
When the root snapshot fails, scan one level down for directories containing
`.git` and resolve each graph against the nested repo that can verify its
commit hash. Hashes are unique, so ownership is unambiguous and no new
metadata is required — existing graphs resolve as-is. Resolution is per graph,
so knowledge and domain graphs may live in different sibling repos.
Timeouts do not trigger the scan, since it would multiply the wait by the
number of nested repos. When nested repos exist but none owns the commit,
the reason is now `graph-commit-unavailable`, which is more accurate than
`git-head-unavailable` once repos are known to exist.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes graph freshness evaluation when the configured project root is a non-repo parent directory containing multiple Git checkouts (nested repos). This aligns the freshness banner behavior with how graphs are actually produced (from a nested repo commit) so the dashboard can correctly verify freshness instead of permanently reporting git-head-unavailable.
Changes:
- Add a fallback path in
getGraphFreshnessBatchthat scans one level down for nested Git repos and resolves each graph against the repo that contains the graph’s commit. - Introduce helpers for nested repo discovery, snapshot creation, and commit ownership resolution.
- Expand integration tests to cover nested-repo scenarios and refactor repository setup helpers for flexible repo placement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| understand-anything-plugin/packages/core/src/staleness.ts | Adds nested-repo scanning + per-graph snapshot resolution when the project root has no Git HEAD. |
| understand-anything-plugin/packages/core/src/tests/graph-freshness.integration.test.ts | Adds integration coverage for nested-repo freshness resolution; refactors repo init helpers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
1
to
+3
| import { execFile, execFileSync } from "child_process"; | ||
| import { existsSync, readdirSync, type Dirent } from "node:fs"; | ||
| import { join } from "node:path"; |
Comment on lines
+234
to
+238
| repoDirs.map(async (repoDir) => { | ||
| try { | ||
| return await createProjectGitSnapshot(repoDir); | ||
| } catch { | ||
| return undefined; |
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
A parent directory holding several checkouts is a valid analysis root:
getGraphFreshnessBatchbuilds one snapshot by runninggit rev-parse --show-toplevel/rev-parse HEADin the project directory. That directory has no HEAD of its own, so the call throws and every graph is reported as:{"status":"unknown","reason":"git-head-unavailable","graphCommitHash":"0818f44…"}The dashboard then shows a permanent "Knowledge graph freshness could not be verified" banner. The confusing part for users is that re-running
/understanddoes not clear it — the trigger is where the dashboard is pointed, not the age of the data, so the banner reappears immediately after a fresh full rebuild. Note the endpoint reads the correctgraphCommitHashfrommeta.json; it simply has no HEAD to compare it against.Fix
When the root snapshot fails, scan one level down for directories containing
.git, and resolve each graph against the nested repo that can verify its commit viarev-parse --verify <hash>^{commit}.Three deliberate choices:
knowledgeanddomaingraphs can live in different sibling repos.git-command-timeoutstill returns immediately.When nested repos exist but none owns the commit, the reason is now
graph-commit-unavailablerather thangit-head-unavailable, which is more accurate once repos are known to exist. A genuinely empty non-repo directory still returnsgit-head-unavailableexactly as before.The scan is capped at 32 subdirectories and skips dotdirs and
node_modules, so a wide parent directory cannot spawn unbounded git processes.Tests
Four cases added to
graph-freshness.integration.test.ts, all against real Git repositories:freshstale/behindwith the rightheadCommitHashandchangedFilesgraph-commit-unavailablecreateRepositorywas refactored to share a newinitRepositoryAthelper so repos can be created at a chosen path.Verified on this branch's base commit:
pnpm --filter @understand-anything/core test→ 980 passed (46 files), including the pre-existinggit-head-unavailableandmissing-graph-commitcasespnpm lint→ cleanpnpm --filter @understand-anything/core build→ cleanAlso verified end-to-end against a real multi-repo parent directory: the dashboard's
/staleness.jsonwent fromgit-head-unavailableto{"status":"fresh","commitsBehind":0,"commitsAhead":0}, and the banner disappeared.🤖 Generated with Claude Code