Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(resilience): guard JSON.parse of external process output with try-catch#23672

Closed
kevinWangSheng wants to merge 1 commit into
openclaw:mainfrom
kevinWangSheng:fix/json-parse-crash-guard
Closed

fix(resilience): guard JSON.parse of external process output with try-catch#23672
kevinWangSheng wants to merge 1 commit into
openclaw:mainfrom
kevinWangSheng:fix/json-parse-crash-guard

Conversation

@kevinWangSheng

@kevinWangSheng kevinWangSheng commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: JSON.parse calls parsing external process stdout (tailscale CLI) and disk-persisted queue entries lack try-catch protection, causing unhandled crashes on malformed input
  • Why it matters: External process output can be truncated, contain non-JSON preamble text, or be corrupted on disk — all of which cause SyntaxError that crashes the gateway
  • What changed: Added try-catch guards around JSON.parse in parseTailscaleStatusIPv4s() (bonjour-discovery.ts) and failDelivery() (delivery-queue.ts), returning safe fallback values on parse failure
  • What did NOT change: Happy-path behavior is identical; only error recovery is added

Change Type

  • Bug fix

Scope

  • Gateway / orchestration

Security Impact

  • 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

Compatibility / Migration

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

Risks and Mitigations

  • Risk: Silent failure on corrupted data could mask underlying issues
    • Mitigation: These are recovery paths where the alternative is a process crash; the calling code already handles empty/null returns gracefully

Greptile Summary

Added defensive JSON.parse guards for external process output in two critical paths: Tailscale CLI output parsing (parseTailscaleStatusIPv4s in bonjour-discovery.ts:124-130) and disk-persisted delivery queue entries (failDelivery in delivery-queue.ts:128-136). Both return safe fallback values (empty array/early return) on parse failure instead of crashing.

  • bonjour-discovery.ts: parseTailscaleStatusIPv4s() now catches malformed/truncated JSON from tailscale status --json and returns empty array, preventing gateway crashes during Tailnet discovery fallback
  • delivery-queue.ts: failDelivery() catches corrupted queue JSON and exits silently, preventing crashes during delivery retry attempts
  • Test coverage is comprehensive, verifying both truncated JSON and missing files are handled gracefully
  • Existing loadPendingDeliveries() already had similar protection (line 176), so this brings failDelivery() to parity

Confidence Score: 5/5

  • Safe to merge with no concerns - defensive error handling added to prevent crashes from malformed external data
  • Changes are minimal, focused, and follow established error-handling patterns in the codebase (see loadPendingDeliveries at line 176 for similar try-catch with graceful skip). Test coverage is comprehensive and verifies the exact failure scenarios. Both changes preserve happy-path behavior while adding critical crash prevention for external/disk data parsing.
  • No files require special attention

Last reviewed commit: 1bc2470

(5/5) You can turn off certain types of comments like style here!

@openclaw-barnacle openclaw-barnacle Bot added size: S agents Agent runtime and tooling labels Feb 22, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants