Skip to content

MVP: Scope recompute to changed schema elements#9467

Draft
BeArchiTek wants to merge 1 commit into
stablefrom
001-scope-computed-attr-recompute
Draft

MVP: Scope recompute to changed schema elements#9467
BeArchiTek wants to merge 1 commit into
stablefrom
001-scope-computed-attr-recompute

Conversation

@BeArchiTek

@BeArchiTek BeArchiTek commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9415. Previously, any schema change recomputed every computed attribute on the branch — and for Python-transform attributes, one recompute job per object of its kind — regardless of relevance. On large datasets this was slow and wasteful.

Recompute is now scoped to the schema elements a change actually touches: a computed attribute is recomputed only when the change affects an element its value depends on (including elements reached through relationships). When the impact cannot be determined precisely, it conservatively falls back to a full recompute so nothing goes stale.

How it works

  • SchemaUpdatedEvent now carries a ChangedElementsPayload (added/removed kinds + per-kind changed fields), built from the SchemaDiff by the two schema-update emitters and threaded through the Prefect triggers into the setup flows.
  • RecomputeScoper (constructor-injected, single entry point) intersects each attribute's dependency set against the changed elements. Per-kind ComputedAttributeDependencyDeriver implementations cover Jinja2 (template dependency graph) and Python transforms (GraphQL query analysis).
  • Conservative fallbacks: no change set → full recompute; unanalyzable or derived reads (display label, human-friendly id) → recompute that attribute on every change, without escalating others.

Scope notes

  • Branch-aware: a change on one branch never broadens recompute onto another.
  • Merge/rebase emit branch/node events (not SchemaUpdatedEvent), so this scoping does not run on the merge path — unchanged from before; merged data changes recompute via the existing data-change path.

Testing

  • Unit (38): scoping decision matrix, both derivers, payload flattening, trigger rendering.
  • Component (8, TestContainers): Jinja2 + Python scoped recompute end-to-end.
  • integration_docker (8, full stack): unrelated change → zero recompute; read-field change (incl. across a relationship) → scoped recompute; branch isolation; merge characterization.
  • ruff + mypy clean.

Also adds backend/tests/integration_docker/conftest.py disabling commit signing for the test session so repo-based integration tests run regardless of a developer's commit.gpgsign.

🤖 Generated with Claude Code


Summary by cubic

Scopes computed-attribute recompute to only the schema elements that changed, instead of recomputing everything on each schema update. Fixes #9415 and reduces unnecessary jobs on large datasets while keeping correctness with conservative fallbacks.

  • Bug Fixes
    • Added ChangedElementsPayload to SchemaUpdatedEvent, populated from SchemaDiff; triggers now pass changed_elements through to setup flows.
    • Introduced RecomputeScoper to intersect each attribute’s dependencies with changed elements; supports Jinja2 and Python transforms via TransformReadSet. Imprecise field reads (display_label, hfid) cause that attribute to always recompute.
    • Fallbacks: no change set → full recompute; branch-scoped behavior preserved; merge/rebase path unchanged.

Written for commit fe7ea71. Summary will update on new commits.

Review in cubic

@BeArchiTek BeArchiTek requested a review from a team as a code owner June 4, 2026 16:40
@github-actions github-actions Bot added group/backend Issue related to the backend (API Server, Git Agent) type/spec A specification for an upcoming change to the project labels Jun 4, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing 001-scope-computed-attr-recompute (fe7ea71) with stable (31f082e)

Open in CodSpeed

@cubic-dev-ai cubic-dev-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.

2 issues found across 27 files

Confidence score: 3/5

  • There is a concrete regression risk in backend/infrahub/computed_attribute/tasks.py: when changed_elements is missing, recomputation appears limited to modified triggers instead of all branch attributes, which can leave computed values stale for users.
  • Given the high confidence and user-facing impact of stale computed attributes, this lands as some merge risk rather than a low-risk housekeeping change.
  • The dev/specs/001-scope-computed-attr-recompute/data-model.md inconsistency (is_available typed as bool but notes implying None) is low severity and mainly documentation/model clarity, so it should not block merge by itself.
  • Pay close attention to backend/infrahub/computed_attribute/tasks.py - verify fallback recomputation covers all branch attributes when changed_elements is unavailable.

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

Comment thread backend/infrahub/computed_attribute/tasks.py Outdated
Comment thread dev/specs/001-scope-computed-attr-recompute/data-model.md
@BeArchiTek BeArchiTek marked this pull request as draft June 4, 2026 17:37
@BeArchiTek BeArchiTek changed the title fix(computed-attribute): scope recompute to changed schema elements (#9415) MVP: Scope recompute to changed schema elements Jun 4, 2026
…9415)

Previously any schema change recomputed every computed attribute on the
branch — for Python-transform attributes, one recompute job per object of
its kind — regardless of relevance. Recompute is now scoped to the schema
elements a change actually touches: a computed attribute is recomputed only
when the change affects an element its value depends on, including elements
reached through relationships. Changes whose impact cannot be determined
fall back to a full recompute so nothing goes stale.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BeArchiTek BeArchiTek force-pushed the 001-scope-computed-attr-recompute branch from d07fc78 to fe7ea71 Compare June 4, 2026 17:46
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Jun 4, 2026
@BeArchiTek BeArchiTek self-assigned this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) type/documentation Improvements or additions to documentation type/spec A specification for an upcoming change to the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: any schema change recomputes all computed attributes, even unrelated ones

1 participant