Skip to content

fix(decofile): drop invalid-JSON blocks instead of wedging the merge - #6183

Merged
guitavano merged 2 commits into
mainfrom
guitavano/fast-preview-stuck-request
Aug 18, 2026
Merged

guitavano merged 2 commits into
mainfrom
guitavano/fast-preview-stuck-request

Conversation

@guitavano

@guitavano guitavano commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Fast Preview stays stuck on the "Iniciando seu preview" / "starting preview" pill and never renders the draft.

Root cause: the Fast Preview decofile read (apps/api/src/decofile/read-decofile.ts) serves an arbitrary GitHub branch head directly, with no write-time validation gate. mergeBlocks splices each .deco/blocks/*.json in raw for performance, so a single corrupt block — e.g. a file that contains raw .tsx source (import { H … }) instead of a JSON object — makes the entire merged document unparseable.

The API then returns 200 with an invalid JSON body. On the client, fetchDecofile does res.json() → throws SyntaxError → retries exhaust → setDecofileDraft never runs → draftPreviewUrl stays null → fastPreviewReady is false → the preview is wedged on the waking pill forever.

Fix

mergeBlocks now validates each block and drops the ones that aren't valid JSON, returning { decofile, skipped }:

  • Valid blocks are still spliced verbatim (byte-for-byte parity with the Go daemon merge for well-formed input; pretty-printing preserved).
  • Invalid blocks are omitted and reported in skipped (key, stem, parse error).
  • Both callers (read-decofile.ts read path and commit-coalescer.ts gen path) console.warn the dropped blocks, so the loss is observable rather than silent.

Net effect: a corrupt block degrades to a partial but valid, renderable document instead of wedging the whole preview.

Notes / follow-ups

  • Cache: the merged doc is content-addressed by head sha (putMerged). A doc cached under the old code (invalid) is served as-is on a warm hit; it self-heals when the branch head moves (new sha ⇒ fresh valid merge). Removing the corrupt block on the branch is the immediate unblock.
  • Go parity: the daemon's generateFromBlocks (packages/sandbox/daemon-go/internal/decofile/merge.go) has the same all-or-nothing design; it's guarded by write-time InvalidBlockJSON today. Mirroring this skip there is a sensible parallel follow-up (not in this PR to keep scope on the Fast Preview bug).

Testing

  • bun test packages/shared/src/decofile/merge.test.ts — 10 pass (adjusted existing + 2 new: drop-invalid-block, decoded-key reporting).
  • tsc --noEmit clean for packages/shared and apps/api.
  • bun run fmt clean.

🤖 Generated with Claude Code


Summary by cubic

Prevents Fast Preview and the sandbox from wedging by dropping invalid-JSON blocks during decofile merge. Previously, one corrupt .deco/blocks/*.json produced a 200 with an unparseable body and the editor stayed on “starting preview.” Now both merges validate each block, omit invalid ones, and always return valid JSON so previews render (possibly partially).

  • Review notes
    • mergeBlocks now returns { decofile, skipped }; update any external call sites accordingly. Valid blocks are still spliced verbatim; output is unchanged for well-formed input.
    • Observability: the read path counts dropped blocks via decofile_skipped_blocks and logs dropped block keys; the generation path logs keys as well. We do not log raw parse errors.
    • Cache: the merged-doc cache key is versioned, so previously cached invalid documents miss immediately after deploy instead of persisting until the branch head changes.
    • Go parity: the daemon’s generateFromBlocks now drops invalid-JSON blocks to match the TypeScript merge.

Written for commit 09be235. Summary will update on new commits.

Review in cubic

The Fast Preview decofile read (`read-decofile.ts`) serves an arbitrary
GitHub branch head with no write-time validation, so a single corrupt
`.deco/blocks/*.json` (e.g. raw `.tsx` source) spliced in raw made the
entire merged document unparseable. The API returned 200 with an invalid
body, `res.json()` threw in the editor, the draft pointer was never seeded,
and the preview stayed stuck on the "starting preview" pill forever.

`mergeBlocks` now validates each block and drops the ones that aren't valid
JSON, returning `{ decofile, skipped }`. Valid blocks are still spliced
verbatim (byte-for-byte parity with the Go daemon merge for well-formed
input). Both callers log the dropped blocks so the loss is observable.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Aug 18, 2026
… path

Follow-up hardening from a multi-perspective review of the previous commit:

- Go daemon parity: `generateFromBlocks` (merge.go) now drops invalid-JSON
  blocks too (json.Valid), so a corrupt block degrades the sandbox path the
  same way it degrades Fast Preview instead of wedging it. Reconciled the
  now-false all-or-nothing doc comment; added a Go test.
- Cache poisoning: version the merged-doc disk key (MERGED_DOC_FORMAT), so an
  invalid document cached by the old all-or-nothing merge misses instead of
  being served as-is on a warm hit under a still-current sha.
- Observability: count dropped blocks via the existing OTel meter
  (decofile_skipped_blocks); log block keys only, never the raw JSON.parse
  message (it can echo block bytes — CLAUDE.md gotcha #8).
- Removed the unused MergeResult/SkippedBlock barrel re-exports (knip).
- Tests: interleaved + multi-skip ordering unit cases, and an e2e asserting
  the decofile GET returns a parseable body with the corrupt block dropped.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@guitavano
guitavano merged commit 2b31dcf into main Aug 18, 2026
29 of 33 checks passed
@guitavano
guitavano deleted the guitavano/fast-preview-stuck-request branch August 18, 2026 17:18
decocms Bot pushed a commit that referenced this pull request Aug 18, 2026
PR: #6183 fix(decofile): drop invalid-JSON blocks instead of wedging the merge
Bump type: patch

- decocms (apps/api/package.json): 4.227.2 -> 4.227.3
- @decocms/native (apps/native/package.json): 4.227.2 -> 4.227.3
- @decocms/e2e (packages/e2e/package.json): 1.35.0 -> 1.35.1
- @decocms/sandbox (packages/sandbox/package.json): 1.55.4 -> 1.55.5
- @decocms/shared (packages/shared/package.json): 0.40.0 -> 0.40.1
- deploy/helm/sandbox-env (chart 0.16.6) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.55.5

Deploy-Scope: server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant