Skip to content

fix(config): handle non-object JSON documents - #2235

Open
fallenmi wants to merge 1 commit into
MemPalace:developfrom
fallenmi:codex/fix-config-top-level-shape
Open

fix(config): handle non-object JSON documents#2235
fallenmi wants to merge 1 commit into
MemPalace:developfrom
fallenmi:codex/fix-config-top-level-shape

Conversation

@fallenmi

@fallenmi fallenmi commented Aug 12, 2026

Copy link
Copy Markdown

What does this PR do?

  • Validates that a successfully parsed config.json is a JSON object before storing it as MemPalace configuration.
  • Falls back to the existing empty/default configuration for valid JSON scalars and arrays instead of crashing on the first .get() call.
  • Adds regressions for null, array, string, number, and boolean top-level documents.

Closes #2234.

Why?

JSON permits non-object values at the top level. MempalaceConfig previously assigned any successful json.load() result to _file_config, while all downstream properties assume a mapping. A file containing null, [], a string, a number, or a boolean therefore raised AttributeError across CLI, MCP, mining, and hook consumers.

The fallback matches the class's existing fail-soft behavior for malformed JSON, Unicode decode errors, and unreadable files. It does not rewrite the user's file, emit output on the MCP stdio channel, or alter valid object configurations.

How to test

python -m pytest -q tests/test_config.py tests/test_hooks_cli.py
pre-commit run --all-files

Local result after rebasing onto current develop: 286 passed, 1 skipped. Ruff check, Ruff format, and git diff --check pass.

Checklist

  • Focused and adjacent tests pass
  • No hardcoded paths
  • Linter and formatter pass

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: valid non-object config.json crashes all consumers

2 participants