Skip to content

Fail on a new required field that old rows would decode as zero - #4

Merged
long1dev merged 3 commits into
mainfrom
feat/proto-new-required
Nov 2, 2026
Merged

long1dev merged 3 commits into
mainfrom
feat/proto-new-required

Conversation

@long1dev

@long1dev long1dev commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

The generated decoder guards only nullable fields with hasX(), so a required field a row never wrote takes its zero value. The proto history has 34 such additions in 28 commits, and nothing looked at them.

  • The ledger records messages and required fields. A new required field on a known message fails until it names a decoder under compat, or says why the zero value is right under zero_value_ok. A rename counts, as old rows hold the old number. A field on a new message passes, and oneof arms are not counted.
  • A decoder may sit on a parent's converter if its body names the message, as _decodeOperationCompat does for LabellingInfo.
  • --update records only what cannot lose data. A message that disappears fails until it is deleted from the ledger by hand, as renaming one keeps its rows.
  • A ledger missing a section is refused. Accepting the proto as it is takes an explicit --init, which refuses a ledger that has messages.

Testing

  • ./check.sh passes: 56 tests in cb_lints, 62 in cb_checks.
  • Replaying the 28 proto commits, with a ledger seeded from each and checking the next, finds exactly 34 new required fields and the real Invoice.due_date drop, with no other output.
  • On copies of cb-mobile's proto, ledger and converters: --init passes at 939 optional and 862 required fields. A new required field and a renamed message fail, and --update leaves them failing. A new OperationInfo arm passes. A ledger missing messages is refused.

An independent review found the oneof, rename, damaged-ledger and validation problems fixed here. These fixes have not been reviewed again.

Not covered

  • A decoder on a table's converter does not reach a copy of that message embedded in another blob, such as the entities inside a queued operation. The check cannot see that, or whether the decoder touches the field.
  • A field that changes type, or a new value at the front of an enum.
  • Fixing @Default fields at the source would be stronger: emit them as optional and decode hasX() ? x : <default>. model_spec.dart already records hasDefault.

After merging: tag v1.3.0, then in cb-mobile move both pins, run --init once, and update CLAUDE.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UESkdYVqQ7NhmMmMfG7ov2

long1dev and others added 3 commits November 2, 2026 04:19
The generated decoder guards only nullable fields with hasX(), so a required
field a row never wrote takes its zero value: a @default(true) bool becomes
false, an enum its first value. The proto's history has 34 such additions in
28 commits, and nothing looked at them.

The ledger now records messages and required fields. A new required field on a
known message fails until it names a decoder, or says under "zero_value_ok" why
the zero value is right. A rename that drops optional is one of these, as old
rows hold the old number. A field on a new message passes, as no old row has it.

--update records only what cannot lose data, so it cannot hide either edit. On a
ledger with no messages it records everything, once. Replaying the 28 commits
finds exactly those 34 fields and the real Invoice.due_date drop.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01UESkdYVqQ7NhmMmMfG7ov2
LabellingInfo and the like are stored inside Operation, so _decodeOperationCompat
is on ProtoEntityConverter<Operation>. Requiring the field's own converter would
reject that correct pattern. It now passes if the decoder's body names the
message, and an unrelated decoder still fails.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01UESkdYVqQ7NhmMmMfG7ov2
Replaying real edits showed oneof arms counted as required, so every new
OperationInfo arm failed with no valid way through. They are now neither.

Renaming a message passed through --update, though its rows remain, so a message
that disappears now fails until it is deleted from the ledger by hand. A removed
required field is dropped by --update, so adding it back counts as new.

A damaged ledger could wipe the record through --update. Parsing now refuses a
missing section, and accepting the proto as it is takes an explicit --init that
refuses a ledger with messages. Every compat entry is validated, and an empty
reason no longer counts.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01UESkdYVqQ7NhmMmMfG7ov2
@long1dev
long1dev merged commit 4f4a7da into main Nov 2, 2026
2 checks passed
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