openclaw - ✅(Solved) Fix Gateway enters infinite error loop: TypeError: Cannot read properties of undefined (reading 'startsWith') [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70502Fetched 2026-04-24 05:57:18
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×2closed ×1referenced ×1

Error Message

TypeError: Cannot read properties of undefined (reading 'startsWith')

Location: dist/subsystem-CSBs8ZPt.js:161 (minified) Triggered by: Gateway request handler (server.impl-STMC_0uD.js:24302)

Root Cause

Likely Root Cause

Fix Action

Fixed

PR fix notes

PR #70535: fix(logging): tolerate malformed subsystem labels (#70502)

Description (problem / solution / changelog)

Summary

  • Problem: the logging console filter path assumed subsystem was always a string and could throw on startsWith(...) when a malformed log entry reached it.
  • Why it matters: this shows up while the gateway is already in trouble, so a logging exception can turn one bad event into a repeated error loop.
  • What changed: made the console subsystem filter null-safe, normalized malformed subsystem labels inside subsystem loggers, and added regression coverage for both the filter check and console emission paths.
  • What did NOT change (scope boundary): this does not change normal subsystem filtering behavior for valid labels, and it does not change log-level policy.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • 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

  • Closes #70502
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: logging helpers called startsWith(...) on subsystem/message values that were typed as strings but could still be malformed at runtime during error handling.
  • Missing detection / guardrail: there was no regression test for malformed subsystem labels under an active console filter or during console emission.
  • Contributing context (if known): once the gateway enters an error path, logging code gets exercised repeatedly, so a small null-safety hole can keep the loop alive.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/logging/subsystem.test.ts
  • Scenario the test should lock in: missing subsystem labels do not throw when filters are active, isEnabled() stays safe, and console emission falls back to [unknown] instead of crashing.
  • Why this is the smallest reliable guardrail: the failure is inside pure logging helpers, so a focused logging unit test catches it without needing a flaky gateway repro.
  • Existing test that already covers this (if any): None.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Malformed subsystem labels no longer crash console logging. If one slips through, console output falls back to [unknown].

Diagram (if applicable)

Before:
bad log entry -> subsystem filter/probe suppression -> startsWith on undefined -> logging crash

After:
bad log entry -> subsystem normalized/guarded -> console logging continues -> gateway stays up

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 (local focused validation)
  • Runtime/container: repo unit-fast Vitest harness
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): console subsystem filter enabled

Steps

  1. Enable a console subsystem filter.
  2. Route a malformed or missing subsystem label through subsystem logging.
  3. Check whether the logging helper throws or safely ignores/emits the line.

Expected

  • Logging should not throw. Filter checks should treat missing subsystem labels as non-matches, and console output should stay stable.

Actual

  • Before this patch, a malformed subsystem label could hit startsWith(...) and crash inside the logging path.

Evidence

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

Focused validation:

  • OPENCLAW_VITEST_INCLUDE_FILE=/tmp/openclaw-70502-vitest-include.json pnpm exec vitest run --config test/vitest/vitest.unit-fast.config.ts
  • Passed:
    • src/logging/subsystem.test.ts

Issue evidence:

  • Reported repeated gateway failure: TypeError: Cannot read properties of undefined (reading 'startsWith')

Human Verification (required)

  • Verified scenarios: exercised filter checks and subsystem logger emission with malformed subsystem labels; both paths now stay non-throwing.
  • Edge cases checked: active console filter, isEnabled(..., "console"), and warn-level console emission with a missing subsystem label.
  • What you did not verify: I did not reproduce the original long-running gateway failure loop end to end, and I did not run the full repo test suite in this environment.

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:

Risks and Mitigations

  • Risk: malformed subsystem labels now render as [unknown], which is less specific than a real label.
    • Mitigation: the fallback is only used for invalid input, and it keeps the logging path alive instead of crashing.

Changed files

  • src/logging/console.ts (modified, +17/-2)
  • src/logging/subsystem.test.ts (modified, +27/-1)
  • src/logging/subsystem.ts (modified, +34/-17)
  • src/plugins/contracts/plugin-sdk-package-contract-guardrails.test.ts (modified, +1/-0)

Code Example

TypeError: Cannot read properties of undefined (reading 'startsWith')

---

// subsystem-CSBs8ZPt.js:85
return filter.some((prefix) => subsystem === prefix || subsystem.startsWith(`${prefix}/`));

