Repository navigation
fix(decofile): drop invalid-JSON blocks instead of wedging the merge - #6183
Merged
Merged
Conversation
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]>
… 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]>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.mergeBlockssplices each.deco/blocks/*.jsonin raw for performance, so a single corrupt block — e.g. a file that contains raw.tsxsource (import { H … }) instead of a JSON object — makes the entire merged document unparseable.The API then returns
200with an invalid JSON body. On the client,fetchDecofiledoesres.json()→ throwsSyntaxError→ retries exhaust →setDecofileDraftnever runs →draftPreviewUrlstaysnull→fastPreviewReadyisfalse→ the preview is wedged on the waking pill forever.Fix
mergeBlocksnow validates each block and drops the ones that aren't valid JSON, returning{ decofile, skipped }:skipped(key, stem, parse error).read-decofile.tsread path andcommit-coalescer.tsgen path)console.warnthe 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
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.generateFromBlocks(packages/sandbox/daemon-go/internal/decofile/merge.go) has the same all-or-nothing design; it's guarded by write-timeInvalidBlockJSONtoday. 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 --noEmitclean forpackages/sharedandapps/api.bun run fmtclean.🤖 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/*.jsonproduced 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).mergeBlocksnow returns{ decofile, skipped }; update any external call sites accordingly. Valid blocks are still spliced verbatim; output is unchanged for well-formed input.decofile_skipped_blocksand logs dropped block keys; the generation path logs keys as well. We do not log raw parse errors.generateFromBlocksnow drops invalid-JSON blocks to match the TypeScript merge.Written for commit 09be235. Summary will update on new commits.