Skip to content

feat: handle location.update node event in gateway - #50936

Closed
yuntan wants to merge 7 commits into
openclaw:mainfrom
yuntan:feature/location-update
Closed

yuntan wants to merge 7 commits into
openclaw:mainfrom
yuntan:feature/location-update

Conversation

@yuntan

@yuntan yuntan commented Mar 20, 2026 •

Copy link
Copy Markdown

Summary

  • Problem: location.update events sent from iOS nodes via node.event were silently dropped by the gateway (default case in handleNodeEvent)
  • Why it matters: The agent could not react to location changes (e.g. severance hooks, memory logging) because the event never reached the heartbeat prompt
  • What changed: Added location.update handler in gateway that enqueues a system event and wakes the heartbeat; classified location-update as wake reason; added tagged-event detection (location:*) so pending location events are included in the heartbeat prompt; added logging on both iOS and gateway sides
  • What did NOT change (scope boundary): No changes to location.get command flow, node command policy, iOS location permissions model, or heartbeat prompt templates

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

None

User-visible / Behavior Changes

  • location.update events from iOS nodes now trigger a heartbeat wake and appear in the agent heartbeat prompt as a system event
  • Gateway logs location.update received node=<id> source=<source> at info level when an event arrives

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS (gateway), iOS simulator
  • Runtime/container: Node 25, pnpm gateway:watch
  • Model/provider: Claude Opus 4.6
  • Integration/channel (if any): iOS node
  • Relevant config (redacted): locationMode: .always, authorizedAlways

Steps

  1. Start the gateway with pnpm gateway:watch
  2. Add the following to the gateway's HEARTBEAT.md:
    ## Location Tracking
    
    - On `location.update` event, append to the Location Log table in `memory/YYYY-MM-DD.md`
    - Format: `| HH:MM | lat, lng | notes |`
    - Create the Location Log table if it does not exist
    
  3. Open the iOS app on a real device with Always location permission granted
  4. Move between locations to trigger iOS Significant Location Change events (or use Xcode > Debug > Simulate Location)

Expected

  • Xcode log shows location.update sent to gateway
  • Gateway log shows [gateway] location.update received node=... source=ios-significant-location
  • memory/YYYY-MM-DD.md is updated with a Location Log table:
    ## Location Log
    
    | Time (JST) | Lat, Lng | Notes |
    |---|---|---|
    | 13:41 | 37.4451, -122.2707 | Near Palo Alto, ±5m |
    | 14:03 | 37.7501, -122.4033 | San Francisco, ±5m |
    | 14:04 | 37.7575, -122.4039 | San Francisco, ±5m |
    

Actual

Same as expected.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: iOS simulator sends location.update, sendEvent completes without error, gateway dist/ contains handler code after build
  • Edge cases checked: missing lat/lon (early return), missing accuracyMeters/source (optional), consecutive duplicate events (deduplicated by enqueueSystemEvent)
  • What you did not verify: end-to-end on real device (pending), heartbeat prompt content with location data

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert the 3 commits on feature/location-update; the default case resumes silently dropping the event
  • Files/config to restore: src/gateway/server-node-events.ts, src/infra/heartbeat-reason.ts, src/infra/heartbeat-runner.ts
  • Known bad symptoms reviewers should watch for: unexpected heartbeat wakes when no location events are expected; excessive system events if a node sends rapid location updates (mitigated by enqueueSystemEvent dedup)

Risks and Mitigations

  • Risk: Rapid location updates from a node could flood the system event queue and trigger frequent heartbeat wakes
    • Mitigation: enqueueSystemEvent deduplicates consecutive identical events per contextKey (location:<nodeId>), and the heartbeat coalesce window (250ms) batches rapid wakes

yuntan added 3 commits March 20, 2026 17:20
Log location change detection, payload encode failure, and
gateway send lifecycle in SignificantLocationMonitor.
Add location.update case to handleNodeEvent that enqueues a system
event and triggers a heartbeat wake. Classify location-update reason
as wake to bypass file gates and inspect pending location events in
the heartbeat prompt. Add info-level logging for received events.
Add location.update event section to location-command.md with payload
spec, heartbeat delivery details, and iOS significant location
monitoring. Add cross-reference in nodes index. Update bridge protocol
event list.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: ios App: ios gateway Gateway runtime size: S labels Mar 20, 2026
@greptile-apps

greptile-apps Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR wires up location.update node events end-to-end: the gateway now handles them by enqueuing a system event with a location:<nodeId> context key and triggering a "location-update" heartbeat wake (classified as "wake" to bypass HEARTBEAT.md file gates), and the iOS SignificantLocationMonitor gains structured OSLog logging for the full send lifecycle.

