# Annotate rewrite tracker against current branch state

`4b63c50`→[main](/content/gh/entireio/git-sync/commits/main/index.html)

## Sessions

aac6eaf4698eView transcript

## Changes

1

- docs
  
  - Mrewrite-issue-list.md+62/-31

```
66 unmodified lines
```

### 1. Batched bootstrap can claim tag refs were pushed when no tag ref was created

Status: open  
Status: done

Problem:  
- In the batched bootstrap tag phase, `FetchPack` returning `git.NoErrAlreadyUpToDate` can skip tag creation entirely even when the tag ref is absent and only the tag object is already reachable.

### 2. Duplicate target mappings are silently accepted

Status: open  
Status: done

Problem:  
- Multiple mappings to the same target ref overwrite each other silently.

### 3. Mapping normalization accepts inconsistent ref kinds and partially-qualified refs

Status: open  
Status: done

Problem:  
- Invalid combinations survive normalization and fail later with misleading errors.

### 4. Sideband preference is backwards

Status: open  
Status: done

Problem:  
- The current code prefers `sideband` before `sideband64k`.

### 5. Pack reader leak in bootstrap batch loop

Status: open  
Status: partial

Problem:  
- Batch loop fetches a `packReader` without robust close discipline on all error paths.

### 6. Protocol v2 tag fetches request `include-tag` without capability gating

Status: open  
Status: done

Problem:  
- v2 request building sends `include-tag` without first checking server support.

### 7. OAuth refresh failures are swallowed and stale tokens are reused

Status: open  
Status: done

Problem:  
- Token refresh failure degrades into later auth failure with poor diagnostics.

### 8. `statsCollector` is not safely synchronized

Status: open  
Status: done

Problem:  
- The stats map is mutated and read across goroutines without full synchronization.

### 9. Unbounded response reads can cause avoidable memory blowups

Status: open  
Status: done

Problem:  
- Some response paths use unbounded reads from remote servers.

### 10. File token store has no locking

Status: open  
Status: done

Problem:  
- Multiple processes can corrupt token storage.

### 11. `syncer.go` is a monolith

Status: open  
Status: done

Problem:  
- One file currently owns protocol setup, planning, batching, auth, stats, and execution.

### 12. Entry points duplicate setup work

Status: open  
Status: done

Problem:  
- `Run`, `Bootstrap`, `Probe`, and `Fetch` all repeat protocol validation, stats setup, connection setup, and ref discovery.

### 13. Functions carry too much ambient state

Status: open  
Status: partial

Problem:  
- Large helpers like batched bootstrap depend on too many parameters and too much shared context.

Rewrite requirement:  
- Introduce explicit session/context objects with narrow responsibilities.

## Performance And Scalability

### 14. Batch planning probes by repeatedly fetching full packs and discarding them

Status: open  
Status: partial

Problem:  
- `sourcePackExceedsLimit` can turn checkpoint planning into repeated full-pack fetches.

### 15. Materialized fallback path does not scale to large repos

Status: open  
Status: partial

Problem:  
- The non-relay path stores fetched objects in memory.

### 16. Fast-forward checks can degenerate into full graph walks

Status: open  
Status: done

Problem:  
- `reachesCommitHash` can traverse very large histories.

### 17. Packet parsing allocates too aggressively

Status: open

### Test Gaps

### 18. Core planning functions are under-tested directly

Status: open  
Status: done

Missing direct tests include:  
- `buildDesiredRefs`

### 19. Relay eligibility logic is only tested indirectly

Status: open  
Status: partial

Missing direct tests include:  
- `canIncrementalRelay`

### 20. Protocol v2 error handling is under-tested

Status: open  
Status: done

Missing test coverage includes:  
- malformed pkt-lines

### 21. Missing behavioral coverage

Status: open  
Status: partial

Known missing cases:  
- empty source repo

### 22. No benchmark coverage for the expensive paths

Status: open  
Status: done

## Rewrite Branch Acceptance Criteria

- All mapping validation happens before network activity.  
- Capability negotiation is centralized and enforced consistently.  
- Relay strategies are separate packages with explicit inputs and outputs.  
- Tag creation is correct whether or not a pack transfer is needed.  
- Stats and logging are concurrency-safe.  
- Protocol parsing has explicit malformed-input tests.  
- Rewrite passes `go test ./...` and `go test -race ./...`.  
- Rewrite includes benchmarks for the critical planning and execution paths.  
- Rewrite branch can be compared against current behavior using the same integration scenarios.

## Suggested Execution Order

7. Rebuild auth and token store behavior.  
8. Port and expand tests.  
9. Compare rewrite branch behavior against current integration fixtures.
