feat(graph): per-branch graph identity (T17 #651)#675
Draft
DvirDukhan wants to merge 1 commit into
Draft
Conversation
Refactor FalkorDB graph naming so each (project, branch) pair gets
its own graph: 'code:{project}:{branch}'. This lets concurrent agents
working on different branches of the same repo index in parallel
without overwriting each other.
Changes:
- api/graph.py: add DEFAULT_BRANCH, compose_graph_name(),
parse_graph_name(); Graph and AsyncGraphQuery constructors now
accept (name, branch=None); Graph.from_raw_name() classmethod for
internal callers that need to bypass composition (e.g. clone());
get_repos()/async_get_repos() now return {project, branch, graph}
dicts.
- api/info.py: branch-aware Redis hash keys
('{repo}:{branch}_info'); reads fall back to legacy '{repo}_info'
for un-migrated graphs.
- api/git_utils: GitRepoName() and switch_commit() thread branch
through; LegacyGitRepoName() retained for the migration helper.
- api/project.py: detect_branch() via 'git rev-parse --abbrev-ref
HEAD'; Project.__init__ / from_git_repository /
from_local_repository accept branch.
- api/index.py: all Pydantic request models gain
'branch: Optional[str]'; endpoints thread it into
AsyncGraphQuery + info functions; responses include 'branch'.
- api/cli.py: --branch flag on index / index-repo / search /
neighbors / paths / info; new 'cgraph migrate' command.
- api/migrations/per_branch.py (NEW): idempotent migration that
renames legacy '<project>' graphs to 'code:<project>:_default',
'{<project>}_info' Redis keys to '{<project>}:_default_info',
and '{<project>}_git' graphs to '{<project>}:_default_git'.
Supports --dry-run.
Tests:
- tests/test_per_branch_graphs.py (NEW): 24 unit tests covering
compose/parse helpers, Graph constructor branch awareness,
AsyncGraphQuery, info-key shape, GitRepoName shape, and migration
idempotency (with mocked FalkorDB).
- tests/test_async_graph.py, tests/test_cli.py,
tests/endpoints/test_list_repos.py: updated assertions for the
new dict return shape from get_repos / async_get_repos.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
This was referenced May 27, 2026
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.
Closes #651.
Stacked on #666 (
mcp/t1-scaffold).What
Each FalkorDB graph is now identified by
(project, branch)ratherthan just
project. Concurrent agents indexing the same repo ondifferent branches no longer overwrite each other.
New graph name format:
code:{project}:{branch}(default branch:_default). The companion Redis info hash becomes{project}:{branch}_infoand the git-history graph becomes{project}:{branch}_git.Highlights
Graph/AsyncGraphQueryconstructors acceptbranch=None./api/*endpoints accept an optionalbranchfield; responsesinclude
branchso the frontend can disambiguate.--branchon every read/index command and auto-detectsfrom
git rev-parse --abbrev-ref HEADwhen omitted.cgraph migratecommand (idempotent,--dry-runsupported)promotes legacy
<project>graphs tocode:<project>:_default.tests/test_per_branch_graphs.py. Existingtest_async_graph.py/test_cli.py/test_list_repos.pyupdated for the new dict return shape of
get_repos.Backward compatibility
Graph("foo")still works → composes tocode:foo:_default.{foo}_infokey when thenew key is absent, so un-migrated repos remain queryable until
the operator runs
cgraph migrate.parse_graph_namereturnsNonefor legacy bare names socallers can detect and special-case them.
Migration story
One-shot rename of legacy artifacts via
cgraph migrate:<project>→code:<project>:_default{<project>}_info→{<project>}:_default_info{<project>}_git→{<project>}:_default_gitSafe to re-run.
--dry-runpreviews actions without writing.Not in scope
process_git_historyalready does (it now writes to the per-branch git graph but does
not yet track multiple branches in a single run).
Test status
tests/test_per_branch_graphs.py: 24 ✅tests/test_async_graph.py: 6 ✅tests/test_cli.py: 10 ✅Pre-existing failures unrelated to T17 (missing
tests/git_repofixture, hard-coded port 6379 in
test_graph_ops.py, analyzertests requiring specific source builds) remain unchanged from
mcp/t1-scaffold.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com