---

return filter.some((prefix) => subsystem === prefix || (subsystem && subsystem.startsWith(`${prefix}/`)));

---

2026-04-22T11:29:31.957+02:00
GatewayClientRequestError: TypeError: Cannot read properties of undefined (reading 'startsWith')

---

[2026-04-22 12:06:28] --- Restarting gateway ---
[2026-04-22 12:06:28] Restart FAILED - gateway still unresponsive
RAW_BUFFERClick to expand / collapse

Bug Report

Version: 2026.4.12 (1c0672b) Severity: High — gateway becomes completely unresponsive, consuming 100%+ CPU

Error

TypeError: Cannot read properties of undefined (reading 'startsWith')

Location: dist/subsystem-CSBs8ZPt.js:161 (minified) Triggered by: Gateway request handler (server.impl-STMC_0uD.js:24302)

Impact

  • Gateway process does not crash — stays alive in infinite error loop
  • CPU usage spikes to 100%+ (observed: 86–154%)
  • Memory usage grows (observed: 800MB–2.6GB)
  • HTTP endpoint on port 18789 becomes completely unresponsive
  • All agent sessions timeout

Likely Root Cause

In shouldLogSubsystemToConsole():

// subsystem-CSBs8ZPt.js:85
return filter.some((prefix) => subsystem === prefix || subsystem.startsWith(`${prefix}/`));

When subsystem is undefined (e.g., malformed log entry during error handling), subsystem.startsWith() throws.

Defensive Fix Suggestion

return filter.some((prefix) => subsystem === prefix || (subsystem && subsystem.startsWith(`${prefix}/`)));

Other startsWith calls in the same file should also be null-safe:

  • Line 101: message.startsWith(...)(message ?? '').startsWith(...)
  • Line 102: message.startsWith(...)(message ?? '').startsWith(...)
  • Line 321: params.subsystem.startsWith(...)(params.subsystem ?? '').startsWith(...)

Reproduction Pattern

Cannot reliably reproduce on demand. Occurs sporadically during normal operation.

Pattern observed:

  • Occurs between 09:16–09:30 on 2026-04-22
  • Gateway had been running for ~9 hours before failure
  • Multiple subagents were active at the time
  • Error repeats every ~5 seconds indefinitely

Environment

  • OS: Linux 6.8.0-110-generic (x64)
  • Node: v22.22.2
  • OpenClaw: 2026.4.12
  • Deployment: Docker container on VPS

Logs

First error:

2026-04-22T11:29:31.957+02:00
GatewayClientRequestError: TypeError: Cannot read properties of undefined (reading 'startsWith')

Repeated every ~5 seconds until 12:06:

[2026-04-22 12:06:28] --- Restarting gateway ---
[2026-04-22 12:06:28] Restart FAILED - gateway still unresponsive

Additional Context

  • Config warning present: Config was last written by a newer OpenClaw (2026.4.15); current version is 2026.4.12
  • No recent config changes before crash
  • System resources were healthy (170GB disk, 12GB RAM available)

extent analysis

TL;DR

Apply a defensive fix to null-safe startsWith calls in the subsystem-CSBs8ZPt.js file to prevent the gateway from becoming unresponsive due to a TypeError.

Guidance

  • Verify the subsystem variable is not undefined before calling startsWith on it, as shown in the defensive fix suggestion.
  • Update the startsWith calls on lines 101, 102, and 321 in subsystem-CSBs8ZPt.js to use null-safe checks, such as (message ?? '').startsWith(...).
  • Consider reviewing the log entry handling to prevent undefined subsystem values from being passed to shouldLogSubsystemToConsole().
  • Monitor the gateway's performance and logs after applying the fix to ensure the issue is resolved.

Example

return filter.some((prefix) => subsystem === prefix || (subsystem && subsystem.startsWith(`${prefix}/`)));

Notes

The provided defensive fix suggestion should prevent the TypeError from occurring, but the root cause of the undefined subsystem value should be investigated to prevent similar issues in the future.

Recommendation

Apply the defensive fix to null-safe startsWith calls, as it directly addresses the reported error and prevents the gateway from becoming unresponsive.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Gateway enters infinite error loop: TypeError: Cannot read properties of undefined (reading 'startsWith') [1 pull requests, 1 participants]