The gateway now ships in the
praisonai-bot package. praisonai serve gateway still works exactly as documented here; for a standalone install see praisonai-bot Migration.Quick Start
1
Enable in gateway.yaml (minimal)
2
Tune for a busier gateway
3
Verify it fires
Grep the gateway logs for the arm line and per-session shrink lines:
How It Works
Each sweep enumerates persisted sessions off-thread, filters idle over-budget candidates, summarises them off the turn critical path, and persists a checkpoint the next user message resumes from.
The sweep reuses the same Context Compaction engine, constructed as
ContextCompactor(max_tokens=min_tokens, target_tokens=int(min_tokens * 0.75), strategy=CompactionStrategy.SUMMARIZE).
Configuration Options
Every knob lives underlifecycle.idle_compaction: in gateway.yaml.
This feature does not surface under
health()["lifecycle"] — unlike Scale to Zero, verify it from the gateway logs (Gateway idle-compaction sweep armed and the per-session [idle-compaction] lines).Requirements
Durable session store
Durable session store
The feature needs
list_sessions + get_working_history + append_compaction_checkpoint. The shipped SQLite transcript store (session.store: "sqlite", default) implements all three. The legacy "file" backend may not — see Gateway Session Persistence and SQLite Transcript Store. If no durable store is bound, the gateway logs Gateway idle_compaction requires a persistent session store; disabling.Persistent sessions
Persistent sessions
Ephemeral (
session.persist: false) gateways cannot use idle_compaction — there is nothing to enumerate.Hot Reload
Enabling or disablingidle_compaction via a gateway.yaml reload takes effect without a full process restart — _reconcile_lifecycle cancels the old task and starts the new one. See Gateway Hot Reload.
Which Compaction Surface?
Four related-but-different compaction surfaces exist; this decision diagram shows which fits which scenario.- “Compact during a single long run” → Context Compaction
- “Cheap
--continue/ resume for one session” → Compacted Session Resume - “Sweep many idle gateway sessions in the background” → this page (
lifecycle.idle_compaction) - “Compact a bot session on save” → Bot Session Compaction
Common Patterns
24/7 gateway with many long-lived users
Aggressive shrink for tight-context models
Very busy gateway (many idle sessions)
scan_limit and max_per_sweep so older idle sessions aren’t starved — stores return newest-first.
Best Practices
Only durable stores support this
Only durable stores support this
Without
persist: true and a store implementing get_working_history / append_compaction_checkpoint, the sweep disables itself. Verify with praisonai gateway start logs — a healthy start prints Gateway idle-compaction sweep armed.Keep sweep_interval_seconds ≥ 60
Keep sweep_interval_seconds ≥ 60
Sub-minute sweeps rarely pay off on real workloads and can pressure the store. Start at the default
300 and lower only if you observe transcripts growing between sweeps.Cool down long enough to avoid re-work
Cool down long enough to avoid re-work
Default
cooldown_seconds: 3600 matches the default idle threshold. If you lower idle_after_seconds, lower cooldown_seconds proportionally so cooled sessions become candidates again on a sensible cadence.Watch for transcript grew during compaction debug logs
Watch for transcript grew during compaction debug logs
This is normal on active sessions — the sweep skips the checkpoint and retries. Persistent recurrence means your
idle_after_seconds is too low for the traffic pattern; increase it so live sessions aren’t candidates.Related
Scale to Zero
Sibling lifecycle policy — idle quiesce for serverless hosts.
Drain Trigger
Sibling lifecycle policy — epoch-safe external drain marker.
Compacted Session Resume
How the checkpoint this feature writes is consumed on the next user turn.
Context Compaction
The in-run compactor this feature reuses.
Session Persistence
The durable session store this feature requires.
Gateway Overview
How lifecycle policies wire into
WebSocketGateway.
