Skip to content

fix: deferred conditional guards drain at correct scope level (#540) - #541

Merged
sini merged 2 commits into
mainfrom
fix/deferred-guard-scope
May 14, 2026
Merged

sini merged 2 commits into
mainfrom
fix/deferred-guard-scope

Conversation

@sini

@sini sini commented May 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes BUG: <entity>.hasAspect doesn't work when it's included at the first place #540: policy.when with hasAspect failed when the conditional was the first include and its dependency was a later sibling
  • drain-conditionals was firing inside every resolve-children call, including nested aspects — the guard re-evaluated before siblings were walked
  • Now drains only at entity-level aspects (__entityKind) or root scope aspects (currentScope == rootScopeId)

Root cause

The conditional's resolve-children drained deferred guards before the parent finished walking all siblings. The pathSet was incomplete, so the guard failed and tombstoned permanently.

Test plan

Co-Authored-by: @fmway who provided amazing tests

@sini
sini requested a review from vic as a code owner May 14, 2026 09:28
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label May 14, 2026
@sini
sini force-pushed the fix/deferred-guard-scope branch from 435734f to c3dbc63 Compare May 14, 2026 09:30
@sini
sini force-pushed the fix/deferred-guard-scope branch 5 times, most recently from b9b9c3c to 82801aa Compare May 14, 2026 14:59
drain-conditionals was firing inside every resolve-children call,
including nested aspects. When a conditional was the first include
and its dependency was a later sibling, the drain fired inside the
conditional's own resolve-children — before the sibling was walked.
The guard re-evaluated against an incomplete pathSet and tombstoned.

Now drain only fires at entity-level aspects (__entityKind) or root
scope aspects (currentScope == rootScopeId), ensuring all siblings
have been walked before guards are re-evaluated.
@sini
sini force-pushed the fix/deferred-guard-scope branch from 82801aa to 8292cb9 Compare May 14, 2026 15:11
@vic vic added the super-autocompleted "Artificial Intelligence" terms nothing real, "Super Intelligence" is even more of a lie. label May 14, 2026
compile-conditional now reads scopedConstraintRegistry + scopeParent
from pipeline state and builds a scope-specific constraint view via
collectScopeConstraints. The guard's hasAspect returns false for
aspects that are in the pathSet but excluded in the current scope.

This correctly handles policy.exclude + policy.when hasAspect in the
same policy: the exclude registers before includes are processed
(emitPolicyEffectsThen emits excludes first), so by the time the
guard fires, the constraint registry already has the exclude entry.

Per-scope isolation: tux's exclude doesn't leak to pingu because
collectScopeConstraints only walks the current scope's ancestry.
@sini
sini force-pushed the fix/deferred-guard-scope branch from 219864f to a07482c Compare May 14, 2026 17:12
@sini
sini enabled auto-merge (squash) May 14, 2026 17:16
@sini
sini merged commit 8ab23d3 into main May 14, 2026
16 checks passed
@sini
sini deleted the fix/deferred-guard-scope branch May 14, 2026 17:19
@fmway

fmway commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Great. Thanks for breakfast 🍞!

charlesfire pushed a commit to charlesfire/den that referenced this pull request May 16, 2026
…#540) (denful#541)

## Summary

- Fixes denful#540: `policy.when` with `hasAspect` failed when the conditional
was the first include and its dependency was a later sibling
- `drain-conditionals` was firing inside every `resolve-children` call,
including nested aspects — the guard re-evaluated before siblings were
walked
- Now drains only at entity-level aspects (`__entityKind`) or root scope
aspects (`currentScope == rootScopeId`)

## Root cause

The conditional's `resolve-children` drained deferred guards before the
parent finished walking all siblings. The pathSet was incomplete, so the
guard failed and tombstoned permanently.

## Test plan

- [x] `test-conditional-before-dependency` — conditional first,
dependency second in aspect includes
- [x] `test-conditional-same-level-schema` — same pattern via schema
includes
- [x] Full CI: 805/805 passing (including all prior denful#525/denful#530 tests)

Co-Authored-by: @fmway who provided amazing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests super-autocompleted "Artificial Intelligence" terms nothing real, "Super Intelligence" is even more of a lie.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: <entity>.hasAspect doesn't work when it's included at the first place

3 participants