Key observations:

  • Payload validation in server-node-events.ts is solid — lat/lon are validated as finite numbers, optional fields degrade gracefully, and the session-key fallback follows existing patterns.
  • Heartbeat preflight correctly adds hasTaggedLocationEvents to both shouldInspectPendingEvents and shouldBypassFileGates, matching the cron-event pattern.
  • Missing prompt path: unlike cron events (which have a dedicated buildCronEventPrompt that embeds event texts into the prompt), location events have no equivalent in resolveHeartbeatRunPrompt. When a location wake fires without exec completions or cron events, the agent receives the generic heartbeat prompt — the location data is only available via the system-events queue. The documentation claim that location data is "included in the heartbeat prompt" is not fully reflected in the prompt-building code.
  • PII in iOS logs: exact GPS coordinates (lat, lon) are logged at .info level, which persists in system logs and may appear in diagnostics shared externally. Consider redacting coordinates or using .debug level.
  • The ctx.Provider field is set to "heartbeat" for location-triggered runs, unlike "cron-event" / "exec-event" for those event types — a minor observability gap.

Confidence Score: 3/5

  • Core plumbing is sound but the location event data may not reach the agent prompt as documented, warranting verification before merge.
  • The gateway-side event handling and heartbeat wake logic are well-implemented and follow existing patterns. The main concern is that resolveHeartbeatRunPrompt has no dedicated location-event prompt path — unlike cron events, location event texts are not explicitly embedded in the prompt. If the system-events queue mechanism delivers them separately at agent-run time this works, but it is not verified in the PR and the documentation implies direct prompt inclusion. Additionally, exact GPS coordinates in iOS system logs is a privacy concern.
  • src/infra/heartbeat-runner.ts — verify that location event texts from the system-events queue actually reach the agent, or add a buildLocationEventPrompt path analogous to buildCronEventPrompt.

Comments Outside Diff (2)

  1. src/infra/heartbeat-runner.ts, line 522-529 (link)

    P1 Location events not embedded in heartbeat prompt

    Unlike cron events — which are explicitly embedded in the prompt via buildCronEventPrompt(cronEvents, ...) — location events have no dedicated prompt path here. When a location-triggered heartbeat fires without any exec completions or cron events present, basePrompt falls through to the generic resolveHeartbeatPrompt, which contains no location data.

    The pendingEvents array is computed when shouldInspectPendingEvents is true (which hasTaggedLocationEvents enables), but it is only used to check hasExecCompletion — the location event texts themselves are never spliced into the prompt. The docs claim the agent "sees the location data (lat, lon, accuracy, source) in the same run", but that data only exists in the system-events queue, and the regular heartbeat prompt gives the agent no signal to look for or act on it.

    If the system-events queue consumption mechanism supplies this separately at agent-run time that would mitigate the issue, but there is no symmetric treatment with buildCronEventPrompt. Consider adding a buildLocationEventPrompt path (similar to cron) that embeds the location text, or at minimum returning hasLocationEvents from resolveHeartbeatRunPrompt so callers can set the right Provider and confirm intent.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/infra/heartbeat-runner.ts
    Line: 522-529
    
    Comment:
    **Location events not embedded in heartbeat prompt**
    
    Unlike cron events — which are explicitly embedded in the prompt via `buildCronEventPrompt(cronEvents, ...)` — location events have no dedicated prompt path here. When a location-triggered heartbeat fires without any exec completions or cron events present, `basePrompt` falls through to the generic `resolveHeartbeatPrompt`, which contains no location data.
    
    The `pendingEvents` array is computed when `shouldInspectPendingEvents` is true (which `hasTaggedLocationEvents` enables), but it is only used to check `hasExecCompletion` — the location event texts themselves are never spliced into the prompt. The docs claim the agent "sees the location data (lat, lon, accuracy, source) in the same run", but that data only exists in the system-events queue, and the regular heartbeat prompt gives the agent no signal to look for or act on it.
    
    If the system-events queue consumption mechanism supplies this separately at agent-run time that would mitigate the issue, but there is no symmetric treatment with `buildCronEventPrompt`. Consider adding a `buildLocationEventPrompt` path (similar to cron) that embeds the location text, or at minimum returning `hasLocationEvents` from `resolveHeartbeatRunPrompt` so callers can set the right `Provider` and confirm intent.
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. src/infra/heartbeat-runner.ts, line 657 (link)

    P2 Provider not surfaced for location-triggered runs

    ctx.Provider is set to "heartbeat" for location-triggered runs (since resolveHeartbeatRunPrompt returns no hasLocationEvents). Cron and exec-event runs get distinguishable provider strings ("cron-event", "exec-event"), which helps with telemetry, log correlation, and any downstream routing that inspects the provider.

    If a hasLocationEvents flag is added to HeartbeatPromptResolution (see the comment on the prompt-building code), this line can be extended to emit "location-event" as the provider consistently.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/infra/heartbeat-runner.ts
    Line: 657
    
    Comment:
    **`Provider` not surfaced for location-triggered runs**
    
    `ctx.Provider` is set to `"heartbeat"` for location-triggered runs (since `resolveHeartbeatRunPrompt` returns no `hasLocationEvents`). Cron and exec-event runs get distinguishable provider strings (`"cron-event"`, `"exec-event"`), which helps with telemetry, log correlation, and any downstream routing that inspects the provider.
    
    If a `hasLocationEvents` flag is added to `HeartbeatPromptResolution` (see the comment on the prompt-building code), this line can be extended to emit `"location-event"` as the provider consistently.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/heartbeat-runner.ts
