Make workspace sync non-destructive#1864
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (24)
📝 WalkthroughWalkthroughThis PR implements default branch detection and non-destructive workspace synchronization to prevent silent destruction of local work in managed clones. It adds a ChangesDefault Branch Tracking and Non-Destructive Sync
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Comprehensive PR ReviewPR: #1864 SummaryPR #1864 makes the important data-loss fix: normal chat-time workspace sync is now non-destructive, while hard reset remains explicit for managed worktree creation. The implementation is directionally sound and has strong regression coverage for the destructive Git behavior, but several merge-blocking risks remain around upgrade safety, Git error classification, missing tests, and stale docs/schema references. The highest-priority issue is the missing SQLite additive migration for Verdict:
🔴 Critical Issues (Auto-fixing)No critical issues were reported. 🟠 High Issues (Auto-fixing)Existing SQLite Databases Never Receive
|
| Option | Approach | Effort | Risk if Skipped |
|---|---|---|---|
| Fix Now | Extend updateCodebase() to accept default_branch and update it when default_cwd changes or the existing branch is missing. |
LOW | Chat sync can target stale branch metadata. |
| Create Issue | Defer stale-branch metadata handling to a separate PR. | LOW | Users replacing managed clones with local checkouts may see sync failures or wrong-branch state. |
| Skip | Accept existing branch metadata as authoritative. | NONE | Branch persistence can become inconsistent with the registered path. |
Recommendation: Fix Now.
Short-SHA Read Failures Are Silently Converted To Empty Strings
📍 packages/git/src/repo.ts:207
readShortSha() catches all git rev-parse --short=8 failures and returns '' without logging. This can suppress sync update telemetry and hide invalid refs or repository access failures.
Options: Fix now | Create issue | Skip
View details
| Option | Approach | Effort | Risk if Skipped |
|---|---|---|---|
| Fix Now | Log a warning with workspacePath and ref, then return ''. |
LOW | Repository mutations may become less visible and harder to debug. |
| Create Issue | Track telemetry hardening separately. | LOW | Silent telemetry failure remains in the sync path. |
| Skip | Keep SHA reads best-effort and silent. | NONE | Future sync debugging loses useful failure context. |
Recommendation: Fix Now.
Orchestrator Registration Branch Detection Is Only Tested As Null
📍 packages/core/src/orchestrator/orchestrator-agent.ts:1716 / packages/core/src/orchestrator/orchestrator-agent.test.ts
The /register-project flow now detects the current branch before creating a codebase, but tests only cover the null branch path.
Options: Fix now | Create issue | Skip
View details
| Option | Approach | Effort | Risk if Skipped |
|---|---|---|---|
| Fix Now | Add one /register-project test where the Git mock returns develop. |
LOW | Chat registration can regress to always storing null. |
| Create Issue | Add command-path branch coverage later. | LOW | Branch-aware sync remains less protected for chat registration. |
| Skip | Rely on clone-handler tests only. | NONE | A distinct registration path remains under-tested. |
Recommendation: Fix Now.
Sync Result SHA Comments Still Say Reset
📍 packages/git/src/types.ts:51
WorkspaceSyncResult.previousHead and newHead comments still say they are before and after "the reset", but sync is now mode-based and usually non-destructive.
Options: Fix now | Create issue | Skip
View details
| Option | Approach | Effort | Risk if Skipped |
|---|---|---|---|
| Fix Now | Replace "reset" with "sync operation". | LOW | Future callers may misread non-reset sync results. |
| Create Issue | Defer comment cleanup. | LOW | Comment rot remains near the public return type. |
| Skip | Leave comments as-is. | NONE | Type documentation contradicts behavior introduced by this PR. |
Recommendation: Fix Now.
CLAUDE.md Sync Guidance Needs New Mode Semantics
📍 CLAUDE.md
Contributor guidance says workspaces automatically sync with origin before worktree creation, but it does not explain that default sync is non-destructive or that hard reset must be explicitly requested by callers that own the checkout.
Options: Fix now | Create issue | Skip
View details
| Option | Approach | Effort | Risk if Skipped |
|---|---|---|---|
| Fix Now | Add short bullets describing default non-destructive sync and explicit mode: 'reset'. |
LOW | Future contributors may reintroduce destructive sync assumptions. |
| Create Issue | Defer contributor-doc update. | LOW | Guidance remains stale after a data-loss fix. |
| Skip | Rely on inline code comments. | NONE | Project-level guidance does not capture the new safety rule. |
Recommendation: Fix Now.
🟢 Low Issues
View 1 low-priority suggestion
| Issue | Location | Suggestion |
|---|---|---|
| Codebase table comment omits default branch metadata | migrations/000_combined.sql:44 |
Add "default branch" to the remote_agent_codebases table comment and refresh generated bundled schema if needed. |
✅ What's Good
- The PR addresses the main destructive behavior: chat workflow discovery no longer passes reset mode, while managed worktree creation still opts into reset explicitly.
syncWorkspacenow returns mode and state, making callers and tests more precise than the previous reset boolean.- Regression tests cover dirty, behind, ahead, diverged, non-target branch, managed reset, and stored branch call-site behavior.
- The orchestrator logs sync failures with codebase context and surfaces a structured "Sync failed - using local state" event where supported.
- Inline comments in
packages/git/src/repo.tsandpackages/isolation/src/providers/worktree.tsclearly describefast-forward,fetch-only, andresetmodes.
📋 Suggested Follow-up Issues
| Issue Title | Priority | Related Finding |
|---|---|---|
| "Keep codebase default_branch in sync when re-registering local paths" | P1 | MEDIUM issue #1 |
| "Add observability for short SHA telemetry failures during workspace sync" | P2 | MEDIUM issue #2 |
| "Document non-destructive workspace sync mode semantics in contributor guidance" | P2 | MEDIUM issue #5 |
| "Refresh codebase metadata comments after default_branch schema change" | P3 | LOW issue #1 |
Next Steps
- ⚡ Auto-fix step will address CRITICAL + HIGH issues
- 📝 Review MEDIUM issues above
- 🎯 Merge when ready
Reviewed by Archon comprehensive-pr-review workflow
Artifacts: /Users/rasmus/.archon/workspaces/coleam00/Archon/artifacts/runs/414edc17b9979f10d79af28a4b193c43/review/
⚡ Self-Fix Report (Aggressive)Status: COMPLETE Fixes Applied (11 total)
View all fixes
Tests Added
Skipped (0)(none — all findings addressed) Suggested Follow-up Issues(none) Validation✅ Type check ( Self-fix by Archon · aggressive mode · fixes pushed to |
Chat sync for managed source clones could hard-reset to origin on ordinary messages, discarding tracked local edits or branch tips. Make sync non-destructive by default and keep destructive reset explicit for worktree creation. Changes: - Added mode-based workspace sync with local/remote state classification - Updated chat sync to use safe fast-forward behavior and clearer sync events - Kept managed worktree creation on explicit reset mode - Persisted detected codebase default branches - Added regression coverage for dirty, ahead, diverged, and fast-forward cases Fixes #1516
Fixed: - Add SQLite default_branch migration for existing databases - Keep codebase branch metadata in sync when re-registering paths - Surface unexpected merge-base failures and log short SHA telemetry failures - Update stale sync/schema docs and comments Tests added: - Branch persistence and detached HEAD coverage for clone/register flows - Orchestrator register-project branch detection coverage - Git sync error handling coverage - SQLite/codebase/schema coverage for default_branch Skipped: - none
5123048 to
c4af65e
Compare
Summary
Describe this PR in 2-5 bullets:
source/clones toorigin/<default_branch>on ordinary messages, which could discard tracked edits or orphan local branch tips.syncWorkspaceis now mode-based and non-destructive by default, chat sync uses safe branch-aware sync, worktree creation explicitly opts into reset where a clean managed base is required, and codebase branch persistence now stores nullable detected default branches.UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory (list every module-to-module edge, mark changes):
packages/core/src/orchestrator/orchestrator-agent.tspackages/git/src/repo.tspackages/git/src/repo.tspackages/isolation/src/providers/worktree.tspackages/git/src/repo.tspackages/core/src/handlers/clone.tspackages/core/src/db/codebases.tspackages/core/src/db/codebases.tsdefault_branch.packages/core/src/schemas/codebase.tsdefault_branch.Label Snapshot
risk: mediumsize: Mcore|isolation|git|server|testscore:orchestrator,git:sync,isolation:worktree,core:codebasesChange Metadata
bugmultiLinked Issue
Validation Evidence (required)
Commands and result summary:
bun run type-check,bun run lint,bun run format:check, fullbun run testwith 4,376 passed, 0 failed, 1 skipped, and successful build. Targeted tests passed with 148 git tests, 123 orchestrator-agent tests, and 142 worktree provider tests.Security Impact (required)
Yes/No): NoYes/No): NoYes/No): NoYes/No): NoYes, describe risk and mitigation: No security-impacting capability changes were introduced.Compatibility / Migration
Yes/No): YesYes/No): NoYes/No): Yesmigrations/023_add_default_branch_to_codebases.sql; SQLite bundled schema and adapter migration behavior were updated soremote_agent_codebases.default_branchis nullable.Human Verification (required)
What was personally validated beyond CI:
/register-projecttest expectation.default_branch.Side Effects / Blast Radius (required)
Rollback Plan (required)
Risks and Mitigations
List real risks in this PR (or write
None).default_branchschema changes may expose drift between Postgres and SQLite behavior.Closes #1273 (same data-loss class — destructive sync now fast-forward-only and respects the configured default_branch).
Summary by CodeRabbit
New Features
fast-forward,fetch-only,reset) and detailed state reporting (in_sync,behind,ahead,diverged,dirty)Documentation