Skip to content

fix(hive): keep HITL notification classification type-aware - #677

Open
HsienW wants to merge 5 commits into
HarnessMD:mainfrom
HsienW:fix/worker-wake-hitl-notification-classification
Open

HsienW wants to merge 5 commits into
HarnessMD:mainfrom
HsienW:fix/worker-wake-hitl-notification-classification

Conversation

@HsienW

@HsienW HsienW commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

What & why

WorkerWake and the renderer currently classify Notification hooks independently, which allows mixed HITL and idle wording to fall through as idle when no authoritative notification type is available.

This change moves notification classification into a shared helper (src/shared/hookClassify.ts), treats known structured notification types as authoritative, and uses HITL first message heuristics only when the type is missing or unknown. It also passes notification_type through to WorkerWake and safely handles non string runtime values without changing the existing NDJSON framing or provider behavior.

notification_type is appended as the last argument of HookServer.onEvent (after tool and source) and of WorkerWakeWatchdog.noteHook (after tool). The existing index.ts callback is kept and only passes it through.

Terminal send guard (ptySubmit)

When ptySubmit cannot read the screen, it asks HookProofRecord.askOpen whether a permission or question prompt is open before typing into the terminal. That record had its own copy of the old rule and never saw notification_type, so it missed both the mixed message from #676 and a permission_prompt with idle wording. Mail delivery and remote sends could still type into an open prompt even though WorkerWake held.

HookProofRecord.note now receives notification_type from HookServer.handle and opens the ask when classifyHook returns needsHuman. Its private rule is removed, and approval, which only that copy matched, is added to the shared HITL markers. Quiet notifications still leave an open ask alone, and the same events close it as before.

Nothing closes an ask on an idle agent, so a false open would hold every send until someone types into the terminal. The HITL markers therefore match whole words only: "Changes approved — waiting for your input" stays idle, while "permissions" and "confirmation" still count.

Desktop toast

The toast checked notification_type === 'idle', but Claude sends idle_prompt, so it only ever fired on the message wording. It now uses the same rules through isIdleWaitNotification:

Notification Toast
idle_prompt yes
Legacy idle type (passed through by the Grok hook shim) yes, as on main
Blocking type (permission_prompt, elicitation_dialog, ...) no
No known type, idle wording, not a HITL prompt yes
Anything else (auth_success, empty message, ...) no

Visible changes:

  • An idle_prompt always toasts, whatever the wording.
  • A mixed permission + idle message with no type no longer toasts.
  • ptySubmit holds instead of typing while such a prompt is open and the screen cannot be read.

Closes #676

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Build / CI

Evidence

Before

The same mixed Notification is classified as idle on main:

Event:    Notification
Message:  Permission required — waiting for your input
Actual:   idle
Expected: needsHuman
2026-10-03-141720

After

The same Notification is classified as needsHuman after the fix:

Event:    Notification
Message:  Permission required — waiting for your input
Actual:   needsHuman
Expected: needsHuman
2026-10-03-141838

The WorkerWake suite, the HookServer.handle wiring and toast tests, and the new HookProofRecord tests all pass:

tests 40
pass 40
fail 0

How I tested it

  • OS: Windows 11.
  • Repro: the mixed Notification from Worker wake can misclassify mixed HITL and idle notification wording #676 returns idle on main and needsHuman on this branch.
  • Unit tests: test/worker-wake.test.cjs, test/hook-server-notification.test.cjs and test/hook-proof.test.cjs, 40 tests, all pass.
    • hook-server-notification.test.cjs drives real payloads through HookServer.handle. Moving notification_type into the 4th onEvent slot still typechecks but fails these tests.
    • hook-proof.test.cjs covers the ptySubmit ask guard. The Worker wake can misclassify mixed HITL and idle notification wording #676 message with no type and permission_prompt with idle wording fail without the HookProofRecord change.
    • Whole-word markers ("Changes approved — waiting for your input" stays idle) and the legacy idle toast type each have a test that fails without the change.
  • Checks: npm run typecheck, npm run build and git diff --check pass.
  • npm run test:focused: 945 tests, 835 passed, 99 failed, 11 skipped. The failures are existing ones on main (Windows symlink, Electron only, i18n, config path and concurrency) in files this PR does not touch. The 23 extra tests over main are the ones this PR adds.
  • Not covered: a live Grok session sending the legacy idle type.

Checklist

  • Before and after evidence is attached above, under both headings.
  • npm run typecheck passes.
  • npm run test:focused passes.
  • npm run build succeeds.
  • This PR is one change. Unrelated fixes belong in their own PR.
  • I read the diff myself before opening this, and there is no debug output,
    commented-out code, or unrelated formatting churn in it.
  • Any new UI derives from DESIGN.md / tokens.ts — no ad-hoc colors,
    spacing, or fonts.
  • If I added art, it's my own or compatibly licensed, and listed in
    ATTRIBUTION.md.

