feat: autonomous (cron) session turn cap#17
Merged
Conversation
CLI --max-turns ceiling + advisory prompt contract + session_budget_stop runlog classification for cron/sdk sessions. Scoped per brainstorming; interactive covered by the shipped UserPromptSubmit guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ering - sdk source doesn't exist yet; scope v1 to source=='cron' (web/api uses dispatchWebSessionRun, separate design) - rate-limit retry engine.run must carry maxTurns + re-classify; Codex fallback advisory-only (no hard cap) - classify error_max_turns FIRST, before dead-session/rate-limit handling - intentional no transient-retry on error_max_turns in ClaudeEngine.run - append budget contract AFTER pre-session hooks (hook may replace prompt) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7 TDD tasks: schema, budget.ts core (tested), --max-turns arg, subtype capture + no-retry, runSession wiring (incl. retry path), runner runlog + alert, end-to-end smoke. Full code per step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…gineResult.subtype, CronJob.maxTurns/sessionBudget, sessions.budget)
…dget stop (incl. retry path)
…p runlog, conditional ops alert
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.
Caps autonomous cron Claude sessions via the CLI's
--max-turnsceiling + anadvisory prompt contract, and classifies a ceiling-hit as a distinct
session_budget_stop(not a generic error). Targets the marathon-session spendconcentration (top ~2% of sessions ≈ 80% of cost; ≥200-turn sessions ≈ 90%).
Design:
docs/superpowers/specs/2026-06-03-autonomous-session-turn-cap-design.mdPlan:
docs/superpowers/plans/2026-06-03-autonomous-session-turn-cap.mdWhat it does
sessions/budget.ts: cap resolution, contract prompt, stop classification (unit-tested).--max-turns <cap>passed to the Claude CLI for cron sessions; default 300,per-job
maxTurnsoverride, opt-out viasessionBudget.hardCap:false.result.subtype === "error_max_turns"(never turn count), before dead-session/rate-limit handling; carried through
the rate-limit retry path. Codex fallback is advisory-only (no hard cap).
EngineResult.subtypenow captured generically;ClaudeEngine.runnevertransient-retries a budget stop.
session_budget_stop(distinct fromsuccess/error) + ops alertonly for
sessionBudget.sideEffects:truejobs.Scope
dispatchWebSessionRun(separate path);interactive is covered by the shipped
UserPromptSubmitguard.sdksourcedoesn't exist yet. No continuation-artifact schema in v1 (deferred to steward data).
Known gap (documented)
A mutating cron without
sessionBudget.sideEffects:trueproduces a runlog-only(Telegram-silent) budget stop. Owners of write/deliver jobs must opt in.
Testing
budget.test.ts+--max-turnsarg cases added); typecheck clean.maxTurns:3throwaway cron:runlog →
{"status":"session_budget_stop","maxTurns":3,"actualTurns":4},session row →
interrupted | session_budget_stop: hit max-turns cap (3),ops-alert fired (sideEffects-gated). Throwaway job removed (byte-exact restore).
🤖 Generated with Claude Code