Skip to content

feat(bots): name the agent's usage limit in Slack thread status lines - #52506

Closed
AmethystLiang wants to merge 5 commits into
mainfrom
AmethystLiang/usage-limit-thread-status
Closed

AmethystLiang wants to merge 5 commits into
mainfrom
AmethystLiang/usage-limit-thread-status

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Still open (30 min), but nothing is running on it right now. Reply here to ask where it stands.

Pausing these automatic updates for now. Reply here to ask where it stands.

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:

Still open ({elapsed}). {Agent} reported a usage limit that resets {time}.

Pausing these automatic updates for now. {Agent} reported a usage limit that resets {time}.

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:

  • Host: 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.
  • When a limit is named: only when all of these hold:
    • the workers are idle and no helpers are running under them;
    • the reported reset is still in the future;
    • the sweep has tied the limit to the account it hit, and since then the chat hasn't moved to another home or saved account, hasn't been relaunched, and the account selection hasn't changed;
    • Orca isn't scheduled to continue the chat before the reset.
  • Which chat's limit: the thread's own chat comes first. If it has none, and every running worker reported a limit, the soonest reset among them is used.
  • Worker chats: each running local chat worker's chat session is taken only from data the activity poll already holds. If a worker has none in memory, no limit is named and no database read is added.
  • Retries: a saved stop line is re-sent only if its text still matches a fresh decision, so a stale limit line is never posted on retry or restart.
  • {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):

  • bot-chat links
  • threads with no open workers
  • remote (paired server) workers and terminal workers
  • held answers
  • chats that a /clear moved on from
  • some structured workers after a restart, until this process has placed them again

Nothing 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:

    • the decision rows and line wording, including the {time} format (thread-status-limit.test.ts, thread-status-counted.test.ts);
    • the host read and its fail-closed cases (structured-agent-session-usage-limit-of.test.ts, structured-agent-session-usage-limit-held-where-hit.test.ts);
    • worker chat-session collection (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):

  • The limit is read only when a status line is actually due to post, which is at most one decision per armed thread per one-minute tick, and the day cap still applies.
  • It is read only when the workers are idle with nothing under them.
  • Each read is an in-memory lookup on the host (status summary, sweep cut, attribution map), with no disk, database or subprocess work.
  • Worker reads stop at the first worker that can't name a limit.
  • The worker activity poll adds no database reads: a worker's chat session comes only from identities the poll already resolved or holds in memory, and per-conversation groups are filled in place rather than copied per worker.
  • A held tick decides without reading or wording the limit.

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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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.
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable defects were found.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable defects were found.

Summary

Adds agent usage-limit details to Slack thread updates when the host can show that the limit still applies.

  • Idle Slack threads now name an agent’s usage limit and reset time.

No actionable issues found. Tests were reviewed but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Status message is due] --> B{Workers idle with no helpers?}
  B -- No --> C[Keep existing wording]
  B -- Yes --> D[Read chat limit from memory]
  D --> E{Limit still applies?}
  E -- No --> F[Check every local worker]
  F --> G{Every worker has a valid limit?}
  G -- No --> C
  G -- Yes --> H[Name the soonest reset]
  E -- Yes --> H
  H --> I[Save message]
  I --> J[Check current wording before sending]
Loading

Reviews (2) · Last reviewed commit: "fix(bots): read the chat record once for..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Worker activity now projects chat-session IDs into conversation worker views. Usage-limit tracking and lookup now provide qualifying limits to thread-status decisions, which can include agent and reset-time information in idle and stop lines.

Merge Risk: Minimal · up to 56cb3

This change names the agent and reset time in Slack thread status lines when a usage limit applies, and otherwise keeps the existing wording. The review found no concrete defect or performance regression. It looks ready to merge, subject to the normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the Slack thread status lines now state the agent's usage limit. It matches the changeset's core purpose, and the title is specific and concise. It uses a conventional…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the core content well. It has a clear ELI5, a before/after of the user-visible status lines, a mechanism section, the reason for the approach, a stated risk level with a backout…
Full details: Title check

Explanation

The title names the main change: the Slack thread status lines now state the agent's usage limit. It matches the changeset's core purpose, and the title is specific and concise. It uses a conventional commit prefix, which is acceptable.

Full details: Description check

Explanation

The description covers the core content well. It has a clear ELI5, a before/after of the user-visible status lines, a mechanism section, the reason for the approach, a stated risk level with a backout plan, a performance rationale, and testing notes that name the test files and state that no live Slack test was run. Remaining gaps: the Linked Issue section cites only 'Related to #49648' and says it does not close it, while the template asks for an actual 'Fixes #' issue link for outside contributors. The Testing checklist leaves 'I manually tested these changes locally' unchecked, and the Review, AI Disclosure, and Visual Proof sections are only partly filled in. The Risk section also omits an explicit 'Level' detail beyond 'Low', which is present. Performance is reasoned from code but not measured, which the author states. The description is mostly complete, so this passes.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3d41ea7-b518-4e61-b914-5051772c75b7
Commits

Reviewing files that changed from the base of the PR and between 24a04dd and 56cb35a.

Files selected for processing: 23

  • src/main/external-conversations/external-conversation-worker-activities.ts
  • src/main/external-conversations/external-conversation-worker-view.ts
  • src/main/external-conversations/external-conversation-workers.test.ts
  • src/main/external-conversations/external-conversation-workers.ts
  • src/main/external-conversations/thread-status/thread-status-counted.test.ts
  • src/main/external-conversations/thread-status/thread-status-decide.ts
  • src/main/external-conversations/thread-status/thread-status-deps.ts
  • src/main/external-conversations/thread-status/thread-status-limit.test.ts
  • src/main/external-conversations/thread-status/thread-status-owed.ts
  • src/main/external-conversations/thread-status/thread-status-start.ts
  • src/main/external-conversations/thread-status/thread-status-test-harness.ts
  • src/main/external-conversations/thread-status/thread-status.ts
  • src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-usage-limit-of.test.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-host-background.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-hold.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-verdict.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-cold-cuts.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-continue.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-disposition.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-held-where-hit.test.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-hit-account.ts
  • src/main/runtime/rpc/methods/orchestration/worker/connector-worker-activity.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/connector-worker-activity.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

Closing: it builds on the automatic thread status lines, which were removed in #52644.

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