Repository navigation
perf(agent,event-log): fix Scenario M O(1) scaling, cell/catalog leaks, history indexes, and RequestComposition dedup - #7115
Merged
Conversation
… soak Adds an opt-in (#[ignore]) release soak harness in products/maka/cli/tests/mainline_reopen/host_forever_soak.rs (real_host_forever_running_o1_soak) to verify that CPU, RSS, FD, latency, and storage do not grow linearly with historical session load: - Phase 1 (Zero-Survivor Pure Churn): 14 waves x 28 heavy sessions (V8 cells, subagents, tools, streams), 100% deleted every wave, sampling RSS, FDs, CPU/session, per-table counts, and SQLite dbstat bytes. - Phase 2 (Scale-Out Dormant Fleet): 250 -> 1,000 -> 3,000 historical sessions (12x jump across idle, archived, removed tombstones, rooms, memories) while 12 slow/churning watch clients hammer the Host, running an identical fixed hot probe (16 active sessions, list, sessionList, observe, recall, usage, usageSummary, remove) and a 3s quiet idle CPU probe at each tier. - Phase 3 (Immortal Session Scale-Deep): 300 turns with rolling compaction on a tight 14k window + 200-post immortal Room. - Phase 4 (Cold Reopen & SIGKILL Recovery): clean reopen and mid-flight SIGKILL reopen under the full ~3,500+ historical session fleet.
…, fix reconciliation join, cap WAL size
…th partial indexes
…ro-leak assertions
…compactions, and P4 crash sentinel
4 of 6 tasks
YongGoose
added a commit
to YongGoose/maka
that referenced
this pull request
Nov 22, 2026
The event log used SQLite's default auto-checkpoint of 1,000 pages. Every commit rewrites the same hot pages, so each checkpoint cycle copied them back into the database again. Checkpointing every 4,000 pages copies them back a quarter as often, and 4,000 pages of 4 KiB still fit within the 16 MiB journal_size_limit set in apache#7115. With 16 concurrent sessions running scripted repair work, storage writes fell from about 27.0 MiB to 24.0 MiB per tool call. Wall time did not regress. Generated-by: Claude Code
3 of 6 tasks
YongGoose
added a commit
to YongGoose/maka
that referenced
this pull request
Nov 23, 2026
The event log used SQLite's default auto-checkpoint of 1,000 pages. Every commit rewrites the same hot pages, so each checkpoint cycle copied them back into the database again. Checkpointing every 4,000 pages copies them back a quarter as often, and 4,000 pages of 4 KiB still fit within the 16 MiB journal_size_limit set in apache#7115. With 16 concurrent sessions running scripted repair work, storage writes fell from about 27.0 MiB to 24.0 MiB per tool call. Wall time did not regress. Generated-by: Claude Code
3 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in Scenario M (forever-running O(1) scaling & steady-state soak test) and fixes the real root-cause leaks, O(N) scheduler query plan, and SQLite storage/payload amplification bottlenecks exposed by its baseline run — with zero backwards-compatibility branches (pre-release direct schema updates + standalone Python migration script below).
Root-Cause Fixes
agent_cells,agent_catalog_sessions,agent_catalog_controls) & dead table removal (802fee0a1):DELETE FROM agent_cells WHERE run=?1toRUN_HISTORY_RELEASES(covers both full and profile-computer tails while preserving standalonerun IS NULLcells and keepingagent_cell_notificationscontent nomination intact).DELETE FROM agent_catalog_sessionsandDELETE FROM agent_catalog_controlstoSESSION_RELEASES(retainingagent_catalog_eventsfor control-command idempotency).agent_cell_operation_pinstable and redundant projection writes (CellView::apply(ChildBound)already enforces immutableRecoveryRefin canonical fold).model_reconciliation_runsquery plan (802fee0a1):FROM candidates p CROSS JOIN agent_runs r ON r.run=p.runso SQLite probesagent_runsby primary key from the smallcandidatesCTE instead of scanning historical completed runs viaagent_runs_due(owner=?)(129×–187× fewer SQLite VM steps at 3,000 runs).802fee0a1):PRAGMA journal_size_limit = 16777216;(16 MiB) on runtime writer initialization (leaving read-only inspection'sEXCLUSIVE/NO_CKPT_ON_CLOSE/query_onlysequence untouched).agent_session_history& 3-column ROWIDagent_history_content_refs(5c57476c9):agent_session_historyfromWITHOUT ROWIDtosequence INTEGER PRIMARY KEY, removed redundant trailingsequencekey columns from secondary indexes, and madeagent_session_history_tool(WHERE tool_use_id IS NOT NULL),agent_session_history_result(WHERE result_source=1), andagent_session_history_message(WHERE opening_message=1) partial indexes.agent_history_content_refsto a 3-column ROWID table(run, content_id, first_sequence, UNIQUE(run,content_id)), dropped redundantagent_history_content_refs_run, and resolved(owner, session)viaJOIN agent_run_specsinagent_history_content.CompositionSurfaceinRequestSpec(2d45d25b0):system_prompt,tools, andsourcesout ofRequestCompositionintoCompositionSurfacereferenced bycomposition.surface: ContentRefand wired intoRequestSpec::content_refs(), so identical tool catalogs/system prompts/source revisions deduplicate across turns and sessions incontents(reducingRequestSpecraw JSON by 9.5× and eliminating SQLite overflow pages).0a0d5f57b,e4202a4a8,d300b0939):real_host_forever_running_o1_soak(#[ignore]) covering 4 phases: 14-wave zero-survivor churn (476 deleted sessions), 12× dormant fleet scale-out (250→1,000→3,000 sessions), 300-turn immortal session with rolling compactions + 200-post room, and clean +SIGKILLcold reopen.application_operationsintact (no blind N=256 pruning that would break replay idempotency / receipt recovery).agent_facts,agent_session_history,agent_history_content_refs,agent_request_specs,agent_cells,agent_catalog_sessions,agent_catalog_controls,orphan_contents) and flatnon_receipt_contents.>= 20durable committedcontext_compactedfacts onimmortal_siddirectly inagent_session_history.SIGKILLon a deterministic in-flight sentinel run (SOAK_P4_CRASH_SENTINEL, confirmed live in bothmockandagent/observe) alongside 12/12 concurrent hot sends, and verifies recovery of that exact crashed run ID after reopen.Scenario M
--releaseA/B Benchmark (3,525 sessions, ~4,913 model calls)0a0d5f57b)d300b0939)agent_cellsresidual (0 survivors)agent_catalog_sessions/controlsresidualorphan_contents/non_receipt_contentsdb + rwal(W14)wal=102.7 MiB)rwal=17.28 MiB)dir)464.2 db + 6.7 wal)contentsB-tree (T3_3000 / final)agent_request_specsraw JSON (T3_3000 / final)agent_session_history+ indexes (T3_3000)agent_history_content_refs+ indexes (T3_3000)context_compacted/+db / 50tintegrity=Ok(2),orphans=0)Local Database Migration (Existing Pre-PR
runtime-rust.sqlite)Because Maka is pre-release and this PR modifies migrations
6,8,33,49andRequestSpec.compositiondirectly without runtime compatibility branches, migrate any existing localruntime-rust.sqlitein place with this standalone, idempotent Python script (creates a timestamped backup automatically, realignsagent_recall_heads.digestand canonicalagent_facts/RequestSpec/CompositionSurfacerun content pins, and verifies all business invariants +PRAGMA foreign_key_check+PRAGMA integrity_checkbefore committing):Verification
cargo test -p maka-event-log -p maka-agent-facts -p maka-agent-state -p maka-agent-engine— 100% pass (incl. new query-plan regression test formodel_reconciliation_runsand cell/catalog reclamation tests).cargo test -p maka-agent-native --lib -- history snapshot recovery removal compaction summary— 106/106 pass.cargo clippy --no-deps -p maka-cli --test mainline_reopen -- -D warnings— 0 warnings.cargo test --release -p maka-cli --test mainline_reopen real_host_forever_running_o1_soak -- --ignored --nocapture --test-threads=1— 0 violations, 315.47s,durable_compactions=32,P4 CRASH SENTINEL run=... state=idle pre_kill_mock_hits=1 hot_accepted=12/12,integrity=Ok(2),orphans=0.0a0d5f57b) SQLite DB across two consecutive runs (migration + idempotent no-op), verifyingagent_recall_heads.digestalignment, canonical fact/request/surfaceagent_content_pins, old blob reclamation, checksums, triggers, FK integrity, andPRAGMA integrity_check = ok.