find bugs in this repo. this repo has so many bugs. for better understanding, go thorugh all the readme and docs, understand what product does and the use case and then figure out exitsing bugs
Assistant
Now let me dive deeper into a few specific areas the agents flagged to verify the mostcritical bugs:
Assistant
User
so let's discuss each bug in deppth
Assistant
Let's go through them one by one. I'll start with the critical ones.
This is the bug this branch is named after. Let me explain the full chain:
How it fails:
code
1. You run `entire enable` inside a repo that has a submodule
2. An agent hook fires inside the submodule checkout
3. The hook calls InitializeSession → which calls GetWorktreeID
4. GetWorktreeID reads the submodule's .git file:
gitdir: ../../.git/modules/go-git
5. It searches for ".git/worktrees/" or ".bare/worktrees/"
6. Neither is found → returns error: "unexpected gitdir format (no worktrees)"
7. Session initialization ABORTS. Entire is completely broken in this submodule.
Here's a comprehensive bug report, organized by severity:
Git submodules have .git files pointing to .git/modules/<name> (not .git/worktrees/). The function errors with "unexpected gitdir format (no worktrees)", blocking all session initialization in submodule checkouts.
2. GetWorktreeID returns wrong worktree ID for submodule inside linked superproject worktree
File:cmd/entire/cli/paths/worktree.go:46
For a submodule inside a linked superproject worktree, the .git file contains something like gitdir: /repo/.git/worktrees/feature/modules/deps. strings.Cut(gitdir, ".git/worktrees/") incorrectly matches the superproject's worktree ID, returning "feature/modules/deps" instead of "".
3. GetWorktreeID cannot parse submodule's own linked worktree
File:cmd/entire/cli/paths/worktree.go:46
A submodule's own linked worktree has gitdir like gitdir: /repo/.git/modules/deps/worktrees/sub-wt. The .git/worktrees/ marker is not present (it's modules/deps/worktrees/), so the function errors instead of returning "sub-wt".
HIGH — Runtime Panics & Data Issues
4. Panic on short checkpoint IDs in non-interactive rewind
File:cmd/entire/cli/rewind.go:556
go
selectedPoint.ID[:7] // panics if ID < 7 chars
The interactive flow at line 204 correctly guards with if len(shortID) > 7, but the non-interactive flow at line 556 slices unconditionally. Short IDs would cause an index-out-of-range panic.
5. Empty session ID falls back to literal "unknown", risking collisions
File:cmd/entire/cli/lifecycle.go:465-468
When event.SessionID is empty, the code assigns sessionID = "unknown". This creates directories like .entire/sessions/unknown/ and shadow branches that collide across different sessions missing their IDs.
6. filepath.Base("") produces "." as session ID in rewind
File:cmd/entire/cli/rewind.go:320
When selectedPoint.SessionID is empty AND selectedPoint.MetadataDir is empty, filepath.Base("") returns ".", producing bogus transcript paths.
MEDIUM — Functional Bugs
7. d.Name() drops subdirectory paths in listAllTempFiles
File:cmd/entire/cli/clean.go:436,443
go
fs.WalkDir(root.FS(), ".", func(_ string, d fs.DirEntry, err error) error {
...
files = append(files, d.Name()) // should use path, not d.Name()
WalkDir provides the full relative path as the first argument, but it's discarded. d.Name() only returns the base filename, so files in subdirectories of .entire/tmp/ cannot be deleted.
8. TOCTOU race on prompt.txt read-then-write during concurrent TurnStart
File:cmd/entire/cli/lifecycle.go:382-400
Two concurrent TurnStart hooks for the same session can read the same existing prompt.txt, then both write their version, causing one prompt to be lost.
9. normalizeToolUsePaths silently drops files when eventCWD is relative
File:cmd/entire/cli/lifecycle.go:337
If an agent provides a relative eventCWD, filepath.Join(eventCWD, f) produces a non-absolute path that FilterAndNormalizePaths then rejects (returns ""), silently dropping those files from tracking.
10. handleLifecycleSubagentEnd hard-fails on WorktreeRoot error
File:cmd/entire/cli/lifecycle.go:931-933
Unlike handleLifecycleToolUse which gracefully degrades, this handler returns a hard error if WorktreeRoot() fails, blocking all subagent processing in edge cases (e.g., submodule worktrees).
11. handleLifecycleSubagentEnd resolves empty SessionRef to CWD-relative path
File:cmd/entire/cli/lifecycle.go:871
filepath.Dir("") returns ".", so an empty SessionRef produces AgentTranscriptPath(".", subagentID) — a relative path resolved against CWD, not repo root.
12. GetMainRepoRoot doesn't handle submodule .git file format
File:cmd/entire/cli/strategy/common.go:1026-1053
For submodules, the gitdir path is relative and contains .git/modules/ instead of .git/worktrees/. strings.LastIndex(gitdir, "/.git/") produces an incorrect parent directory.
13. goroutineID() collision risk in acquireSessionGate
If goroutineID() returns -1 for two different goroutines (e.g., if runtime.Stack parsing fails), they'd see gate.owner == -1 and treat each other as the same goroutine, causing one goroutine's mutations to be silently skipped.
Unlike EnsureMetadataBranch and condensation code which call checkpoint.SignCommitBestEffort(), this function creates unsigned commits on entire/checkpoints/v1. On repos enforcing commit signature verification, pushes would be rejected.
LOW — Minor / Edge Cases
15. formatRelativeDuration returns "just now" for negative durations
File:cmd/entire/cli/status.go:237-248
Negative time.Since() (from future timestamps/clock skew) falls into d < time.Minute and returns "just now".
16. saveEnabledState asymmetry in settings sync
File:cmd/entire/cli/setup.go:1141-1158
When saving to local settings, the project settings file is NOT updated, so a conflicting enabled field in project settings can override the local value.
17. performGitResetHard only validates leading -
File:cmd/entire/cli/rewind.go:1173-1182
Only checks for leading dash, doesn't validate that the commit hash is purely hex. (Defense-in-depth: exec.Command prevents shell injection.)
18. protectedDirs() cache has no test-facing reset function
File:cmd/entire/cli/strategy/common.go:362-373
A comment mentions resetProtectedDirsForTest() but it doesn't exist, so tests that mutate the agent registry after the first call see stale results.
19. Rewind doesn't skip submodule entries in checkpoint tree
File:cmd/entire/cli/strategy/manual_commit_rewind.go:402-440
Iterating over tree files that include submodule entries (mode 160000) would fail when trying f.Contents() since submodules are commit references, not blobs.
The branch name (fix-submodule-gitdir-worktree-id) directly targets bugs #1-3. The issue-640-submodule-gitdir.html file in the repo root documents the exact failure flow and expected fix boundaries for those.
Why it happens: The function assumes any .gitfile (as opposed to directory) is a linked worktree pointer. But git submodules also use .git files — they just point to .git/modules/<name> instead of .git/worktrees/<id>.
The correct behavior: An ordinary submodule checkout is the main worktree of the submodule repository. It should return "" (empty string), just like a regular main worktree where .git is a directory.
What questions do you have about this one? Want me to dig deeper into any aspect — the call chain, how shadow branches use the worktree ID, the test coverage, or the fix approach?