Skip to content

Wait out provider usage limits, and spending limits for chats, Bots and routines - #592

Merged
sambitcreate merged 28 commits into
mainfrom
claude/project-thread-8u7kd6
Oct 29, 2026
Merged

sambitcreate merged 28 commits into
mainfrom
claude/project-thread-8u7kd6

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Requested by sbt · project thread

What this does

Usage limits. When a provider turns a request away before any reply because of a rate limit, an overload or a plan window, the reply waits instead of failing.

How long it waits:

  • It waits until the reset time the provider gave. Aiden reads it from retry-after, the x-ratelimit-*, ratelimit-* and anthropic-ratelimit-* headers, the Codex window headers, or the error text.
  • Without a reset time it backs off: 15 s, 30 s, 1 min, 2 min, 5 min, then every 10 min, for up to 30 minutes.
  • A plan limit with no time is retried every 15 minutes.
  • The owner sets the longest wait in Settings → Limits & spending: Don't wait, 1, 6 (the default), 12 or 24 hours.
  • Limits that last days, like a weekly cap, and billing problems fail at once and name the reset time.
  • A 503 or 408 waits only when it reads as an overload (a reset time, or rate-limit/overload wording). A plain server error goes to the automatic retries.

When the limit clears:

  • One test request goes out first. The other waiting requests then go one at a time, oldest first.
  • The model never changes.

What people see:

  • Chats show a "Waiting for X's usage limit · next try at …" row with Retry now. Bot chats show a card with the same button.
  • Aiden sends a notification only when it gives up waiting.

Scope:

  • Waits survive a restart (userData/usage-limits.json).
  • The wait applies to chats, Bots, routines, Telegram and subagents. Background chores never wait.
  • The Bot stuck-run watchdog skips a run while its request is held back for a usage limit; the test request that goes out when it clears is watched as usual.

