magic-context icon indicating copy to clipboard operation
magic-context copied to clipboard

maintain-docs parses proposal JSON after model fallback validation has already succeeded

Open breakbeatkid opened this issue 1 month ago • 2 comments

Short description

maintain-docs accepts nonempty assistant prose at the validated-output retry boundary, then fails JSON parsing after that boundary has returned. A malformed primary response therefore fails the task without trying its configured fallback model.

What happened?

An OpenCode 1 Dreamer run reached the end of its child model loop and then logged:

[dreamer] maintain-docs failed validation: SyntaxError: JSON Parse error: Unexpected identifier "I"

The exact loaded plugin version for that historical run was not established. The validation placement was subsequently checked in the v0.49.19 release source and remains present there. This report distinguishes the observed failure from the current source analysis; it does not claim a new live reproduction on v0.49.19.

Source trace (v0.49.19)

  • packages/plugin/src/features/magic-context/dreamer/task-executor.ts: runAgenticTask uses promptSyncWithValidatedOutputRetry, but the maintain-docs output validator accepts any nonempty assistant text. The task calls writeDocsProposal only after that retry operation and child teardown.
  • packages/plugin/src/features/magic-context/dreamer/docs-proposals.ts: writeDocsProposal calls validateDocsProposal, which extracts a fenced JSON block if present and then calls JSON.parse.
  • Consequently a response such as I could not produce the proposal. passes the retry validator but fails afterward, outside configured model fallback handling.

Sources:

  • https://github.com/cortexkit/magic-context/blob/v0.49.19/packages/plugin/src/features/magic-context/dreamer/task-executor.ts
  • https://github.com/cortexkit/magic-context/blob/v0.49.19/packages/plugin/src/features/magic-context/dreamer/docs-proposals.ts

Minimal regression case to add

Use the existing docs-proposal executor fixture with committed root documentation and a later relevant source commit:

  1. Configure a primary model and a fallback model.
  2. Have the primary return a nonempty, non-JSON assistant response.
  3. Have the fallback return a valid section-change JSON array.
  4. Assert that the fallback is invoked and the validated proposal is produced without directly editing the root docs.

Additional cases: all attempts invalid must fail without a success anchor or proposal; whitespace/fenced empty JSON arrays should receive the same intended no-change treatment as literal []; protected-region, base-drift, structure and token-budget failures must retain their safety semantics.

Expected behavior

Malformed proposal output should be recognized inside the validated-output retry boundary so that the configured fallback can be attempted. Retain final host-side revalidation before writing a proposal, including protected bytes, base hashes, allowed files, Markdown structure and token budget. Do not turn permission refusals or protection failures into bypasses.

Diagnostics

Targeted source and sanitized log evidence supplied manually. No broad configuration/provider dump attached.

Baseline only: the existing docs-proposals-e2e.test.ts and map-memories.test.ts suites passed together (44 tests, zero failures) in an isolated v0.49.19 source checkout with Bun 1.4.4. No new regression test or implementation patch is claimed.

Plugin version

0.49.19 source inspected; historical failing host version unknown.

OpenCode version

OpenCode 1.x; exact failing host version not established.

Platform

macOS arm64

Client

OpenCode TUI

Log output

2026-10-23T08:04:36.909Z [dreamer] maintain-docs failed validation: SyntaxError: JSON Parse error: Unexpected identifier "I"

breakbeatkid avatar Oct 23 '26 09:10 breakbeatkid

Thanks, confirmed against current source. The maintain-docs retry accepts any nonempty text, and the proposal JSON is parsed only after the retry has returned, so a prose answer fails the task instead of moving to the fallback model. We're moving that parse inside the retry, keeping the full protected-region, base-hash and budget checks before anything is written, and treating a whitespace-padded or fenced [] the same as a literal one. The fix ships in the next patch, crediting you.

magic-alfonso[bot] avatar Oct 23 '26 09:10 magic-alfonso[bot]

Shipped in 0.49.21. maintain-docs now validates the proposal JSON inside the same retry loop as the model call. So a model that answers with prose instead of the JSON proposal now falls through to your configured fallback model, where before the task failed. Host-side errors (the token budget, base drift, protected sections) still fail without a retry. Thanks, @breakbeatkid.

magic-alfonso[bot] avatar Oct 25 '26 09:10 magic-alfonso[bot]