Repository navigation
fix: toast only when the resident agent actually acted - #46
Merged
Merged
Conversation
…rates The resident agent wakes on every observed event, and a small model often narrates "no user request; nothing to act on" instead of staying silent as its prompt asks. The watch loop toasted on any non-empty reply, so under a home-dir file-I/O flood that became a popup every few seconds — the anti-pattern the notify path already guarded against for failed turns. Gate the toast on whether the turn ran a world-changing tool. Pi fires `tool_call` before each tool; a new `turnActionTracker` latches only the side-effecting built-ins (bash/edit/write) and ignores read-only orientation — `query_recent_events` (whose own description invites the model to look back) and Pi's `read`. The real session resets it at the top of each `prompt()` and exposes it as `ResidentSession.actedInLastTurn()`. O(1) per event, deliberately not `getSessionStats().toolCalls`, which rescans the whole unbounded continue-d history on every read. The panel and the JSON log still record every reply — only the desktop's one interruption is gated. A pure-narration or read-only-orientation turn stays on the panel and in the log, where a no-op is read; it no longer rings the doorbell. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The resident agent wakes on every observed event. Under a whole-home-directory
file-I/O flood, a small model often narrates "no user request; nothing to act
on" instead of staying silent as its prompt asks — and the watch loop toasted
on any non-empty reply, so that became a desktop popup every few seconds.
This is the same anti-pattern the notify path already guards against for failed
turns; it just wasn't guarding against idle narration.
Now the desktop toast fires only when the turn ran a world-changing tool.
The panel and the JSON log still record every reply — only the one desktop
interruption is gated.
How
turnActionTracker(inresident-agent.ts) hooks Pi'stool_callevent andlatches "acted" only for side-effecting built-ins (
bash/edit/write).Read-only orientation —
query_recent_events(whose own description invitesthe model to "check what happened while you were thinking") and Pi's
read—does not count, so an orient-then-narrate turn no longer toasts either.
prompt()and exposes itas
ResidentSession.actedInLastTurn(); the watch loop reads it after the turnand gates
notifier.notifyon it.getSessionStats().toolCalls, whichrescans the whole unbounded
continue-d history on every read (a realper-turn cost on a 24/7 resident agent).
The read/act distinction
An adversarial review flagged that counting any tool call would let a
read-only orientation call (
query_recent_events) re-open the exact spam thischange targets — the model orients, finds nothing, narrates anyway, and still
toasts. The
ACTING_TOOL_NAMESallowlist fixes that: unknown/new tools failsafe toward silence, matching the goal of the change.
Testing
bun run typecheck(src + tests): clean.bun test: 816 pass / 0 fail (7 skip) on Linux.bash/editbut notquery_recent_events/read;createResidentAgentdelegatesactedInLastTurn; the watch loop toasts whenacted and stays quiet (panel line still broadcast) when the turn acted on nothing.
Backend-only (no
ui/changes), so the Rust panel binary does not need rebuilding.🤖 Generated with Claude Code