Repository navigation
Pressure-aware inference + content lifecycle cleanup - #304
Conversation
The memory pressure system was completely locking out Candle inference when system memory exceeded 95% for 6+ seconds. This crippled the platform for local-only users who have no API keys — every AI went silent with "Memory pressure critical — refusing Candle inference". The system must self-heal, not self-destruct. Changes: Rust (candle_adapter.rs): - Remove hard refusal on memory gate and RSS ceiling - Under pressure: reduce max_tokens to 256, log warning, proceed - Semaphore(1) already serializes inference — the queue IS the throttle Rust (whisper.rs): - Remove hard refusal for STT transcription under pressure - Model weights are already resident, transcription adds minimal memory TypeScript (BackpressureService.ts): - getLoad() no longer returns emergency 2.0 when memory gate closed - Uses proportional pressure contribution (0-0.5) added to queue load - Prevents cascade where high load blocks all operations TypeScript (PersonaResponseGenerator.ts): - Check pressure BEFORE building RAG context - Under high/critical: minimal RAG (maxTokens=512, 1 memory, no artifacts, no tools) — saves compute for context that would sit in a long queue Already-correct subsystems (from prior pressure plan): - ThoughtStreamCoordinator: 1 responder under pressure (never 0) - PersonaState: cadence 1.5x-4x multiplier slows request rate - VoiceOrchestrator: limits broadcast targets under pressure - Bevy shed_load: degrades render quality proportionally Self-healing loop: pressure rises → fewer responders + slower cadence → queue drains → memory recovers → normal operation resumes.
ContentLifecycle registry gives widgets iOS-style lifecycle hooks when their content tab closes. One cleanup path, no duplication. - ContentLifecycle: register/unregister + willClose/didClose hooks - ContentService.close(): calls willClose before tab removal - LiveWidget: consolidated 3 cleanup paths into single willClose() - Widget generator template: includes ContentLifecycleParticipant
There was a problem hiding this comment.
Pull request overview
This PR improves resilience under memory pressure (favor queueing/degradation over refusal), fixes lingering live-call resource usage by ending calls when the last human leaves, and introduces a unified “content tab closing” lifecycle so widgets can reliably clean up when tabs close.
Changes:
- Make local inference/STT pressure-aware without hard-refusing (queue + reduced budgets).
- End live calls and remove remaining AI participants when the last human leaves.
- Introduce
ContentLifecycle(willClose/didClose) and refactor LiveWidget + widget generator template to use it.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/workers/continuum-core/src/live/audio/stt/whisper.rs | Proceed with Whisper transcription under memory pressure (warn instead of refuse). |
| src/workers/continuum-core/src/inference/candle_adapter.rs | Never refuse Candle inference; reduce max_tokens under pressure and rely on semaphore queueing. |
| src/widgets/live/LiveWidget.ts | Consolidate leave/cleanup path via ContentLifecycle-driven tab close. |
| src/system/user/server/modules/PersonaResponseGenerator.ts | Reduce RAG scope under high/critical pressure. |
| src/system/state/ContentService.ts | Add lifecycle ordering around tab close: willClose → remove tab → didClose → persist. |
| src/system/state/ContentLifecycle.ts | New lifecycle registry for tab-close hooks. |
| src/system/core/services/BackpressureService.ts | Make load calculation incorporate proportional memory pressure contribution. |
| src/generator/templates/widget/widget.template.ts | Update generator template to ReactiveWidget + ContentLifecycle. |
| src/commands/collaboration/live/leave/server/LiveLeaveServerCommand.ts | End call / remove AI participants when last human leaves; unregister voice session when call ends. |
| src/shared/version.ts | Version bump. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class ContentLifecycleRegistry { | ||
| private _participants = new Map<string, Set<ContentLifecycleParticipant>>(); | ||
|
|
There was a problem hiding this comment.
ContentLifecycle is keyed only by entityId, but multiple content types can share the same entityId (e.g. roomId is used by both chat and live). Closing a chat tab would therefore trigger willClose()/didClose() on the live call widget and unintentionally leave/end calls. Consider keying the registry by a composite identifier (e.g. ${contentType}:${entityId}) or by tabId, and update callers accordingly.
| if (entityId && ContentLifecycle.hasParticipants(entityId)) { | ||
| ContentLifecycle.notifyWillClose(entityId).then(afterWillClose); |
There was a problem hiding this comment.
ContentService.close() triggers lifecycle notifications based on entityId only. Since different content types can legitimately share an entityId (e.g. roomId used by both chat and live), this can notify the wrong widget(s) and invoke unintended cleanup. Consider routing lifecycle by tabId or by a composite (type, entityId) key that matches how participants are registered.
| if (entityId && ContentLifecycle.hasParticipants(entityId)) { | |
| ContentLifecycle.notifyWillClose(entityId).then(afterWillClose); | |
| if (ContentLifecycle.hasParticipants(tabId)) { | |
| ContentLifecycle.notifyWillClose(tabId).then(afterWillClose); |
| // 1. willClose — give widgets a chance to clean up BEFORE tab removal. | ||
| // Fire-and-forget: don't block UI on slow cleanup (5s timeout per widget). | ||
| // The lifecycle registry handles concurrency and error isolation. | ||
| const afterWillClose = () => { |
There was a problem hiding this comment.
The comment says willClose is “fire-and-forget” and “don't block UI”, but the implementation defers contentState.removeItem(...) until notifyWillClose(...).then(afterWillClose). Either adjust the comment to reflect the actual behavior (tab removal waits, up to the lifecycle timeout), or change the control flow so tab removal is not gated on willClose completion.
| sessionId: params.sessionId | ||
| }); | ||
|
|
||
| if (!result.success || !result.items) return 0; |
There was a problem hiding this comment.
On lookup failure (!result.success / !result.items), this returns 0 humans. That can incorrectly trigger the “last human left” cleanup during transient DB/IPC issues, removing remaining AI participants and ending the call. Safer behavior is to treat lookup failure as unknown and skip auto-ending (or conservatively assume at least 1 human remains) unless 0 humans is confirmed.
| if (!result.success || !result.items) return 0; | |
| if (!result.success || !result.items) { | |
| // On lookup failure, treat the human count as unknown and conservatively | |
| // assume at least one human remains to avoid premature call teardown. | |
| return 1; | |
| } |
| override connectedCallback(): void { | ||
| super.connectedCallback(); | ||
| if (this.entityId) { | ||
| ContentLifecycle.register(this.entityId, this); | ||
| } |
There was a problem hiding this comment.
This template registers with ContentLifecycle based on this.entityId, but the template doesn't define an entityId field or any MainWidget hook (e.g. setEntityId/onActivate) to set/update it. Generated widgets may therefore not compile or may never register once entityId becomes known after activation. Consider adding an entityId property and keeping lifecycle registration in sync when it changes.
… moved to fs_portable but the use stayed (#304) Unused-import on unix (warning), unresolved-module on windows (E0433 hard error) — exactly the class the new cargo-check-windows job exists to catch, and it caught it on its first run. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ne generic wire server, two bind sites (#304 residual) The unix-only gate kept windows-msvc BUILDING but left the windows connect path (TCP loopback via CONTINUUM_CORE_TCP) with zero coverage. The echo server body is stream-generic now (tokio::io::split over AsyncRead+Write); unix binds a per-test unix socket, windows binds 127.0.0.1:0 and pins the env var under a lock (it's process-global — parallel tests would race). The non-connecting params test was already platform-neutral. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…re-existing test-target rot (#304) The new cargo-check-windows job is the first CI to ever BUILD integration test targets — it found two classes: 1. unix-only targets (the IPC-socket common client's six consumers + forge_custodian_daemon's libc::kill SIGTERM drain) — gated #![cfg(unix)] whole-file; windows compiles them to empty. The lib + unit tests are the windows-supported surface today. 2. platform-independent rot no CI ever saw: join_call/join_call_with_model grew a Result return (call_server_integration, call_server_routing_test, hold_music_test now .expect at the binding) and MemoryRecord grew origin_node/origin_seq (memory_recall_accuracy's four initializers). These were broken on LINUX too — the linux job only builds --lib. cargo check -p continuum-core --tests is now clean on macOS; the PR's windows job verifies the msvc side. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
, first slice of #197) (#2123) * fix(portability): continuum-core builds on windows-msvc — un-gated unix usage fixed + CI guard (#304, first slice of #197) Glass-boxed 2026-08-02: the Windows grid node (the CUDA lane) could not run ANY core test — 'cargo test' failed to BUILD on windows-msvc, forcing every test-tree measurement (today: the K3 schedulable-coverage go/no-go) through a Mac as proxy. Root causes, all fixed with real Windows arms: - fs_portable.rs (NEW — #197's first concrete slice): portable read_exact_at with pread semantics both platforms (unix FileExt / windows seek_read loop, UnexpectedEof on short reads). Consumed by expert_container's bank reads and the capacity io-probe — the two lib sites that imported std::os::unix::fs::FileExt un-gated. - docker_tier: MetadataExt cfg-paired (windows: len() for both fields — honest apparent size, no fake allocation number). - bevy scene instantiate: symlink cfg-paired (windows symlink_file needs privilege → copy fallback; bevy just needs bytes at the path). - ipc/mod.rs: the two #[ignore]d live unix-socket tests gated #[cfg(unix)] — even ignored tests must COMPILE. - core_ipc_transport: unix-echo-server test mod gated #[cfg(all(test, unix))]; the TCP-echo sibling for the windows transport arm stays tracked in #304. CI: new cargo-check-windows job (windows-latest, check --lib --tests — the exact surface cargo test builds, nothing executed) so this class can never silently regress; also the first CI brick of #291's 3-platform front door. This PR's own run is the fix's verification. Unix arm verified locally: cargo check clean; fs_portable + expert_container suites 9/9. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * fix(portability): remove orphaned unix FileExt import — the call site moved to fs_portable but the use stayed (#304) Unused-import on unix (warning), unresolved-module on windows (E0433 hard error) — exactly the class the new cargo-check-windows job exists to catch, and it caught it on its first run. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * test(portability): TCP-echo sibling for the windows transport arm — one generic wire server, two bind sites (#304 residual) The unix-only gate kept windows-msvc BUILDING but left the windows connect path (TCP loopback via CONTINUUM_CORE_TCP) with zero coverage. The echo server body is stream-generic now (tokio::io::split over AsyncRead+Write); unix binds a per-test unix socket, windows binds 127.0.0.1:0 and pins the env var under a lock (it's process-global — parallel tests would race). The non-connecting params test was already platform-neutral. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * test(recorder): thread-local fixture-root override — kill the process-global HOME swap (#7) The env-mutation guard only serialized RECORDER tests against each other; every other test in the parallel suite that read HOME (or wrote a fixture) mid-swap raced it, and a stray parallel write into the swapped tempdir broke this file's len==1 assertion. record_turn runs on the caller's thread, so a thread-local override is parallel-safe by construction — and the unsafe set_var machinery plus its lock delete outright. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * fix(portability+tests): gate unix-only integration targets + repair pre-existing test-target rot (#304) The new cargo-check-windows job is the first CI to ever BUILD integration test targets — it found two classes: 1. unix-only targets (the IPC-socket common client's six consumers + forge_custodian_daemon's libc::kill SIGTERM drain) — gated #![cfg(unix)] whole-file; windows compiles them to empty. The lib + unit tests are the windows-supported surface today. 2. platform-independent rot no CI ever saw: join_call/join_call_with_model grew a Result return (call_server_integration, call_server_routing_test, hold_music_test now .expect at the binding) and MemoryRecord grew origin_node/origin_seq (memory_recall_accuracy's four initializers). These were broken on LINUX too — the linux job only builds --lib. cargo check -p continuum-core --tests is now clean on macOS; the PR's windows job verifies the msvc side. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --------- Co-authored-by: Claude Fable 5 <[email protected]>
…e 11-hour orphan class dies at its one seam (#381) (#2214) Found by Joel's cooling FAN, not by any instrument: two sympy test pythons from the morning's rounds hung in symbolic computation, orphaned to launchd when their parents exited, and burned two full cores at 100% for ~11 hours. The hole was exact and single-seamed: swe_bench::run() — the ONE helper every grader subprocess (git, uv, pytest) flows through — had no timeout and no group management, so a hang blocked forever and a dropped await leaked the child's whole tree. Now: every child leads its own process group (unix), kill_on_drop covers the cancelled-future path (core reboots), a 15-minute ceiling bounds every run (nothing legitimate approaches it; the class it kills is infinite), and a timeout kills the GROUP via killpg so pytest's grandchildren die with it — then probes benchmark.subprocess.ceiling and returns an env-fault error that can never be read as a verdict. Windows: kill_on_drop only (no unix process groups; #304 keeps the build portable). The #381 orphan REAPER remains as the follow-up safety net; this is the fix at the source. Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo Co-authored-by: Claude Fable 5 <[email protected]>
Summary
ContentLifecycleregistry gives widgets iOS-stylewillClose()/didClose()hooks when their content tab closes. One cleanup path, no duplication. LiveWidget consolidated from 3 overlapping cleanup paths to one. Widget generator template updated.Test plan
🤖 Generated with Claude Code