Skip to content

fix(decoderbufs): default op to INSERT for protobufjs 8.2+ compatibility#182

Closed
kibae wants to merge 2 commits into
mainfrom
fix/decoderbufs-protobufjs-8.2.0
Closed

fix(decoderbufs): default op to INSERT for protobufjs 8.2+ compatibility#182
kibae wants to merge 2 commits into
mainfrom
fix/decoderbufs-protobufjs-8.2.0

Conversation

@kibae
Copy link
Copy Markdown
Owner

@kibae kibae commented May 12, 2026

Problem

Upgrading protobufjs from 8.0.x to 8.2.0 (#179) broke decoder-decoderbufs.spec.ts:

FAIL src/test/decoder-decoderbufs.spec.ts
  decoderbufs › Insert, Delete(w/FK)
    Expected: 5
    Received: 0

Root cause

The Postgres decoderbufs output plugin (the C extension) omits the op field on the wire for INSERT events to save bytes (the value would be 0, which is the proto3 implicit default).

  • protobufjs 8.0.x: A missing enum field on a proto2 message decoded to 0. We happened to read op === 0 and treated it as INSERT.
  • protobufjs 8.2.0: Fixed proto2 enum default behavior to follow the spec — a missing enum field now decodes to the first declared value.

Our enum starts with UNKNOWN = -1:

Op: { values: { UNKNOWN: -1, INSERT: 0, UPDATE: 1, DELETE: 2, BEGIN: 3, COMMIT: 4 } }

So after 8.2.0, INSERT events arrive as op = -1 (UNKNOWN) and never match ProtocolBuffersOperation.INSERT.

Fix

Add an explicit "default": "INSERT" to the op field so messages without an op on the wire decode as INSERT(0). This matches the wire-format intent of postgres-decoderbufs and works on both 8.0.x and 8.2.0.

Verification

With protobufjs@8.2.0 and PG 17:

PASS src/test/decoder-decoderbufs.spec.ts
  decoderbufs
    ✓ Insert, Delete(w/FK) (1671 ms)
    ✓ Update (1120 ms)

Test Suites: 6 passed, 6 total
Tests:       16 passed, 16 total

Related

Unblocks #179 (bump protobufjs from 8.0.1 to 8.2.0).

dependabot Bot and others added 2 commits May 12, 2026 01:57
Bumps [protobufjs](https://github.com/protobufjs/protobuf.js) from 8.0.1 to 8.2.0.
- [Release notes](https://github.com/protobufjs/protobuf.js/releases)
- [Changelog](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md)
- [Commits](protobufjs/protobuf.js@protobufjs-v8.0.1...protobufjs-v8.2.0)

---
updated-dependencies:
- dependency-name: protobufjs
  dependency-version: 8.2.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
protobufjs 8.2.0 fixed proto2 enum default behavior: a missing enum
field now decodes to the first declared value (UNKNOWN = -1) instead
of being implicitly set to 0. Postgres decoderbufs omits the 'op' field
for INSERT events, so messages arrived with op=-1 (UNKNOWN) instead of
op=0 (INSERT), breaking type detection.

Add explicit "default": "INSERT" to the op field so decoderbufs row
messages without an op field decode as INSERT, matching the wire-format
intent of postgres-decoderbufs.
@kibae
Copy link
Copy Markdown
Owner Author

kibae commented May 12, 2026

Closing — this was a workaround for what turned out to be an upstream protobufjs 8.2.0 regression (see #179). The right fix is to wait for an upstream patch rather than papering over it in our proto definition. Will file a protobufjs issue separately.

@kibae kibae closed this May 12, 2026
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.

1 participant