Repository navigation
fix(storage): ignore invalid ancestor Git markers - #4807
Conversation
hqhq1025
left a comment
There was a problem hiding this comment.
I found one correctness gap in the ancestor-marker validation. The patch fixes the reported missing-HEAD shape, but other structurally invalid ancestor markers still enter the Git path and fail project/workspace resolution. The exact-head build, Storage typecheck, full Storage suite (1,113 passed, 10 skipped), Biome, ASF header audit, diff check, and a patch-preserving merge onto current main passed. GitHub currently exposes only the label check for this head.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
7b0a560 to
79730f7
Compare
hqhq1025
left a comment
There was a problem hiding this comment.
I found one remaining correctness gap in the new Git-directory validator. The newly added fixtures cover the four previously reported malformed shapes, but malformed symbolic HEAD refs can still enter the Git path and fail both project and workspace resolution. Clean installation, build:test, Storage typecheck, the full Storage suite (1,125 passed, 10 skipped), focused affected tests (42/42), changed-file Biome, ASF headers, diff check, and a clean patch-preserving merge onto current main (774389072) passed. GitHub exposes no hosted checks for this head; native Windows path and symlink behavior was not run locally.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed exact head 108d0ab24b9e21169399eeea226d8d834a8cbb70. The change correctly stops the covered malformed ancestor .git shapes from being treated as repositories, but one valid detached-HEAD form is still rejected.
Local verification passed: clean install, build:test, Storage typecheck, the focused project/workspace suites (42/42), the full Storage suite (1125 passed, 10 skipped), Biome, repository format, ASF headers, git diff --check, and a clean merge-tree against current main c0229b0c6. GitHub exposes no hosted checks for this head.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks for delegating Git-format interpretation to Git. At fa427ad34, the previous malformed-format issues are resolved, but two negative-probe paths still bypass the enclosing repository and its marker-ignore obligation. Both were reproduced with real Git and the exact-head production workspace resolver. Please retain Git as the format authority while distinguishing invalid, inaccessible, and not-yet-found ancestors; do not restore a handwritten HEAD parser.
中文
委托 Git 识别格式的方向正确,旧格式问题已修。仍有两个负向探测路径绕过真实仓库和 marker 忽略义务,已用真实 Git 与当前生产 resolver 复现。应区分无效、不可读和尚未找到祖先,不恢复手写 HEAD 语法。
AI-assisted review using OpenAI Codex/Astra; coordinating-agent checks and probe limits are stated above. This is not an independent human review.
fa427ad to
76ac9d4
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Verified against head 76ac9d4. My earlier negative-probe findings are resolved — unreadable ancestor metadata now throws, execution failures (missing git, timeout, non-128 exits) fail closed, and the layered decisions mirror Git's own discovery (setup_git_directory_gently_1): selected-dir .git always wins, invalid .git directories are skipped, nearest-valid ancestor takes precedence. Both consumers re-derive the answer through git -C itself, so the probe can't produce a stale identity.
Three P3s, all non-blocking:
P3 — invalid .git file ancestors degrade where Git dies (② edge path). git-entry.ts:74-76,103-107 — Git aborts discovery fatally on any invalid gitfile (GIT_DIR_INVALID_GITFILE); the skip-and-continue behavior only exists for invalid .git directories, so the comment at git-entry.ts:46-47 overclaims parity. With no outer repo, a subtree under a stale submodule gitfile resolves folder: where Git errors; if the target reappears the identity flips to git: → duplicate project + session split. Bounded and recoverable via relink, and arguably a deliberate simplification — but either throw for non-directory .git 128s (matching Git and your own fail-closed invariant) or narrow the comment to directories.
P3 — unbounded, type-blind readFile of .git files (②/edge-③). git-entry.ts:104 reads any non-directory .git entry fully: a FIFO hangs the walk forever; a multi-GB file loads entirely (Git caps gitfile reads at ~1MB); a symlink-to-directory surfaces a raw EISDIR. Fix: only read when entryStat.isFile() and size ≤ ~64KB.
P3 — duplicated Git env scrub (minor). git-entry.ts:55-59 replicates gitEnvironment() (git-exec.ts:68-79) instead of sharing it; drift risk if the scrub list grows.
Rebase before merge — this head predates main's directory guard in project-catalog.ts:864-869 and same-region test additions in project-catalog.test.ts.
me2seeks
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.
Summary
Ignores invalid ancestor Git markers when resolving a nested folder: git-entry.ts now validates a discovered ancestor .git via git rev-parse --resolve-git-dir with a scrubbed environment (GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE/GIT_COMMON_DIR deleted, GIT_OPTIONAL_LOCKS=0, 3s timeout), continuing the outward walk when Git rejects the entry (exit 128) — mirroring Git's own behavior of skipping invalid directories and searching outward. Crucially, unreadable metadata still surfaces (execution failures rethrow; the selected directory's own broken metadata still returns true), so a missing Git executable cannot downgrade a repository to a plain folder. The fixture covers five broken shapes (HEAD as directory, garbage HEAD, gitfile with garbage target HEAD, symref missing refs/ prefix, missing objects+refs) and both catalog and workspace-identity tests pin the skip behavior.
Findings
- [P3] No CI has run on this branch ("no checks reported") — for a change touching project identity resolution (the seam that decides "repository vs plain folder"), the
testlane must run green before merge.
Verdict
merge-ready — correct Git-mirroring skip behavior with env scrubbing and honest failure surfacing; request CI.
3760780 to
821f0ba
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
Incremental review of 76ac9d40 → 821f0ba4 (rebased onto f10a74d8, plus the re-probe and docs commits). All three prior P3s are fixed. A non-directory 128 now throws. No readFile remains, and gitfiles go through bounded rev-parse --resolve-git-dir with the HEAD read capped at 255 B. The env scrub is shared via execGitText. The rebase is done, and main's 4 newer commits don't overlap.
One new P3 (inline). CI test passes, and the PR is mergeable.
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
Incremental review: 821f0ba4 (our last reviewed head) to d2ea6fd6. There is one new commit, "fix(storage): anchor git entry probes on the entry directory" (+30/-4). The merge-base with main is unchanged (f10a74d8).
The change. assertGitEntry used to run git -C process.cwd() rev-parse --resolve-git-dir <gitPath>. If the host's ambient cwd had been deleted or made unsearchable, -C failed with a generic exit 128, which was then read as Git rejecting the entry. It now anchors -C on parse(gitPath).dir, the directory that lstat just proved holds the entry. hasEnclosingGitEntry now starts from resolve(path), so every gitPath in the walk is absolute and no step depends on the inherited cwd. --resolve-git-dir still judges gitPath itself, so where Git starts does not change the verdict. The new test fakes process.cwd to a removed directory and checks that an enclosing repository is still found.
Findings: None at P0-P3. Earlier P3 notes are unchanged. CI test passes on d2ea6fd6, and the PR is MERGEABLE. No protocol files, so there is no epoch impact.
Generated-by: OpenAI Codex
An ancestor with valid .git/objects and .git/refs but HEAD set to `ref: gk` passed isGitDirectory(), while git rev-parse exits 128 on it. resolveProjectLocation() then threw and resolveWorkspaceIdentity() returned workspace_io_failed, so the malformed ancestor still blocked the nested-folder workflows this change is meant to recover. Git itself only accepts HEAD symrefs pointing under refs/ (verified: ref: gk, ref: HEAD, ref: gk/x all exit 128 even with objects/ and refs/ present; ref: refs/... passes even when the branch does not exist yet), so the check matches exactly that and no more. The case is added to the shared broken-metadata fixture as head-symref-no-refs-prefix, covering both the project-catalog and workspace-identity broken-ancestor tests.
…e snapshot Git's exit-128 rejection of an ancestor .git directory conflates a format verdict with metadata it could not actually read. Trust the verdict only after auditing the inputs is_git_directory consults (HEAD readable, objects/refs searchable) inside a stat snapshot, then re-probe and require the snapshot to be unchanged so repaired or replaced metadata cannot inherit a stale rejection. Entries that cannot be classified — commondir or GIT_OBJECT_DIRECTORY redirection, special files, gitfile/symlink indirection, and any failure on the selected directory's own .git — now surface as errors instead of silently downgrading to folder identity. Generated-by: OpenAI Codex
…xclusions Generated-by: OpenAI Codex
assertGitEntry ran git -C process.cwd() merely to give Git a place to start; --resolve-git-dir judges gitPath itself. When the host's cwd has been deleted or is unsearchable, -C fails before the probe runs and the generic exit 128 is taken as Git's verdict on the entry. The audit re-probes under the same broken anchor, a valid enclosing repository is skipped, and resolveProjectLocation silently downgrades it to folder:. Anchor -C on parse(gitPath).dir instead — lstat already proved that directory exists — and resolve() the walk start so a relative path can never hand the ambient-cwd dependency back through a relative -C. Generated-by: OpenAI Codex (swe-2)
d2ea6fd to
8c5817c
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
Incremental review: d2ea6fd6 to 8c5817c3. This is a pure rebase, from merge-base f10a74d8 onto 49c3ecc0 (main). There are no new author commits. Range-diff shows commits 1-6 and 8 unchanged. The only rewritten commit is 7 ("record new git marker and workspace identity Windows exclusions"), where docs/windows-test-inventory.md was rebased onto main's 6 new platform-contract rows:
- before: portable 53→56, platform 40→42, total 120→125
- after: portable 53→56, platform 46→48, total 126→131
The PR's own contribution is unchanged (+3 portable-candidate, +2 platform-contract). git diff d2ea6fd6 8c5817c3 restricted to the PR's files touches only that doc. The storage code and tests (git-entry.ts, the fixtures, git-entry, project-catalog, workspace-identity tests) are byte-identical to what we last reviewed.
Prior findings: none open. The earlier P3 notes are unchanged.
New findings: none. No protocol files are touched, so there is no epoch impact.
Mergeability/CI: CI test passes on 8c5817c3, which includes the inventory consistency check. git merge-tree against current main (2463d86c, one commit past the new base) is clean. GitHub's mergeable state was UNKNOWN (recomputing) when checked.
Verdict: clean rebase, no P0-P3 findings.
Astro-Han
left a comment
There was a problem hiding this comment.
Approved at @Astro-Han's explicit request: the automated review of this exact head found no blocking (P0–P2) issues, and CI is green.
Summary
hasEnclosingGitEntrytreated a folder as "inside a repository" whenever it couldlstata.gitentry, without checking that the entry was a repository Git can actually use. A structurally invalid ancestor.git— for example a.git/holding only unrelated subdirectories, or aHEADthat is not a valid symref underrefs/— therefore marked every nested plain folder as a repository. Classification passed that corrupted ancestor state to the downstream Git probe, which exits 128, and the add-folder action surfaced asproject.catalog.mutate → commit_outcome_unknown.This changes ancestor classification to defer to Git instead of trusting the filesystem entry:
.gitentry in a strict ancestor is accepted only when Git itself accepts it (git rev-parse --resolve-git-dir). When Git rejects the entry, the walk continues outward, matching how Git's own discovery skips markers it cannot use. Valid Git directories,gitdir:indirection files, repositories, and linked worktrees continue to resolve as before..gitentry in the selected folder itself still returnstruewithout consulting Git, preserving the existing fail-closed behavior for a malformed marker in the directory being classified.HEAD,objects,refs, or a gitfile's target — raises instead of being downgraded to an ordinary folder. Execution failures propagate for the same reason, so a missing Git executable cannot silently turn a repository into a plain folder.Regression coverage adds a shared fixture that writes broken Git metadata in several shapes (
HEADreplaced by a directory, garbageHEAD, aref:symref outsiderefs/, a gitfile pointing at a bare repo with a brokenHEAD, and a repository missingobjectsandrefs), together with tests for Project Catalog classification, workspace identity marker publication, and fail-closed behavior while an ancestor repository's metadata is unreadable.Fixes #4806
Review focus
Classification of strict ancestors now depends on the Git executable, so the tests exercise real
gitrather than a stub and the suite needs Git onPATH(the unreadable-metadata test uses POSIX permissions and is skipped on Windows). The exit-128 handling inisGitEntryis the subtle part: review that an invalid format and an unreadable repository stay distinguishable, since collapsing the two is what produced the original bug.Verification
npm --workspace @maka/storage run buildnpm --workspace @maka/storage run typechecknpm --workspace @maka/storage run test:dist— 1,112 passed, 8 skipped, 0 failednpx biome check packages/storage/src/git-entry.ts packages/storage/src/__tests__/project-catalog.test.ts packages/storage/src/__tests__/workspace-identity.test.tsnpm run check:asf-headerskind: 'folder'AI use
Select exactly one:
Tool(s) and scope: OpenAI Codex — root-cause analysis, implementation, regression tests, verification, and PR drafting.
Checklist
Does this PR entail a change in behavior?