Automatic retries (#595). The wait sits under the automatic model-request retries.

  • When a usage limit is one the wait gave up on, outlasts the longest wait, or was refused after a recent give-up, the error carries a marker. A chat's retry check skips it, so the reply fails once with the reset time instead of retrying five times.
  • After a give-up, Aiden refuses that limit for 5 minutes. Bots retry through Pi Durable, so those retries end at once.
  • With waiting off, a usage limit is retried like any other failure.

Spending limits (owner's model A).

Limits:

  • Each chat has a total limit, each Bot a monthly limit, and each routine run its own limit.
  • Each Bot's month starts on a day the owner picks, the 1st to the 28th (default the 1st).
  • Defaults live in Settings. A Bot's Profile has a Monthly limit row (Default, No limit, or an amount).

What counts:

  • The ledger uses the per-response cost Pi already records.
  • Only API-key requests count. Sign-ins and local models count as $0.
  • Subagents count toward their chat. Routine runs count toward both their run and their Bot's month.

At and near the limit:

  • A quiet note appears at 80% of the limit.
  • The step that crosses the limit finishes. After that, the chat or Bot refuses new requests with a clear line, which Telegram gets too.
  • Allow $X more adds the limit amount again.
  • A routine run that hits its limit stops, and the next run starts fresh.

Phones: Remote revision 47 (spending-limits-v1, provisional, re-claim at merge).

  • New routes GET /chats/{id}/spending, GET /bots/{id}/spending, and POST …/spending/allow-more (with If-Match).
  • Allow more is compare-and-set, so two taps that cross add the amount only once.
  • iOS and Android show the same notice with Allow more.
  • A send over the limit is refused with 409 operation_stale carrying the limit's line, so older phones need no change.
  • Fixtures and OpenAPI are updated.

Not in this PR

  • A subscription usage meter. The owner chose to leave it out (2026-10-28); the only source is an unofficial sign-in endpoint.
  • Counting Bot compaction summaries, the Bot memory review and chat titles.
  • CLI support for either feature.

Revision note

Written as 40, then moved to 43 (main at 42), 44 (#631 took 43) and 45 (#639 took 44) on 2026-10-28, and on 2026-10-29 to 46 (#626 took 45) and 47 (#629 took 46). The number appears in AIDEN_REMOTE_SPENDING_LIMITS_CONTRACT_REVISION, in both contractRevision fields of fixtures/contract.json, and in the iOS AidenRemotePhase0Tests. If another revision merges first, re-claim the next free one.

Tests

New suites:

  • usage-limit-core, usage-limit-stream, spending-core and spending-service.
  • handlers/spending and renderer/shared/{usage-limits,spending}.
  • The spending notice, plus cases in the protocol, router and chats suites.
  • iOS AidenSpendingTests plus client tests, and Android AidenSpendingTest.

New Electron e2e usage-limit-wait.spec.ts:

  • The test model server answers 429 with retry-after.
  • The reply waits and shows the row, and the provider's error stays hidden.
  • Retry now sends the request again with the same model.

New pi-compaction-core case: a usage-limit give-up from the real wait is not retried, while the same rejection with waiting off is retried. Without the fix the case fails. bot-run-watchdog and usage-limit-stream cases cover the watchdog during a wait and a hung test request.

The Bot images and browser recordings older-revision protocol checks now also drop the newer spending section before re-parsing, as the other older-revision checks do.

Passed locally after merging main at b8f42df:

  • tsc and focused lint.
  • test:usage-limits, test:spending, every suite that reads the shared Remote fixture, and the router suite (344).
  • After the main merge at 366583f: test:bot-runtime (297) and the watchdog suite.
  • Earlier on 2026-10-28: test:bot-issues, test:bot-proactive, the chats, routine, compaction, agent-activity and Bot chat suites, and the e2e specs usage-limit-wait and model-call-retry.

iOS and Android were not compiled locally; CI covers them.

Docs

  • New guide docs/usage-limits-and-spending.md, which has an "Automatic retries" section, and plan docs/plans/usage-limits-and-spending-plan.md.
  • Revision 47 section in docs/aiden-remote-api-v1.md.
  • Updated: README, PRODUCT, docs/settings-design-system.md, docs/aiden-on-the-go-remote-access.md, docs/activity-marks.md, docs/bot-routines.md, ios/CHANGELOG.md, the plan index and .memory/.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

When a provider's rate limit or plan window turns a request away before
any reply, the request waits for the reset the provider gave (or backs
off), sends one test request, then lets the other waiting replies go one
at a time. It keeps the same model. Chats, Bots, routines and helpers all
wait; a window of days and billing problems fail at once with the reset
time. The owner sets the longest wait in Settings, Limits & spending.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
Each chat has a total limit, each Bot a monthly limit (its own or the
default, starting on the owner's chosen day) and each routine run its own
limit. Only pay-as-you-go keys count; sign-ins and models on this Mac are
$0. The request that crosses a limit finishes its step, then the chat,
Bot or run stops with a clear line and an "Allow $X more" action.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
Phones read a chat's or Bot's spending and allow more through
GET/POST /chats/{chatId}/spending and /bots/{botId}/spending
(`spending-limits-v1`, provisional contract revision 40). Allow more
takes the status revision in If-Match, so a repeated tap is a conflict
rather than a second allowance. A phone turn over its chat's limit is
refused with operation_stale and the limit's own line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
Chats and Bot chats show a quiet line from 80% of the limit and, once
it is reached, a card with "Allow $X more" that sends the status
revision, so a tap another device already answered re-reads instead
of adding twice. Hidden when the Mac does not offer spending-limits-v1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
…abel

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
…ng limits

Adds the usage limits and spending limits guide, the revision 40 section
of the Remote API doc, the plan with the owner's decisions, and the
README, product, settings, phone, activity mark, iOS changelog and plan
index entries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
…for a rate-limited reply

The chat's spending notice now sits in the chat content column, like the
approval card, instead of spanning the whole pane. A new end-to-end test
has the test model server answer 429 with retry-after: the reply waits,
shows the waiting row, and Retry now sends it again with the same model.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
@sambitcreate sambitcreate self-assigned this Oct 26, 2026
JUnit 4 rejects a test method that returns a value, and one body ended
in assertThrows, which returns the exception, so the class failed to
initialize.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
@very-hermes-bot

very-hermes-bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes review failed

Hermes could not produce a code-review verdict for this head SHA.

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 148eb44c41379269f5fbb9859f1aebfd59b1efe3
Generated: 2026-10-29T05:10:28+00:00
Failure phase: engine

Safe summary:

Command '['/home/sambit1/.local/bin/agy', '--print-timeout', '30m0s', '--sandbox', '--add-dir', '/tmp/hermes-review-bot/aiden-agent-pr-592-148eb44c4137', '--model', 'gemini-3.8-flash-high', '--input-format', 'stream-json', '--output-format', 'stream-json', '--print', '']' timed out after 1920 seconds

Local logs: /home/sambit1/.hermes/logs/review-bot/aiden-agent.log

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Spending caps have enforcement gaps, inherited usage waits can exceed the configured maximum, and the iOS checks need fixes before merging.

Reviewed changes Reviewed provider retry coordination, spending enforcement and persistence, desktop UI, Remote contracts, and both native clients at 6c7c123.

  • Usage-limit waits: Adds reset parsing, backoff, persistent provider/model holds, coordinated test requests, cancellation, Retry now, and give-up notifications across chats, Bots and helpers.
  • Spending enforcement: Adds chat totals, monthly Bot caps and per-routine budgets, API-key cost accounting, admission checks, and additional allowances.
  • Desktop controls: Adds Limits & spending settings, Bot monthly overrides, spending notices, and waiting activity states.
  • Remote and mobile: Adds provisional revision 40 spending routes with compare-and-set allowances, compatible send refusals, and iOS/Android notices.
  • Documentation and coverage: Adds the feature guide, plan, shared fixtures, focused behavioral tests, and a rate-limit Electron scenario.

Validation passed: usage-limit tests (28), spending tests (18), Remote protocol/router tests (136), the focused Bot spending test, and the focused Android spending tests. test:ios-release failed its two source-inventory checks; a minimal Swift/XCTest typecheck independently reproduced the async-autoclosure error below. Runtime probes reproduced the accounting, restart-budget and inherited-wait failures. Full iOS and Electron execution was not performed on this Linux runner.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread main/services/spending-core.ts Resolved
Comment thread main/services/usage-limit-stream.ts Resolved
Comment thread main/services/usage-limit-core.ts Resolved
A fast tool turn could send the next request before the previous
response's cost was recorded, so a Bot or routine run could pass its
spending limit by more than one step. afterResponse now awaits the
record, which never throws.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@very-hermes-bot very-hermes-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

- A request that joins a held limit (another chat's, or one saved by an
  earlier run) stops waiting when the limit clears after its longest wait;
  changing the setting applies to waits already running, and Don't wait
  sends them.
- Compact reset durations such as OpenAI's 6m0s parse in full.
- A routine run's spend is saved, so a run resumed after a restart keeps
  its balance.
- iOS: await outside XCTUnwrap; list the new Swift files in the shipping
  target inventories.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues found in this update. Approval remains withheld while the other findings from the previous review are unresolved.

Reviewed changes Reviewed 0df2e4e against the prior reviewed head, 6c7c123, with the full PR diff as context.

  • Awaited Bot response accounting through credential classification and ledger recording before the next request can be admitted, preserving nonfatal accounting errors.
  • Extended spending enforcement coverage with delayed asynchronous recording, verifying that the crossing step finishes but no subsequent provider request runs.

Validation passed: test:bot-runtime (273 tests), test:spending (18 tests), and npx tsc --noEmit. The accounting-race thread is resolved. Native mobile and Electron suites were not rerun for this desktop-only delta.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Copy link
Copy Markdown
Owner Author

Hermes [P2] (unawaited Bot spend record): fixed in 0df2e4e. afterResponse awaits record, so the next beforeRequest sees the spend; test (b2) now records asynchronously and fails without the fix. The cost lookup stays per response rather than cached, because a Bot's sign-in can change between turns.


Generated by Claude Code

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Turning waiting off during an active usage-limit wait can start an unbounded resend loop against the rate-limited provider.

Reviewed changes Reviewed 4bfee02 against the previously reviewed head, 0df2e4e, with the full PR diff as context.

  • Applied inherited-wait limits during gate acquisition and propagated longest-wait setting changes to active waiters.
  • Persisted routine-run spending balances across restarts and extended reload coverage.
  • Corrected compact reset durations such as 6m0s and 1h2m3.5s, with classification tests.
  • Fixed iOS test integration by awaiting responses before XCTUnwrap and registering both new Swift files in the shipping inventories.
  • Updated documentation and project memory for live wait-policy changes and persisted routine balances.

Validation passed: test:usage-limits (29 tests), test:spending (18 tests), test:ios-release (20 Ruby tests and 30 Node tests), and npx tsc --noEmit. A runtime probe reproduced the resend loop, stopping it deliberately after five rejected calls. Native iOS and Electron execution were not performed on this Linux runner.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread main/services/usage-limit-core.ts Resolved
The Bot chat showed the reached notice but kept its composer ready, so a
send failed with a toast. It now says why in the composer, as a workspace
chat does, until Allow more.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

Copy link
Copy Markdown
Owner Author

Hermes [P2] (Bot chat composer stays ready at the limit): fixed in 8c83983 (not yet pushed). The composer is not ready while the Bot's status is reached and shows the same line as the notice; a new Bot chat pane test sends nothing until Allow more, then sends.

The Linux x64, Linux arm64 and CI required failures on 6c7c123 were jobs cancelled by the next push (LINUX_RESULT: cancelled), not test failures.


Generated by Claude Code

A request sent because waiting was turned off during its wait joined the
still-held limit again on a rejection and resent at once, in a loop. The
send ticket now says waiting is off, so the rejection fails as it would
with waiting off.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

An open Bot chat can remain unable to send after its monthly spending limit resets.

Reviewed changes Reviewed 8c83983 and the arriving 2756db3 update against the prior reviewed head, 4bfee02, using the full PR diff as context.

  • Added Bot composer enforcement that blocks sending at the spending cap, displays the limit explanation, and re-enables sending after Allow more, with component coverage and updated documentation.
  • Fixed disabled-wait rejection handling so turning waiting off during an active wait sends once and surfaces a continuing rate-limit rejection instead of resending indefinitely.

Validation passed: Bot chat component tests (66), spending tests (18), usage-limit tests (29), and npx tsc --noEmit. A separate probe using the real component and spending service reproduced the monthly-rollover lockout and confirmed that a status refresh unblocks sending. Native mobile and Electron suites were not rerun for this desktop-only delta.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread renderer/main/bots/bot-chat-pane.tsx Resolved
The reached status was only re-read on mount or a change event, and the
month ending sends neither, so the composer stayed blocked. The status is
now read again once its period has ended, checked at least each minute so
a Mac that slept through the boundary catches up.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed d4cdb39 against the prior reviewed head, 2756db3, with the full PR diff as context.

  • Added monthly status refresh to the shared desktop spending hook so an open Bot chat becomes usable when its spending month resets, including a boundary crossed while suspended.
  • Extended Bot chat coverage to verify sending after rollover without Allow more or reopening the chat, and updated the usage guide.

Validation passed: Bot chat component tests (67), spending tests (18), and npx tsc --noEmit. An independent hook test against the real spending service also passed simulated suspension catch-up and timer cleanup. Native mobile and Electron suites were not rerun for this desktop-only delta.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

Copy link
Copy Markdown
Owner Author

Desktop tests (renderer-other) failed on 2756db3 (job). This PR didn't cause it. The job now runs on the self-hosted Mac runner (/Users/ci/runner-1, routed by 4292ceb on main), whose openssl is macOS's LibreSSL. scripts/aiden-remote-physical-device-spike-server.mjs:107 and scripts/aiden-remote-lan-transport-spike.mjs:63 sign certificates with openssl x509 -req ... -copy_extensions copy, and LibreSSL rejects that with unknown option -copy_extensions. Three spike tests in scripts/aiden-remote-lan-transport-spike.test.mjs (lines 158, 187 and 274) fail before their bodies run. Any PR that runs this job on that runner will hit the same failure.

No fix exists yet. Proposed patch, which works with both OpenSSL and LibreSSL: write the extensions the request already carries into a small extfile and sign with -extfile <file> -extensions v3 in place of -copy_extensions copy:

[v3]
subjectAltName=<same SAN>
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature
extendedKeyUsage=serverAuth

The other option is to put Homebrew OpenSSL 3 first on the runner's PATH. I'm leaving this out of this PR because it belongs with the runner setup.


Generated by Claude Code

child-agent-runtime imported the Electron-bound usage-limit and spending
singletons at load, so plain Node tests that reach it (the Pi upgrade
evaluation) failed to import electron. llm-client now binds them through
setLimits, as it already does for health metrics.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

Copy link
Copy Markdown
Owner Author

Desktop tests (core-git) failed on 2756db3: main/services/pi-upgrade-evaluation.test.ts could not load because electron does not export BrowserWindow. This PR caused it. child-agent-runtime.ts imported the Electron-bound usage-limit and spending singletons at load. Fixed in ec09567: llm-client now binds them with subagentRuntimeRegistry.setLimits, the same way it binds health metrics, and the test passes locally (14/14).


Generated by Claude Code

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new initialization call breaks two existing host tests because their registry doubles do not implement setLimits.

Reviewed changes Reviewed ec09567 against the prior reviewed head, d4cdb39, with the full PR diff as context.

  • Moved helper-limit binding into Electron-main llm-client.ts, preserving the desktop usage-limit and spending services through SubagentRuntimeRegistry.setLimits.
  • Removed Electron-bound singleton imports from the shared child runtime so plain Node replay and subagent tests can load it independently.

Validation passed: replay and subagent suites (113 tests), usage-limit tests (29), spending tests (18), and npx tsc --noEmit. After building the normal native-lock and compaction-worker prerequisites, the Bot-pause and cache-warming suites passed 30 of 32 tests; both remaining failures are covered by the inline finding. Native mobile and Electron suites were not rerun for this main-process-only delta.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread main/services/llm-client.ts Resolved
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j
…age-limit and spending branch

package.json test:serial keeps both test:follow-through and the
usage-limit and spending suites.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the a21e36d merge against the prior reviewed head, 7d15b41, with the complete PR diff as context.

  • Merged coding follow-through and CI routing from main, preserving spending admission for unattended follow-up turns and both follow-through and spending cleanup when deleting a chat.
  • Preserved test-chain coverage from both merge parents, including test:follow-through, test:usage-limits and test:spending.

Validation passed: usage-limit tests (29), spending tests (18), follow-through tests (76), CI-policy tests (69), chat application-service tests (11), and npx tsc --noEmit. All prior Pullfrog threads remain resolved. Native mobile and Electron suites were not rerun locally; hosted CI on this exact head is still queued or running, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

Copy link
Copy Markdown
Owner Author

The failing Hermes Review Bot status on a21e36d isn't caused by this PR's code. The review engine timed out after 1,920 s before it produced a verdict (failure phase engine). The only change since the last clean Hermes summary, on 7d15b41, is a merge of main. In that merge, the test:serial chain kept test:follow-through, test:usage-limits and test:spending.

I can't re-run the bot from here. It needs a fresh run on its host. Pullfrog's review of the same head found no new issues. Hosted CI on a21e36d is green so far, and the Electron E2E, desktop build and runtime-subagents jobs are still queued.


Generated by Claude Code

…ote revision 43

Brings in Bot autonomy (issues, events, learning), automatic model-request
retries (#595), the web page extract recap (38), scheduled-task approval
cards (39), hand-off notes (40), context pressure (41), Bot issues (42), the
Electron security update and hosted Mac CI.

Spending limits on phones move from provisional revision 40 to 43 in the
host constant, the shared fixture, OpenAPI, the iOS Phase0 test, phone
comments and the docs. Conflicts resolve by union: the test:serial chain,
agent-activity's limited and retrying phases, the e2e fixture hooks, the Bot
profile sections and the router helpers. Routine delivery moved to main's
funnel, so the routine ports keep spendingStop and drop deliverResult.

A usage limit the wait gave up on, one that outlasts the longest wait, or one
a recent give-up refused now carries a marker, and a chat's automatic retries
skip it: the reply fails once with the reset time instead of showing "Trying
again" five times. With waiting off it is retried like any other failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The merged Bot watchdog cancels valid provider-limit waits before their reset time, so waiting routines can fail as stalled instead of resuming.

Reviewed changes Reviewed ec2a3d0 against the prior reviewed head, a21e36d, with the complete PR diff as context.

  • Merged newer main integrations, including Bot autonomy, automatic model-request retries, delivery-funnel changes, and the combined test chains.
  • Added final usage-limit retry suppression, preserving a marker through Pi’s actual message lifecycle so workspace chats do not retry errors after Aiden gives up waiting.
  • Reclaimed Remote revision 43 for spending limits across the host, shared fixture, iOS expectation, OpenAPI, and documentation, retaining main’s revisions 38–42.

⚠️ Valid Provider Waits Are Treated As Stalled Runs

The incoming watchdog exempts hand-offs, approvals and questions, but not the provider-limit waits this PR adds. A routine waiting for a valid 30-minute reset under the default six-hour maximum is stopped after roughly ten minutes without transcript progress; an attended Bot wait instead produces a misleading “Still working?” issue.

Technical details
# Integrate provider-limit waits with the Bot stall watchdog

## Affected sites
- `main/services/bot-runtime/bot-session-main.ts:627-640`: the watchdog's waiting predicate checks only pending hand-offs, approvals and questions.
- `main/services/bot-runtime/bot-run-watchdog.ts:42-51`: ten minutes without progress stops a routine or raises an attended-run issue.
- `main/services/usage-limit-stream.ts:219-245`: a held request waits without emitting stream content; `usage-limit-service.ts` broadcasts on `usageLimits:changed`, outside the Bot transcript feed that updates `watchedRuns.at`.
- `main/services/bot-runtime/live-projection.ts:1110-1115`: unchanged activity does not emit progress, and there is no periodic progress heartbeat to protect the wait.

## Evidence
An independent fake-clock probe used the real `UsageLimitGate`, `withUsageLimitWait` and `createBotRunWatchdog`, with a provider rejecting once with “Try again in 30 minutes” and succeeding on the next call. With the current waiting exclusions, checking at ten minutes called Stop and produced `stopReason: aborted` after only one provider call. A positive control exempting the active usage wait made no Stop call and completed successfully with two provider calls at the reset.

This interaction is new to the branch after `ec2a3d0` merged the watchdog from main. The watchdog wiring is outside the base-to-head PR hunks, so the missing integration is reported here rather than anchored to unrelated changed lines.

## Required outcome
- Do not stop or flag a Bot as stalled while it is deliberately waiting for a provider limit within the configured policy.
- Give resumed inference a fresh progress window when the hold clears, rather than immediately treating the elapsed hold as a stall.
- Extend behavioral watchdog/host coverage to a provider wait longer than ten minutes, preserving genuine-stall detection.

Validation passed: usage-limit and spending suites, Remote protocol/router/chats, chat activity and Bot chat components, compaction and actual generation-harness suites, Bot extension/routine/recovery tests, CI policy, iOS shipping checks, TypeScript, and focused ESLint. Android validation was blocked locally by the uncached org.gradle.toolchains.foojay-resolver-convention plugin; the online retry returned Tool 'shell' timed out after 120000ms. Native iOS and Electron execution were not performed on this Linux runner, and exact-head hosted CI is still incomplete.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

A routine waiting for a provider's reset made no transcript progress, so
the watchdog stopped it as stalled after 10 minutes, and an attended Bot
got a "Still working?" card. A usage-limit wait now counts as progress:
the run is neither stopped nor flagged while it waits, and its 10 minutes
start again when the limit clears.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The long-wait cancellation is fixed, but the watchdog exclusion also covers already-sent retries, allowing a hung retry to bypass stall recovery indefinitely.

Reviewed changes Reviewed e7a8289 against the prior reviewed head, ec2a3d0, with the complete PR diff as context.

  • Exempted Bot provider-limit waits from the stuck-run watchdog and refreshed the progress window during those waits.
  • Extended watchdog coverage and documentation for a 30-minute hold, resumed stall detection, and attended-run behavior.

Validation passed: test:bot-runtime (297 tests), test:usage-limits (29 tests), routine execution/recovery suites (64 tests), TypeScript, and focused ESLint. An independent probe using the real Bot model wrapper and Google adapter reproduced the inline finding; a queued-only exclusion restored stall recovery while a healthy 30-minute wait still completed. Native mobile and Electron suites were not rerun for this desktop-main-only delta; exact-head hosted CI remains incomplete.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

The watchdog skipped a Bot for as long as the usage-limit gate listed a
wait for it, which includes the test request already sent once the limit
clears. A test request that hung without content then kept the run alive
forever. It now skips a Bot only while one of its requests is held back
(UsageLimitGate.isHeld), so a sent request is watched as usual.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed 63c7a00 against the prior reviewed head, e7a8289, with the complete PR diff as context.

  • Restricted watchdog exemptions to requests still held in the usage-limit queue, keeping already-dispatched retries subject to normal stall recovery.
  • Added queued-to-flight coverage through the real stream wrapper and gate, and clarified the behavior in the routine and usage-limit guides.

Validation passed: test:usage-limits (30 tests), test:bot-runtime (297 tests), routine execution/recovery suites (64 tests), TypeScript, and focused ESLint. An independent four-case probe combining the real gate, stream wrapper, and watchdog confirmed that 30-minute holds remain protected, healthy retries complete, and hung retries trigger routine Stop or one attended-run stall card. All prior Pullfrog threads are resolved. Native mobile and Electron suites were not rerun for this desktop-main-only delta; exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

A 503 or 408 now waits only when it reads as an overload: it carries a
reset time or rate-limit/overload wording. A plain server error goes to
the chat's own retries again, which the retry e2e spec expects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed ed3ae65 against the prior reviewed head, 63c7a00, with the complete PR diff as context.

  • Routed bare server failures (503 and 408) to automatic retries instead of usage-limit waits, preserving waits for explicit overloads, rate limits, and reset headers.
  • Extended classification coverage and documentation to distinguish ordinary server failures from provider usage limits.

Validation passed: test:usage-limits (30 tests), compaction and provider-failure suites (123 tests), TypeScript, and focused ESLint. An independent probe through the real stream wrapper and retry coordinator confirmed bounded retry budgets for bare 503/408 errors and preserved waiting behavior for five overload/reset/rate-limit controls. The compaction suite required its normal build:vcc prerequisite before passing. All prior Pullfrog threads remain resolved. Native mobile and Electron suites were not rerun for this core-only delta; exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

…imit and spending branch; move spending limits to Remote revision 44

#631 took revision 43 on main, so spending-limits-v1 now claims 44
(still provisional) across the host constant, the shared fixture,
OpenAPI, the iOS and Android comments and tests, and the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the updates since ed3ae65, focusing on the 8d721c8 merge and revision change, with the complete PR diff as context.

  • Merged Bot hand-off integration from main, preserving usage-limit watchdog handling, spending enforcement, and capability-gated Remote audiences.
  • Reclaimed Remote revision 44 for spending limits across the host, shared fixture, iOS expectation, OpenAPI, and documentation, leaving revision 43 for hand-offs on the Mac.
  • Recorded the subscription-meter exclusion as the owner's decision, without changing runtime behavior.

Validation passed: usage-limit tests (30), spending tests (18), Remote protocol/router/chats (226), Remote Bot-session/handoffs and operation-contract tests plus Bot models/watchdog (131), iOS shipping/release-policy checks (20 Ruby and 30 Node), TypeScript, and focused ESLint. The Bot integration suites required their normal build:lease-flock prerequisite before passing. Android validation was blocked by the uncached org.gradle.toolchains.foojay-resolver-convention plugin; the online retry returned Tool 'shell' timed out after 120000ms. Native iOS XCTest and Electron execution were not performed on this Linux runner, and exact-head hosted CI is not yet established, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

…g branch

Keeps main's wider Bot file-tool protected roots alongside the Bot
runtime's usage-limit wait, and appends test:usage-limits and
test:spending to main's test:serial chain. Main is still at Remote
revision 43, so spending limits keep provisional 44.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the 5385b7b merge against the prior reviewed head, 8d721c8, using the incremental diff and relevant full-PR context.

  • Preserved Bot runtime integration while merging main's expanded file-tool protection, retaining usage-limit waits, spending accounting, and queued-only watchdog exemptions.
  • Updated host and notification integration, retaining the cache-warming test double's limit bindings alongside the new workspace-file notifier and preserving the preload notification channels.
  • Combined test-chain coverage from both merge parents, keeping main's workspace-file tests and this PR's usage-limit and spending suites.

Validation passed: usage-limit tests (30), spending tests (18), seven affected host/Bot/file-notification suites (83), CI-policy tests (67), TypeScript, and focused ESLint. The file-router cases required the normal build:subagent-file-mutator prerequisite before passing. All prior Pullfrog threads remain resolved. Native mobile and Electron suites were not rerun for this merge-integration delta; exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

… and spending branch; move spending limits to Remote revision 45

#639 took revision 44, so spending-limits-v1 now claims 45 (still
provisional). Also restores main's revision-40 hand-off note comment
that an earlier renumbering had changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the eef7f39 merge against the previously reviewed head, 5385b7b, using the incremental diff and relevant full-PR context.

  • Merged image-placement integration from main, preserving spending admission, usage-limit handling, and spending notices across the affected chat surfaces.
  • Reclaimed Remote revision 45 for spending limits across the host, shared fixture, iOS expectation, OpenAPI, and documentation, retaining main's revision 44 for image placement.
  • Preserved Bot send-state behavior from main, keeping Getting ready for slow sends alongside spending-cap enforcement and monthly rollover coverage.

Validation passed: usage-limit tests (30), spending tests (18), Remote protocol/router/chats (227), remaining shared-fixture consumer suites (187), affected transcript/Bot/image suites (121), CI-policy tests (67), iOS shipping/release-policy checks (20 Ruby and 30 Node), TypeScript, and focused ESLint. All prior inline findings remain resolved.

Android validation was blocked by the uncached org.gradle.toolchains.foojay-resolver-convention plugin; the online retry returned Tool 'shell' timed out after 120000ms. Native iOS XCTest and Electron execution were not performed on this Linux runner. Exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

…spending branch; move spending limits to Remote revision 46

#626 took revision 45, so spending-limits-v1 now claims 46 (still
provisional). The Bot images older-revision check now also drops the
newer spending section before it re-parses the fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the 4e3153d merge against the previously reviewed head, eef7f39, using the incremental diff and relevant full-PR and merge context.

  • Reclaimed Remote revision 46 for spending limits across the host, shared fixture, iOS expectation, OpenAPI, and documentation, retaining main's revision 45 for Bot shared images.
  • Preserved Bot image and spending integration across the Remote routes and both native chat surfaces, retaining spending notices, refresh behavior, and capability-gated audiences.
  • Updated older-revision fixture coverage to remove the newer spending section before parsing a pre-image fixture, and retained usage/spending settings validation alongside main's config-store changes.

Validation passed: usage-limit tests (30), spending tests (18), Remote protocol/router/chats and config-store tests (351), other shared-fixture consumers and local/remote Bot chat tests (266), CI-policy tests (67), iOS shipping/release-policy checks (20 Ruby and 30 Node), TypeScript, and focused ESLint. All prior inline findings remain resolved.

Android validation was blocked by the uncached org.gradle.toolchains.foojay-resolver-convention plugin; the online retry returned Tool 'shell' timed out after 120000ms. Native iOS XCTest and Electron execution were not performed on this Linux runner. Exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

…mit and spending branch; move spending limits to Remote revision 47

#629 took revision 46, so spending-limits-v1 now claims 47 (still
provisional). The browser recordings older-revision check now also
drops the newer spending section before it re-parses the fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the d03a049 merge against the previously reviewed head, 4e3153d, using the complete incremental diff and relevant full-PR and merge context.

  • Reclaimed Remote revision 47 for spending limits across the host, shared fixture, iOS expectation, OpenAPI, and documentation, retaining main's revision 46 for browser recordings.
  • Preserved recording and spending integration across Remote routes and desktop/iOS/Android chat surfaces, including independent feature gates and existing spending notices and refresh behavior.
  • Updated older-revision fixture coverage to remove spending before parsing a pre-recording fixture, and retained the usage-limit and spending suites alongside main's browser-recording test registration.

Validation passed: usage-limit tests (30), spending tests (18), Remote protocol/router/chats (234), remaining shared-fixture consumers (191), merged transcript/Bot/recording suites (150), CI-policy tests (67), iOS shipping/release-policy checks (20 Ruby and 30 Node), TypeScript, focused ESLint, and Swift syntax parsing. All prior inline findings remain resolved.

Android validation was blocked by the uncached org.gradle.toolchains.foojay-resolver-convention plugin; the dependency-enabled retry returned Tool 'shell' timed out after 120000ms. Native iOS XCTest and Electron execution were not performed on this Linux runner. Exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

…ranch

Main is still at Remote revision 46, so spending limits keep provisional 47.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUyFpdzcwFxDEpoKBof81j

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the 148eb44 merge against the previously reviewed head, d03a049, using the complete incremental diff and relevant full-PR and merge context.

  • Merged Bot self-wake integration from main, preserving routine request attribution, spending admission and accounting, usage-limit waits, and watchdog handling.
  • Preserved Bot chat limit controls alongside wake-up chips and cancellation, including reached-cap enforcement, Allow more, and monthly rollover behavior.
  • Retained Remote revision 47 and test coverage, keeping the desktop-only wake-up entry outside phone transcripts and preserving the usage-limit and spending suites alongside main's new wake-up tests.

Validation passed: usage-limit tests (30), spending tests (18), seven scheduler/Bot/wake-up integration suites (176), Remote Bot-session/protocol tests (140), CI-policy tests (67), TypeScript, and focused ESLint. All prior inline findings remain resolved.

Native mobile and Electron suites were not rerun for this desktop merge-integration delta. Exact-head hosted CI remains incomplete, so this review does not establish merge readiness.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@sambitcreate
sambitcreate merged commit f4e7d02 into main Oct 29, 2026
26 of 27 checks passed
@sambitcreate
sambitcreate deleted the claude/project-thread-8u7kd6 branch October 29, 2026 05:10
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.

3 participants