Repository navigation
fix(git-sync): root a new repo at /home/developer and verify init through the agent server (#2938) - #2943
Conversation
…it is verified through the agent server (#2938) `initialize_git_in_container` chose the repo root with a content probe: any non-empty `/home/developer/workspace` was treated as a legacy repo root, so an agent whose template ships files into `workspace/` got its brand-new repo created there. The agent server's git router reads exactly one root, `/home/developer`, so the next status poll answered `git_enabled: false` and Sync / Log / the git panel all reported "not enabled" — right after the init endpoint returned 200, because its verify ran in the directory the backend had chosen and could only agree with itself. - `_detect_git_dir`: a container with no repository answers `NEW_REPO_ROOT` (`/home/developer`) whatever `workspace/` holds; the pre-#2075 `_detect_git_dir_fallback` content heuristic is removed. An existing repo — a legacy workspace-rooted one included — is still wherever `git rev-parse --show-toplevel` finds it. - `initialize_git_in_container`: after the backend's own `git rev-parse --git-dir`, ask the agent server's `GET /api/git/status`. `git_enabled: false` fails the init with a named reason (the router answers 400 and rolls the config row back); an unanswerable probe (unreachable, non-200, not JSON) warns and keeps the backend verdict. - Tests: `test_2938_git_init_repo_root.py` drives the real init end-to-end with the exec and the agent-server call faked — placement with a populated workspace, no content probe, legacy re-init in place, and the three probe verdicts. Ten of eleven fail on the pre-fix code. `test_2075_detect_git_dir.py` updated for the retired fallback. Fixes #2938 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ged" (#2943) — mechanical, per the merge-train note on the PR The agent server's status route is a bare Path("/home/developer/.git").exists(), so a repo git roots at workspace/ answers git_enabled: false deterministically and the new Step 6 verify turns that into a 400 with the config rolled back. The legacy test stubbed the agent server as git_enabled: true — a combination production cannot produce — and the feature flow / requirements said the case was "re-initialised in place, unchanged". Model the real answer in the test and state the actual outcome in both docs. No code change. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
merge-train 2026-09-22: riding this train, with one mechanical commit pushed to this branch (validated lane B: What the pushed commit does — the legacy case was described as "re-initialised in place, unchanged", but the code refuses it. The agent server's For you to consider as a follow-up (a design choice, so not done here): the refusal fires after the GitHub repo is created and |
Summary
POST /api/agents/{name}/git/initializeplaced a new repository in/home/developer/workspacewhenever that directory held anything (a template that ships files intoworkspace/, a data directory, …). The agent server's git router reads exactly one root —/home/developer— so the very next status poll answeredgit_enabled: falseand Sync, Log and the git panel all reported "not enabled". The init endpoint had returned 200, because its verify (git rev-parse --git-dir) ran in the directory the backend chose and could only agree with itself.Two changes, both in
services/git_service:/home/developer(gitignore.NEW_REPO_ROOT)._detect_git_dirkeeps git's own answer for an existing repo — a genuine legacy workspace-rooted one still resolves toworkspace/and is re-initialised in place, after which the agent-server verify in (2) refuses it with a 400, since the agent server reads only/home/developer— but the pre-_detect_git_dirpicks the wrong repo root for agents with a populatedworkspace/data directory #2075_detect_git_dir_fallbackcontent heuristic ("populatedworkspace/⇒ legacy root") is removed. A populatedworkspace/is content under home the initial commit should include, not a reason to move the root.rev-parse,initialize_git_in_containerasks the agent server'sGET /api/git/status:git_enabled: false→GitInitResult(success=False, error="the agent server cannot see the repository at … (#2938)")— the router already turns that into a 400 and rolls theagent_git_configrow back, so the operator gets the reason instead of a green toast.Tests
tests/unit/test_2938_git_init_repo_root.pydrives the realinitialize_git_in_containerend-to-end with the container exec andagent_httpx_clientfaked:workspace/, no repo →git initruns at/home/developer, nothing runs inworkspace/find … -mindepth) is executed; exactly onerev-parse --show-toplevelworkspace/(legacy) → re-init in place, then the agent-server verify refuses it with the named reason (the real agent server answersgit_enabled: falsefor a workspace-rooted repo; before bug(git-sync): initialize places a new repo in workspace/ when it is non-empty, but the agent server only looks at /home/developer — init reports success, everything after says "not enabled" #2938 this case returned 200 and stayed "not enabled")git_enabled: false→ failed result with the named reason; five unanswerable shapes → success + warning; the helper's True/False/None mappingNegative control (same tests on
origin/dev'sgitignore.py+provisioning.py): 10 failed, 1 passed (the legacy-in-place case — the only one whose placement is unchanged; its verify outcome is new, see the merge-train note below). With the fix: 11 passed.test_2075_detect_git_dir.pyupdated for the retired fallback (12 passed). Git/compat unit suites:757 passed, 2 skipped.Docs
docs/memory/feature-flows/github-repo-initialization.md— step 1 placement, LEGACY case, Directory Detection Logic, Verifydocs/memory/requirements/github.md§11.2 — repo-root and verified-where-consumed rulesOut of scope
_apply_git_env_from_db's per-agent PAT gate (ent#162 class) is untouched; this PR changes only where a new repo lands and how init is confirmed.Fixes #2938
🤖 Generated with Claude Code