Repository navigation
fix(runtime): a query with a NUL byte is refused as invalid_request and still logged - #683
Merged
Merged
Conversation
…nd still logged RuntimeLog.begin writes the call row before the operation checks its arguments, and Postgres text can't hold NUL. A published query or PostHog name carrying one failed the INSERT: the patch got source_unavailable, no row and no correlation id. begin now stores resource and sql as audit text, replacing what the PostgresText rule refuses (NUL, unpaired surrogates) with U+FFFD before the 8 KiB cut. The arguments are untouched, so the operation still refuses them with invalid_request. The dev door's own NUL cleaning goes. Closes #666 Co-Authored-By: Claude Opus 5.5 <[email protected]>
allisonmahmood
force-pushed
the
fix/666-nul-safe-call-row
branch
from
October 15, 2026 17:26
dc5e855 to
b2c1f7a
Compare
allisonmahmood
added a commit
that referenced
this pull request
Oct 16, 2026
…u when they fail (#720) Release 13's What's new entry, written from `c9b8fc4`, ahead of deploying it. `patchy` and `CURRENT_RELEASE` move to `0.13.0`, so CLIs and patch repos installed before this deploy are told to upgrade. | Change | PRs | | --- | --- | | New: Home puts the patches you use first | #713, #716, #719 | | New: Every patch in one list | #715 | | Improved: Each patch's page leads with Open | #717 | | New: See when your tools are failing | #718 | | Fixed: Everyone has a name | #687 | | Improved: Your company's look is easier to get right | #697, #696, #703, #688 | | Improved: Forms follow your look's error states | #691, #692 | | Improved: Clearer answers when a publish goes wrong | #686, #685, #689 | | Fixed: Your agent's Patchy commands are steadier | #695, #704, #680, #681 | | Behind the scenes: stricter checks on static pages and tools' database requests; malformed requests are logged | #682, #693, #683 | | Behind the scenes: usage numbers count every publish, sharing change and restore | #698, #699, #700, #690 | | Test and tooling only, no line | #705, #702, #701, #694, #684, #607 | Made by Claude Opus 5.5 in Claude Code, running in T3 Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
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
RuntimeLog.beginwrites the call row before the operation checks its arguments, and Postgres text can't hold NUL. So a published Postgres query, or a PostHog query or name, carrying a NUL failed the INSERT: the patch gotsource_unavailable, with no call row and no correlation id. The dev door (/api/connections/dev-read) avoided this with its own cleaning.Fix
RuntimeLog.beginstoresresourceandsqlas audit text: whatever the existingPostgresTextrule refuses (NUL, unpaired surrogates) becomes U+FFFD. The query is cleaned before the 8 KiB cut, because U+FFFD takes 3 bytes where NUL takes 1 and the column checksoctet_length(sql) <= 8192.toPostgresText, sits next toPostgresTextinpackages/api/src/schemas.tsand reuses its regex, so the two definitions can't drift apart.invalid_request, now carrying the row's correlation id.auditcleaning is removed.Tests, one per path. Published:
postgres/Runtime.test.tssends a NUL insqland gets 400invalid_request, with the row logged holding the stand-in. Dev:DevReads.test.tsnow assertsinvalid_requestplus the row's outcome and cleanedresource. Run against main'sRuntimeLog.ts(with the dev door's cleaning removed), both fail with 503.Tested by hand
I used
pnpm dev up teamwith a Postgres and a PostHog connection inserted directly into the local database. The connector refuses loopback sources and PostHog needs a real key, but neither NUL call reaches a source.ctx.connections.sales.query("SELECT 1\u0000 AS id", …); I published it as Ada and opened it as Ben withpnpm dev shot. The action received{ code: "invalid_request", correlationId: "call_…" }. The row showspostgres.query, session, Ben,failure/invalid_request, andsql=SELECT 1� AS id./api/connections/dev-readwith the environment CLI's machine key, once with a NUL inqueryand once with one inname. Both got 400invalid_requestwith a correlation id. Both rows exist as machine calls on the PostHog connection, with U+FFFD insqland inresourcerespectively.patchy devitself never sends either query to the instance. Postgres reads PGlite fixtures, and the local PostHog binding decodesPostHogQuery, which refuses NUL, before forwarding.Surfaces
I walked CLAUDE.md's "Hit every surface" list and none of it needed changes. The wire contract is the same (docs/API.md already says every dev-door call is recorded, refusals included). Nothing changes in the CLI, the dev loop, vocabulary, migrations or company resources. On served pages, the connection pages render the stored text, and I checked them by hand.
Closes #666
Made by Claude Opus 5.5 in Claude Code, running in T3 Code.