Skip to content

fix(event-log,agent,js-runtime): fix Host stress bugs, bound V8 ArrayBuffers, and remove SQLite hot-path bottlenecks - #7100

Merged
M4n5ter merged 6 commits into
rust-previewfrom
stress/hell-tier-host-torture
Nov 20, 2026
Merged

M4n5ter merged 6 commits into
rust-previewfrom
stress/hell-tier-host-torture

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes 6 real runtime/durability bugs and 4 SQLite/V8 hot-path scaling bottlenecks exposed by a new opt-in Hell-Tier Host stress suite (Scenarios H–L).

Bug fixes

  • Concurrent fresh-workspace creation race (platform/event-log, plugins/agent/native): refresh ProjectWorkspacePlan under the serialized root-store write lock (ProjectWorkspacePlan::refresh_under_mutation) so concurrent agent/create calls on the same fresh directory converge on a single project instead of failing with ProjectError::Changed.
  • Unbounded V8 off-heap backing stores (platform/js-runtime): wire a v8::new_rust_allocator backed by an atomic ArrayBufferBudget (bounded_create_params) into JS cells, REPL, and plugin engines, guard resizable ArrayBuffer/SharedArrayBuffer constructors, and strip WebAssembly/SharedArrayBuffer/Atomics in plugin runtime_base so off-heap backing stores cannot bypass heap_bytes.
  • SummaryRepair mutating frozen cut & output cap (plugins/agent/engine, plugins/agent/native): introduce preparation::OutputBudget::{Compute, Frozen} and preserve provenance, composition.max_output_tokens, adjudications, and compaction_recovery when repair == true in summary_repair.rs and materialize.rs so FrozenSummary::Repair preserves the original frozen Summary cut and dispatched max_tokens.
  • O(N × M) per-notification Cell child knowledge explosion (plugins/agent/native): capture and project [Host Cell child knowledge] once per distinct Cell per step cut instead of repeating up to 256 KiB on every notification in a batch (FrozenNotification gains top-level through: u64 and knowledge: Option<FrozenCellKnowledge>).
  • Cell stop-race CleanupUnconfirmed (plugins/agent/native, plugins/agent/engine): use RunAccess::original_frontier() (original_driver_frontier) in driver_cells.rs (quarantine, NativeCellPort::new, NativeCellPort::commit) so an agent/stop arriving mid-Cell cleanly rejects new admission with ToolError::Failed("Cell admission is stopped") and records ChildRejected instead of misclassifying stop as ToolError::Persistence -> ToolError::CleanupUnconfirmed.
  • Swallowed original errors on OperationCleanup::Unconfirmed (plugins/agent/engine, plugins/agent/native): log underlying driven / outcome / observe_tool error details in driver_assembly.rs, queue.rs, and cleanup.rs instead of discarding them.

SQLite & Host hot-path improvements

  • Bounded, cancel-safe reader dispatcher (platform/event-log): replace ReadSlots broadcast wakeups with ReadDispatcher (Mutex<ReadQueue> + Condvar, BTreeMap<u64, ReadJob>, available_parallelism().clamp(4, 8) readers) that eliminates thundering herds and drops cancelled read payloads/custody immediately outside the lock with zero stale queue IDs.
  • Zero-TTL retained-FD lease fencing (platform/event-log): fast-path RootOwner::validate_current on Unix via F_GETPATH / /proc/self/fd + lstat + pread and expose EventLog::root_owner_ref.
  • Per-Run cancel-safe driver slot (plugins/agent/state): replace the global Domain::drivers mutex held across SQLite I/O with per-Run RunSlot backed by tokio::sync::RwLock<Weak<Ticket>> so takeover awaits lock acquisition before atomically replacing and retiring the prior claim.
  • SQLite contention & FTS5 flush reduction (.cargo/config.toml, platform/event-log, plugins/agent/state): disable SQLITE_DEFAULT_MEMSTATUS=0 at compile time for bundled SQLite, reuse prepare_cached on hot read paths (diagnostics, recall, session_history), and defer Recall FTS5 indexing to transaction end in admit / append (after deliver_held) to avoid implicit per-fact savepoint fts5IndexFlush.

Opt-in Hell-Tier Host stress suite

  • Added products/maka/cli/tests/mainline_reopen/host_hell_stress.rs (#[ignore], Scenarios H–L):
Scenario Workload Result (release) Key metrics
H 5× SIGKILL + 160 sessions + concurrent fresh-workspace creation & forks 19.06s, PASS Pre-SIGKILL #1 verified 100/100 active runs, 160/160 idle, fresh_plus_fork=25/25, SQLite integrity OK, 0 orphans
I 456 sessions (36 3-level trees, 10 live agent/stop sabotaged, 60 80-chunk streams) + 32 UI clients 72.95s, PASS list p50 11ms / p95 120ms, history p50 69ms, search p50 6ms, ui_errs=0, host.stderr.log 0 ERRORs, FDs 57→57
J 200 turns + Depth-5 nested fork (+50 turns), 121 compactions, 20 HTTP 400 overflows, 55 live editQueue 29.02s, PASS 20/20 overflow recovery, latency 118.9ms → 125.2ms (1.05× flat), bg history p50 7ms / search p50 2ms, FDs 57→57
K 110 sessions (4×80-way JS + 2×40-way Py + 40 memory/CPU bombs + 32 PTY/pipe + 32 canaries) 19.11s, PASS 40/40 bombs contained, 32/32 canaries + strict archive: readback verified, peak RSS 2844.8 → 566.8 MiB, 0 orphans
L 10 waves × 60 = 600 churned sessions, 509 deleted (149 verified requested=true mid-run stops), 16 Goals, 16 ScheduledTasks (32 fires), 440 memory ops 52.36s, PASS goals=16/16 verified via agent/goal, list p50 7ms, RSS W3 498.3 → W10 478.7 MiB, WAL flat 20.7 MiB, FDs 57→57

Local database migration (optional)

FrozenNotification now requires a top-level through field (with knowledge optional on new steps). Sessions without Cell notifications (notifications: []) are unaffected.

If you have an existing local runtime-rust.sqlite containing pre-PR Cell notification steps that you want to keep continuing, stop Maka and run the migration script once:

python3 migrate_frozen_notifications.py /path/to/runtime-rust.sqlite --dry-run
python3 migrate_frozen_notifications.py /path/to/runtime-rust.sqlite

The script backfills notice["through"] = notice["knowledge"]["through"] while keeping each historical notice's knowledge intact for exact replay, updates dependent FrozenRecovery, PrefixProof, ItemContinuation, RequestSpec, RecordedFact, ContextCompacted, agent_attempts, agent_steps.body, agent_runs.baseline, agent_session_history.prefix_digest, and agent_recall_heads.digest, prunes stale pins, and nominates replaced blobs in pending_content_releases.

Verification

  • Code review converged after 3 rounds of codex/gpt-6.2-astra review (merge approved on 09e4498dd).
  • Unit / regression tests:
    • cargo test -p maka-event-log (45/45, incl. bundled_sqlite_disables_memstatus, cancelled_queued_read_drops_payload_and_skips_execution, validate_current_fences_marker_tampering_and_parent_rebind, concurrent_fresh_workspace_creation_converges_on_single_project)
    • cargo test -p maka-agent-state (55/55, incl. distinct_runs_do_not_block_and_takeover_fences_prior_claim, cancelled_contested_takeover_preserves_prior_claim)
    • cargo test -p maka-js-runtime (34/34, incl. array_buffer_budget_enforces_direct_single_and_cumulative_bounds, array_buffer_allocations_are_bounded_by_heap_limit, pure_and_scoped_plugins_enforce_off_heap_budget_and_disable_wasm)
    • cargo test -p maka-agent-engine (32/32)
    • cargo test -p maka-agent-native --lib (stopped_run_rejects_cell_child_admission_without_poisoning_cleanup, model_recovery::compaction 3/3, tool_history 13/13)
  • Hell-Tier suite (--release -p maka-cli --test mainline_reopen -- --ignored --nocapture --test-threads=1): Scenarios H, I, J, K, L all green.
  • cargo clippy --no-deps (0 warnings across touched crates), rustfmt --edition 2024 --check, git diff --check, node scripts/asf-license-headers.mjs check.
  • Verified migrate_frozen_notifications.py end-to-end against a fresh SQLite DB with all event-log and agent-state migrations applied (--dry-run, migration, prefix_digest + agent_recall_heads verification, PRAGMA integrity_check, PRAGMA foreign_key_check, and idempotent re-run).

… stop-race cleanup

- P1-1 (js-runtime): disable resizable ArrayBuffer and growable SharedArrayBuffer across all three isolate entry points so backing stores cannot bypass ArrayBufferBudget; replace infinite-loop test with finite in-budget, over-budget, and resizable-rejection assertions.
- P1-2 (agent-state): switch RunSlot.current to tokio::sync::RwLock so contested takeover waits are natively cancel-safe and swap+retirement occur within the same poll; add contested cancelled-takeover regression test.
- P1-3 (event-log): replace runtime sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 0) with compile-time LIBSQLITE3_FLAGS=SQLITE_DEFAULT_MEMSTATUS=0 in .cargo/config.toml and verify PRAGMA compile_options.
- P1-4 (agent-engine, agent-native): introduce preparation::OutputBudget (Compute vs Frozen) so materialize and SummaryRepair preserve the frozen max_output_tokens instead of re-applying the default 200k Summary 4% floor; assert dispatched max_tokens == 4096 in compaction test.
- P2-1 (event-log): make queued ReadDispatcher jobs cancel-on-drop to release closure/custody immediately and skip cancelled jobs before authority validation or connection open.
- P2-2..5 (cli stress): tighten Scenario H/I/J/K/L assertions (wave-1 messageIds & in-flight load, UI/background reader error & sample counts, canary fixture_0 content & strict 80/80 archive readback, durable agent/goal status, active runId stop + kind==removed).
- Bonus Bug #8 (agent-native): use original_frontier() in driver_cells.rs (quarantine, NativeCellPort::new, NativeCellPort::commit) so stopping a Run mid-Cell cleanly rejects new child admission instead of triggering Run is no longer executable -> failed quarantine -> CleanupUnconfirmed; log error detail in cleanup.rs::observe_tool and add unit regression test.
@M4n5ter
M4n5ter force-pushed the stress/hell-tier-host-torture branch from de0865a to ce46952 Compare November 20, 2026 17:21
- Strip WebAssembly, SharedArrayBuffer, and Atomics in plugin/engine.rs
  runtime_base so neither Pure nor Scoped plugin isolates can allocate
  unmetered page-allocator backing stores; add pure/scoped integration tests.
- Replace ReadQueue's VecDeque+HashMap pair with a single BTreeMap<u64, ReadJob>
  so repeated cancellations while another read stays pending leave zero stale IDs.
- Tighten Scenario H to verify >= 50 wave-1 runs actively working via agent/observe
  immediately before SIGKILL #1 (observed 100/100) with no post-check sleep.
- Tighten Scenario L so total_active_deleted only counts runs where agent/stop
  returned requested=true, settlement succeeded, and changeSession removed the session.
- Replace the racy 40-Write cell stop test with a deterministic Rig test pausing
  inside PreparedTool::prepare before committing StopRequested so
  NativeCellPort::commit(ChildAdmitted) deterministically hits view.stopped and
  records ChildRejected without poisoning cleanup.
@M4n5ter
M4n5ter force-pushed the stress/hell-tier-host-torture branch from cb6e9a0 to 09e4498 Compare November 20, 2026 17:56
@M4n5ter
M4n5ter merged commit 871e747 into rust-preview Nov 20, 2026
@M4n5ter
M4n5ter deleted the stress/hell-tier-host-torture branch November 20, 2026 17:59
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