Repository navigation
Commit 01eab23
fix(rest): a refused json export answers the 400 envelope, not a truncated 200 stream (#27753)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DM77tsfTXyZb3uxqJzawYo9)_
domain:server#3 · os-elon-musk · session_016WV4d1cSb5LKsNDntVL6VG
Fixes #27682
## What changes
- `packages/rest/src/data-action-routes.ts`: the json export writes its
opening `[` after the first `findData` answers, not before it. One line
moved into the read loop (`if (format === 'json' && firstChunk)
res.write('[')`), placed before the zero-row break so an empty export is
still `[]`. Nothing else in the route changes, and the import-job region
(#27711) is untouched.
- `packages/rest/src/export-json-refusal-envelope.test.ts` (new): pins
both halves through the real `HonoHttpServer`.
- `.changeset/27682-json-export-read-first.md`: patch for
`@objectstack/rest`.
## Why
The first `res.write` commits the Hono adapter to a streaming 200.
Writing `[` before the first read meant a query that read refused
reached the client as a 200 whose body was a lone `[`, while
`format=csv` answered the 400 envelope. Triage 6504427279: the json
export reads its first page before it writes any byte and answers the
same envelope. A refusal on a later page is not widened here.
## Verification
- Pin, over a real `SqlDriver` (SQLite): `?search=x&searchFields=nope`
(the card's repro, `400 INVALID_FIELD`) and `?search=x&searchFields=,`
(`400 VALIDATION_ERROR`) answer the same status and body for
`format=json` as for `format=csv`. Ablation: with the early write
restored, both json rows are red (200); restored, green.
- Byte identity: a successful json export over one page, three pages
(`page=50`, 120 rows) and zero rows answers exactly `[` + rows joined by
`,` + `]` (or `[]`), `Content-Type: application/json; charset=utf-8`,
with the same number of reads. Green on the unfixed code too, so the
success path did not move.
- `dispatch-gates --ran`: 59 derived families, 58 run green, 1 NOT
MEASURED (`check:dual-build-cjs-loads`, exit 3, needs a whole-tree
build). `pnpm lint` green; `@objectstack/rest` typecheck and full suite
green (343 files, 6702 passed) after merging `main`.
Out of scope finding: `format=xlsx` has the same early commit. Its
workbook writer is created before the first read, and the card's repro
answers 200 there too (measured). Not fixed or pinned here; the seat can
file it.
Clause-②: no
Metadata-protocol: none
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4d1cSb5LKsNDntVL6VG
Co-authored-by: Claude <noreply@anthropic.com>1 parent 2cbe559 commit 01eab23
3 files changed
Lines changed: 172 additions & 1 deletion
File tree
- .changeset
- packages/rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1437 | 1437 | | |
1438 | 1438 | | |
1439 | 1439 | | |
1440 | | - | |
1441 | 1440 | | |
1442 | 1441 | | |
1443 | 1442 | | |
| |||
1480 | 1479 | | |
1481 | 1480 | | |
1482 | 1481 | | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
1483 | 1491 | | |
1484 | 1492 | | |
1485 | 1493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
0 commit comments