Line: 522-529

Comment:
**Location events not embedded in heartbeat prompt**

Unlike cron events — which are explicitly embedded in the prompt via `buildCronEventPrompt(cronEvents, ...)` — location events have no dedicated prompt path here. When a location-triggered heartbeat fires without any exec completions or cron events present, `basePrompt` falls through to the generic `resolveHeartbeatPrompt`, which contains no location data.

The `pendingEvents` array is computed when `shouldInspectPendingEvents` is true (which `hasTaggedLocationEvents` enables), but it is only used to check `hasExecCompletion` — the location event texts themselves are never spliced into the prompt. The docs claim the agent "sees the location data (lat, lon, accuracy, source) in the same run", but that data only exists in the system-events queue, and the regular heartbeat prompt gives the agent no signal to look for or act on it.

If the system-events queue consumption mechanism supplies this separately at agent-run time that would mitigate the issue, but there is no symmetric treatment with `buildCronEventPrompt`. Consider adding a `buildLocationEventPrompt` path (similar to cron) that embeds the location text, or at minimum returning `hasLocationEvents` from `resolveHeartbeatRunPrompt` so callers can set the right `Provider` and confirm intent.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: apps/ios/Sources/Location/SignificantLocationMonitor.swift
Line: 22-25

Comment:
**Exact GPS coordinates logged at info level**

`lat`, `lon`, and `accuracyMeters` are precise location coordinates and qualify as sensitive PII. Logging them at `.info` level means they are persisted in the system log and may surface in device diagnostics, crash reports, or unified logging exports shared with Apple.

Consider redacting or rounding the values in the log line, e.g.:

```suggestion
            logger.info("Significant location change detected accuracyMeters=\(accuracy)")
```

If the full coordinates are genuinely needed for debugging, consider logging them at `.debug` level (which is stripped from release builds unless explicitly captured) rather than `.info`.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/infra/heartbeat-runner.ts
Line: 657

Comment:
**`Provider` not surfaced for location-triggered runs**

`ctx.Provider` is set to `"heartbeat"` for location-triggered runs (since `resolveHeartbeatRunPrompt` returns no `hasLocationEvents`). Cron and exec-event runs get distinguishable provider strings (`"cron-event"`, `"exec-event"`), which helps with telemetry, log correlation, and any downstream routing that inspects the provider.

If a `hasLocationEvents` flag is added to `HeartbeatPromptResolution` (see the comment on the prompt-building code), this line can be extended to emit `"location-event"` as the provider consistently.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "docs: document locat..."

yuntan added 3 commits March 20, 2026 18:20
Exact lat/lon are sensitive PII. Keep accuracyMeters at info level
and move coordinates to debug which is stripped from release builds.
Add buildLocationEventPrompt that embeds location data directly in
the heartbeat prompt, matching the cron event pattern. Return
hasLocationEvents from resolveHeartbeatRunPrompt and set Provider
to location-event for telemetry. Fix test mocks for logGateway.info.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3997e94a4f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server-node-events.ts Resolved
Normalize the node-provided source string with compactNotificationEventText
to collapse whitespace and cap length before interpolating into system-event
summaries and log lines.
@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Current main still has the source-level gap: iOS emits location.update, while the gateway has no matching handler. This PR is focused and useful, but it is not merge-ready because it conflicts with current main, uses a stale heartbeat wake shape, lacks contributor real behavior proof, and needs privacy/security review for passive precise-location delivery.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, source-level: current main's iOS SignificantLocationMonitor emits location.update, while the gateway handler has no matching case. I did not run a live iOS/gateway scenario in this read-only review.

Is this the best way to solve the issue?

No, not as submitted: the direction is focused and useful, but the branch must be rebased to current heartbeat wake APIs, fully sanitize node-controlled fields, and prove the real iOS-to-heartbeat behavior before it is the right merge shape.

Security review:

Security review needs attention: The diff has no supply-chain change, but it expands passive precise-location delivery into agent/system context and leaves one node-controlled field insufficiently sanitized.

  • [medium] Review passive precise location delivery — src/gateway/server-node-events.ts:600
    The handler formats exact latitude, longitude, and accuracy into a system-event summary that heartbeat can process, which is a privacy-sensitive data-flow expansion even when the node already has location permission.
    Confidence: 0.78
  • [medium] Sanitize the location source field as untrusted input — src/gateway/server-node-events.ts:593
    The proposed source handling collapses whitespace but does not neutralize bracketed system/internal markers before the value is embedded into a System: event line.
    Confidence: 0.84

What I checked:

  • stale F-rated PR: PR was opened 2026-03-20T08:25:12Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 578e73f66763.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label May 22, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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

Labels

app: ios App: ios docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant