Repository navigation
Closed
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p1Critical paththeme-reliabilityTheme: Reliabilitytype-featureNew functionality
Description
Summary
Enforce the "working branches are per-instance-only" invariant to prevent silent data loss when two agents push to the same branch.
Context
Problem P5: Two Trinity agents can be configured to push to the same (repo, branch) tuple with no collision check. Force-pushes silently clobber each other — whoever pushed last wins.
Real incident: 2026-04-17, alpaca-vybe-live and alpaca-vybe-live-2 both pushed to trinity/alpaca-vybe-live/a702560e within 12 seconds. One agent's 50KB of state was silently overwritten.
Problem P7: generate_instance_id() is called at three sites with no cross-check:
src/backend/services/agent_service/crud.py:225src/backend/routers/git.py:367src/backend/services/git_service.py:405
Acceptance Criteria
Layer 0: Consolidate instance ID generation
- Create single
reserve_and_generate_instance_id(agent_name, github_repo)helper - Check
git ls-remoteto verify branch doesn't exist on remote - Retry up to 5x on collision
- All three call sites use the new helper
Layer 1: Creation-time remote check
- Covered by Layer 0
Layer 2: DB uniqueness constraint
- Add partial UNIQUE index:
UNIQUE(github_repo, working_branch) WHERE source_mode = 0 - Migration tolerates existing duplicates (flag first, let operators resolve)
- Pre-flight audit query to detect existing duplicates
Layer 3: Push-time guard
- Replace
git push --forcewithgit push --force-with-lease=<ref>:<expected-sha> - Persist last remote SHA in
.trinity/last-remote-sha/<branch>after fetch - Surface collision to operator queue with structured error
Observability
- Fleet dashboard shows branch bindings tab
- Duplicate bindings shown in red
- One-click rebinding flow: "Assign fresh working branch"
Technical Notes
Files to modify:
src/backend/services/git_service.py— newreserve_and_generate_instance_id,check_remote_branch_existssrc/backend/db/schema.py,db/migrations.py— partial UNIQUE indexsrc/backend/routers/agents.py,routers/git.py,routers/agent_config.py— validate on create/updatedocker/base-image/agent_server/routers/git.py—--force-with-lease, persist last-remote-sha- Frontend — fleet binding warnings
Migration note: Deploy validation as warnings first, fix known duplicates, then flip the constraint.
Part of Epic #381
Metadata
Metadata
Assignees
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p1Critical paththeme-reliabilityTheme: Reliabilitytype-featureNew functionality
Activity
test(git): add S7 branch-ownership tests for Abilityai#382
feat(db): add S7 Layer 2 partial UNIQUE index on agent_git_config (Ab…
feat(git): consolidate instance-id generation behind S7 Layer 0 helper (
feat(agent-server): push with --force-with-lease and surface collisio…
feat(git): sync health observability + auto-sync heartbeat (Abilityai…
feat(fleet): GET /api/fleet/sync-audit with duplicate-binding flag (A…
feat(agent-server): reset-to-main-preserve-state routine (S3, Ability…
docs(feature-flows): document S7 Layers 0/2 in github-repo-initializa…
docs(feature-flows): document S7 Layer 3 push-time guard in github-sy…
docs(requirements): add §11.3 Branch Ownership Enforcement (S7, Abili…
docs(requirements): add §11.3 Parallel-History Detection (S2, Ability…
feat(fleet): GET /api/fleet/sync-audit with duplicate-binding flag (A…
docs(requirements): add §11.3 Operator-Readable Conflict Diagnosis (S5,
10 remaining items
docs(requirements): add §11.3 Branch Ownership Enforcement (S7, Abili…
feat: branch ownership enforcement (S7, #382) (#396)
feat(git): sync health observability + auto-sync heartbeat (Abilityai…
feat(fleet): GET /api/fleet/sync-audit with duplicate-binding flag (A…
feat(agent-server): reset-to-main-preserve-state routine (S3, Ability…
feat(agent-server): reset-to-main-preserve-state routine (S3, Ability…
feat(git): reset-to-main-preserve-state operation (S3, #384) (#400)
feat(git): sync health observability + auto-sync heartbeat (Abilityai…
feat(git): sync health observability + auto-sync heartbeat (#389 S1 +…
feat(fleet): GET /api/fleet/sync-audit with duplicate-binding flag (A…
feat(fleet): GET /api/fleet/sync-audit with duplicate-binding flag (#390
refactor(agents): decompose create_agent_internal behind a characteri…