Skip to content

fix(gateway): keep device notification events passive - #196989

Closed
VACInc wants to merge 1 commit into
mainfrom
fix/notification-events-passive
Closed

VACInc wants to merge 1 commit into
mainfrom
fix/notification-events-passive

Conversation

@VACInc

@VACInc VACInc commented Nov 11, 2026

Copy link
Copy Markdown
Member

Summary

High Level TLDR

Every phone notification forwarded by a paired Android node (notifications.changed, posted or removed) started its own full agent turn. With notification forwarding on, a phone with normal traffic turns into a steady stream of model runs (and every per-turn plugin, such as memory extraction, runs too), billed to whatever model the target session uses. This makes device notifications passive again: they are queued as system events for the target session and the next real turn sees them. A notification never starts a turn on its own.

Change

  • src/gateway/server-node-events-notifications.ts: queue the notification with enqueueSystemEventEntry and return. Removed the enqueueSessionEventForHost handoff and its receipt consumption from this handler.
  • Tests: a 100-event burst over posted/removed and routed/unrouted notifications asserts 100 queued events and zero turn handoffs, dispatches, or chat runs. A new source guard (server-node-events-notifications.guard.test.ts) fails if the handler references any turn-starting API again.
  • docs/platforms/android.md: states that forwarded notifications are passive context.

Scope: only notifications.changed. Other node events (exec completion, voice transcripts, agent requests) are unchanged.

Root Cause

#180106 (commit e897d98) changed this handler from "queue the event and request a batched heartbeat" to "queue the event and call enqueueSessionEventForHost" for each event. enqueueSessionEventForHost admits a session-event turn, so each posted or removed notification became one agent run in the target session (the system agent's main session by default). The commit ships in v2026.11.5-beta.1 and beta.2. It is not in v2026.11.3 stable.

RCA proof, from a live Gateway on v2026.11.5-beta with an Android node forwarding notifications (identifiers redacted):

  • The main session ran about 172 turns per hour whose whole prompt was the untrusted-source marker plus Notification posted (node=<redacted> key=<redacted> ...) / Notification removed (...) lines. There was no user message in them.
  • Each of those turns also ran the memory extraction plugin against a local model, which kept that GPU at 100%.
  • Turning the phone's forwarding toggle off made the turns stop. That ties them to this event path.
  • Reading the code: before e897d98 the handler only enqueued and woke the heartbeat. After it, the handler calls enqueueSessionEventForHost on every event.

Real behavior proof

  • New and updated tests against the fixed handler: pnpm vitest run src/gateway/server-node-events.test.ts src/gateway/server-node-events-notifications.guard.test.ts src/gateway/server-node-events.system-event-owner.test.ts src/gateway/server-node-events.session-events.test.ts gives 4 files and 71 tests passing.
  • The same tests with the origin/main handler restored: 5 failed. These were the source guard, the 100-event burst, the passive-queue test, and both routing tests (each one sees a turn handoff).
  • Live mitigation on the affected Gateway: a local before_agent_reply hook drops notification-only turns. After it went in, there were 0 notification turns in the main session over the next window. That proves which turns were involved. It is not proof of this patch on a device.

What was not tested

  • No end-to-end run of this patched build with a real Android device forwarding notifications.
  • No benchmark. The change removes one agent turn per notification event and adds no work to the path, but no before/after timing was measured.

Verification

  • pnpm vitest run on the 4 files above: 71/71 passing. 5 fail on the old handler.
  • pnpm check:changed: format, typecheck core and core tests, lint, import cycles, and boundary guards all ok. The dead export scan fails on existing exports in files this PR does not touch (for example extensions/knowledge/src/tool-results.ts and src/plugins/types.ts). None of the flagged exports come from this change.

Notification posted/removed events from paired nodes started one agent
turn each. Queue them as system events only; the next real turn in the
target session drains them. Adds a burst regression test and a source
guard that fails if the handler regains a turn-starting call.
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android gateway Gateway runtime size: S labels Nov 11, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR queues Android notification events as passive session context instead of starting an agent turn for each event.

