Skip to content

perf: speed up full Project reconciliation - #10935

Merged
zouyonghe merged 5 commits into
AstrBotDevs:masterfrom
zouyonghe:perf/project-sync-full-scan
Nov 1, 2026
Merged

zouyonghe merged 5 commits into
AstrBotDevs:masterfrom
zouyonghe:perf/project-sync-full-scan

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replace per-commit/per-release git merge-base subprocess loops with cached git tag --contains ancestry sets, retaining earliest published stable-release selection and failing closed if an expected release tag was not fetched.
  • Emit flushed phase/page and candidate progress during full scans so long API and local ancestry work is visible in Actions logs.
  • Document the measured Git-only microbenchmark and its limits.

Verification

  • 48 focused offline tests pass (15 entrypoint/workflow, 27 delivery, 6 bounded event tests).
  • Full repository Ruff checks and Actionlint pass.
  • Git ancestry test covers lightweight/annotated tags, divergent ancestry, and fail-closed missing history.
  • Local microbenchmark: 237 release-style tags / 20 sampled commits; old loop 2,110 processes / 31.67s; new loop 20 processes / 0.35s. This measures Git ancestry only, not GraphQL or total Actions runtime.

This follows the Project sync implementation merged in #10905. No live Project write performed.

Summary by Sourcery

Speed up full Project reconciliation with cached Git ancestry checks, safer release verification, and improved scan progress visibility.

Bug Fixes:

  • Fail closed when stable release tags or ancestry history are unavailable, preventing incorrect published-release assignments.
  • Ensure bounded subject syncs retrieve all nested Project field values across pages.

Enhancements:

  • Accelerate full reconciliation release detection by replacing per-commit and per-release ancestry checks with cached tag-containment lookups while preserving earliest stable-release selection.
  • Add flushed phase, pagination, and candidate-processing progress to full reconciliation logs.

Documentation:

  • Document the Git ancestry performance benchmark and clarify that it excludes GraphQL and full-workflow runtime.

Tests:

  • Add coverage for tag containment across lightweight, annotated, and divergent tags, missing history, nested field-value pagination, and progress logging.

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the containment query classifies a commit against the wrong release tag, reconciliation could write an incorrect delivery value to a Project item. That value is persisted, but it can be corrected by rerunning reconciliation or reverting the change.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@zouyonghe

Copy link
Copy Markdown
Member Author

Follow-up fix in 80e7a2f: read_subject() now flattens each Project item’s nested fieldValues connection after paginating it. Added regression tests using the actual GraphQL connection shape, including a second page. Verified all 50 focused tests, repository Ruff checks, and Actionlint locally.

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_project_events.py" line_range="265" />
<code_context>
+            result["projectItems"][0]["fieldValues"], [first_value, second_value]
+        )
+        self.assertEqual(graphql.call_count, 2)
+        self.assertEqual(graphql.call_args_list[1].args[1]["cursor"], "CURSOR")
+
     def test_apply_failure_reports_confirmed_unknown_and_unattempted(self):
</code_context>
<issue_to_address>
**Wrong item IDs go undetected**

When the pagination request uses an ID other than the Project item’s ID, when `read_subject` requests the next field-values page using the wrong item ID, `test_subject_paginates_nested_project_field_values` still passes: its mocked GraphQL response ignores the request, and line 265 checks only the cursor.

Assert that the second GraphQL call passes `id="ITEM"` (and, if needed, that its query requests `ProjectV2Item.fieldValues`).
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the tag-containment calculation is wrong, reconciliation could write an incorrect release or delivery status into Project fields; those values persist after a revert but can be corrected by fixing the code and rerunning reconciliation. The added pagination can also change which field values bounded sync sees, but its effects are likewise repairable Project data.

Blocking findings: tests/test_project_events.py:265


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_project_events.py Resolved
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_project_delivery.py" line_range="243" />
<code_context>
+        with (
+            patch.object(sync, "ancestor", return_value=True),
+            patch.object(sync, "tag_names", return_value={"v1"}),
+            patch.object(sync, "tags_containing", side_effect=[{"v1"}, set()]),
         ):
             desired = sync.delivery(issue, {}, prs, releases, "c" * 40)
</code_context>
<issue_to_address>
**Commit mock is order-sensitive**

When set iteration visits the `b` commit first and delivery is broken to check only the first commit, `test_multiple_implementations_need_all_commits_in_release` assigns `tags_containing` results by call order, but `delivery` iterates an `integrated` set; if the `b` commit is visited first, a broken implementation that checks only that commit gets an empty set and passes the no-release assertions at `tests/test_project_delivery.py:246-247`.

Return containment results based on the commit argument and assert both commit OIDs were checked.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the new tag-containment calculation misclassifies a release, reconciliation could write an incorrect release or delivery status to a Project item. Those values are bounded and can be corrected by rerunning reconciliation; reverting alone would not undo an already-written value.

Blocking findings: tests/test_project_delivery.py:243


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_project_delivery.py Resolved
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_project_events.py" line_range="268" />
<code_context>
+        self.assertEqual(graphql.call_args_list[1].args[1]["cursor"], "CURSOR")
+        self.assertEqual(graphql.call_args_list[1].args[1]["id"], "ITEM")
+        self.assertIn("ProjectV2Item", graphql.call_args_list[1].args[0])
+        self.assertIn("fieldValues", graphql.call_args_list[1].args[0])
+
     def test_apply_failure_reports_confirmed_unknown_and_unattempted(self):
</code_context>
<issue_to_address>
**Cursor use goes unchecked**

When the nested query omits the cursor from its `fieldValues` connection, a nested field-values query that selects `fieldValues` but does not use `after:$cursor` still satisfies `test_subject_paginates_nested_project_field_values`: line 268 checks only a substring, while the mocked second response supplies the next page regardless of the query, so broken pagination passes the test.

Assert that the query binds `$cursor` to the nested `fieldValues` connection's `after` argument.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the new tag-containment check or paginated field reads produce the wrong delivery result, reconciliation could write an incorrect release or status value to a Project item. Reverting stops future writes, but the value already written remains until a later reconciliation corrects it.

Blocking findings: tests/test_project_events.py:268


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_project_events.py Resolved
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the tag-containment check picks the wrong release, reconciliation could write an incorrect delivery status or release value to a Project item. Reverting the code would not undo that stored value, but a corrected reconciliation can repair it.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@zouyonghe
zouyonghe merged commit c9a8cf3 into AstrBotDevs:master Nov 1, 2026
26 of 27 checks passed
@zouyonghe

Copy link
Copy Markdown
Member Author

Added diagnostic tracing in fe19b7d. Full scans already log phase/page and candidate progress; release ancestry now logs start/complete, commit prefix, tag count, and elapsed seconds to stderr. Added regression coverage for the diagnostic output. No sync semantics changed. Local suites: 15 entry, 27 delivery, 8 event tests; Ruff and Actionlint pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant