feat: implement collision detection and management for cross-session edits#2257
Open
aditisingh02 wants to merge 1 commit into
Open
feat: implement collision detection and management for cross-session edits#2257aditisingh02 wants to merge 1 commit into
aditisingh02 wants to merge 1 commit into
Conversation
…edits - Add a new `session_collision` table to track overlapping edits between sessions. - Implement CRUD operations for collisions in the SQLite store. - Create a convergence observer to detect and classify collisions as "hot" or "soft". - Introduce API endpoints to list project collisions and return collision details. - Add tests for collision store functionality and observer behavior. - Update frontend schema to include collision data structures and API interactions.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & Why
Closes #2258.
Agent Orchestrator's core premise is running many agents in parallel, each in its own isolated Git worktree. That isolation has a blind spot: two agents can silently modify the same code without knowing about each other.
Today, AO only detects this reactively—after both agents have opened PRs and GitHub reports a merge conflict. At that point,
lifecycle.ApplyPRObservationcan only nudge an agent to rebase, meaning the duplicate parallel work has already been done.Convergence Radar closes this gap.
It introduces a new observation loop that continuously diffs every active worktree, computes pairwise overlap at both file and hunk-range granularity, persists those overlaps as durable facts, and proactively nudges colliding agents to coordinate before either opens a PR.
Rather than being a bolt-on feature, it follows AO's existing architecture. The convergence observer is a sibling of the SCM observer, reusing
observe.StartPollLoop, the durable-facts model, and the existing agent nudge pipeline. The result shifts AO from a conflict resolver into a conflict preventer.How It Works (OBSERVE → UPDATE → ACT)
OBSERVE
ports.WorkspaceDiffer.ChangedRegionsdiffs each worktree against the merge-base ofHEADand its base branch, including both committed and uncommitted tracked changes. It parsesgit diff --unified=0hunk headers into per-file line ranges.UPDATE
The convergence observer groups active sessions by project, compares every pair of worktrees, and classifies shared files as:
The observer reconciles durable
session_collisionfacts. A content signature ensures stable overlaps are written only once and re-evaluated only when the underlying changes actually differ.ACT
lifecycle.ApplyCollisionsends each affected live session a deduplicated coordination nudge identifying the peer session and the overlapping files.Current collisions are also exposed via:
GET /api/v1/projects/{id}/collisionsSurface Area
New
internal/observe/convergenceinternal/daemon/convergence_wiring.godomain.SessionCollision0020_session_collisionsports.WorkspaceDifferports.LineRangeExtended
GET /api/v1/projects/{id}/collisionscontrollerArchitectural Notes
The implementation follows existing AO patterns:
Durable facts only (status is derived at read time)
Loopback-only observation
No manual CDC
Code-first regeneration via:
npm run sqlcnpm run apiTesting
Validated with:
go build ./...go vetgofmtclean across all modified packagesgo test -racepassing for every touched package, including spec parity/drift testsNew test coverage includes:
Notes / Follow-ups
The desktop ⚡ Overlaps chip is intentionally deferred as a lightweight follow-up built on the new endpoint and derived facts.
Live user feedback is provided through agent nudges and the read endpoint. V1 intentionally avoids the
change_log/ notificationsCHECK-constraint table rebuild migrations.Existing unrelated failures remain unchanged:
TestManager_AddWorkspaceRejectsBareParent(currently fails on cleanmainwith newer Git)