Skip to content

fix(bonjour): suppress ciao IPv4 address-change assertion crash#42698

Open
androidshu wants to merge 1 commit intoopenclaw:mainfrom
androidshu:codex/fix-bonjour-ciao-ipv4-assert
Open

fix(bonjour): suppress ciao IPv4 address-change assertion crash#42698
androidshu wants to merge 1 commit intoopenclaw:mainfrom
androidshu:codex/fix-bonjour-ciao-ipv4-assert

Conversation

@androidshu
Copy link
Copy Markdown

Summary

  • Problem: gateway exits on unhandled rejection when @homebridge/ciao throws an IPv4 transition assertion (Reached illegal state! IPv4 address changed...).
  • Why it matters: transient network/interface churn (sleep/wake, VPN toggle, Wi-Fi changes) can kill a healthy gateway process.
  • What changed: extended ignoreCiaoCancellationRejection() to also suppress ciao IPv4 assertion variants and added focused unit tests.
  • What did NOT change (scope boundary): no behavior changes outside ciao unhandled-rejection filtering; no gateway restart/health-monitor policy changes.

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

User-visible / Behavior Changes

  • Gateway no longer exits when the known ciao IPv4 transition assertions are emitted as unhandled rejections; process continues and logs a warning.

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)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS 26.2 (arm64)
  • Runtime/container: Node 24.x, local gateway mode
  • Model/provider: gmn / gpt-5.3-codex
  • Integration/channel (if any): DingTalk channel enabled
  • Relevant config (redacted): default local gateway, bonjour enabled

Steps

  1. Start gateway with bonjour enabled.
  2. Trigger interface churn (sleep/wake, VPN toggle, or network transition) causing ciao assertion.
  3. Observe unhandled rejection behavior.

Expected

  • Gateway should not crash on known transient ciao IPv4 assertion transitions.

Actual

  • Before: process exits on unhandled rejection.
  • After: rejection is suppressed and logged as non-fatal warning.

Evidence

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

Crash trace observed before fix:

Unhandled promise rejection: AssertionError [ERR_ASSERTION]: Reached illegal state! IPv4 address changed from undefined to defined!
    at MDNSServer.handleUpdatedNetworkInterfaces (.../@homebridge/ciao/src/MDNSServer.ts:691:18)

Validation run:

pnpm vitest run src/infra/bonjour-ciao.test.ts src/infra/bonjour.test.ts src/infra/unhandled-rejections.test.ts
# 3 files, 43 tests passed

Note: repository-wide pnpm check currently fails on upstream formatting in src/cli/daemon-cli/lifecycle.test.ts (unrelated to this PR).

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • Known ciao cancellation rejection remains suppressed.
    • Two IPv4 assertion message variants are suppressed.
    • Unrelated errors are not suppressed.
  • Edge cases checked:
    • Both “address change” and “address changed” message forms.
    • Case-insensitive matching through existing uppercase normalization.
  • What you did not verify:
    • Full end-to-end live network churn reproduction in this PR branch runtime.

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)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
    • Revert this commit.
  • Files/config to restore:
    • src/infra/bonjour-ciao.ts
    • src/infra/bonjour-ciao.test.ts
  • Known bad symptoms reviewers should watch for:
    • Over-broad suppression accidentally swallowing unrelated unhandled rejections.

Risks and Mitigations

  • Risk:
    • Matching too broadly could mask non-ciao assertion failures with similar text.
    • Mitigation:
      • Pattern remains tightly scoped to ciao-specific illegal-state IPv4 assertion text; tests assert unrelated errors remain unsuppressed.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR suppresses a known @homebridge/ciao assertion crash (Reached illegal state! IPv4 address changed...) that could kill the gateway process during transient network events (sleep/wake, VPN toggle, Wi-Fi changes). The fix extends the existing ignoreCiaoCancellationRejection filter with two new pattern entries and logs suppressed assertions at WARN level instead of silently dropping them, keeping the change well-scoped and observable.

Key changes:

  • Added two CIAO_TRANSIENT_PATTERNS entries to match IPv4 address-change assertion messages.
  • Differentiated log severity: IPv4 assertion suppressions now emit logWarn while the existing cancellation still uses logDebug.
  • Added a focused test file (bonjour-ciao.test.ts) covering all new suppression paths and confirming unrelated errors are not swallowed.

Code clarity note: The second IPv4 pattern ("REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGED") is fully subsumed by the first ("REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE") due to substring matching in the includes() check, making it dead code. The first pattern alone covers both variants and could include a comment to clarify this intent.

Confidence Score: 4/5

  • Safe to merge; the change is tightly scoped to ciao unhandled-rejection filtering with no behavioral impact outside that path.
  • The fix is correct and well-tested. The only issue is a minor code clarity matter: a redundant pattern entry that is dead code due to substring matching. This does not affect runtime behavior, correctness, or unintended suppressions. The scope boundary is clearly respected, and all new suppression paths are properly tested.
  • src/infra/bonjour-ciao.ts — consider removing the redundant second IPv4 pattern and clarifying the intent in a comment.

Last reviewed commit: ca577dd

Comment on lines +10 to +11
"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE",
"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGED",
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.

The second IPv4 pattern on line 11 ("REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGED") is fully subsumed by the first pattern on line 10 ("REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE"). Since the matching uses String.prototype.includes() for substring matching, any error message triggering the second pattern would already be caught by the first. This makes the second entry dead code that doesn't affect correctness but could mislead future maintainers.

Consider removing the second pattern and adding a clarifying comment:

Suggested change
"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE",
"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGED",
"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE", // covers both "change" and "changed" variants
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/bonjour-ciao.ts
Line: 10-11

Comment:
The second IPv4 pattern on line 11 (`"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGED"`) is fully subsumed by the first pattern on line 10 (`"REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE"`). Since the matching uses `String.prototype.includes()` for substring matching, any error message triggering the second pattern would already be caught by the first. This makes the second entry dead code that doesn't affect correctness but could mislead future maintainers.

Consider removing the second pattern and adding a clarifying comment:

```suggestion
  "REACHED ILLEGAL STATE! IPV4 ADDRESS CHANGE", // covers both "change" and "changed" variants
```

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway crashes with AssertionError when IPv4 address transitions from defined to undefined

1 participant