Skip to content

feat(backend): configure revision sort order#1379

Open
DivyamTalwar wants to merge 7 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/feat-1016-revision-sort-config
Open

feat(backend): configure revision sort order#1379
DivyamTalwar wants to merge 7 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/feat-1016-revision-sort-config

Conversation

@DivyamTalwar

@DivyamTalwar DivyamTalwar commented Jun 28, 2026

Copy link
Copy Markdown

Fixes #1016

Problem

When revisions.branches or revisions.tags match more refs than Sourcebot can index, the order used before truncation determines which refs survive. Branches and tags currently use hardcoded ordering, so users cannot choose lexicographic ref-name ordering or use the maintainer-approved sort config from the issue.

Root cause

getBranches() always sorted by -committerdate, getTags() always sorted by -creatordate, and the connection schema only exposed branch/tag glob arrays. The index manager had no metadata field to pass sort preferences into Git ref discovery. The docs also needed to match the existing runtime cap: Sourcebot keeps one global 64-revision budget, including the default branch, and considers matching branches before matching tags.

Solution

  • Add revisions.branchSort and revisions.tagSort to the v3 schema with committerdate, creatordate, and refname values.
  • Preserve current defaults: branches use newest commit date first, tags use newest creator date first.
  • Persist the sort config in repo metadata for every supported connection type.
  • Pass configured sort values into Git ref lookup before matching and truncation.
  • Document the global 64-revision cap, branch-before-tag ordering, and Git for-each-ref sort semantics.
  • Regenerate schema artifacts.

Tests

  • Added Git regression tests for explicit refname ordering on branches and tags.
  • Added index-manager coverage proving configured sort values are passed into branch/tag lookup.
  • Added mixed branch/tag overflow coverage proving the default branch is kept first, branches are considered before tags, and the combined list is truncated to 64 revisions.
  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts src/zoekt.test.ts
  • node .yarn/releases/yarn-4.7.0.cjs build:deps
  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend build
  • rg check for stale independent branch/tag cap wording
  • git diff --check origin/main...HEAD

Risk

Moderate. The schema artifacts are broad because the shared GitRevisions schema is dereferenced by every v3 connection schema, but the runtime behavior is limited to revision ordering before existing matching/deduplication/truncation.

Summary by CodeRabbit

  • New Features
    • Added branchSort and tagSort options for indexed revisions to control ordering of candidate branches vs tags before the global revision cap is applied.
    • Supports committerdate, creatordate, and refname, with different defaults for branches vs tags.
  • Documentation
    • Updated revision-indexing docs and JSON schemas to clarify branch-before-tag selection and the “up to 64 total revisions” truncation behavior.
  • Tests
    • Added coverage for refname sorting and for ensuring configured sort settings are applied during indexing.

Constraint: Issue sourcebot-dev#1016 has maintainer-approved config names branchSort and tagSort, and existing behavior must remain the default.

Rejected: Changing the 64-revision cap or adding per-kind limits | useful follow-up, but broader than the approved sort-control scope.

Confidence: high

Scope-risk: moderate

Directive: Keep date-based revision sorts newest-first so unset config and explicit date config preserve current indexing priority.

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/schemas build; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/shared build; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend build

Not-tested: Full monorepo test suite.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8df4d367-ebd9-4c28-98fe-716eb1e3e0ae

📥 Commits

Reviewing files that changed from the base of the PR and between c32d8b6 and 77a0454.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

Adds configurable branch/tag sort options to revision schemas, threads them into repository metadata and indexing, and updates git lookup, tests, changelog, and docs for the combined 64-revision cap and branch-before-tag selection order.

Changes

Configurable revision sorting

Layer / File(s) Summary
Revision config contracts and schemas
packages/shared/src/types.ts, packages/schemas/src/v3/*.type.ts, packages/schemas/src/v3/*.schema.ts, docs/snippets/schemas/v3/*.mdx, schemas/v3/shared.json
Adds branchSort and tagSort to shared and host-specific revision types/schemas, and updates revision-selection wording to describe the combined 64-revision cap and branch-before-tag ordering.
Git ref sorting and lookup
packages/backend/src/git.ts, packages/backend/src/git.test.ts
Adds configurable git for-each-ref sort mapping and updates branch/tag lookup tests for refname ordering.
Metadata propagation and indexing
packages/backend/src/repoCompileUtils.ts, packages/backend/src/repoIndexManager.ts, packages/backend/src/repoIndexManager.test.ts
Carries sort settings into repo metadata and indexing, and verifies truncation plus sort forwarding in worker tests.
Docs and changelog
CHANGELOG.md, docs/docs/features/search/multi-branch-indexing.mdx
Documents the new revision sort options and the updated indexing order.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: sourcebot-team

Suggested reviewers: brendan-kellam, msukkari

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: configurable revision sort order in the backend.
Linked Issues check ✅ Passed Implements #1016 by adding branchSort/tagSort config, applying it before truncation, and preserving the 64-revision cap.
Out of Scope Changes check ✅ Passed No unrelated code changes are evident; the edits all support revision sort configuration, docs, schema, and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Constraint: Sourcebot requires every non-doc PR to add an Unreleased changelog entry that links to the PR.

Confidence: high

Scope-risk: narrow

Directive: Keep schema/config additions under Added unless they are pure fixes.

Tested: Changelog format matched adjacent Unreleased Added entries.

Not-tested: No code tests run for changelog-only commit.
@DivyamTalwar DivyamTalwar marked this pull request as ready for review June 28, 2026 00:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/git.test.ts`:
- Around line 95-119: The getTags/getBranches sort tests are currently masked by
the shared repo fixture’s refname defaults, so they don’t verify the new sort
argument is used. In the getTags and getBranches test cases, override the repo
config to a different default sort before calling getTags(..., { sort: "refname"
}) / getBranches(..., { sort: "refname" }), then assert the returned order
changes only because of the explicit sort option. Use the existing getTags,
getBranches, createTempRepo, and runGit helpers to set up the conflicting config
inside each test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5275d52d-c96f-4442-b450-e39fee67b14b

📥 Commits

Reviewing files that changed from the base of the PR and between 82b5c1f and 4adba13.

📒 Files selected for processing (39)
  • CHANGELOG.md
  • docs/docs/features/search/multi-branch-indexing.mdx
  • docs/snippets/schemas/v3/azuredevops.schema.mdx
  • docs/snippets/schemas/v3/bitbucket.schema.mdx
  • docs/snippets/schemas/v3/connection.schema.mdx
  • docs/snippets/schemas/v3/genericGitHost.schema.mdx
  • docs/snippets/schemas/v3/gerrit.schema.mdx
  • docs/snippets/schemas/v3/gitea.schema.mdx
  • docs/snippets/schemas/v3/github.schema.mdx
  • docs/snippets/schemas/v3/gitlab.schema.mdx
  • docs/snippets/schemas/v3/index.schema.mdx
  • docs/snippets/schemas/v3/shared.schema.mdx
  • packages/backend/src/git.test.ts
  • packages/backend/src/git.ts
  • packages/backend/src/repoCompileUtils.ts
  • packages/backend/src/repoIndexManager.test.ts
  • packages/backend/src/repoIndexManager.ts
  • packages/schemas/src/v3/azuredevops.schema.ts
  • packages/schemas/src/v3/azuredevops.type.ts
  • packages/schemas/src/v3/bitbucket.schema.ts
  • packages/schemas/src/v3/bitbucket.type.ts
  • packages/schemas/src/v3/connection.schema.ts
  • packages/schemas/src/v3/connection.type.ts
  • packages/schemas/src/v3/genericGitHost.schema.ts
  • packages/schemas/src/v3/genericGitHost.type.ts
  • packages/schemas/src/v3/gerrit.schema.ts
  • packages/schemas/src/v3/gerrit.type.ts
  • packages/schemas/src/v3/gitea.schema.ts
  • packages/schemas/src/v3/gitea.type.ts
  • packages/schemas/src/v3/github.schema.ts
  • packages/schemas/src/v3/github.type.ts
  • packages/schemas/src/v3/gitlab.schema.ts
  • packages/schemas/src/v3/gitlab.type.ts
  • packages/schemas/src/v3/index.schema.ts
  • packages/schemas/src/v3/index.type.ts
  • packages/schemas/src/v3/shared.schema.ts
  • packages/schemas/src/v3/shared.type.ts
  • packages/shared/src/types.ts
  • schemas/v3/shared.json

Comment thread packages/backend/src/git.test.ts
Clarify that Sourcebot applies one global revision budget after the default branch, then matching branches, then matching tags. Add a mixed branch/tag overflow regression so future changes cannot accidentally present branch and tag limits as independent.

Constraint: Existing runtime behavior has a 64 total revision cap including the default branch, with matching branches considered before matching tags.
Rejected: Changing selection semantics in this PR | larger behavioral change than the scoped sort-configuration fix and would need maintainer direction.
Confidence: high
Scope-risk: moderate
Directive: Do not describe branch and tag caps as independent; tags can be skipped when branches fill the revision budget.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts; node .yarn/releases/yarn-4.7.0.cjs build:deps; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend build; rg stale 64 branch/tag wording; git diff --check.
Not-tested: Full monorepo test suite.
Bring the remote branch's main merge into the local PR branch so the reviewer-blocker fix can be pushed without force. The integration is limited to the upstream zoekt argument hardening commit and its changelog entry.

Constraint: Remote branch had advanced with origin/main and rejected a fast-forward push.
Rejected: Force-pushing over the remote branch | would discard branch history and violate the safe PR workflow.
Confidence: high
Scope-risk: narrow
Directive: Preserve upstream merge commits on contributor branches unless maintainers explicitly ask for a history rewrite.
Tested: git diff --check --cached.
Not-tested: Post-merge backend test/build rerun before this commit; those run after integration.
Strengthen the explicit revision sort regression tests so they fail if the sort argument is ignored and repo-local defaults would otherwise mask the behavior.

Constraint: CodeRabbit found the explicit-sort tests inherited matching repo config defaults.

Rejected: Change production git sort handling | existing implementation already passes --sort for branch and tag reads.

Confidence: high

Scope-risk: narrow

Directive: Keep revision ordering tests configured so explicit sort options conflict with repo defaults.

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts

Not-tested: Full monorepo test suite; change is limited to backend git regression tests.
…6-revision-sort-config

# Conflicts:
#	CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]Sort tags and branches list before 64-revision cap so pruning keeps newest N refs

1 participant