Repository navigation
fix(doctor): avoid sync remedy for dangling config symlinks #3561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Alan-TheGentleman
merged 11 commits into
Gentleman-Programming:main
from
decode2:fix/3557-doctor-dangling-symlink
Aug 27, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9072f4a
fix(doctor): avoid sync remedy for dangling symlinks
decode2 5b555a2
fix(doctor): report unreadable managed config paths
decode2 a8fc18d
ci: retry flaky unit test
decode2 c846fcb
test(bench): expose doctor state drift
decode2 47b18a9
test(bench): isolate doctor state assertions
decode2 f2b1b15
chore: integrate current main
decode2 b4bb9c0
chore: merge current main into doctor fix
decode2 68c2921
fix(doctor): warn on managed config symlink loops
decode2 a5ff615
fix(bench): propagate unexpected symlink setup errors
decode2 3e4671f
fix(doctor): classify dangling ancestor symlinks
Alan-TheGentleman 97e97aa
test(bench): drive dangling-ancestor doctor journey
Alan-TheGentleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| const windowsErrorPrivilegeNotHeld = syscall.Errno(1314) | ||
|
|
||
| func issue3557DanglingSymlinkFixture(sandbox *Sandbox) error { | ||
| if err := baseRepo(sandbox); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| configPath := filepath.Join(sandbox.Home, ".config", "opencode") | ||
| targetPath := filepath.Join(sandbox.Root, "missing-external-opencode-config") | ||
| if err := os.Symlink(targetPath, configPath); err != nil { | ||
| if !errors.Is(err, windowsErrorPrivilegeNotHeld) { | ||
| return err | ||
| } | ||
| sandbox.Scratch["issue-3557-symlink-unavailable"] = err.Error() | ||
| return nil | ||
| } | ||
| if err := os.MkdirAll(filepath.Join(sandbox.Home, ".claude"), 0o755); err != nil { | ||
| return err | ||
| } | ||
| statePath := filepath.Join(sandbox.Home, ".gentle-ai", "state.json") | ||
| state := fmt.Sprintf(`{"installed_agents":["opencode","claude-code"],"last_update_check":%q}`, time.Now().UTC().Format(time.RFC3339Nano)) | ||
| if err := sandbox.write(statePath, state); err != nil { | ||
| return err | ||
| } | ||
| claudeConfig := `{"mcpServers":{"engram":{"command":"engram-not-installed-for-issue-3557","args":[]}}}` | ||
| if err := sandbox.write(filepath.Join(sandbox.Home, ".claude.json"), claudeConfig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sandbox.Scratch["issue-3557-config"] = configPath | ||
| sandbox.Scratch["issue-3557-target"] = targetPath | ||
| sandbox.Scratch["issue-3557-state"] = statePath | ||
| sandbox.Scratch["issue-3557-state-content"] = state | ||
| sandbox.Scratch["issue-3557-link-target"] = targetPath | ||
| return nil | ||
| } | ||
|
|
||
| func issue3557DoctorArgs(*Sandbox) ([]string, error) { return []string{"doctor"}, nil } | ||
|
|
||
| func issue3557SymlinkSkip(sandbox *Sandbox) string { | ||
| if reason := sandbox.Scratch["issue-3557-symlink-unavailable"]; reason != "" { | ||
| return "managed config symlink unavailable: " + reason | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func issue3557VerifyDoctor(sandbox *Sandbox, observation Observation) error { | ||
| if observation.ExitCode != 0 { | ||
| return fmt.Errorf("gentle-ai doctor exited %d: %s", observation.ExitCode, firstLine(observation.Stderr)) | ||
| } | ||
| if strings.Contains(observation.Stdout, "gentle-ai sync") { | ||
| return fmt.Errorf("doctor recommended the unrunnable sync recovery: %s", observation.Stdout) | ||
| } | ||
| for _, want := range []string{sandbox.Scratch["issue-3557-config"], "inspect", "gentle-ai doctor"} { | ||
| if !strings.Contains(observation.Stdout, want) { | ||
| return fmt.Errorf("doctor output missing %q: %s", want, observation.Stdout) | ||
| } | ||
| } | ||
|
|
||
| configPath := sandbox.Scratch["issue-3557-config"] | ||
| info, err := os.Lstat(configPath) | ||
| if err != nil { | ||
| return fmt.Errorf("lstat managed config symlink after doctor: %w", err) | ||
| } | ||
| if info.Mode()&os.ModeSymlink == 0 { | ||
| return fmt.Errorf("doctor changed managed config path into %s", info.Mode()) | ||
| } | ||
| linkTarget, err := os.Readlink(configPath) | ||
| if err != nil { | ||
| return fmt.Errorf("read managed config symlink after doctor: %w", err) | ||
| } | ||
| if linkTarget != sandbox.Scratch["issue-3557-link-target"] { | ||
| return fmt.Errorf("doctor changed symlink target from %q to %q", sandbox.Scratch["issue-3557-link-target"], linkTarget) | ||
| } | ||
| targetPath := sandbox.Scratch["issue-3557-target"] | ||
| if _, err := os.Lstat(targetPath); err == nil { | ||
| return fmt.Errorf("doctor unexpectedly created %q", targetPath) | ||
| } else if !os.IsNotExist(err) { | ||
| return fmt.Errorf("doctor changed %q: %w", targetPath, err) | ||
| } | ||
| state, err := os.ReadFile(sandbox.Scratch["issue-3557-state"]) | ||
| if err != nil { | ||
| return fmt.Errorf("read state after doctor: %w", err) | ||
| } | ||
| if string(state) != sandbox.Scratch["issue-3557-state-content"] { | ||
| return fmt.Errorf("doctor changed state.json: got %q, want %q", string(state), sandbox.Scratch["issue-3557-state-content"]) | ||
| } | ||
| backupPath := filepath.Join(sandbox.Home, ".gentle-ai", "backups") | ||
| if _, err := os.Lstat(backupPath); err == nil { | ||
| return fmt.Errorf("doctor unexpectedly created %q", backupPath) | ||
| } else if !os.IsNotExist(err) { | ||
| return fmt.Errorf("doctor could not inspect %q: %w", backupPath, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func issue3557Journeys() []Journey { | ||
| return []Journey{{ | ||
| ID: "j117-doctor-dangling-managed-config", | ||
| Review: reviewUntouched, | ||
| Title: "Doctor identifies a dangling managed config symlink without recommending sync", | ||
| Source: "https://github.com/Gentleman-Programming/gentle-ai/issues/3557", | ||
| Steps: []Step{ | ||
| {Name: "fixture: dangling OpenCode managed config symlink", Fixture: issue3557DanglingSymlinkFixture}, | ||
| {Name: "doctor reports manual repair and preserves the filesystem", Skip: issue3557SymlinkSkip, Args: issue3557DoctorArgs, After: issue3557VerifyDoctor}, | ||
| }, | ||
| }} | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| func issue3561DanglingAncestorFixture(sandbox *Sandbox) error { | ||
| if err := baseRepo(sandbox); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // The sandbox pre-creates ~/.config as a real directory; replace it with | ||
| // a symlink whose target does not exist so the managed opencode path | ||
| // (~/.config/opencode) sits below a dangling ANCESTOR while not being a | ||
| // symlink itself. | ||
| ancestorPath := filepath.Join(sandbox.Home, ".config") | ||
| targetPath := filepath.Join(sandbox.Root, "missing-external-config-root") | ||
| if err := os.Remove(ancestorPath); err != nil { | ||
| return err | ||
| } | ||
| if err := os.Symlink(targetPath, ancestorPath); err != nil { | ||
| if !errors.Is(err, windowsErrorPrivilegeNotHeld) { | ||
| return err | ||
| } | ||
| if mkdirErr := os.MkdirAll(ancestorPath, 0o755); mkdirErr != nil { | ||
| return mkdirErr | ||
| } | ||
| sandbox.Scratch["issue-3561-symlink-unavailable"] = err.Error() | ||
| return nil | ||
| } | ||
| if err := os.MkdirAll(filepath.Join(sandbox.Home, ".claude"), 0o755); err != nil { | ||
| return err | ||
| } | ||
| statePath := filepath.Join(sandbox.Home, ".gentle-ai", "state.json") | ||
| state := fmt.Sprintf(`{"installed_agents":["opencode","claude-code"],"last_update_check":%q}`, time.Now().UTC().Format(time.RFC3339Nano)) | ||
| if err := sandbox.write(statePath, state); err != nil { | ||
| return err | ||
| } | ||
| claudeConfig := `{"mcpServers":{"engram":{"command":"engram-not-installed-for-issue-3561","args":[]}}}` | ||
| if err := sandbox.write(filepath.Join(sandbox.Home, ".claude.json"), claudeConfig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sandbox.Scratch["issue-3561-ancestor"] = ancestorPath | ||
| sandbox.Scratch["issue-3561-config"] = filepath.Join(ancestorPath, "opencode") | ||
| sandbox.Scratch["issue-3561-target"] = targetPath | ||
| sandbox.Scratch["issue-3561-state"] = statePath | ||
| sandbox.Scratch["issue-3561-state-content"] = state | ||
| sandbox.Scratch["issue-3561-link-target"] = targetPath | ||
| return nil | ||
| } | ||
|
|
||
| func issue3561DoctorArgs(*Sandbox) ([]string, error) { return []string{"doctor"}, nil } | ||
|
|
||
| func issue3561SymlinkSkip(sandbox *Sandbox) string { | ||
| if reason := sandbox.Scratch["issue-3561-symlink-unavailable"]; reason != "" { | ||
| return "managed config ancestor symlink unavailable: " + reason | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func issue3561VerifyDoctor(sandbox *Sandbox, observation Observation) error { | ||
| if observation.ExitCode != 0 { | ||
| return fmt.Errorf("gentle-ai doctor exited %d: %s", observation.ExitCode, firstLine(observation.Stderr)) | ||
| } | ||
| if strings.Contains(observation.Stdout, "gentle-ai sync") { | ||
| return fmt.Errorf("doctor recommended the unrunnable sync recovery: %s", observation.Stdout) | ||
| } | ||
| ancestorPath := sandbox.Scratch["issue-3561-ancestor"] | ||
| for _, want := range []string{sandbox.Scratch["issue-3561-config"], "dangling ancestor symlink " + ancestorPath, "inspect", "gentle-ai doctor"} { | ||
| if !strings.Contains(observation.Stdout, want) { | ||
| return fmt.Errorf("doctor output missing %q: %s", want, observation.Stdout) | ||
| } | ||
| } | ||
|
|
||
| info, err := os.Lstat(ancestorPath) | ||
| if err != nil { | ||
| return fmt.Errorf("lstat config ancestor symlink after doctor: %w", err) | ||
| } | ||
| if info.Mode()&os.ModeSymlink == 0 { | ||
| return fmt.Errorf("doctor changed config ancestor into %s", info.Mode()) | ||
| } | ||
| linkTarget, err := os.Readlink(ancestorPath) | ||
| if err != nil { | ||
| return fmt.Errorf("read config ancestor symlink after doctor: %w", err) | ||
| } | ||
| if linkTarget != sandbox.Scratch["issue-3561-link-target"] { | ||
| return fmt.Errorf("doctor changed ancestor symlink target from %q to %q", sandbox.Scratch["issue-3561-link-target"], linkTarget) | ||
| } | ||
| targetPath := sandbox.Scratch["issue-3561-target"] | ||
| if _, err := os.Lstat(targetPath); err == nil { | ||
| return fmt.Errorf("doctor unexpectedly created %q", targetPath) | ||
| } else if !os.IsNotExist(err) { | ||
| return fmt.Errorf("doctor changed %q: %w", targetPath, err) | ||
| } | ||
| configPath := sandbox.Scratch["issue-3561-config"] | ||
| if _, err := os.Lstat(configPath); err == nil { | ||
| return fmt.Errorf("doctor unexpectedly created %q", configPath) | ||
| } else if !os.IsNotExist(err) { | ||
| return fmt.Errorf("doctor changed %q: %w", configPath, err) | ||
| } | ||
| state, err := os.ReadFile(sandbox.Scratch["issue-3561-state"]) | ||
| if err != nil { | ||
| return fmt.Errorf("read state after doctor: %w", err) | ||
| } | ||
| if string(state) != sandbox.Scratch["issue-3561-state-content"] { | ||
| return fmt.Errorf("doctor changed state.json: got %q, want %q", string(state), sandbox.Scratch["issue-3561-state-content"]) | ||
| } | ||
| backupPath := filepath.Join(sandbox.Home, ".gentle-ai", "backups") | ||
| if _, err := os.Lstat(backupPath); err == nil { | ||
| return fmt.Errorf("doctor unexpectedly created %q", backupPath) | ||
| } else if !os.IsNotExist(err) { | ||
| return fmt.Errorf("doctor could not inspect %q: %w", backupPath, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func issue3561Journeys() []Journey { | ||
| return []Journey{{ | ||
| ID: "j118-doctor-dangling-config-ancestor", | ||
| Review: reviewUntouched, | ||
| Title: "Doctor identifies a dangling ancestor of a managed config path without recommending sync", | ||
| Source: "https://github.com/Gentleman-Programming/gentle-ai/pull/3561", | ||
| Steps: []Step{ | ||
| {Name: "fixture: dangling ~/.config ancestor over the OpenCode managed path", Fixture: issue3561DanglingAncestorFixture}, | ||
| {Name: "doctor reports manual repair and preserves the filesystem", Skip: issue3561SymlinkSkip, Args: issue3561DoctorArgs, After: issue3561VerifyDoctor}, | ||
| }, | ||
| }} | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.