[Feature]: Token-aware gating and configurable reuse policy for background specialist sessions
Description
PR #885 resolved #868 by introducing backgroundJobs.maxContextLines (default: 50,000) to prevent background jobs from reusing sessions with excessive accumulated context.
Currently, this threshold is calculated strictly by summing contextFiles[].lineCount. This does not account for total token consumption from conversation history, system/user prompts, web or tool execution outputs, or actual provider token usage. Consequently, in workflows with heavy tool output or long multi-turn interactions, a specialist session can exceed 50k tokens while still being considered reusable because tracked file line counts remain below 50,000 lines.
Requested Behavior
To better manage session context growth without silently rewriting tool calls, we suggest considering:
- Token-Aware / Effective-Context Gating: Where feasible, gate session reuse on estimated total tokens or reported provider token usage rather than file line counts alone.
- Configurable Reuse Policy: Provide an option to control session reuse strategy (e.g., fresh session by default vs. explicit continuation).
- Retain
maxContextLinesas Fallback: KeepbackgroundJobs.maxContextLinesas a lightweight secondary guardrail or fallback when token usage metadata is not directly available.
Related References
- Issue #868 (context accumulation in background jobs)
- PR #885 (added
backgroundJobs.maxContextLinesconfig)
Source: alvinunreal/oh-my-opencode-slim