Skip to content

fix: dedupe background process notifications#15277

Open
realraelrr wants to merge 1 commit into
NousResearch:mainfrom
realraelrr:fix/dedupe-bg-process-notifications
Open

fix: dedupe background process notifications#15277
realraelrr wants to merge 1 commit into
NousResearch:mainfrom
realraelrr:fix/dedupe-bg-process-notifications

Conversation

@realraelrr

@realraelrr realraelrr commented Apr 24, 2026

Copy link
Copy Markdown

Closes #15276

Summary

This PR prevents duplicate agent-facing background-process notifications when notify_on_complete and watch_patterns both apply to the same process.

The fix makes successful gateway delivery of a completion notification update the same consumed state already used by wait, poll, and read_log. Watch notifications now check that state before interrupting the agent, so a process that has already delivered its completion event cannot later send a duplicate watch notification for the same completed session.

Problem

Background processes already track whether completion has been consumed, but that state was only updated through tool read paths such as wait, poll, and read_log.

When the gateway itself injected a synthetic notify_on_complete message into the agent thread, the registry still considered the completion unconsumed. If the same process also produced output matching watch_patterns, the watch path could inject another synthetic notification for that already-completed process.

Changes

  • Added ProcessRegistry.mark_completion_consumed(session_id) for explicit gateway-side completion delivery.
  • Mark completion consumed after a successful gateway notify_on_complete injection.
  • Skip _inject_watch_notification for process sessions whose completion has already been consumed.
  • Added regression coverage for:
    • direct registry marking,
    • gateway completion injection marking the process consumed,
    • watch notifications being skipped after completion consumption.

Files Changed

  • tools/process_registry.py
    • Adds the explicit consumed-state marker used by gateway delivery.
  • gateway/run.py
    • Marks completion consumed after successful synthetic completion injection.
    • Suppresses watch notifications for already-consumed process sessions.
  • tests/tools/test_notify_on_complete.py
    • Covers direct consumed-state marking.
  • tests/gateway/test_internal_event_bypass_pairing.py
    • Covers gateway completion injection and watch-notification suppression.

Behavior Notes

  • This does not change wait, poll, or read_log completion semantics.
  • Watch patterns still work for active processes before completion is consumed.
  • The new suppression only applies when a process session has already had its completion consumed or delivered.

Test Plan

uv run --extra dev pytest tests/tools/test_notify_on_complete.py tests/gateway/test_internal_event_bypass_pairing.py tests/tools/test_watch_patterns.py
python3.11 -m py_compile gateway/run.py tools/process_registry.py

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/tools Tool registry, model_tools, toolsets labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background process completion and watch notifications can duplicate

2 participants