Skip to content

fix(stack): restore scope drift intervals after restart - #4961

Merged
ScriptedAlchemy merged 2 commits into
masterfrom
triage/stack-grammar-audit
Nov 25, 2026
Merged

ScriptedAlchemy merged 2 commits into
masterfrom
triage/stack-grammar-audit

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What this changes

#4436 — one lifetime-owned stack scope state, plus production restart restoration.

  • DaemonGitHubStackCoordinatorV1::register_scope(scope, stacked_pr_policy, circuit_policy) now writes the policy, circuit policy, current observation and drift intervals into the scope's single ScopeObservationState and returns the GitHubStackScopeV1 handle. The separate register_circuit_policy is deleted.
  • Project open hands that one handle to the native delivery runtime mount and to GitHubReviewRuntimeOwnerConfigV1; the review owner joins it instead of re-looking-up the scope key with retain_scope. The old block-scoped _stack_registration is gone, so the policy registration no longer depends on another owner keeping the scope alive.
  • New observability::restore_github_stack_drift_intervals reads this project's newest durable drift receipts through the canonical ObservabilityQueryPort (bounded: 64 events/page × 8 pages) and rebuilds a still-open interval only when the envelope trace binds the exact scope digest, drift kind and opening time. GitHubReviewRuntimeOwnerV1::refresh runs it once per mounted owner before it can publish a sample, so the next observation closes the original durable trace instead of opening a duplicate interval.
  • A sibling worktree of the same project shares the receipt scope reference but not the scope digest; its receipt is counted as unbound and skipped. restore_open_drift_interval takes the live handle and keeps the earlier opening time, so a late or repeated restore cannot rewrite newer live evidence or a successor registration.

No manifest, lockfile, generated BUILD, or release-file change; no repin or gen_builds run was needed.

Evidence

Focused Bazel runs (all --test_output=all, exact paths through scripts/require-exact-test.sh where pinned):

Test Result
github_stack_coordinator::retired_scope_registrations_release_all_state 1 passed; 0 failed
github_stack_coordinator::a_late_restore_cannot_rewrite_a_live_open_interval (asserts ScopeAlreadyObserved, live interval unchanged) 1 passed; 0 failed
github_stack_drift_observability::restore_reduces_drift_kinds_by_event_time_across_unsorted_pages 1 passed; 0 failed
github_stack_drift_observability::restart_restores_only_this_scope_open_drift_and_closes_its_original_trace 1 passed; 0 failed
github_stack_coordinator::scope_state_retires_after_the_last_mounted_owner_and_provider_read 1 passed; 0 failed
github_stack_coordinator::restarted_owner_refuses_pre_restart_reads_and_settles_restored_drift 1 passed; 0 failed
//crates/tracedecay-application:application_suite (full, uncached) 102 passed; 0 failed
stack-filtered subset (coordinator + drift observability) 31 passed; 0 failed
preflight module through the migrated registration 9 passed; 0 failed
//crates/tracedecay-agent-hosts:unit_test stack journeys (declared_stack_runtime_shares_native_preview…, checked_out_declared_stack_conflict…, expired_stack_notice_expansion…) 1 passed each
bazel build //crates/tracedecay-cli:tracedecay and //crates/tracedecay:daemon_suite build success
rustfmt_check_2024 for application, agent-hosts, tracedecay success

Review fixes (58147b6095)

  • Configuration reload overwrites live drift — restoration is now a mount transition: GitHubStackScopeV1::is_mount_fresh() gates it, restore_github_stack_drift_intervals returns scope_already_live without reading or writing once an observation exists, and restore_open_drift_interval refuses the write with the typed ScopeAlreadyObserved error. A concurrent observation winning that transition is folded into the same typed outcome.
  • Older receipt hides newer interval — the scan now reduces each drift kind by greatest event_time_micros across the bounded pages instead of stopping at its first receipt, because the observability port pages by insertion id and sorts only within a page. Coverage is Known only when the scan reaches the end of the project's drift receipts.

One full-suite run under peak parallel load showed a transient failure in observability_runtime_contract::real_work_owner_receipts_converge_to_rollup; it passes in isolation and the following uncached full run is 102/102.

The restart test drives the real registered project database and the real bounded observability producer, then restores through RegisteredObservabilityPortV1 into a fresh coordinator and asserts the persisted trace closes at the next observation.

Pre-existing failures, proven at base 9d2d6c0a62 by stashing this branch

  • daemon_suite: store_shutdown_checkpoint_test::{route_bind_eviction_cannot_retire_a_reopened_projects_owners, capacity_retirement_behind_a_parked_bind_eviction_cleanup_completes} (suite: 35 passed / 2 failed; each fails in isolation at base).
  • application unit_test: 3 pr_tracking::worktrees git-index tests (615 passed / 3 failed at base).

