Skip to content

fix: preserve quoted content when stripping JSONC trailing commas - #118

Open
specetator wants to merge 1 commit into
supermemoryai:mainfrom
specetator:fix/jsonc-quoted-content-20261024
Open

specetator wants to merge 1 commit into
supermemoryai:mainfrom
specetator:fix/jsonc-quoted-content-20261024

Conversation

@specetator

Copy link
Copy Markdown

Problem

The trailing-comma replacement in stripJsoncComments also matches inside JSON strings. For example, a configured prompt containing ,} or , ] loses that punctuation during loading.

This affects both supermemory.jsonc and plain supermemory.json, since loadRawConfig sends both through the helper. It changes the actual CONFIG.filterPrompt and CONFIG.recallDirective values; the former is subsequently used in the memory client's settings update.

Change

Consume string spans before matching structural trailing commas, preserving quoted content and escaped quotes/backslashes. Consume unterminated string spans as well, avoiding repeated attempts to match escaped quotes in malformed input; JSON.parse still rejects that input.

This is a narrow correction to the trailing-comma handling introduced in #16. Earlier #14 was closed in favor of #16; no currently open competing fix was found. There are no dependency changes and this branch is independent of #115.

Regression coverage

  • Quoted comma-delimiter sequences alongside actual trailing commas, comments, nested arrays/objects, escaped quotes/backslashes and a URL.
  • Fresh-process production CONFIG loading from both supported filenames in temporary isolated homes.
  • A 100 KB unterminated escaped-quote string remains unchanged and invalid, without a timing-sensitive assertion.

On base 762137de375d3b1920ba91fbdc400a030df92513, all four new tests fail. On the final patch:

  • bun run test: 37 passed, 0 failed
  • bun run typecheck: passed
  • bun run build: passed
  • git diff --check: passed

Environment: Linux, Node 24.22.1, Bun 1.4.4, TypeScript 5.9.3; bun install --frozen-lockfile. Tests use isolated HOME directories and make no hosted memory/model API calls. Windows/macOS and live provider behavior were not tested.

Scope and AI disclosure

This does not turn the helper into a strict JSONC validator or change the existing fallback-to-default configuration behavior on parse errors. Other malformed-input permissiveness is outside scope.

OpenAI coding agents implemented and independently reviewed the change; no human line-by-line review is claimed. Independent checks also exercised valid-string round trips and malformed production-config fallback. The final published two file blobs were verified against the tested patch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant