Skip to content

fix: avoid unrecoverable database write failures - #400

Merged
Sekhmet merged 3 commits into
masterfrom
sekhmet/presave-checks
Aug 3, 2026
Merged

Sekhmet merged 3 commits into
masterfrom
sekhmet/presave-checks

Conversation

@Sekhmet

@Sekhmet Sekhmet commented Aug 3, 2026

Copy link
Copy Markdown
Member

SX API in some cases writes bad data into ORM. This previously was handled as failures would be surfaced on .save call.
But now as writes are buffered this becomes an issue when writes are flushed and at this point it's not possible to handle that at writer level.

To avoid that we add two edge case handling in ORM setter:

  1. varchar overflows 256 characters.
  2. varchar or string based value contains NUL byte.

When writer tries to set such value it will throw in-place where writer can react to it.

There was another issue with jsonb index size. This index isn't actually used for the queries we use (not applicable for operators we use), so we simply remove it.

Sekhmet added 2 commits August 3, 2026 14:06
Some values can throw when writing to Postgres.

This includes text longer than 256 bytes for varchars and
NUL byte in string based values.

Before it would throw when calling save, which could be handled with
try/catch, but with writes now buffered we need to check that case ahead
of time.
This index has length restrictions which caused some writes to fail.

This index was not used as it doesn't apply to operators with use on
jsonb columns.
@Sekhmet
Sekhmet requested a review from bonustrack August 3, 2026 12:25

@bonustrack bonustrack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK

@tony8713 tony8713 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran both halves against a local Postgres 16. They do what the description says, and the jsonb index removal is the half that actually unblocks a stuck indexer: a btree over a jsonb column rejects any row whose index tuple gets too big (index row size 4496 exceeds btree version 4 maximum 2704). The value itself is perfectly legal, so no amount of writer-side validation can save it. It trips on incompressible content rather than on big JSON, which is why it looks intermittent in production. If that's the "writes stopping our indexers", this is it.

One thing I'd fix before merge (value !== null in codegen) plus a deploy note, inline.

Nothing here touches ids, dedup or conflict handling, so it won't move the delegatedVotes drift.

Approving.

🤖 Generated with Claude Code

Comment thread src/graphql/controller.ts Resolved
Comment thread src/codegen.ts Resolved
Comment thread test/unit/codegen.test.ts Resolved
@tony8713

tony8713 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fixed: a number into a Decimal field, a number into an Int-keyed ref and undefined into a nullable String all persist as they do on master again, and the 256-char / NUL / 256-emoji behaviour is unchanged.

Also correcting myself on the test thread: the jsonb change is already covered, reverting that index line fails the createEntityStores snapshot. That half of my ask was wrong.

🤖 Generated with Claude Code

@Sekhmet
Sekhmet merged commit d7302f3 into master Aug 3, 2026
1 check passed
@Sekhmet
Sekhmet deleted the sekhmet/presave-checks branch August 3, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants