Repository navigation
Conversation
The worker's set_auto_compaction wrote settings.json and the worker's connection-state flag, but never the live core session's compaction settings. The threshold and overflow arms read the core flag, which kept its build-time value: a running session kept auto-compacting after the user turned it off (and never started after turning it on) until the session was rebuilt. The command now also forwards the toggle to the built core session through SessionEngine::set_auto_compaction_enabled, as RPC mode already does. An unbuilt session reads the saved setting at its build.
This branch has not been deployed
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.
Turning auto-compaction on or off in a running daemon session had no effect on the session itself: it only took hold after the session was rebuilt (e.g. on restart), while the UI already showed the new value. The toggle now reaches the built session immediately and applies from the next turn.
Cause
set_auto_compaction(the command the TUI/clients use) wrotesettings.jsonand the worker flagSessionCore.auto_compaction_enabled, but that flag is only read for the session summary. The threshold and overflow compaction arms read the core session'sCompactionSettings.enabled, which was set once when the session was built. So a running session kept the old value until it was rebuilt. RPC mode did not have the bug:rpc/commands.rsalready updated the core flag.Fix
engine.rs: newSessionEngine::set_auto_compaction_enabledtrait method; a default no-op, documented as blocking (call off the runtime).agent_engine/session_engine_impl.rs:AgentSessionEngineimplements it by forwarding to the built core session (pa_corewiringset_auto_compaction_enabled) under the session mutex viablocking_lock.compaction.rs:CompactionManager::set_auto_compactionis nowasync; it still writes the worker flag, then calls the engine throughspawn_blocking.setting_switches.rs:handle_set_auto_compactionbecomesasyncand awaits the compaction manager (worker/commands.rscall site updated). An unbuilt session reads the persisted setting when it builds.Test
pa-daemon setting_switches::tests::set_auto_compaction_reaches_the_built_session: a faux-engine worker whose settings start with compaction disabled and a reserve that puts the threshold at 1616 tokens. Turn 1 (off) does not threshold-compact, toggling on makes turn 2 threshold-compact, toggling off makes turn 3 not compact again. It countscompaction_startevents with reasonthreshold.Fails on main (main 74591cd + only the test):
Notes
SessionCore.auto_compaction_enabledis kept on purpose: the session summary is composed under the worker's std core lock on async threads, where the session's tokio mutex cannot be taken. The same command writes both flags.cargo fmt --all --check,cargo clippy --workspace --all-targets -D warnings, andcargo test -p pa-daemon --no-fail-fastall pass..changes/auto-compaction-live-2026-11-07.mdadded.worker/session_core.rsandsummary.rs(not changed here). No other open PR touchessetting_switches.rsor the daemon'scompaction.rs.Note
Medium Risk
Changes live compaction behavior on every turn boundary and adds async/blocking coordination on a frequently toggled setting; scope is confined to daemon compaction wiring with new regression coverage.
Overview
Auto-compaction on/off now affects already-built daemon sessions from the next turn, not only after a rebuild. Previously
set_auto_compactionupdatedsettings.jsonand the worker connection-state flag, while threshold/overflow compaction still read the value frozen at session build.The fix threads a live update through the engine: new
SessionEngine::set_auto_compaction_enabled(blocking, off-runtime), implemented onAgentSessionEngineby callingpa_core's session toggle under the session lock.CompactionManager::set_auto_compactionisasyncand invokes that hook viaspawn_blockingafter updating the worker flag;handle_set_auto_compactionawaits it, and the worker command dispatch does too.A faux-engine test toggles compaction between turns and asserts threshold
compaction_startevents match the switch. A short changelog note documents the behavior change.Reviewed by Cursor Bugbot for commit eae93df. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Make the auto-compaction toggle affect a running daemon session
Previously, changing the auto-compaction setting only updated connection state; a built session kept its old behavior until rebuilt. Now a successful
set_auto_compactionalso forwards the toggle to the live session.SessionEngine.set_auto_compaction_enabledtrait method with a no-op default, and implements it inAgentSessionEngineto forward the value to the built session (engine.rs, session_engine_impl.rs)CompactionManager.set_auto_compactionasync: it updates connection state, then invokes the engine setter on Tokio's blocking thread pool and awaits it (compaction.rs)Worker.handle_set_auto_compactionasync and awaits it in the dispatcher; it still saves the setting first and leaves runtime state unchanged if the save fails (setting_switches.rs, commands.rs)set_auto_compaction_reaches_the_built_sessionverifying threshold compaction events appear and disappear on later turns after togglingset_auto_compactionis now async, so dispatch waits for the live-session update before returning; engine setters that may block should be invoked off the runtime per the new trait docs📊 Macroscope summarized eae93df. 6 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues