Skip to content

feat(event): add published-prefix SPSC primitives and failure-atomic admission (ADR-0006..0009) - #1861

Merged
lavkushry merged 1 commit into
mainfrom
feat/event-spsc-published-prefix
Jul 13, 2026
Merged

feat(event): add published-prefix SPSC primitives and failure-atomic admission (ADR-0006..0009)#1861
lavkushry merged 1 commit into
mainfrom
feat/event-spsc-published-prefix

Conversation

@lavkushry

@lavkushry lavkushry commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the unwired aegis-event prototype crate (lib/event/) implementing the Week-4 roadmap deliverables under four new Proposed ADRs, in two commits:

Commit 1 — 9d7208e (ADR-0006..0008 primitives)

  • ADR-0006 — cache-padded SPSC event fabric: SPSC ring with 64-byte-separated producer/consumer cursors, Acquire/Release sequence publication, 32-byte descriptors, bounded closure/drop behavior (ring.rs, descriptor.rs).
  • ADR-0007 — sealed generation-tagged slab pages: safe seal-before-publish ownership oracle used as the differential reference (slab.rs).
  • ADR-0008 — append-only published-prefix slab pages: packed Release/Acquire state publishing descriptor count, byte watermark, and closure for immediate immutable-prefix resolution (published_slab.rs).

Commit 2 — 5d4c491 (ADR-0009 failure-atomic admission)

  • ADR-0009 — failure-atomic slab/ring admission: composite volatile channel binding one published-prefix page to one descriptor ring (admission.rs).
  • try_admit publishes page-then-ring with no fallible work between the publication phases; a caught unwind closes the page, Release-stores FAULTED, closes the ring, and resumes the panic — a retained producer is terminal, never an atomically open poisoned lane.
  • Consumer validation fails closed: sequence gap/duplicate/reorder, arena identity, payload range, and CRC faults withhold the tail, disconnect the producer, and poison the consumer; ring invariant errors Release-close the ring before surfacing. Malformed terminal closure states never report CleanEnd.
  • Endpoints are Send but deliberately not Sync; frame leases are neither Send nor Sync — enforced by compile_fail doc-tests.
  • Success tokens are documented as volatile publication only — never a receipt, durability acknowledgement, or authorization result.

Status honesty (per docs/architecture.md vocabulary)

  • The prototypes are current only as isolated, unwired code + tests. The production event fabric remains target — no shadow traffic, no production wiring, cannot carry protected evidence, and no performance claims are made.
  • ADR-0006–0009 are Proposed, permitting only unwired prototypes until accepted.
  • Docs updated in the same change per the architecture-law documentation rule: Implementation_Status.md (v2 migration ledger), MIGRATION_MATRIX.md (post-audit delta against frozen baseline f027d07), ROADMAP.md, current-vs-roadmap.md, ARCHITECTURE.md, docs/LLD.md, ADR index, README.md, mkdocs.yml.
  • Remaining gates are listed explicitly (ADR acceptance/security review, green hosted sanitizer CI artifacts, authenticated registry, bounded page rotation, generation reuse/epochs, NUMA-owner reclamation, shadow wiring, UBSan toolchain support, qualification).

CI

New jobs gate the crate: event-concurrency (native + all-features tests, Loom models, all-feature clippy, exact runtime dependency-allowlist assertion, bench compile check), event-miri, and event-sanitizers (ASan/TSan matrix; Miri remains the Rust UB/provenance gate — nightly has no undefined sanitizer for Rust). The admission suite is wired into all three lanes.

Test plan

All re-verified locally on the final state of both commits:

  • cargo fmt --all -- --check, cargo clippy -p aegis-event --all-targets --all-features -- -D warnings
  • cargo test -p aegis-event and --all-features (incl. retained-producer caught-unwind tests at every publication phase, corrupt-descriptor and terminal-state fail-closed fixtures)
  • cargo test -p aegis-event --features loom loom_ (incl. validation-failure vs reserved-publication race model)
  • cargo +nightly miri test -p aegis-event (incl. all compile_fail doc-tests)
  • ASan + TSan (-Zbuild-std) on admission + published_slab integration suites
  • cargo check --workspace, node scripts/validate-docs.mjs (0 errors/warnings), node scripts/audit-doc-quality.mjs --check
  • PR CI: event-concurrency, event-miri, event-sanitizers lanes green on this PR

Copilot AI review requested due to automatic review settings July 13, 2026 17:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ecc-tools

ecc-tools Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@lavkushry
lavkushry merged commit 16580f5 into main Jul 13, 2026
30 of 32 checks passed
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 999966df-0d81-4e3d-a82d-bf236d451172

📥 Commits

Reviewing files that changed from the base of the PR and between eebcd58 and 9d7208e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (27)
  • .github/workflows/ci.yml
  • Cargo.toml
  • MIGRATION_MATRIX.md
  • README.md
  • ROADMAP.md
  • docs/Documentation_Quality_Report.md
  • docs/Implementation_Status.md
  • docs/LLD.md
  • docs/adr/0006-cache-padded-spsc-event-fabric.md
  • docs/adr/0007-sealed-generation-tagged-slab-pages.md
  • docs/adr/0008-append-only-published-prefix-slab-pages.md
  • docs/adr/index.md
  • docs/current-vs-roadmap.md
  • lib/event/Cargo.toml
  • lib/event/benches/published_slab.rs
  • lib/event/benches/spsc_ring.rs
  • lib/event/src/descriptor.rs
  • lib/event/src/lib.rs
  • lib/event/src/published_slab.rs
  • lib/event/src/ring.rs
  • lib/event/src/slab.rs
  • lib/event/tests/descriptor.rs
  • lib/event/tests/published_allocations.rs
  • lib/event/tests/published_slab.rs
  • lib/event/tests/slab.rs
  • lib/event/tests/spsc.rs
  • mkdocs.yml

📝 Walkthrough

Walkthrough

Changes

Event fabric prototypes

