Skip to content

refactor(agent-hooks): add provider hook state slots - #47838

Open
noter wants to merge 2 commits into
stablyai:mainfrom
codeious:ac/02-f5-hook-state-slots
Open

noter wants to merge 2 commits into
stablyai:mainfrom
codeious:ac/02-f5-hook-state-slots

Conversation

@noter

@noter noter commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Each agent that reports status through hooks keeps a little memory per terminal pane. This gives that memory one registration point, so cleanup reaches every agent without listing each by hand.

What Changed

Rebased onto main at 845867a. It depends on #47839; until it merges, this diff also shows its commit. Review only this PR's commit c1f1e4136c.

  • Adds ProviderHookStateSlots: provider-owned pane maps register once, and pane teardown, moves and claim checks reach them through the registry.
  • Moves Claude's two claim-bearing maps and its prompt turn order onto slots.
  • Turns Claude's owed-notification timers into one lease provider behind a generic AgentLeaseExpiryTimers, armed after every stored row by both main and the WSL relay.
  • Claude rows restate exactly as before.

Review fixes since the first push:

  • Claude's lease timer now acts only on Claude rows, so another provider's row in the same pane is never restated as Claude's.

Why

The Droid child-work PR (#47841) needs per-pane Droid state. Without slots, each new map has to be wired into listener-state teardown, moves and claims by hand, and a missed spot leaks state across panes.

Linked Issue

Groundwork for #47841 and #47842. #47826 itself was closed by #47836.

Visual Proof

N/A: internal refactor with no visible change.

Testing

Local macOS only.

  • ORCA_CODE_QUALITY_BASE=ac/03-f7-process-exit-watch pnpm check:changed passed on this commit after the rebase (format, oxlint, typecheck, tests importing the change, selected ratchets).
  • Full unit suite (pnpm test --maxWorkers=6) on this branch: 1322 test files passed, 3 failed, 15 skipped. The failing files also fail on main at 845867a on this machine: agent-cli-update-timeout (timing), bot-upcoming-copy (locale), worktree-removal-real-git (temp-dir cleanup).
  • Golden E2E journeys ran on the previous stack tip (main at 59f3122): 8 passed, 4 skipped (Windows-only), and golden-fresh-profile-terminal failed the same way on main. Not rerun after the rebase.

Not run: Linux, Windows, or SSH remote hosts.

  • 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

Changed test files:

  • None. No test meets the repo's bar for this change.

Performance

None, because the same timers and maps run as before; registration happens once per provider at module load.

Risk

Level: Medium

This touches Claude hook-state teardown and notification timers. If a slot were missed, a Claude pane could keep a stale claim or fire an owed notification late. Back out with a plain revert.

AI Disclosure

Review

Self-reviewed this PR's single commit for correctness, security, and performance. Merge order:

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

Considered security, macOS/Linux/Windows paths, SSH remote hosts, mobile compatibility, folder workspaces, and performance. Execution coverage is limited to the checks listed under Testing.

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)

Merge message

refactor(agent-hooks): add provider hook state slots

New hook providers keep pane state that teardown, moves and claim
checks must reach. Register provider maps as state slots instead of
listing each in listener-state, and run Claude's owed-notification
timers as a lease provider behind shared AgentLeaseExpiryTimers.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Hook expiry now uses provider-supplied leases, with server and retry-scheduler paths arming the generic lease timers. Listener state delegates provider-owned map clearing, moving, and claim checks to ProviderHookStateSlots. The changes also add AgentProcessExitWatch, which retries process probes with bounded delays and ignores results from replaced or stopped watches.

Merge Risk: Minimal · up to 2736a

This refactor moves Claude's claim-bearing state onto shared provider slots and puts owed-notification timers behind a shared lease provider, and Claude rows are meant to stay unchanged. Review found no concrete defect introduced by the change. The unchanged cleanup and claim behavior was checked against the merge base. The new process exit watch has no production consumer yet. Risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "refactor(agent-hooks): add provider hook state slots" names the main change. The PR adds a ProviderHookStateSlots registry for provider-owned pane state, and it also moves Claude's owed-not…
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 follows the repository template and covers the core sections: ELI5, What Changed, Why, Testing, Performance, Risk, and Review. It explains the refactor (provider hook state slots, Clau…
Full details: Title check

Explanation

The title "refactor(agent-hooks): add provider hook state slots" names the main change. The PR adds a ProviderHookStateSlots registry for provider-owned pane state, and it also moves Claude's owed-notification timers behind a shared lease provider. The title covers the primary change but not the lease-timer refactor, which is a secondary part of the diff.

Full details: Description check

Explanation

The description follows the repository template and covers the core sections: ELI5, What Changed, Why, Testing, Performance, Risk, and Review. It explains the refactor (provider hook state slots, Claude lease provider behind AgentLeaseExpiryTimers) and the mechanism. It also gives a Risk level with a back-out plan and a Performance rationale. Testing lists commands and results, but it covers local macOS only. The Linked Issue section names groundwork issues (#47841, #47842) but has no 'Fixes #' or equivalent issue link for this PR. The AI Disclosure section is left as an unfilled HTML comment. The 'Agent skill upstream boundary' box is checked. Several template checklist items are unchecked, including the lint/typecheck/test/build item. The description is mostly complete, so it passes, but the gaps below should be fixed.

  • 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: d64ddbec-6326-467e-acaa-bf1c07c6747d
Commits

Reviewing files that changed from the base of the PR and between da23b8c and 2736a71.

Files selected for processing: 5

  • src/main/agent-hooks/server/server-cleanup.ts
  • src/shared/agent-hook-listener/listener-state.ts
  • src/shared/agent-hook-listener/providers/claude/background-tasks/claude-owed-notification-expiry-timers.ts
  • src/shared/agent-status/process/agent-process-exit-watch.test.ts
  • src/shared/agent-status/process/agent-process-exit-watch.ts

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

@noter
noter force-pushed the ac/02-f5-hook-state-slots branch from da23b8c to 2736a71 Compare November 26, 2026 11:29
…ng its end

AgentProcessExitWatch probes a pane's agent process after it reports a
session end, backing off from 250 ms to 8 s for at most 90 s, and stops as
soon as the probe confirms the exit, has nothing to check, or the pane no
longer holds what the watch started for. A probe that settles after a stop
or restart is ignored.

Hook providers whose SessionEnd can precede the process exit (a /clear also
ends a session) use it to end the row only once the process is gone.
…se timers

Provider-owned pane maps now register with ProviderHookStateSlots, so pane
teardown, moves and claim checks reach them without each map being listed
in listener-state by hand. Claude's two claim-bearing maps and its prompt
turn order move onto slots.

Claude's owed-notification timers become one lease provider behind a
generic AgentLeaseExpiryTimers, which main and the WSL relay both arm
after every stored row. Claude rows restate exactly as before.
@noter
noter force-pushed the ac/02-f5-hook-state-slots branch from 2736a71 to c1f1e41 Compare November 26, 2026 11:47

This branch has not been deployed

No deployments
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