@HsienW
HsienW requested a review from chaitanyagiri as a code owner October 3, 2026 14:43
@gpinkham

Copy link
Copy Markdown
Contributor

Good catch: the watchdog and the floor both read "Permission required, waiting for your input" as idle today, and trusting notification_type first is the right fix. It needs a rebase onto main:

  • HookServer is now in src/core/hookServer.ts, and onEvent already takes (agentId, event, message, tool, source). Add notificationType as the last argument, not the 4th, or tool_name lands in the wrong slot and typecheck still passes.
  • noteHook already has tool as its 5th argument, so notificationType goes after it. Keep the current index.ts callback (loginPastOnHook, agentDemand.touch, wakeFiling.noteHook).
  • A test through HookServer.handle would catch an argument-order slip, since every new parameter is unknown.
  • Optional: the desktop toast checks notification_type === 'idle', but Claude sends idle_prompt. Routing it through classifyHook would fix that too.

@gpinkham gpinkham added guardrails Circuit breaker, hooks, process limits and other safety rails bug Something isn't working orchestration Component: orchestration risk:medium Moderate blast radius size/m PR size: m labels Nov 27, 2026
- Share notification classification across WorkerWake and renderer paths.

- Prefer known structured notification types and fall back to HITL-first message heuristics.

- Pass notification types into WorkerWake and guard malformed runtime field values.
- Drive real Notification payloads through HookServer.handle and assert each field reaches onEvent in its own slot.
- Wire a real WorkerWakeWatchdog the way index.ts does so permission_prompt arms the HITL hold and idle_prompt does not.
- Catches a notificationType or tool slot slip that typecheck cannot, since the trailing parameters are loosely typed.
- Replace the dead notification_type === 'idle' check: Claude Code sends idle_prompt, so the toast only ever fired through the message wording.
- Add isIdleWaitNotification to hookClassify so the toast shares the watchdog's type rules: idle_prompt notifies, blocking types never do.
- Without a known type, toast only on idle wording that is not a HITL prompt, so auth_success, empty, and mixed permission messages stay quiet.
- Cover the toast through HookServer.handle with a real notifier.
@HsienW
HsienW force-pushed the fix/worker-wake-hitl-notification-classification branch from ada1303 to cd3a3e1 Compare December 1, 2026 10:42
@HsienW

HsienW commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Good catch: the watchdog and the floor both read "Permission required, waiting for your input" as idle today, and trusting notification_type first is the right fix. It needs a rebase onto main:

  • HookServer is now in src/core/hookServer.ts, and onEvent already takes (agentId, event, message, tool, source). Add notificationType as the last argument, not the 4th, or tool_name lands in the wrong slot and typecheck still passes.
  • noteHook already has tool as its 5th argument, so notificationType goes after it. Keep the current index.ts callback (loginPastOnHook, agentDemand.touch, wakeFiling.noteHook).
  • A test through HookServer.handle would catch an argument-order slip, since every new parameter is unknown.
  • Optional: the desktop toast checks notification_type === 'idle', but Claude sends idle_prompt. Routing it through classifyHook would fix that too.

@gpinkham Thanks! Rebased onto main and fixed all four:

  1. notificationType is now the last arg of onEvent, after tool and source.
  2. Same for noteHook: it goes after tool. The index.ts callback is kept as is and just passes it through.
  3. Added test/hook-server-notification.test.cjs, which goes through HookServer.handle. I tried putting the type in the 4th slot on purpose: typecheck still passed, the tests failed.
  4. Fixed the toast too. classifyHook(...) === 'idle' would also toast on auth_success, plugin_notification or an empty message, since idle there only means "not HITL". So I added a small isIdleWaitNotification in hookClassify.ts: same type sets, toasts on idle_prompt, and unknown types go through classifyHook plus the old idle wording check.

Typecheck and build pass, and test:focused has no new failures vs main.

@HsienW

HsienW commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

/copilot-review claude-opus-5.5 medium

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Copilot review

Asked by @HsienW. Model: claude-opus-5.5. Effort: medium. Head: cd3a3e1c6.

Checking whether the renderer event actually carries notificationType.

1. ptySubmit still uses the old rules, so the bug remains on one path that types into the terminal (src/main/hookProof.ts:43-50, 74, used by src/main/ptySubmit.ts:348)

The PR moves Notification classification into hookClassify.ts so that the main process and the renderer "cannot disagree". HookProofRecord still has its own copy of the old rule, and the PR doesn't change it:

return !!m && ASKS_PERSON.test(m) && !QUIET.test(m);

This copy also never sees notification_type. ptySubmit relies on proof.askOpen(agentId) whenever it can't read the screen (no window, or the grid hasn't been drawn). In that case it decides whether to type into the agent's terminal or hold off.

Concrete cases where askOpenAt stays 0 and typing goes ahead:

  • { message: 'Permission required — waiting for your input' } with no type. This is the exact message from Worker wake can misclassify mixed HITL and idle notification wording #676. classifyHook now returns needsHuman, but asksPerson returns false because QUIET matches.
  • { message: 'Claude is waiting for your input', notification_type: 'permission_prompt' }. The WorkerWake watchdog now holds, but ptySubmit doesn't.

So the watchdog stops its own nudge, but any other send through ptySubmit (mail delivery, remote sends) can still type into an open permission or elicitation prompt. That is the outcome the issue is meant to prevent.

Fix: have HookProofRecord.note receive notification_type and call classifyHook(event, message, type) === 'needsHuman' instead of asksPerson. asksPerson also matches approval, which HITL_MESSAGE_MARKERS doesn't, so add it to the shared marker list or the two will still differ.

2. The toast test for non-Notification events is weak (test/hook-server-notification.test.cjs, last toast test)

The test sends a Stop with message: 'waiting for your input' and only checks that no toast body equals that string. If isIdleWaitNotification's event !== 'Notification' guard were removed, a Stop would still only toast when notifications is on and the wording matched. But the server is built with getStandingGoal/onEvent left out, and the Stop path may fire its own toast with a different body. So the assertion passes whether or not the guard exists, and the test doesn't check what its name says.

An exact check such as toasts.filter(t => t.body === 'waiting for your input').length === 0 has the same weakness. A useful version would call isIdleWaitNotification('Stop', 'waiting for your input', 'idle_prompt') === false directly.

Everything else looks right:

  • notification_type reaches the renderer through HookEvent.notificationType (hookServer.ts:914).
  • onEvent and noteHook receive the arguments in the correct positions.
  • Non-string values are normalised, so they can't make the classifier throw.

- HookProofRecord.note now takes notification_type and opens the ask when classifyHook says needsHuman, replacing its own ASKS_PERSON/QUIET copy
- HookServer.handle passes notification_type to the proof record
- Add 'approval' to the shared HITL message markers so no old match is lost
- Cover the mixed permission/idle message and a permission_prompt with idle wording in test/hook-proof.test.cjs and through HookServer.handle
- Assert isIdleWaitNotification is false for non-Notification events directly instead of inspecting toast bodies
@HsienW

HsienW commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

/copilot-review claude-opus-5.5 medium

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Copilot review

Asked by @HsienW. Model: claude-opus-5.5. Effort: medium. Head: b54ca6664.

No blocking bugs found. Two lower-severity issues:

  1. src/core/hookServer.ts ~L867: idle toasts with the type 'idle' can disappear. The old code toasted when notification_type === 'idle', whatever the message said. Now 'idle' is an unknown type, so it falls back to the wording and toasts only if the message contains "waiting for your input." Claude may never send 'idle', but GROK_HOOK_SHIM (src/main/hive.ts:5566) passes Grok's notificationType through unchanged. Example: Grok sends notification_type: 'idle' with the message "Grok finished". main toasts and this PR does not. Either add 'idle' to CLAUDE_IDLE_NOTIFICATION_TYPES or confirm that no engine sends it.

  2. src/shared/hookClassify.ts L42–45: dropping the idle-wording veto can block sends until someone types manually. Without a known type, a message that mentions confirm, approve, approval, permission or needs your is now needsHuman, even if it is an idle notice. Matching is by substring, so "confirmed" and "approved" also count. In HookProofRecord.note, that opens askOpenAt, which has no expiry. Only PostToolUse, PostToolUseFailure, UserPromptSubmit or SessionStart closes it.

    An idle agent produces none of those. When ptySubmit cannot read the screen, it relies on askOpen and holds every mail or remote send, so nothing gets submitted to close the ask. Example: an engine with no Claude type sends "Changes approved — waiting for your input". main treats it as quiet. This PR opens the ask, and sends to that agent stay held until a person types into it.

    The Worker wake can misclassify mixed HITL and idle notification wording #676 fix needs the HITL signal to win over idle wording, so this is a trade-off. Consider whole-word matching, or letting the next idle-type notification clear an ask that the text fallback opened.

…toast

- Match the HITL message markers as whole words, so an idle report such as "Changes approved — waiting for your input" no longer opens a ptySubmit ask that nothing closes on an idle agent
- Keep "permissions" and "confirmation" as HITL wording
- Toast on the legacy notification_type 'idle' again, as main did; the Grok hook shim passes its type through unchanged
- Cover both cases in the classifier, HookProofRecord and HookServer toast tests
@HsienW

HsienW commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

/copilot-review claude-opus-5.5 medium

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Copilot review

Asked by @HsienW. Model: claude-opus-5.5. Effort: medium. Head: a4af093fc.

No blocking problems found. The shared classifier, the notification_type argument order, the HookProofRecord ask guard and the toast rules are wired correctly, and the new tests check the behaviour they claim to.

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

bug Something isn't working guardrails Circuit breaker, hooks, process limits and other safety rails orchestration Component: orchestration risk:medium Moderate blast radius size/m PR size: m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worker wake can misclassify mixed HITL and idle notification wording

2 participants