sim-one-alpha

Session Context Budget

Flue Session Findings

Flue sessions are named conversation state inside an initialized harness. harness.session(name) gets or creates a session, while harness.sessions.get(name) only loads an existing session and throws when it does not exist. A session runs one active prompt, skill, task, shell, or compact operation at a time.

Sources:

Flue persists session state through the configured PersistenceAdapter. On Node, the current Flue persistence entrypoint is a source-root src/db.ts file that exports an adapter such as sqlite('./data/flue.db'). Without db.ts, the Node target uses in-memory state that disappears when the process exits. SessionData is version 6 and contains affinityKey, entries, leafId, task-session references, metadata, and timestamps.

session.prompt(...) appends the user prompt to the active session and runs against the session’s current conversation context. The runtime rebuilds the agent harness state from stored session history when opening a session, then syncs newly produced messages back into session history after each prompt.

PromptResponse.usage is post-call telemetry. Flue aggregates token and cost usage across model work performed by one prompt, skill, or task call. The installed runtime also folds compaction summarization usage into the operation that triggered compaction.

Flue exposes compaction in two ways:

CompactionConfig has reserveTokens, keepRecentTokens, and model. Flue automatic threshold compaction triggers when the current context token count is greater than contextWindow - reserveTokens. The installed runtime estimates context with provider usage from the latest assistant message plus a character-count estimate for trailing messages. It also has overflow recovery that compacts and retries after a provider context overflow.

Flue does not expose a public pre-prompt exact token count for application code in the installed @flue/runtime package. SIM-ONE Alpha owns the pre-prompt budget layer by estimating the next prompt and the persisted session context before calling session.prompt(...).

Implemented SIM-ONE Alpha Layer

The active runtime model card now drives context budgeting and compaction:

Flue remains the owner of canonical SessionData. The SIM-ONE Alpha wrapper indexes latest data by logical harness/session name for workflows and by instance/harness/session identity for durable direct-agent sessions.

The durable chat ingress sequence is:

normalize message
-> resolve product session and pre-LLM slash commands
-> persist normalized event context
-> call the durable /agents/orchestrator/:sessionId route for normal prompts
-> Flue admits the prompt into durable direct-agent submission storage
-> store updated Flue SessionData through the persistence adapter
-> index session memory chunks

This keeps Flue’s native automatic compaction enabled on the durable direct-agent path. Explicit /compact opens the same durable direct-agent session and calls session.compact() without sending the command text to the model.

Persistence And Session Memory Boundary

src/db.ts is the Flue persistence boundary. src/engine/session/session-database.ts is the SIM-ONE Alpha sidecar index for product session records and extracted session-memory retrieval.

Current behavior:

The SQLite implementation stores:

Session memory does not fork conversation truth into a separate transcript. It indexes text extracted from Flue SessionData and returns matching chunks through the memory tool. Structured memory, document retrieval, and vector indexes remain separate retrieval sources.

Budget Inputs

The calculator enforces the provider-reported context window first, then the guaranteed window, then the advertised window. Output reserve is capped at 25 percent of the enforced context window so models with very large reported output ceilings still retain a usable input budget.

Compaction Decision Points

Compaction flow:

durable direct-agent session
-> native Flue threshold and overflow compaction during prompt work
-> explicit /compact when the user or client requests compaction
-> session.compact()
-> persisted SessionData and session-memory index update

Flue’s own threshold and overflow compaction still run during and after the prompt. The SIM-ONE Alpha layer keeps the budget data available so RAG can receive a real remaining-token budget before retrieved context is injected.

The backup card is configured metadata. Current durable chat execution prompts with the primary configured card and does not perform automatic backup-card failover. Every active model path must use its own card-derived context budget.

RAG Allocation Rule

RAG must receive only the remaining input budget after these items are accounted for:

RAG asks the budget layer for remaining tokens before adding search results, document chunks, or memory summaries to the prompt. Web search enters through the researcher-owned web-research workflow, which uses the retrieval workflow as lower-level machinery. Returned snippets and fetched pages are packed to the configured retrieval budget before they are returned to the researcher. Ollama Search is the default web provider because it uses the existing Ollama API key already needed for cloud model testing.

Current retrieval controls:

The researcher subagent uses these controls through web_research. This keeps context packing and provider failures in workflow machinery while preserving the ownership boundary: the orchestrator delegates web/current/source-backed work to the researcher, and the researcher owns web search decisions.

Slash Commands

Slash commands are parsed before the LLM receives the prompt:

The Ratatui TUI also owns local commands that do not require backend slash-command handling: /session, /sessions [limit], /help, and /exit. /sessions reads the scope-filtered lifecycle list endpoint; the others are purely local UI behavior. Backend slash commands include /new, /clear, /resume, /rename, and /compact; /clear creates a replacement durable TUI session while preserving the old session for explicit resume. Default TUI startup uses POST /api/chat/sessions, while Telegram alone currently retains connector-conversation active-session persistence.

Unsupported slash commands are handled by application code and are not sent to the LLM.

See docs/architecture/tui-cli-session-flow.md and docs/tui/session-management.md for the product TUI command flow.