Repository navigation
The TypeScript member merge copies documents without decoding them, so a string that is not UTF-8 reaches the converter - #1962
Conversation
scip_merge_indexes.py parsed each member's index as one scip.Index, and python-protobuf refuses a whole message when any string in it is not UTF-8. scip-typescript writes such strings, so one document failed the merge, and the pass, after every member had been indexed. The merge now reads the top-level records and each document's relative_path with the converter's reader, applies the same ownership rule, and writes the kept records out byte for byte. Nothing is decoded, the parts are memory-mapped, and the converter decides what to do with a document it cannot read. The output is written beside its target and swapped in with os.replace, so --output may name one of the inputs while those are still mapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
The merge preserves an undecodable string for the converter. It also accepts truncated top-level records that the old merge rejected.
_top_level_records cut a record to the bytes that were left when its declared length ran past the end of the data. The merge then wrote a fresh header for the shorter slice, so a truncated or damaged part came out as a valid document where the whole-index parse had refused it. The converter read the same slice and converted it. The reader now raises ValueError naming the offset and how far the record overruns. The merge stops with the part's name for that error and for a part that ends inside a record header. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The length-delimited truncation tests pass. The merge still accepts a truncated fixed-width record that the protobuf parser rejects.
_top_level_records bounds-checked length-delimited records only. A fixed32 or fixed64 field cut short was skipped by moving past the end of the data, so a part whose valid records were followed by one payload byte merged and converted with exit 0 where the protobuf parser refuses the index. The reader now refuses what the parser refuses and raises ValueError in the existing form: fixed32 and fixed64 spans that run past the end, a varint or tag that runs off the end or exceeds ten bytes, field number 0, and unbalanced or mismatched groups and wire types 6 and 7. A closed group in an unknown field is skipped, as the parser skips it. The merge's IndexError branch is gone because the reader no longer raises it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The truncated fixed-width records are rejected. A field number outside protobuf’s allowed range can still pass the new reader.
_top_level_records refused only field number 0. A field number of 2**29 or more, at the top level or in a group tag, is refused by the parser but was skipped here, so a part carrying one merged and converted with exit 0. Tags and length prefixes are now read as the parser reads them: a varint of at most five bytes that fits in 32 bits, which bounds the field number to 1..2**29 - 1. Value varints keep the ten-byte limit. The reserved range 19000..19999 and redundant trailing zero bytes inside the five-byte limit are accepted, as the parser accepts them. Lengths of 2**63 and above were already refused and are pinned. Behaviour was compared with the upb parser, the installed default. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The 159 focused merge and converter tests pass, including the new tag bounds. A valid document can still be merged under the wrong path.
_document_path returned the first relative_path record in a document. The protobuf parser keeps the last value of a singular field, so a document carrying pkg/first.ts then pkg/second.ts is pkg/second.ts, and the merge treated it as pkg/first.ts and dropped a separate pkg/first.ts document as its duplicate. The converter shares the reader and ordered, filtered and deduplicated by the wrong path. _document_path now returns the last relative_path. Metadata is the other singular field read from raw records: the parser merges repeated metadata records, but _project_root used the first and the merge copied only the last. _project_root now merges every metadata record before the first document, and the merge copies every metadata record of the first part. Document, symbol and occurrence fields are parsed by the protobuf runtime and need no change. Each reader is compared with the parser on the same bytes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 0267d57. Configure here.
A value varint of ten bytes is accepted whatever its tenth byte holds. The protobuf parser (upb, and the pure-Python backend) accepts it, so a part with such a trailing unknown varint parses whole and merges the same way. Tag and length varints are bounded at five bytes and refused beyond, as the parser refuses them. The reader already matches, so this adds tests only: a value varint ending in 0x00, 0x01, 0x02 or 0x7f, at top level and inside a group, is accepted by the reader and the merge, each compared with the parser. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The last relative_path value now wins for duplicate protobuf fields, and all 189 focused tests passed. Distinct document paths can still collapse into one merge record.
The merge keyed documents by the relative_path decoded with replacement, so two paths that differ only by a malformed byte and a literal U+FFFD collapsed to one key and the later document replaced the earlier one. Reversing the inputs dropped the other document. The merge now keys on the raw path bytes (the last value of field 1) and decodes the path only to ask which project owns it. Ownership is unchanged: both names decode to the same text, so both get the same answer. scip_to_delta gains _document_path_bytes; _document_path decodes it as before. The new test merges a document named with a 0xff byte and one named with U+FFFD, in both input orders, with and without a project; both survive. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
mypy on the two modules stays at its baseline of 54 errors. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The analyzer job reports the same mentor evidence shape mismatch on this head's tested base. The focused test passes on current main with the snapshot update from #1957. The existing digest repair in #1990 addresses the SQL comment that made the literal affect the shape. Failed CI job · Digest repair
The merge keys its documents on raw bytes, so a caller that matches the kept set against member paths (text) would never find a path in it. merge_indexes now returns the kept paths decoded with "replace", the same text ownership reads, and deduplication still runs on the bytes. The unused `_document_path` alias is gone; the one test that read the converter's function through it names the converter. Assisted-by: Claude Code:claude-sonnet-5-5 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
Raw path keys now preserve both documents in the earlier collision. The merge can still truncate an input when it opens the temporary output.
An input named <output>.tmp was truncated when the merge opened its temporary output, and removed on an error. Create the temporary beside the output with exclusive creation under a fresh name, then replace the output once the write succeeds. Assisted-by: Claude Code Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The merge uses an exclusive temporary file beside the output. It preserves an input named like the old temporary path and replaces the output only after the write succeeds. All 195 focused merge and converter tests passed.

Related: #1959
Related: #1782
Related: #1704
This covers the merge case of the linked issue. A pass over such a document completes only together with #1704 (open), which would make the converter skip the document; without it the pass still exits 1, one step later, in the converter.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The merge of a TypeScript pass over member projects no longer fails when one document holds a string that is not valid UTF-8: the merge copies the documents without decoding them. With the converter change in #1704, such a document is skipped and its file keeps its rows, marked stale.
Why
scip_merge_indexes.pyparsed each member's index as onescip.Index, and python-protobuf refuses the whole message when any string in it is not valid UTF-8. scip-typescript writes such strings, so on the repository from #1678 every pass that indexes itssrcproject exited 1 in the merge, after every member had been indexed. #1704 (open) would make the converter skip an undecodable document, but that cannot help while the merge parses first.The merge needs only the top-level records and each document's
relative_pathfor the ownership rule. It now reads those with the converter's_top_level_recordsand_document_path, applies the same rule (_keeps, the body moved out of the loop), and writes the kept records out byte for byte. The parts are memory-mapped through the converter's_read_index, so a part is never held as parsed messages.Scope and risk
scripts/scip_harness/scip_merge_indexes.pyand its tests. The output is written to<output>.tmpand moved over--outputwithos.replace, because the parts stay memory-mapped while it is written;--outputmay name one of the inputs. The CLI, the ownership rule, the order of documents, which copy of a path wins, the metadata from the first non-empty part and the concatenated external symbols are as before; the existing merge and harness tests pass with only their protobuf loader changed. A document the converter cannot decode now reaches the converter: with #1704 it is skipped and its file keeps its rows, marked stale; without it the converter fails withDecodeError ... 'scip.Document', as it does on a non-member index today._ensure_scip_pb2leaves the merge, which no longer imports protobuf; the tests load the vendored bindings themselves.The file-name case in the linked issue is not part of this change.
Compatibility, rollout and rollback
Tests
tests/unit/test_scip_merge_indexes.py::test_merge_copies_a_document_whose_strings_are_not_utf8: one part holds an owned document, an owned document with a string that is not UTF-8 and a document another member owns. The merge keeps the first two, with the invalid bytes as they were, and drops the third. Onmainit fails withDecodeError: ... String field had bad UTF-8atscip_merge_indexes.py:95.test_merge_may_write_over_one_of_its_inputs:--outputnames one of the inputs. It passes onmaintoo, and guards the mapped-input case for the rewrite (writing in place truncates a mapped part).test_merge_keeps_every_parts_external_symbols: the external symbols of two parts are concatenated in order. It passes onmaintoo and pins that behaviour for the rewrite.831373cdf, cut frommainat3058a5816: the merge,test_run_typescript_delta_umbrella.py,test_run_typescript_delta_projects.pyandtest_scip_ts_projects.pytests, 51 passed;test_tunable_constants.pyandtest_public_copy.pypass.ruff check,ruff format --check, the function-length gate and mypy on the merge module pass.scripts/gates/mypy_gate.pyreports errors inserver/llm/vertex_auth.pyon this host (missinggoogle.authstubs in the environment), a file this change does not touch. The full unit suite was not run here; CI runs it.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and the tests. Checked: I reviewed the whole diff and its tests; the runs listed under Tests are the agent's.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py). None are affected.main; no merged migration is edited. There is no migration.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version: no plugin file changed.npm --prefix frontend run build) and its tests pass, iffrontend/changed: it did not.docs/describe the system as it now is, and this description names any operator steps and wire changes: no page describes the merge's parsing.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Note
Medium Risk
Core TypeScript index merge path changes parsing and I/O behavior; correctness is heavily tested but any mismatch in streaming protobuf logic could affect indexing passes.
Overview
Replaces whole-index protobuf parsing in
scip_merge_indexes.pywith a byte-level stream merge: it walks top-level SCIP records via shared helpers fromscip_to_delta, keys documents on raw path bytes (UTF-8 decode only for ownership), and re-serializes kept payloads unchanged—so indexes containing non-UTF-8 strings no longer fail in the merge step. Output is written through a temp file +os.replaceso inputs can be memory-mapped and--outputcan name an input file;merge_indexesnow returns the set of kept document paths as text.scip_to_delta._top_level_recordsis tightened to reject or skip wire data the same way python-protobuf does (varint/tag/length limits, groups, corrupt tails)._document_path_bytesand metadata merging in_project_rootalign streaming reads with parser semantics. Tests add broad coverage for UTF-8 documents, corruption, protobuf parity, and converter CLI behavior.Reviewed by Cursor Bugbot for commit cdc76fe. Bugbot is set up for automated code reviews on this repo. Configure here.