Skip to content

fix(stack): publish scoped observations and drift atomically - #4820

Draft
ScriptedAlchemy wants to merge 3 commits into
masterfrom
fix/4436-atomic-stack-drift-observations
Draft

ScriptedAlchemy wants to merge 3 commits into
masterfrom
fix/4436-atomic-stack-drift-observations

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Scope

Refs #4436 — eliminate the split ownership of a stack's current observation and open drift intervals. This is a focused correctness/ownership slice, not full scope-lifetime retirement.

Previously store_observation read the prior snapshot under one mutex, calculated and updated drift under a second mutex, then published the observation after reacquiring the first mutex. Concurrent equivalent provider updates could both calculate drift from the same previous snapshot, emit duplicate transition observations, and race the interval frontier.

This change:

  • Replaces the separate observations and drift_intervals maps with a single ScopeObservationState entry holding both under the existing coordinator owner.
  • Serializes prior-snapshot comparison, drift update and snapshot publication as one in-memory transition, without holding the lock across network or database I/O.
  • Computes new drift intervals before replacing prior intervals, so failed identity derivation leaves the previous intervals unchanged.
  • Keeps persisted interval restoration under the same owner.
  • Prevents an unavailable policy snapshot prepared before a provider result from overwriting a newly published enabled/degraded provider observation (without changing the behavior of a real provider-unavailable response).

Behavioral regression

concurrent_identical_provider_publications_have_one_drift_transition starts 24 real threads behind a barrier, publishes the same changed stack head, and checks exactly one stack-tip transition and one opening BaseAdvanced interval, plus validation of every emitted drift receipt. This targets the prior read/modify/publish race rather than testing source shape.

Existing typed provider-state, drift close/restore and preflight tests remain.

Verification and limits

  • Independently reviewed the exact two-commit, three-file diff against master 91c72aba; no generated contracts or unrelated contributor paths changed.
  • Bazel Rust test, format and Clippy have not run locally (the current execution environment does not provide Bazel/rustc/rustfmt). Do not count an unexecuted test as green. Hosted exact-head CI is required before marking ready.
  • Remaining simplify(stack): replace parallel scope registries with one lifetime-owned coordinator state #4436 acceptance: consolidate the policy/circuit registrations and pass a lifetime-owned scope handle, refuse late cleanup from prior registrations, retire state only after the last owner/in-flight settlement, verify durable drift recovery, and measure bounded scope retention. This PR must stay draft until reviewed and validated; it does not close the issue.

No Kev/decision model, release, infrastructure, secret, beta.99 or mixed #4776 changes.

@changeset-bot

changeset-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7fbf287

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

No deployments
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.

1 participant