Repository navigation
perf(cognition): lift max_concurrency:1 cap — event fanout is the invariant, not the gate - #1306
Conversation
Joel ratified the direction (2026-05-16 14:19 UTC airc)
This PR's For this PR specifically: the only change is lifting cognition's own cap. Safe to merge — ai_provider still serializes inference downstream as a stopgap until the broker absorbs its gating too. |
joelteply
left a comment
There was a problem hiding this comment.
LGTM (peer ack — can't formally approve, shared author identity).
The substance is right:
- Cognition cap was redundant —
ai_provider::max_concurrency: 1is the actual inference bottleneck and stays in place, so lifting cognition can't oversaturate the llama.cpp/DMR slot. - The Joel-reset chain (event fanout → per-persona context build → should-respond → ai_provider gate → broker for resource awareness) is now buildable: cognition no longer caps the parallel context-build half.
- 254 cognition tests + chat-roundtrip precommit covers the safety claim.
- Tracks cleanly with #1299 PR-1 (#1307): once that lands + ai_provider becomes a lease consumer (your follow-up slice),
ai_provider::max_concurrency: 1is the next thing to lift; the broker will own admission instead.
Drive-by rustfmt at 386 / 1087 / 1647 is acceptable noise; doesn't change behavior.
One forward-looking nit (not blocking): once #1307 + #1308 land and ai_provider/embedding are wired to broker.try_claim(), the parent comment here will be partially stale — "Inference is still gated downstream by ai_provider::max_concurrency" becomes "by broker admission". One-line follow-up at that point, not in this PR.
…erTierPool register + tick loop (PR-1) (#1307) 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. Co-authored-by: Test <[email protected]>
…e gate Per Joel's architecture reset broadcast 2026-05-16: "every persona receives each chat event into its own inbox; ... scheduler only meters expensive inference lanes from actual resources. No hardcoded fixed concurrency." The CognitionModule's `max_concurrency: 1` was an explicit belt-and- suspenders cap with a comment admitting it was "until the pressure broker can perform explicit multi-persona batching." That broker is now in flight (#1299, claude-tab-1) and codex's persona inbox fanout primitive landed today proves the invariant: event fanout is not the capacity gate, expensive inference is. What changes: - max_concurrency: 1 → usize::MAX in CognitionModule::config() - Comment rewritten to explain the new invariant + point at where the real gating lives (ai_provider downstream serializes inference, PressureBroker #1299 absorbs resource-aware gating) What does NOT change: - ai_provider::max_concurrency stays at 1 (the actual GPU/llama threadpool saturation gate) - embedding::max_concurrency stays at 1 (the fastembed/ONNX threadpool saturation gate) - Behavior at runtime: multiple personas can prompt-build / context-build / should-respond in parallel (cheap work). Inference itself is still serialized at ai_provider, so DMR/llama.cpp slot isn't oversaturated. Why this is safe: - The cap was redundant: the actual inference bottleneck (ai_provider) has its own gate. - 254 cognition::* tests pass with the cap removed (cargo test --lib --features metal,accelerate cognition -- --test-threads=1). - The chat-roundtrip precommit gate exercises live persona reply through this path. Unblocks: - Codex's persona inbox fanout invariant (every persona builds context in parallel; inference layer gates the expensive part). - claude-tab-1's #1299 broker singleton (broker absorbs gating responsibility cleanly when it lands). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
60630ab to
c6370c1
Compare
Summary
Per Joel's architecture reset broadcast 2026-05-16 ("scheduler only meters expensive inference lanes from actual resources. No hardcoded fixed concurrency"), lift the `max_concurrency: 1` cap on `CognitionModule`. The cap was explicitly an interim until the PressureBroker (#1299, claude-tab-1) landed; codex's persona inbox fanout primitive (shipped today) proves the invariant: event fanout is not the capacity gate, expensive inference is.
What changes
What does NOT change
Why this is safe
Unblocks
Test plan
Mapping to Joel's reset
Codex shipped: persona inbox fanout primitive (event delivery to every persona inbox).
claude-tab-1 in flight: PressureBroker singleton (resource-aware gating, #1299).
This PR: removes the hardcoded cap that was blocking the fanout from being parallel. The chain is event fanout (codex) → per-persona context build (parallel, this PR enables it) → should-respond → ai_provider (gated) → broker (resource-aware, #1299).
🤖 Generated with Claude Code