Skip to content

fix(v2): mark nested Git symlinks and alternates incomplete in reclaim digest - #435

Merged
EricWvi merged 2 commits into
ora-space:mainfrom
wanglongan587:fix/1387-nested-git-symlink-digest
Nov 23, 2026
Merged

EricWvi merged 2 commits into
ora-space:mainfrom
wanglongan587:fix/1387-nested-git-symlink-digest

Conversation

@wanglongan587

@wanglongan587 wanglongan587 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs ora-space/circus#1387
Parent: ora-space/circus#1354

Summary

Fixes a fail-open gap in workspace reclaim preview (gitIdentity): when a nested repository uses symlinks, objects/info/alternates, or .git/modules/<name>/commondir inside its nested Git metadata, tree only hashed link paths/targets without failing closed. A symlinked or external shared Git target could therefore change commits, refs, objects, or index state outside the bound digest, letting discard proceed against an unchanged revision and delete unpreviewed Git state.

Following D2 of the reclaim design (digest without following symlinks and fail closed when exact content cannot be verified), symlinks and objects/info/alternates inside nested Git metadata are now marked incomplete (GitIdentityComplete = false), causing discardable to become false and discard to return 409 discard_unverifiable.

Changes

  • v2-server/internal/workspacefs/reclaim_check.go
    • Reject symlinks, special files, and objects/info/alternates inside nested Git directories via digester.gitTree, digester.walkTree, digester.checkGitDir, and digester.rejectAlternates.
    • Track checkedGitDirs alongside digested in gitIdentity so nested repo/.git directories already hashed during tree(root, repo) still undergo strict nested-Git validation.
    • Reject commondir entries inside .git/modules/<name> and reject nested GitDir/CommonDir resolving to the checkout root (rel == ".").
    • Keep symlinks in nested repositories' working trees valid (GitIdentityComplete = true).
  • v2-server/internal/workspacefs/reclaim_check_test.go
    • Add TestInspectReclaimMarksSymlinksAndAlternatesInNestedGitIncomplete covering 8 fail-closed cases (symlinked nested refs/objects, symlink inside gitfile target, symlinked .git/modules/<name>, commondir inside .git/modules/<name>, objects/info/alternates, symlinked nested index, symlink inside commondir target, symlink inside .git/modules/<name>) plus working-tree symlink regression check.
  • v2-server/internal/workspacereclaim/reclaim_test.go
    • Add TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates (symlinked shared Git state, symlinked nested index, alternates, symlink swapped in after preview -> ErrDeletionPreviewStale / ErrDiscardUnverifiable) and TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository.
  • v2-server/internal/workspacefs/README.md & v2-server/README.md
    • Document that symlinks and objects/info/alternates inside nested Git directories make the digest incomplete (discardable = false).

Specs / ADR Status

  • Target ADR in ora-space/specs: decisions/cloud/project-git/20261119-reclaim-deleted-conversation-workspace.md (currently status: implemented).
  • Per our workflow, after this PR passes review and is merged, a follow-up specs landing run will add the nested-Git symlink/alternates fail-closed clarification and update test-cases/cloud/project-git/workspace-reclaim.md evidence with the merged commit SHA.

Verification

Run in WSL as non-root wanglongan (uid=1000) against PostgreSQL 18 (TEST_DATABASE_URL="postgres:///ora_1354_test?host=/var/run/postgresql"):

  • gofmt -l ./internal/workspacefs ./internal/workspacereclaim -> empty (gofmt ok)
  • go vet ./... -> pass
  • go build -buildvcs=false ./... -> pass (VCS stamping disabled only for UID mismatch across WSL DrvFs mount)
  • go test -race -count=1 ./internal/workspacefs ./internal/workspacereclaim ./internal/gitexclude ./internal/store ./internal/chat ./internal/boot ./internal/agentruntime ./internal/server -> all 8 packages ok (workspacefs 6.400s, workspacereclaim 19.786s, gitexclude 1.101s, store 59.550s, chat 4.225s, boot 1.011s, agentruntime 5.997s, server 80.238s)
  • go test -v -race -count=1 ./internal/workspacefs -run "TestInspectReclaimMarksSymlinksAndAlternatesInNestedGitIncomplete" -> 9/9 subcases PASS (0.53s)
  • go test -v -race -count=1 ./internal/workspacereclaim -run "TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates|TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository|TestReclaimRetriesWhenHEADsObjectIsUnreadable" -> all PASS (TestReclaimRetriesWhenHEADsObjectIsUnreadable 0.31s, TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates 4/4 subcases 1.61s, TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository 0.30s)
  • git diff --check -> pass

@zhangxinhao zhangxinhao 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.

LGTM(c50c648)

@wanglongan587 我看了这个 PR,理解它是要在嵌套 Git 元数据含符号链接、特殊文件或 alternates 等无法完整验证的内容时拒绝丢弃工作区,同时继续允许嵌套工作树里的普通符号链接。可以合并。已覆盖常见的嵌套 Git 目录布局,建议后续补齐工作树已移除、名称含斜杠的子模块。

  • 🔧 1 处小改已写成建议(nit-1):见行内 suggestion,可以一键采纳,也可以不改或留到以后。
  • 📌 建议另开 PR 处理:P2-1 多层子模块目录漏检共享 Git 状态(不影响这次合并)
  • 测试:go test -race -count=1 -timeout=4m ./internal/workspacefs -run 'TestInspectReclaim' 通过;go test -v -race -count=1 -timeout=4m ./internal/workspacereclaim -run 'TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates|TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository' 没跑(未设置 TEST_DATABASE_URL,所有选中的集成用例均被跳过。);git diff --check bec67e2a2404402e060ef94e81d630ca034e1644 HEAD 通过;没跑全量和 e2e。

涉及删除数据,建议 owner 再看一眼。

以上都是建议,怎么处理由你决定。

自动检视 · 基于 c50c648 · 第 1 轮(全量)

Comment on lines +324 to +327
if _, err := modules.Lstat(path.Join(name, "commondir")); err == nil || !errors.Is(err, fs.ErrNotExist) {
d.incomplete("commondir inside nested module", err)
}
d.gitTree(modules, name)

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.

P2-1(建议) git submodule deinit 后,名为 group/lib 的子模块仍会在 .git/modules/group/lib 保留 Git 元数据,工作树里已经没有 .git 供后续解析。gitState 只枚举 modules 的直接子项,所以这里检查的是 group 根下的 commondir 和 objects/info/alternates,漏掉了真正的子模块目录。若它引用了 checkout 内被忽略的共享 Git 状态,该状态变动后 revision 仍可能保持不变,旧确认可以删掉未预览的数据。建议按实际的子模块 Git 目录执行检查,并补一条 deinit 后仍应拒绝丢弃的回归测试。

改动较大,建议另开 PR 处理,不影响这次合并。

Comment on lines +1435 to +1437
if status := git(t, wt, "status", "--short"); !strings.Contains(status, "lib.txt") {
t.Fatalf("unexpected git status through symlinked index: %q", status)
}

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.

nit-1(可选) status --short 里出现 lib.txt 也可能只是报告未跟踪或删除,无法证明 Git 通过符号链接读到了暂存内容。直接读取 index 里的 blob,也能避免 status 刷新索引。

Suggested change
if status := git(t, wt, "status", "--short"); !strings.Contains(status, "lib.txt") {
t.Fatalf("unexpected git status through symlinked index: %q", status)
}
if got := git(t, wt, "show", ":lib.txt"); got != "staged" {
t.Fatalf("staged content through symlinked index = %q, want %q", got, "staged")
}

可直接采纳,也可以不改。

@EricWvi
EricWvi merged commit fe0b378 into ora-space:main Nov 23, 2026
3 checks passed
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.

3 participants