Skip to content

fix(runtime): a configured row limit above the batch limit no longer refuses ordinary rows - #356

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/328-runtime-body-cap
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/328-runtime-body-cap

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Stacked on #355 (branch fix/337-content-store-enoent).

If the configured single-row limit was larger than both the batch limit and the Postgres limit, the runtime refused an ordinary tables.insert or tables.update with 413 before that row's own limit was checked. Default limits are unaffected. Closes #328.

The HTTP reader caps each request body at Runtime.maxCallBytes, which was max(batchBytes + callBytes, postgresBytes). That maximum now also includes rowBytes + callBytes. The per-operation and stored-row checks are unchanged.

Test evidence: a new Runtime.test.ts case uses the ticket's settings (row 2048, batch 512, call 512, postgres 512). It sends an insert through the real runtime HTTP handler, which returned 413 before the fix and returns 200 after it. pnpm typecheck and pnpm lint pass. In pnpm test, 942 tests passed. Two integration Postgres tests timed out under machine load and pass when run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:server Touches the server area size:s Under 100 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed c241f9e against origin/fix/337-content-store-enoent at 476e751, using issue #328 as the spec. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. Adding the missing term to the existing Math.max is the smallest fix. The fixture's configuration override supports the regression without introducing production abstractions.

Spec

No merge-blocking intent findings. The global body cap now includes rowBytes + callBytes, exactly as #328 requests. Default limits, per-operation checks and stored-row checks are unchanged.

Verification: pnpm exec vitest run packages/runtime/src/Runtime.test.ts passed all 13 tests, including the new nondefault-limit regression and the existing operation-cap checks. The regression exercises HTTP admission with a stub insert handler, not table persistence or a live server.

Summary: Standards 0 blockers; Spec 0 blockers. No blocking issue on either axis.

@allisonmahmood allisonmahmood left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change does what issue 328 asks. Runtime.maxCallBytes now includes rowBytes + callBytes, so a configured single-row limit above the batch and Postgres limits admits an ordinary tables.insert or tables.update up to that row's own cap. Defaults stay max(8 MiB + 64 KiB, 256 KiB). I would land it.

Standards

No hard documented-standard violations. No Effect service findings.

The new ceiling matches runtimeBodyLimit in packages/api/src/runtime.ts. Insert and update are rowBytes + callBytes. tables.insertMany is batchBytes + callBytes. postgres.* is postgresBytes, with no envelope added. docs/API.md already states those per-operation defaults for POST /api/runtime/call, and this diff leaves them as written. The shell broker already calls runtimeBodyLimit per operation. Runtime.make still reads config from the environment. The fixture override is a ConfigProvider test seam. The new test sends a 1351-byte JSON body, above the old 1024-byte reader cap and under the new 2560-byte cap.

Judgement call, duplicated code. maxCallBytes repeats the three branches of runtimeBodyLimit.

maxCallBytes: Math.max(
  settings.rowBytes + settings.callBytes,
  settings.batchBytes + settings.callBytes,
  settings.postgresBytes
)

That split is how the row term was dropped. CLAUDE.md asks for the smallest model that makes the correct behavior unsurprising, and it treats the api package as the source the rest follows. One ceiling beside runtimeBodyLimit would keep the next edit on one function. This hunk now matches the helper's arithmetic. Nothing else in the diff copies the formula. I would not block on it. Issue 328 asked for this term in the existing max.

Spec

Issue 328 says: "Include rowBytes + callBytes in the maximum, keeping the existing operation and stored-row checks." It also says the failure is when rowBytes + callBytes exceeds both batchBytes + callBytes and postgresBytes, that the keys have no rowBytes <= batchBytes invariant, and that this is a nondefault configuration bug.

Missing or partial. None. The new maximum is max(rowBytes + callBytes, batchBytes + callBytes, postgresBytes). runtimeBodyLimit is unchanged, so insert and update stay rowBytes + callBytes. TableOperations still checks rowBytes and batchBytes. The diff adds no rowBytes <= batchBytes invariant. Defaults are unchanged.

Scope creep. None. The fixture config argument supplies the ConfigProvider keys named in the reproduction. No other limit, route, or invariant changed.

Implemented but wrong. None. With row 2048, batch 512, call 512, and postgres 512, the old reader cap is 1024 and bodyLimit("tables.insert") is 2560. The new test's body is 1351 bytes, so the old cap refuses it and the new cap admits it. postgresBytes stays a bare cap, matching runtimeBodyLimit.

Method

readCall counts the raw POST body before the operation is known, so the reader cap is the largest class limit. dispatch still applies bodyLimit(op) after decode.

For non-negative row and batch limits, both sums dominate bare callBytes. The three-term max then equals the max of every runtimeBodyLimit result. With the ticket's settings, insert and update allow 2560, insertMany allows 1024, and postgres and every other call allow 512. The reader cap is 2560. A body of 2560 passes both gates. A body of 2561 is refused before decode.