Unresolved #4436 criteria (Refs, not Closes)

  • No end-to-end durable-restart journey through GitHubReviewRuntimeOwnerV1::refresh and no mounted-runtime-drop journey test. The restore mechanics are pinned against the real store/coordinator, and the refresh call site is compile-verified, but journey-level acceptance remains open.
  • The 10-agent design's settled ruling 13 deferred a production reader. This PR implements it because the lane brief asked for production restart restoration; the coordinator may drop this commit to restore that ruling.

#4229 grammar decision: no change

The decision rule requires a measured cost reduction beyond run-to-run spread and lacking demand or quality.

  • Measured today: extractor rlib full 9,061,376 B vs lite variant 6,700,704 B (Δ 2,360,672 B); tokensave-large-treesitters rlib 15,460,664 B is linked only by the full tier. The fastbuild CLI is 662,556,384 B with debug info, so it makes no release-size claim.
  • Missing: clean/warm build-time, release-artifact and startup deltas require a clean build in a solo granted slot. Partially opting languages out of large-grammars also only helps if linker GC keeps the gain, which is unmeasured.
  • Demand: COBOL/Fortran/BASIC/Quint/Lean are named only by Make additional niche grammar sets opt-in based on measured quality, demand, and build cost #4229 (plus one closed COBOL parser bug); no fixture in crates/tracedecay-code-extraction/fixtures or benchmark_data exercises .cob/.f90/.bas/.quint/.lean.
  • Quality: extraction suites pass (664 unit + 50 integration, 0 failed), so no quality signal justifies removal either.

No set qualifies; defaults are unchanged and #4229 stays open with the remaining measurements named above.

Tracker audits (no tracker edits in this PR)

Refs #4436
Refs #4229

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 58147b6

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

Each mounted stack scope now holds one registration that owns its
stacked-PR policy, preflight circuit and scope state, so project open
hands the exact handle to the delivery runtime and the review owner
instead of registering the same scope key twice.

A restarted daemon reads its newest durable drift receipts for the
exact scope before the review owner publishes its first observation.
Receipts bind through the canonical envelope trace (scope digest,
drift kind, opening time), a foreign worktree's receipt is skipped,
and only a still-open interval is rebuilt with its original trace so
the next observation closes it instead of opening a duplicate.

Refs #4436
@ScriptedAlchemy
ScriptedAlchemy force-pushed the triage/stack-grammar-audit branch from 737f984 to bd9682f Compare November 24, 2026 22:11
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

No changeset applies here: this repository releases through release-please (.github/workflows/release-please.yml, .release-please-manifest.json), has no .changeset directory or config, and every crate touched by this PR is publish = false. No version bump is expected for this internal fix commit.

devin-ai-integration[bot]

This comment was marked as resolved.

Restoration is now a mount transition. A registration that already
published an observation returns `scope_already_live` and its live drift
state is left untouched, so a configuration reload that rebuilds the
review owner cannot replace a newer live interval with an older durable
receipt the producer has not caught up with. `restore_open_drift_interval`
refuses such a write with `ScopeAlreadyObserved`.

The receipt scan also reduces each drift kind by its greatest event
time instead of stopping at its first receipt. The observability port
pages by insertion id and sorts only within a page, so a late-persisted
close can precede a newer open interval; the old early exit could hide
that open interval and leave it untracked after restart.

Refs #4436
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Fixed in 58147b6 (thread: configuration reload).

Restoration is now a mount transition: restore_github_stack_drift_intervals checks GitHubStackScopeV1::is_mount_fresh() first and returns scope_already_live without reading or writing when the registration already published an observation. restore_open_drift_interval additionally refuses the write with the new typed ScopeAlreadyObserved error, so a rebuilt review owner can never replace live drift state with a receipt the producer has not persisted yet. A concurrent observation that wins the mount transition is treated as the same typed refusal rather than an error.

Covered by github_stack_coordinator::a_late_restore_cannot_rewrite_a_live_open_interval (now asserts the refusal and that the live interval still closes on its own trace).

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Fixed in 58147b6 (thread: older receipt hides newer interval).

Confirmed against the code you cited: query_analytics_events orders observability rows by id DESC and the adapter sorts only within the returned page, so insertion order can invert event time. The scan no longer stops at the first receipt per kind; it now reduces each StackDriftKindV1 to the receipt with the greatest event_time_micros across the bounded pages (64/page × 8 pages), and only that reduction decides Open vs Closed. Coverage is Known only when the scan reaches the end of the project's drift receipts.

New pin github_stack_drift_observability::restore_reduces_drift_kinds_by_event_time_across_unsorted_pages feeds a fake port with the reviewed shape — an earlier page carrying a late-persisted close (event time 1500) ahead of a later page carrying the newer open (event time 2000) — and asserts the open interval is restored and closes on its original trace. The old early-exit scan returns 0 restored against that fixture.

@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) November 24, 2026 22:58
@ScriptedAlchemy
ScriptedAlchemy merged commit fc80c47 into master Nov 25, 2026
16 checks passed
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