Skip to content

Config parse error is silently swallowed: entire magic-context.jsonc falls back to defaults with only a log-file warning #421

Description

@G0-0000

What happened?

A single-character syntax error in magic-context.jsonc silently disables the entire config file — every customized option falls back to schema defaults with no error surfaced to the user.

Repro:

  1. Introduce any JSONC syntax error into ~/.config/cortexkit/magic-context.jsonc — in our real incident, the first line was accidentally written as \{ instead of { (one stray backslash).
  2. Start a Pi session. The plugin loads normally; no error is shown anywhere in the UI.
  3. Observe that ALL config customizations are now inert: cache_ttl reverts to "5m", custom dreamer schedules, model routing, thresholds, etc. all silently revert to schema defaults.

Root cause (0.41.2): loadConfigFile wraps comment-json parsing in a try/catch; on parse failure it returns config: {} plus a warning string "failed to load config: ...; using defaults for this file." (Pi bundle dist/index-ys39wb43.js L40295-40330; CLI bundle dist/index.js L43242-43280). The Zod schema then fills every field with its default (e.g. cache_ttl union has .default("5m"), CLI bundle L37669). The warning is only emitted via logPiConfigLoadwarn() (dist/index.js L30525-30539), which writes to the magic-context log file (/tmp/magic-context.log) — it is never surfaced as a UI notification, so from the user's perspective everything looks normal while the whole config is dead.

In our incident (2026-09-02) this went unnoticed and misdirected debugging: /ctx-status showed Cache TTL: 5m despite "cache_ttl": "1h" in the file, and we spent time checking env vars, version drift, and backup diffs before finding the single stray \ on line 1. A more forgiving parser (jsonc-parser) skips the bad first character and still reads the rest of the file — the rest of the config was perfectly valid; one character killed everything.

Expected:

  • Parse errors should be fail-loud: surface a UI warning/notification at session start ("config file failed to parse — running on defaults"), and/or
  • /ctx-status (or doctor) should prominently report "config parse failed, using defaults" as a health state, and/or
  • Optionally: attempt tolerant parsing (e.g. jsonc-parser's error-recovery) and apply the recoverable subset instead of discarding the entire file.

A single typo silently reverting the whole configuration is a sharp edge: the failure mode is indistinguishable from "config ignored", which is the hardest class of config bug to diagnose.

Diagnostics

doctor --issue unavailable: `npx @cortexkit/magic-context@latest doctor --issue --harness pi` launched an interactive TUI (prompted for Issue title: "Short summary of the Pi problem") instead of dumping diagnostics to stdout or a report file; exit 0, no issue-report file produced.

Non-interactive `npx @cortexkit/magic-context@latest doctor --harness pi` output (2026-09-08):

Running doctor for Pi…
Magic Context for Pi Doctor
PASS Pi 0.84.4 detected at /home/g0/.local/bin/pi
PASS Pi version meets minimum 0.74.0 requirement
PASS Magic Context Pi CLI v0.41.2 is current (npm latest v0.41.2)
PASS Pi settings found at /home/g0/.pi/agent/settings.json
PASS npm:@cortexkit/pi-magic-context is registered in packages[]
PASS user magic-context.jsonc is valid JSONC: /home/g0/.config/cortexkit/magic-context.jsonc
INFO No project Magic Context config found at /home/g0/ttt/.cortexkit/magic-context.jsonc
PASS Pi Magic Context config loads successfully
INFO Shared storage: /home/g0/.local/share/cortexkit/magic-context (source: platform default)
PASS Shared context DB exists at /home/g0/.local/share/cortexkit/magic-context/context.db
PASS Opened shared DB read-only supported schema
INFO Storage versions: context_db_schema_version=83, plugin_supported_version=83
INFO Upstream migration fence: context.db and build are both v83.
PASS SQLite integrity_check: ok
INFO Shared DB row counts: tags=64144, compartments=85, memories=308, notes=14, dream_runs=335
PASS Embedding endpoint OK (200, 2560-dim vectors)
PASS No conflicting magic-context entries in Pi packages[]
INFO Other Pi extensions registered: npm:pi-subagents, git:github.com/Leechael/pi-provider-kimi-code, npm:@ff-labs/pi-fff, npm:@victor-software-house/pi-curated-themes, npm:pi-open-tui, npm:pi-mcp-adapter, npm:pi-rtk-optimizer, npm:@juicesharp/rpiv-ask-user-question, npm:@tmustier/pi-usage-extension, npm:pi-cache-guardian
INFO log: /tmp/pi/magic-context/magic-context.log (3887 KB)
INFO [2026-09-04T17:53:05.266Z] projects=1
PASS 13  WARN 0  FAIL 0

Plugin version: 0.41.2

OpenCode version: N/A

Platform: linux x64

Client: Pi

Log output (optional)

[magic-context] WARN config: /home/…/magic-context.jsonc: failed to load config: Line 1: Unexpected token ILLEGAL; using defaults for this file.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions