Skip to content

feat(paging,#1299): PressureBrokerModule bootstrap — singleton + DockerTierPool register + tick loop (PR-1) - #1307

Merged
joelteply merged 1 commit into
canaryfrom
feat/pressure-broker-bootstrap-1299
May 16, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/pressure-broker-bootstrap-1299

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

PR-1 of #1299 (Phase 2 of #1239). Brings the cross-pool PressureBroker online:

  • New modules::pressure_broker_module::PressureBrokerModule wraps Arc<PressureBroker> and pre-registers DockerTierPool on construction.
  • Hands the broker's relieve() tick to the runtime's standard start_tick_loops() machinery (cadence = BrokerConfig.tick_interval, default 5s, matching DMR_TICK_INTERVAL).
  • tick() wraps relieve() in spawn_blocking because DockerTierPool::evict_at_least shells out to docker system prune which can take seconds.
  • Observer-only: empty command_prefixes so the runtime router never dispatches here. Typed system/pressure-broker-state IPC lands in PR-2; chat-substrate alert sink lands in PR-3.
  • broker() getter so the ipc/mod.rs bootstrap can expose the broker to other subsystems (VRAM/KV-cache pool registration, alert sink wiring) without re-instantiating.
  • Registered in ipc/mod.rs::start_server next to SystemResourceModule using the standard runtime.register(Arc::new(...)) pattern.

Acceptance items closed by this PR (per #1299)

  • (1) Singleton instantiated at server boot
  • (2) DockerTierPool registered on boot
  • (3) Tick loop calling relieve() on cadence
  • (6) Test with fake ResourcePool

Deferred to follow-up slices on this same card

  • (4) Chat-substrate alert sink → PR-3
  • (5) system/pressure-broker-state IPC + bin/continuum status row → PR-2

Test plan

  • 6 new unit tests pass (cargo test --lib --features metal,accelerate modules::pressure_broker_module):
    • DockerTierPool present in broker right after ::new()
    • ModuleConfig tick_interval mirrors BrokerConfig
    • command_prefixes empty in PR-1 (regression guard for future maintainers)
    • tick → relieve fires eviction when fake pool is at ~95% pressure
    • tick is a no-op when all pools below threshold
    • handle_command error explains the PR-1-observer-only staging
  • cargo build --lib --features metal,accelerate: clean (no new warnings; pre-existing 52 unchanged)
  • CI green on this PR
  • Live: start the server, watch the pressure-broker tick loop appear in Started N tick loops log line

Why a wrapper module vs OnceLock<Arc<PressureBroker>> directly

Every other singleton in this server (gpu_manager, system_monitor, etc.) either lives behind a ServiceModule or is owned by one. Following that pattern keeps the boot sequence in ipc/mod.rs uniform and gives the broker the same shutdown / metrics treatment as everything else.

Coordination

Aligned with codex's parallel #1306 — that PR lifts cognition's hardcoded max_concurrency: 1 cap with this broker as the real backpressure source it was deferring to.

🤖 Generated with Claude Code

…erTierPool register + tick loop (PR-1)

Phase 2 of #1239 follow-on. Phase 1 (PR #1297) shipped the data-surface
`system/docker-tier-stats` IPC that bypassed the broker. This module
brings the broker online so disk-tier pressure can drive real eviction
instead of just sitting in the data layer.

What lands here (PR-1 of #1299)

- New `modules::pressure_broker_module::PressureBrokerModule`. Wraps an
  `Arc<PressureBroker>` and pre-registers `DockerTierPool` as a
  `ResourcePool` on the broker at construction. Acceptance items 1, 2.
- ServiceModule impl declares `tick_interval = BrokerConfig.tick_interval`
  (default 5s, matching `DMR_TICK_INTERVAL`). The runtime's existing
  `start_tick_loops()` machinery owns the cadence; we just implement
  `tick()` to call `PressureBroker::relieve()`. Acceptance item 3.
- `tick()` wraps `relieve()` in `tokio::task::spawn_blocking` because
  `DockerTierPool::evict_at_least` shells out to `docker system prune`
  which can take seconds — the broker tick must never stall other
  tokio tasks sharing the runtime.
- Observer-only: `command_prefixes` is empty so the runtime command
  router never dispatches to this module. The typed
  `system/pressure-broker-state` IPC lands in PR-2; chat-substrate
  alert sink lands in PR-3.
- `broker()` getter on the module so the ipc/mod.rs bootstrap can
  expose the broker to other subsystems (VRAM/KV-cache pools that
  want to register; PR-3's alert sink wiring) without re-instantiating.
- Registered in `ipc/mod.rs::start_server` next to `SystemResourceModule`
  using the same `runtime.register(Arc::new(...))` pattern every other
  ServiceModule uses.

Tests (acceptance item 6 — fake ResourcePool)

- `FakePool` whose pressure is driven by a test-controlled `AtomicU64`
  and whose `evict_at_least` stamps the bytes requested so the test
  can assert the broker actually invoked eviction.
- `module_registers_docker_pool_at_construction` — DockerTierPool is on
  the broker right after `::new()`, before any external call.
- `module_advertises_tick_interval_from_config` — ModuleConfig's
  tick_interval mirrors BrokerConfig so runtime cadence matches policy.
- `module_exposes_no_command_prefixes_in_pr1` — guards against a future
  PR adding prefixes without handlers (catches a common scoping mistake).
- `tick_drives_relieve_and_fires_eviction_over_threshold` — fake pool
  at ~95% pressure, one tick, assert evict_at_least was called with
  positive bytes. Proves end-to-end: tick → relieve → eviction path
  is wired, not just relieve() being called.
- `tick_is_a_noop_when_all_pools_below_threshold` — mirror at ~30%,
  assert evict_at_least was NOT called.
- `handle_command_returns_pr1_observer_only_error` — error message
  explains the staging so a future maintainer knows where commands
  land instead of silently failing.

Why a wrapper module vs `OnceLock<Arc<PressureBroker>>` direct: every
other singleton in this server (gpu_manager, system_monitor, etc.)
either lives behind a ServiceModule or is owned by one. Following that
pattern keeps the boot sequence in ipc/mod.rs uniform and gives the
broker the same shutdown / metrics treatment as everything else.

Validation
- 6/6 new tests pass: cargo test --lib --features metal,accelerate modules::pressure_broker_module
- 2296 other lib tests still filtered correctly (no incidental breakage)
- cargo build --lib --features metal,accelerate: clean
- No new warnings introduced; pre-existing 52 warnings unchanged

Follow-on PRs on this same card
- PR-2: typed `system/pressure-broker-state` IPC + ts-rs export +
  `bin/continuum status` row (acceptance item 5)
- PR-3: chat-substrate alert sink via existing airc bridge — broker
  emits `PressureAlert`, sink posts `📢 PressureAlert tier=docker ...`
  to #cambriantech (acceptance item 4)

Refs continuum#1239 (parent), continuum#1297 (Phase 1 PR), continuum#1299 (this card).
Aligned with codex's parallel #1306 work that lifts cognition's
hardcoded `max_concurrency: 1` cap — the broker is now the real
backpressure source that cap was deferring to.
@joelteply
joelteply merged commit a7f6c59 into canary May 16, 2026
3 checks passed
@joelteply
joelteply deleted the feat/pressure-broker-bootstrap-1299 branch May 16, 2026 14:24
joelteply pushed a commit that referenced this pull request May 16, 2026
…rface (PR-2)

Continues #1299 (Phase 2 of #1239). Adds the IPC + wire types on top
of PR-1's (PR #1307) singleton + tick loop:

- PressureBrokerModule now declares `command_prefixes = &["system/pressure-broker-state"]`
  and implements handle_command to return BrokerSnapshot as JSON. Single
  probe per call (atomic pressure reads + max over pool list) — no
  eviction fires, cheap to poll.
- ts-rs-exports BrokerSnapshot + PoolView + PoolStats + PressureTier
  with camelCase serde so the TS mixin reads the same shape the Rust
  module emits — no manual remap layer. PressureTier serialized
  lowercase to match the existing label() impl + every other tier
  string the system emits in logs.
- Generated files land at shared/generated/paging/{BrokerSnapshot,PoolView,PoolStats,PressureTier}.ts;
  barrel re-exports updated via `npx tsx generator/generate-rust-bindings.ts`.

PR-1 tests updated to reflect the new behavior:
- `module_routes_only_pressure_broker_state_command` replaces the
  empty-prefixes guard from PR-1 with a one-prefix invariant.
- `handle_command_returns_typed_snapshot_for_routed_command` pins the
  wire contract: every camelCase BrokerSnapshot key must be present,
  globalTier must be lowercase normal|warning|high|critical (catches
  serde rename regressions).
- `handle_command_rejects_unknown_command` validates the error path
  names the actually-handled command.

7/7 tests pass: cargo test --lib --features metal,accelerate modules::pressure_broker_module
70/70 paging tests pass (ts-rs export_bindings tests included).

What this PR is NOT
- No TS mixin yet on RustCoreIPCClient (PR-2b candidate, follow-up small
  PR, follows the docker-tier-stats pattern from #1297).
- No `bin/continuum status` row (PR-3 candidate alongside the alert sink).

Stacked on PR #1307 (PR-1). Base = canary; will rebase if #1307 lands first.
joelteply added a commit that referenced this pull request May 16, 2026
…rface (PR-2) (#1308)

Continues #1299 (Phase 2 of #1239). Adds the IPC + wire types on top
of PR-1's (PR #1307) singleton + tick loop:

- PressureBrokerModule now declares `command_prefixes = &["system/pressure-broker-state"]`
  and implements handle_command to return BrokerSnapshot as JSON. Single
  probe per call (atomic pressure reads + max over pool list) — no
  eviction fires, cheap to poll.
- ts-rs-exports BrokerSnapshot + PoolView + PoolStats + PressureTier
  with camelCase serde so the TS mixin reads the same shape the Rust
  module emits — no manual remap layer. PressureTier serialized
  lowercase to match the existing label() impl + every other tier
  string the system emits in logs.
- Generated files land at shared/generated/paging/{BrokerSnapshot,PoolView,PoolStats,PressureTier}.ts;
  barrel re-exports updated via `npx tsx generator/generate-rust-bindings.ts`.

PR-1 tests updated to reflect the new behavior:
- `module_routes_only_pressure_broker_state_command` replaces the
  empty-prefixes guard from PR-1 with a one-prefix invariant.
- `handle_command_returns_typed_snapshot_for_routed_command` pins the
  wire contract: every camelCase BrokerSnapshot key must be present,
  globalTier must be lowercase normal|warning|high|critical (catches
  serde rename regressions).
- `handle_command_rejects_unknown_command` validates the error path
  names the actually-handled command.

7/7 tests pass: cargo test --lib --features metal,accelerate modules::pressure_broker_module
70/70 paging tests pass (ts-rs export_bindings tests included).

What this PR is NOT
- No TS mixin yet on RustCoreIPCClient (PR-2b candidate, follow-up small
  PR, follows the docker-tier-stats pattern from #1297).
- No `bin/continuum status` row (PR-3 candidate alongside the alert sink).

Stacked on PR #1307 (PR-1). Base = canary; will rebase if #1307 lands first.

Co-authored-by: Test <[email protected]>
joelteply added a commit that referenced this pull request May 16, 2026
… document map; lane status truth-up (#1316)

* docs(alpha): refresh status against 2026-05-16 canary

Three changes to ALPHA-GAP-ANALYSIS.md:

1. Header date 2026-05-13 -> 2026-05-16. Add explicit cross-link to
   CBAR-SUBSTRATE-ARCHITECTURE.md as the runtime substrate spec.

2. Restructure the Document Map (was a flat list) into categorized
   references (Runtime substrate / Cognition migration / Memory paging /
   Model registry / Grid), and add the precedence rule: if any supporting
   doc disagrees with ALPHA-GAP on the substrate contract (concurrency,
   scheduling, memory, pressure, telemetry, artifact handles), defer to
   CBAR-SUBSTRATE-ARCHITECTURE.md.

3. Refresh the Current Snapshot table against canary @ 2026-05-16:
   - Rust core row reflects the PressureBroker bootstrap stack
     (#1307 / #1308 / #1310), runtime lease broker (#1313), cognition
     oxidization (#1284 / #1290 / #1291 / #1293 / #1298 / #1301 / #1303
     / #1292), dead-Candle deletes (#1277 / #1279 / #1281 / #1288), and
     the inference-grpc fail-closed (#1314). GRID-INFERENCE-ROUTING
     PR-1 announcer in flight on feat/grid-inference-routing-pr2-announcer.
   - Node/TS row notes net-negative trend (~2500 LOC TS deleted via the
     8-PR cognition stacks).
   - Docker row records Docker tier Phase 1 (#1297).
   - Config row records SQLite-first default (#1271).
   - Tests row records the no-CPU-fallback contract gap: the existing
     regression test in workers/continuum-core covers llama.cpp / ORT
     only, not the Candle-side paths where the orpheus + inference-grpc
     fallbacks lived before #1314.

* docs(alpha): refresh lane status table and immediate-next-actions

Two updates to ALPHA-GAP-ANALYSIS.md:

1. Lane status table now reflects actual state @ 2026-05-16, not aspiration:
   - Lane A: in progress, model_registry/ exists with admission resolver.
   - Lane B: Phase 1 landed (#1297 docker-tier-stats); GPU profile +
     tier-pool eviction (#1238 / #1239) still open.
   - Lane C: structured RuntimeMetric emits from inference paths;
     vdd-report-command not yet bound.
   - Lane D: UNSTARTED — flagged as the highest-leverage open lane because
     Lane E (PressureBroker) and the inbox coalescing pattern both
     presuppose RuntimeFrame / CognitionTurnFrame.
   - Lane E: bootstrap landed (#1307 / #1308 / #1310 / #1313); paging and
     pre-broker concurrency-hack deletion remain. Concrete deletion target
     called out: get_num_workers() in inference-grpc/main.rs, which reads
     INFERENCE_WORKERS from config.env and otherwise picks worker count
     from system memory at startup — both branches violate the
     "we do not hard code" / "dynamic, broker-owned concurrency" rule.
   - Lane F: ~2500 LOC TS deleted manually this session; mechanical CI
     ratchet still not landed (deletion is reversible until it is).
   - Lane G: refresh in flight on joel/docs-alpha-refresh.

   Adds an "adjacent active workstream" note for GRID-INFERENCE-ROUTING
   (PR-1 announcer + probe + registry in flight on
   feat/grid-inference-routing-pr2-announcer) as the grid-side counterpart
   to Lane A.

2. Immediate Next Actions reordered by alpha leverage, not by who is
   online. Top three items are Lane D claim, the universal-trait "for free"
   triplet (RuntimeModule base trait + derive macro + scaffold generator
   from CBAR-SUBSTRATE-ARCHITECTURE.md), and the
   get_num_workers() deletion. Adds the Lane C VDD report command and the
   widening of no_cpu_fallback_contract.rs to cover Candle paths. Adds
   doc-refresh follow-ups so each supporting doc gets cross-linked back
   into the Document Map.

* docs(alpha): add Lane H + GENOME-FOUNDRY-SENTINEL cross-links

Three updates to ALPHA-GAP-ANALYSIS.md following continuum#1327:

1. Lane H added to the lane status table: Substrate governor + tiered
   genome cache. Sibling to Lane E (broker owns admission; governor
   owns sizing). 7-PR implementation sequence detailed in
   GENOME-FOUNDRY-SENTINEL.md Part 13. Currently Proposed, needs owner
   claim.

2. Lane claim update at end of the lane discussion: Lane H proposed
   via continuum#1327 with full design pinned to that doc; sibling to
   Lane E with the boundary stated explicitly.

3. Document Map gets GENOME-FOUNDRY-SENTINEL entry under "Runtime
   substrate (load-bearing)" — the artifact-sharing economy on top of
   the CBAR substrate. Tiered genome cache, page faults, foundry as JIT,
   sentinel-AI as profile-guided optimizer, demand-aligned recall,
   composer + speculator, SubstrateGovernor (DVFS).

4. Immediate Next Actions step 9 added: claim Lane H. Step 10 (formerly
   step 9) updated to reflect what's landed in this doc batch
   (CBAR-SUBSTRATE refinement via #1324, CONTINUUM-ARCHITECTURE refresh
   via #1317, CONTINUUM-VISION refresh via #1320, GENOME-FOUNDRY-SENTINEL
   via #1327) and what's next (CLAUDE.md substrate pointer; stale-section
   deprecations in UNIVERSAL-SENSORY / LEARNING / QUEUE-DRIVEN-COGNITION).

---------

Co-authored-by: Test <[email protected]>
joelteply added a commit that referenced this pull request May 16, 2026
…strate contract cross-link, lane-shaped roadmap, per-engine status notes (#1317)

* docs(architecture): refresh CONTINUUM-ARCHITECTURE against 2026-05-16 canary

Five surgical refinements to docs/CONTINUUM-ARCHITECTURE.md, in service
of the "philosophy of docs: extreme elegance" bar:

1. Doc Status @ 2026-05-16 section near the top. Names the doc's vintage,
   what has moved since (cognition migration in lanes, PressureBroker
   bootstrap landed via #1307/#1308/#1310/#1313, 8-PR cognition
   oxidization stack, inference-grpc + orpheus fail-closed via #1314),
   and cross-links the two canonical truth docs:
   CBAR-SUBSTRATE-ARCHITECTURE.md for substrate contract, ALPHA-GAP for
   the lane-shaped roadmap. Establishes the precedence rule (CBAR
   wins on substrate-shaped questions).

2. New "Substrate Contract" section after "Why Rust." Names the three
   things every Rust engine in continuum-core inherits from the
   substrate: a new engine implements ServiceModule and inherits the
   contract (does not re-declare it); concurrency is broker-owned, not
   config-loaded (with the inference-grpc/main.rs::get_num_workers()
   anti-pattern called out as a Lane E deletion target); no silent
   fallbacks (typed Deferred/Coalesced/Failed instead).

3. Per-engine Status @ 2026-05-16 notes on RAG, Persona, Voice, Memory,
   and Genome subsections. Each names what is shipped vs. illustrative
   so a reader knows the pseudocode below is a sketch of intent and
   the linked module is authoritative when shapes differ. RagEngine's
   shipped shape (sources + default_budget) called out as leaner than
   the sketch (which had named EmbeddingBatcher / BudgetManager /
   thread_pool substructs that the substrate now owns).

4. Migration Roadmap Phase 1–5 weeks block replaced with a pointer to
   ALPHA-GAP's lane structure (A–G) and a one-paragraph explanation of
   why lanes replaced phases (phases assumed a linear migration with a
   single owner; the team is multi-agent and the substrate moves in
   parallel, which lanes admit and phases never did).

5. See Also reorganized to lead with the two canonical truth docs
   (CBAR-SUBSTRATE-ARCHITECTURE, ALPHA-GAP-ANALYSIS), then
   CONTINUUM-VISION, then supporting docs.

The Rust pseudocode blocks throughout the doc are kept intact — they
still read cleanly as sketches of intent — but framed correctly so a
reader does not mistake them for shipped API. The pseudocode is
explicitly labelled illustrative in the new lead-in to the Engine
Specifications section.

Doc-only change. No code touched.

* docs(architecture): incorporate codex asks — persona-cognition invariants

Codex raised on #cambriantech that #1317 should preserve four
persona-cognition guarantees explicitly, not implicitly. Adding them
to the Substrate Contract section:

1. Sharpens "No silent fallbacks" → "No silent fallbacks. No fake
   fallback paths." Names the specific lies the substrate must not
   tell: no placeholder model, no default-stand-in persona, no
   fallback-RAG-source that quietly produces empty context.

2. New fourth bullet: "Persona-cognition invariants." Calls out three
   structural guarantees that survive the migration from TS to Rust,
   because they are easy to lose in a refactor:
   - Independent persona inboxes — two personas in one room do not
     share an inbox queue. Per-persona read cursor / dedupe / priority.
     Cross-persona signaling goes through the bus / RuntimeFrame, not
     through shared inbox state.
   - Per-persona RAG + hippocampus assembly — the frame may share raw
     artifacts (room snapshot, media handles, embeddings) across
     personas; it must not share the assembled context itself. Persona
     A's RAG is composed from A's sources and consolidated through A's
     hippocampus.
   - Record / replay — every cognition turn must be replayable from
     its trace record. A trace that does not reproduce the prompt /
     RAG / tool-output of the original turn is a broken trace, not
     "close enough." This is what makes the substrate auditable and
     what makes regressions diagnosable instead of guessable.

Doc-only change. Builds on the open #1317.

---------

Co-authored-by: Test <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant