Conversation
Add dev/bend2/ipc_stream_ordering, a checked Bend 2 model of the message-ordering rules of the Arrow IPC streaming and file formats: schema first and once, dictionaries defined before a record batch uses them, delta batches appending to an existing dictionary, replacement batches accepted in streams and rejected in files, and nothing accepted after end-of-stream. main.bend is the validating reader (a state machine over abstract messages with a dictionary table of id -> segment count) plus a writer model and a runnable trace. LAWS.bend states 22 laws, each quoting the spec sentence or the ArrowReader/ArrowWriter behaviour it formalises, and keeps four more commented out as not expressible or not modelled (8-byte padding, int64 lengths, footer consistency, footer-order delta application). PROOF.bend proves all 22; `bend PROOF.bend` prints "All terms check." in 0.3 s. The README documents the model, every law, how to run, the JS and native builds, and seven mutation tests (undefined dictionary accepted, replacement allowed in files, messages accepted after EOS, delta with no base, delta ignored, schema omitted by the writer, second schema accepted), each of which the checker rejects. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SGvC3jYdiD3415vL8FrKtx
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.
What's Changed
Adds
dev/bend2/ipc_stream_ordering/, a proof of concept that uses the Bend 2 language to specify and machine-check the message-ordering rules of the Arrow IPC streaming and file formats. Nothing outside that directory changes; no Java code is touched.main.bend: a validating reader modelled as a state machine over abstract messages (MSchema{ids},MDict{id, isDelta},MBatch{refs},MEos), with a dictionary table of id to segment count, plus a writer model (schema, dictionaries, batches, EOS) and a runnablemainthat prints six traces.LAWS.bend: 22 laws, each quoting the sentence ofColumnar.rstor theArrowReader/ArrowWriterbehaviour it formalises.PROOF.bend: proofs of all 22.bend PROOF.bendprintsAll terms check.in 0.3 s.README.md: the model, every law with its spec sentence, how to run, build and mutation results.Laws proven
schema_first,schema_accepted,schema_once.batch_needs_dictionary,batch_accepted,all_null_batch_needs_no_dictionary(the spec's all-null edge case).delta_needs_base,delta_appends(segment count grows by one).dictionary_defined,replacement_in_stream,no_replacement_in_file,undeclared_dictionary_rejected, and the invariantdeclared_start/declared_kept(the table only holds ids the schema declared).eos_accepted,nothing_after_eos,eos_is_final(trace form).spec_delta_example,spec_replacement_example_stream,spec_replacement_example_file(file reader answers exactlyaccept accept accept reject accept accept).writer_round_tripandwriter_round_trip_state: for either format, any distinct dictionary ids and any number of batches, the writer's output is accepted in full and every dictionary ends up defined.Laws commented out
Kept in
LAWS.bendwith a reason above each:metadata_padded_to_8(NOT EXPRESSIBLE): no bytes in the model, and Bend's Base has noNat.modtheory.body_length_fits_int64(NOT EXPRESSIBLE): Bend has no 64-bit integer type.footer_matches_streamand footer-order delta application (NOT MODELLED): the footer and random access are outside this model; the reader is the sequential stream reader a file embeds.Modelling choices worth a look
ArrowReader.loadDictionaryis more lenient and appends to the empty vector created from the schema. Mutation M4 shows the checker catches a switch to Java's rule.ArrowStreamReader.checkDictionariesis effectively vacuous:dictionariesis populated for every declared id ininitialize(), so!dictionaries.containsKey(id)is never true. Noted in the README; not changed here.Mutation tests
Each bug was introduced into a copy of
main.bend,bend PROOF.bendrun, and the copy discarded. All seven are rejected:batch_needs_dictionaryno_replace.fin(no_replacement_in_file)declared_keptfirst, thennothing_after_eosdelta_base.fin(delta_needs_base)segs_bump.fin(delta_appends)writer_round_tripschema_onceBuilds
bend main.bend -o out.js(26 KB, runs under node) andbend main.bend -o out(1.1 MB native via clang) both build and print the six traces. No build outputs are committed.How to run
🤖 Generated with Claude Code
https://claude.ai/code/session_015wBzfARVa1g7nkB1muT5Sj
Generated by Claude Code