Skip to content

feat(server): stop idle sessions that spend without delivery - #118

Merged
nullStack65 merged 3 commits into
mainfrom
feat/clo-922-session-spend-guard
Nov 20, 2026
Merged

nullStack65 merged 3 commits into
mainfrom
feat/clo-922-session-spend-guard

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Idle sessions could keep spending after the useful work stopped. This prices context-window updates and, by default, stops a thread once idle spend passes $50 or the session total passes $200. Flag mode only records the warning. Off disables it.

The provider reactor refuses the next automated turn when that ceiling is hit, and also when the thread still has the default title after its first turn or has no execution scope (an imported or legacy session). A background check records the flag or stop. A live turn is interrupted only when the session ceiling is crossed; an idle stop waits for the next turn so the interrupt checkpoint cannot clear the idle window. A linked pull request, a file-changing checkpoint, or a spend-guard.released activity starts the idle window over. Settled threads wake when the guard flags or stops them.

Untitled and ownerless refusals apply to cli and to a missing client surface. web, desktop, and mobile stay exempt. A compaction replay keeps the original client origin, so a human message queued behind compaction is not treated as automated.

This is the idle-session spend guard for CLO-922.

Head 0d990dcd53cb56fd17768336a3a466b7b2e444b3.

Review on ae80a452936cd819f2c92c92ae1f95b85250a628 (one round, not repeated):

  • Fixed: session spend now reads every context-window row, not the latest 500. A 501-row reactor test refuses the turn when only the oldest row is costly.
  • Fixed: cli and a missing surface are refused; only web, desktop, and mobile skip the untitled and ownerless checks.
  • Fixed: compaction replay forwards the original client origin.
  • Fixed: a running turn is interrupted only for the ceiling. An idle stop records the activity and the next turn is refused.
  • Fixed: flag mode keeps the stop reason. A ceiling flag says the ceiling was reached and is not suppressed by an earlier idle flag.
  • Declined: pricing still uses usagePriceOverrides, then sessionSpendGuard.fallbackRate. The turn path does not call LiteLLM, and UsageService does not expose its rate table.
  • Not added: a client command that writes spend-guard.released. That activity still resets spend if a server path writes it. Continuing after a ceiling stop means raising sessionSpendGuard.sessionCeilingUsd. The refusal text no longer tells a person to append that activity.

Verified on this head:

  • vp test run src/orchestration/SessionSpendGuard.test.ts (14 passed)
  • vp test run src/orchestration/Layers/ProviderCommandReactor.test.ts -t "session ceiling" (2 passed, 82 skipped)

Earlier on the previous head: the full provider reactor file (82 passed), contracts settings and settled decider tests, and tsc --noEmit in apps/server (no errors; pre-existing suggestions only). Those were not re-run after this fix.

Not verified: the integration suite, and there is no settings-form control for these fields yet. Operators can patch sessionSpendGuard on server settings. Hosted CI (ci.yml) is disabled_manually. closura-arc-ci.yml only runs on feat/assemblyai-current, so this branch has no Actions run.

Model: grok-4.7
Task: fix
Agent: grok
Lane: magpie
Harness: t3/codex
Model-family: Grok
Model-generation: 4.7

Idle threads could keep spending after the useful work stopped. Price context-window updates and stop or flag a thread once idle spend or the session ceiling is crossed. Enforce is the default. The next automated turn is also refused on an untitled thread or one with no execution scope.

A linked pull request, a file-changing checkpoint, or a spend-guard.released activity starts the window over. Settled threads wake when the guard flags or stops them.

Model: grok-4.7
Task: feature
Agent: grok
Harness: t3/codex
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…equest

A standing manager can keep spending through status nudges and child callbacks after a real pull request, which resets the idle window. Cover that ceiling stop in the evaluator and in the provider reactor.

Model: grok-4.7
Task: feature
Agent: grok
Lane: magpie
Harness: t3/codex
Model-family: Grok
Model-generation: 4.7
The thread detail query capped activities at 500 rows, so a long manager thread could stay under the ceiling. Read every spend-guard activity, interrupt a live turn only for the ceiling, and keep untitled or ownerless refusals on cli and missing surfaces.

Model: grok-4.7
Task: fix
Agent: grok
Lane: magpie
Harness: t3/codex
Model-family: Grok
Model-generation: 4.7
@nullStack65
nullStack65 merged commit a777dad into main Nov 20, 2026
1 check passed
@nullStack65

Copy link
Copy Markdown
Owner Author

This merged into main, which the fleet does not build, so it never shipped. It is ported onto release/native-0.1.10 in #125 (Linear CLO-941).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant