Repository navigation
feat(bots): name the agent's usage limit in Slack thread status lines - #52506
AmethystLiang wants to merge 5 commits into
Conversation
When a per-thread bot's workers sit idle because the agent hit its usage
limit, the idle update and the stop line now say so, with the reset the
agent reported:
Still open (30 min). Claude reported a usage limit that resets Dec 5, 2:00 AM PST.
Pausing these automatic updates for now. Claude reported a usage limit that resets Dec 5, 2:00 AM PST.
Every other line is unchanged. The limit is named only while the workers
are idle with no helpers, the reset is still ahead, and the chat has not
moved to another account. It comes from the thread's own chat, or else
from the soonest of its running workers when every one of them reported a
limit.
- Host: usageLimitOf(host, id) reads a chat's limit with no I/O. An
unloaded chat reads the sweep's cold cut through the same published()
path, so a tabless chat closed by the idle sweep still has it.
- Workers: each running local chat worker carries its chatSessionId into
the view as liveSessions. A read that fails clears it.
- A saved stop line is re-sent only if its text still matches a fresh
decision, so a limit line is never posted stale on retry or restart.
- {time} is built from separate date and time parts in en-US with plain
spaces, because ICU builds differ ("Dec 5 at 2:00 AM" under Bun).
… now - A known-reset limit is named only once the usage-limit sweep has attributed the cut to the account it hit, with no move to another home or saved account, no relaunch, and no account selection change since; and never once a continue is due before the reported reset. - An unloaded chat reads only the sweep's cut, never its retained summary; a cold cut read before attribution names nothing. - Worker chat identities are read only for conversations whose running workers are all local, idle and without helpers, stopping at the first worker with no chat. - The /clear resolver is reused until the store's lineage revision moves. - Thread status reads limits only for a due line on idle workers, the thread's own chat first. - The ready check moves beside the verdict it reads, unchanged.
…oved saved account - Thread status: keep each chat's /clear end across lineage changes and walk only past it, instead of re-walking the whole chain after every unrelated clear or removal. - Worker activity: resolve an idle worker's chat session once per Dispatch and handle, misses included, so a row with no handle or an uncached one stops costing database reads every poll. - A cut on a saved account holds only while that same account is selected; with none selected (or the selection not read yet) it no longer holds. - A held tick decides without wording the line, so it no longer reads or formats the limit.
- Drop the thread status /clear resolver and its per-chat cache. The limit is read for the chat the link or worker names, as named; a chat a committed /clear moved on from names no limit (one in-memory record read), so its thread shows today's line. - Drop the cached worker identity lookup. A worker's chat comes only from what the poll already holds: the activity read's own lookup, unchanged, a chat assignee handle, or a structured worker identity in memory. Anything else names no limit, with no database read. - Tests for the removed caches go; tests pin both fail-closed cases.
…rker reads in place usageLimitOf now reads the record (not a conversation view) for both the /clear successor and the unloaded chat's agent, and fails closed when there is no record, which the attribution check already did. Its host is a narrow exported type, so tests stub only what it reads without a cast; the held-where-hit stub that lacked getConversation no longer crashes. Worker activity reads push into their group instead of copying it per worker.
[Low impact] The PR appears safe to merge; no actionable defects were found. SummaryAdds agent usage-limit details to Slack thread updates when the host can show that the limit still applies.
No actionable issues found. Tests were reviewed but not run.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Closing: it builds on the automatic thread status lines, which were removed in #52644. |
ELI5
When a Slack bot thread's agent stops because it hit its usage limit, the thread's automatic status update used to say "nothing is running on it right now", which made the work look abandoned. Now the update says the agent reported a usage limit and when that limit resets.
What Changed
Before: an idle bot thread got
even when the agent was idle only because it had hit its usage limit.
After: when the agent reported a usage limit with a known reset that still applies, the same two lines read:
For example:
Still open (30 min). Claude reported a usage limit that resets Dec 5, 2:00 AM PST.Every other line is unchanged, and the "working" line is never replaced.
Mechanism:
usageLimitOf(host, id)reads a chat's usage limit from memory, with no I/O. A loaded chat's limit comes from its published status. A chat that isn't loaded uses the cut the usage-limit sweep last read from its journal.{time}: built from separate en-US date and time parts with plain spaces, because ICU builds join them differently.Not covered (these still show today's line):
/clearmoved on fromNothing is recovered or switched automatically. This only changes the wording of the status line.
Why
"Nothing is running" was misleading when the real reason was a usage limit. Telling people in the thread that the agent hit a limit and when it resets lets them decide whether to wait or step in. The rules fail closed: if Orca can't prove the limit still applies where the chat would run now, it keeps the existing wording rather than risk naming a reset that no longer applies. Checked against how comparable products handle this.
Linked Issue
Related to #49648 (this PR does not close it: it doesn't switch agents or recover workers).
Visual Proof
N/A: this is a text-only change inside a Slack message, with no Orca UI change. The new lines are quoted above under What Changed.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Unit tests cover:
{time}format (thread-status-limit.test.ts,thread-status-counted.test.ts);structured-agent-session-usage-limit-of.test.ts,structured-agent-session-usage-limit-held-where-hit.test.ts);connector-worker-activity.test.ts,external-conversation-workers.test.ts).All 6 changed test files pass locally on macOS (40 tests).
Not tested live: I didn't run this against a real Slack thread with an agent at its usage limit. Behavior is verified by unit tests only.
Performance
No meaningful added work, judging from the code (not measured):
Risk
Level: Low
The riskiest part is naming a reset that no longer applies, for example after a chat moved to another account. The attribution and binding checks guard against this and fail closed to today's wording. If they went wrong, a Slack thread would show a wrong or stale reset time in the status line. Nothing else in the thread or chat behavior changes. Backing out is a plain revert, with no saved data or settings changes.
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Remote workers on a paired server publish their limits there, so they are left out here and keep today's line.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)