File PUT and GET use readFile(runtime.fileBytes) on their own routes. Their bytes never enter maxCallBytes.

The fixture spreads config into ConfigProvider.fromUnknown on the same Config.Int keys make reads, so the test builds the real maxCallBytes. "é".repeat(600) is 1200 UTF-8 bytes of text. JSON.stringify of the envelope is 1351 bytes, with Content-Length set to that. Issue 328's sample was 1212 encoded bytes in a 1381-byte request. Both sit in the open interval above 1024 and at or under 2560. The handler is stubbed with Effect.succeed(null), so this case exercises RuntimeApi and dispatch. Stored-row checks stay where they were, in TableOperations.

YAGNI

The patch is the right size. One formula term, one test, and a config argument on the fixture layer because that layer already installs the ConfigProvider.

The comment on maxCallBytes is partly narration. "The largest per-operation body limit" restates Math.max. "The configured limits are independent" is the constraint worth keeping, because the default batch limit sits above the default row limit and the new term looks idle. The JSDoc on config restates the parameter.

The test is the smallest proof of the false refusal. Status 200 is the regression the ticket describes. The sibling test still expects 413 when a default-limit body exceeds its own operation cap.

Standards: 1 finding. The worst is the duplicated ceiling, and it is a judgement call. Spec: 0 findings.

Reviewed by Grok 4.7 in Grok Build.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review follow-up (Astra and Grok 4.7). Neither review found a blocker.

Fixed

  • Grok's comment note: the maxCallBytes comment no longer restates Math.max. It now says the ceiling must cover every runtimeBodyLimit branch, because the limits are configured independently (3558237).

Kept as is

  • Duplicated arithmetic (maxCallBytes vs runtimeBodyLimit). Deriving the ceiling from the helper isn't actually smaller. It would still need a list of one representative op per branch (tables.insert, tables.insertMany, postgres.*, other), and that list has to stay in sync with the helper, just like the formula does now. Removing the duplication for real means restructuring runtimeBodyLimit into a table of limit classes, which is a refactor beyond runtime: the global body cap omits the configured single-row limit #328. The updated comment ties the two together, so the next person who edits the helper sees the ceiling.
  • The fixture's config JSDoc: kept. It says the overrides go on top of the fixture's test defaults, which the signature doesn't show.

Verification: Runtime.test.ts passes 13/13, including the new regression. pnpm typecheck and pnpm lint pass on 3558237.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@allisonmahmood
allisonmahmood force-pushed the fix/337-content-store-enoent branch from 476e751 to db3cbc6 Compare September 24, 2026 13:11
Base automatically changed from fix/337-content-store-enoent to main September 24, 2026 13:19
allisonmahmood and others added 2 commits September 24, 2026 15:20
… a batch

Runtime.maxCallBytes, which the HTTP reader enforces before dispatch, took
max(batchBytes + callBytes, postgresBytes) and left out rowBytes + callBytes.
With independent nondefault limits where the row cap exceeds both, an ordinary
tables.insert/update was refused 413 before its own per-operation cap applied.
Include the row term in the maximum. Defaults are unaffected.

Closes #328

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/328-runtime-body-cap branch from 3558237 to 3c35c41 Compare September 24, 2026 13:20
@allisonmahmood
allisonmahmood merged commit 340cdc6 into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/328-runtime-body-cap branch September 24, 2026 13:28
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…ine (#357)

Stacked on #356 (branch fix/328-runtime-body-cap).

Table and file mutations logged a 30-second deadline but nothing enforced it. Only integration calls had a timeout, so a mutation could keep running after its own log row already read `unknown`. Tier 2 will hold company-database transactions open for a hosted mutation, and that plan counts on this deadline being real.

Every logged call now runs under the same `timeoutOrElse`. The timeout uses the `deadlineMs` that goes into the runtime log, so a mutation past `PATCHY_RUNTIME_MUTATION_DEADLINE_MS` fails with `timeout` (504) and its log row records `failure`/`timeout`. Behaviour change: a file PUT is logged before its body is read, so the upload itself now has to finish inside the 30-second (configurable) mutation deadline. `docs/API.md` says so. The `Timeout` message no longer says "integration".

Tests:
- New `Runtime.test.ts` case: a never-returning `tables.insert` with a 5 s configured deadline gets a 504 `timeout` at exactly 5,000 ms, its handler is interrupted, and the log row has `deadlineMs` and `durationMs` of 5,000. On the unmodified code the call never returned.
- The existing "remains unknown after interruption" case now interrupts before the deadline, then checks `pending` → `unknown`. Its old version advanced past the deadline first, which only worked because the deadline wasn't enforced.
- `pnpm typecheck` and `pnpm lint` are clean. `pnpm test`: 944/945. The one failure was a 5 s timeout in `integrations/src/postgres/Runtime.test.ts` while other test runs were loading the machine; it passes when run alone.

Closes #317

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime: the global body cap omits the configured single-row limit

1 participant