Layer / File(s) Summary
Ring, descriptor, and crate foundation
Cargo.toml, lib/event/src/*, lib/event/tests/descriptor.rs, lib/event/tests/spsc.rs, lib/event/benches/spsc_ring.rs, docs/adr/0006-*
Adds the aegis-event crate, descriptor validation, cache-padded SPSC ring, public exports, tests, benchmarks, and ADR-0006.
Sealed slab page implementation
lib/event/src/slab.rs, lib/event/tests/slab.rs, docs/adr/0007-*
Adds bounded mutable slab construction, sealing, CRC-validated resolution, typed errors, and coverage for lifecycle, corruption, wraparound, and concurrency behavior.
Published-prefix slab implementation
lib/event/src/published_slab.rs, lib/event/tests/published_slab.rs, lib/event/tests/published_allocations.rs, lib/event/benches/published_slab.rs, docs/adr/0008-*
Adds append-only Release/Acquire publication, reader validation, payload resolution, Loom/native tests, allocation checks, and benchmarks.
Safety gates and architecture status
.github/workflows/ci.yml, README.md, ROADMAP.md, MIGRATION_MATRIX.md, docs/*, mkdocs.yml
Adds event-specific native, Loom, Miri, sanitizer, Clippy, and benchmark CI lanes while documenting prototype status, evidence, blockers, ADR navigation, and generated inventory changes.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Producer
  participant SpscRing
  participant Consumer
  participant PublishedSlabReader
  Producer->>SpscRing: try_push descriptor
  Consumer->>SpscRing: try_pop descriptor
  Consumer->>PublishedSlabReader: resolve descriptor
  PublishedSlabReader-->>Consumer: validated payload
Loading

Suggested reviewers: copilot, dependabot[bot]

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/event-spsc-published-prefix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the aegis-event crate (lib/event), which implements high-performance, unwired v2 event primitives for the target data plane, including a cache-padded SPSC ring buffer, a safe sealed-page oracle, and an append-only published-prefix slab page. These additions are accompanied by extensive documentation updates, including proposed ADRs (0006, 0007, and 0008), benchmarks, and unit/integration tests. The reviewer suggested a valuable improvement to enforce the SPSC ring capacity constraints at compile time using const assertions instead of runtime checks, which would simplify the public API.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread lib/event/src/ring.rs
Comment on lines +211 to +222
fn validate_capacity<const N: usize>() -> Result<(), RingConfigError> {
if N == 0 {
return Err(RingConfigError::ZeroCapacity);
}
if !N.is_power_of_two() {
return Err(RingConfigError::NotPowerOfTwo { capacity: N });
}
if (N as u128) >= (1_u128 << 63) {
return Err(RingConfigError::SequenceAmbiguous { capacity: N });
}
Ok(())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The runtime check validate_capacity is called on every instantiation of SpscRing. Since N is a const generic parameter, we can enforce these constraints at compile time using a const assertion. This would turn potential runtime errors into compile-time errors, simplifying the public API by allowing SpscRing::new to return Self directly instead of a Result (though keeping the Result for backwards compatibility or transition is also fine).

const _ASSERT_VALID_CAPACITY: () = {
    assert!(N > 0, "SPSC ring capacity must be non-zero");
    assert!(N.is_power_of_two(), "SPSC ring capacity must be a power of two");
    assert!(N < (1 << 63), "SPSC ring capacity must be smaller than 2^63");
};

fn validate_capacity<const N: usize>() -> Result<(), RingConfigError> {
    Ok(())
}

@lavkushry lavkushry changed the title feat(event): add published-prefix SPSC primitives (ADR-0006..0008 prototypes) feat(event): SPSC/published-prefix primitives + failure-atomic admission (ADR-0006..0009 prototypes) Jul 13, 2026
@lavkushry lavkushry changed the title feat(event): SPSC/published-prefix primitives + failure-atomic admission (ADR-0006..0009 prototypes) feat(event): add published-prefix SPSC primitives and failure-atomic admission (ADR-0006..0009) Jul 13, 2026
lavkushry added a commit that referenced this pull request Jul 14, 2026
Conformance scan findings: the workspace tree omitted lib/event (present
on main since #1861 under Proposed ADRs), and 'introduced only through
accepted ADRs' contradicted the ADR index rule that Proposed ADRs permit
unwired prototypes — which is exactly how lib/event exists today.
lavkushry added a commit that referenced this pull request Jul 14, 2026
* feat(event): add ADR-0010 rotating admission prototype (unwired)

RotatingAdmissionChannel<N, P>: one SPSC descriptor ring spanning a
continuous sequence across a bounded series of published-prefix page
epochs (generation tag = epoch as u32, at most P live).

- rotation only on typed page/descriptor-full results and only before
  ring reservation; ADR-0009's [P]->[R]->[C] phase discipline unchanged
- typed PageQuotaExhausted backpressure with zero page/ring mutation
  when all P slots are outstanding (quota check precedes the seal)
- reclamation via one consumer->producer released-epoch Release/Acquire
  edge; the frame lease's mutable borrow of the consumer proves no
  payload borrow survives a release
- successor readers travel a bounded SPSC handoff ring whose publication
  happens-before the epoch's first data-ring descriptor; an absent
  handoff at a seam is terminal, never transient
- seam-strengthened terminal semantics: epoch-boundary committed-count
  shortfall, generation skip, handoff identity mismatch, orphaned final
  prefix all fail closed; caught-unwind rotation faults leave a retained
  producer terminal

Disclosed prototype deviations (ADR §Prototype notes): rebind allocates
one bounded page per rotation (in-place reuse precedes shadow); P is a
power of two >= 2; construction rejects a nonzero arena_generation.

Evidence: 11 native unit tests (rotation at byte/descriptor exhaustion
with sequence/generation continuity, quota refusal + recovery with
nothing mutated, seam shortfall, generation skip, faulted orphan, clean
aggregate end, post-seal unwind, alignment), 10k-event cross-thread
rotation stress + pool-bound test (wired into the ASan/TSan CI lanes as
--test rotating), a bounded Loom seam model (seal/handoff/[R]/[E]
interleavings; the initial unbounded-poll model was rewritten after it
demonstrably exploded Loom's state space), full Miri, all-features
clippy. Status honesty: ADR-0010 remains Proposed; the fabric remains
target with no shadow traffic and no performance claim.

* docs: align CLAUDE.md with the shipped tree and ADR vocabulary

Conformance scan findings: the workspace tree omitted lib/event (present
on main since #1861 under Proposed ADRs), and 'introduced only through
accepted ADRs' contradicted the ADR index rule that Proposed ADRs permit
unwired prototypes — which is exactly how lib/event exists today.

* docs: correct code_tour gateway layout to the real src/src tree

Conformance scan: the onboarding tour pointed agents at settings.rs,
axum_app.rs, tonic_app.rs, handlers/, middleware.rs and startup.rs —
none of which exist. The actual gateway binary is src/src/ with main.rs,
routes/, and grpc.rs; the thin-adapter law those names illustrated lives
in docs/architecture.md §5 and is unchanged.
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.

2 participants