Example: A paired Android phone posts notification notif-1 from com.example.chat.

  • Before: The Gateway queues the notification and admits a separate model turn.
  • After: The Gateway queues the notification for the target session’s next ordinary turn.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The production change is focused and useful, but submitted proof stops at tests and the introduced test growth fails an enforced gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Normal Android notification traffic repeatedly starts billed model turns and per-turn plugins without a user message.
Reason: The maintainer-authored direction removes the demonstrated per-notification admission cause with a small producer change.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR addresses notification-triggered model runs still present on main, but its added tests exceed the enforced test-line budget.

Priority: P1
Reviewed head: 4f251bcd417acb9e4610fdd779085918978a18ec

Before merge

  • Reconcile the added tests with the enforced line budget (P2) - This patch adds 54 net test lines without an offset or allocation. Exact-head checks-fast-baseline-ratchets reports test-lines failed, and scripts/check-test-lines-ratchet.mts rejects positive growth above the ceiling. Consolidate the redundant coverage and add a narrow justified allocation for any necessary remaining growth, leaving the shared baseline unchanged.

Findings

  • [P2] Reconcile the added tests with the enforced line budget — src/gateway/server-node-events-notifications.guard.test.ts:25-29

Tests

  • Low-value test src/gateway/server-node-events-notifications.guard.test.ts: Remove the source-name blacklist: it duplicates behavioral no-handoff assertions, fails on harmless identifier references, and can miss an equivalent turn starter behind another name.
  • Low-value test src/gateway/server-node-events.test.ts: Consolidate the 100-iteration burst with the existing posted/removed routing cases: enqueue is mocked, so repetition proves neither real queue capacity nor a distinct batching boundary.
  • Missing end-to-end proof: Show the patched Gateway receiving posted and removed Android notifications without starting turns, then consuming retained notification context on the next ordinary turn for default and explicit routing.
Agent review details

How this fits together

Android nodes send notifications.changed events to the Gateway, which resolves the session owner and queues notification text for prompt preparation.

flowchart LR
  A[Android notification] --> B[Gateway node event]
  B --> C[Session and connection checks]
  C --> D[Session system event queue]
  D --> E[Next ordinary turn]
  E --> F[Model prompt]
Loading

Technical review

Best possible solution:

Keep the focused producer-side handoff removal, retain concise behavioral coverage using existing session owners, and reconcile the remaining justified test growth.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly queues and admits each accepted notification as a session-event turn, consistent with the author’s affected-Gateway report; no target code was executed during this review.

Is this the best way to solve the issue?

Removing turn admission at the notification producer addresses the stated cause while preserving routing and immediate currentness checks, without adding another scheduler or configuration option.

Full review comments:

  • [P2] Reconcile the added tests with the enforced line budget — src/gateway/server-node-events-notifications.guard.test.ts:25-29
    This patch adds 54 net test lines without an offset or allocation. Exact-head checks-fast-baseline-ratchets reports test-lines failed, and scripts/check-test-lines-ratchet.mts rejects positive growth above the ceiling. Consolidate the redundant coverage and add a narrow justified allocation for any necessary remaining growth, leaving the shared baseline unchanged.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c9caa4c75ca2.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm vitest run src/gateway/server-node-events.test.ts src/gateway/server-node-events.system-event-owner.test.ts src/gateway/server-node-events.session-events.test.ts
  • pnpm exec tsx scripts/check-test-lines-ratchet.mts
  • pnpm check:changed
  • git diff --check

What I checked:

PR surface

Source -30, Tests +54, Docs +2. Total +26 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 6 36 -30
Tests 3 65 11 +54
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 73 47 +26

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +6/-36; tests +65/-11 Production simplifies appropriately; the net 54 test lines include a source-name guard and repeated mock-only coverage that can be reduced.

Labels

Label changes:

  • add P1: The reported beta workflow produces roughly 172 unwanted model turns per hour, with model charges and repeated plugin work; current-main source confirms the per-event admission path.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The reported beta workflow produces roughly 172 unwanted model turns per hour, with model charges and repeated plugin work; current-main source confirms the per-event admission path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 10, 2026, 10:02 PM ET / November 11, 2026, 03:02 UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant