Skip to content

fix(graph): skip malformed tunnel records - #2269

Draft
fallenmi wants to merge 1 commit into
MemPalace:developfrom
fallenmi:codex/fix-malformed-tunnel-records
Draft

fix(graph): skip malformed tunnel records#2269
fallenmi wants to merge 1 commit into
MemPalace:developfrom
fallenmi:codex/fix-malformed-tunnel-records

Conversation

@fallenmi

Copy link
Copy Markdown

What does this PR do?

  • validates each decoded tunnels.json entry centrally in _load_tunnels
  • keeps legacy-compatible records with a non-empty string ID and complete string wing/room endpoints
  • preserves all optional fields, including older records without kind, timestamps, drawer IDs, or dynamics
  • skips unusable records with one aggregated warning containing only the file path and count
  • warns on unsupported top-level JSON types without auto-wrapping or logging payload contents
  • adds regressions proving create, filtered list, follow, and delete remain usable when valid and malformed records coexist

The root cause was that _load_tunnels validated only the outer list. Consumers then called .get or indexed endpoint keys on arbitrary JSON elements, so one null, string, phantom dict, or partial endpoint blocked every valid tunnel behind it and surfaced through MCP as an internal tool error.

Read-only list/follow calls do not rewrite the sidecar. A later create/delete persists the filtered valid set through the existing atomic write path, matching the loader's established fail-soft recovery behavior. Unsupported non-list roots remain unsupported; changing destructive recovery for those files is intentionally outside this patch.

Closes #2266

How to test

  • .venv/bin/python -m pytest -q tests/test_palace_graph_tunnels.py — 59 passed
  • .venv/bin/python -m pytest -q tests/test_closets.py tests/test_miner.py — 202 passed
  • .venv/bin/python -m pytest -q tests/test_mcp_server.py — 368 passed
  • broad regression run excluding the unrelated installation-layout subprocess check — 4,299 passed, 31 skipped
  • .venv/bin/pre-commit run --all-files — Ruff check and format passed

Checklist

  • Tests pass
  • No hardcoded paths
  • Linter passes

@igorls igorls added bug Something isn't working area/kg Knowledge graph needs-rebase PR has merge conflicts with develop and needs rebase labels Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kg Knowledge graph bug Something isn't working needs-rebase PR has merge conflicts with develop and needs rebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed records in tunnels.json crash all tunnel operations

2 participants