PR #483 — Conventions and duplication review (head 2b4a31e, base main 27716185)
Key findings
No blocking findings and no should-fix findings remain in this lens. The revised head resolves every structural finding from my earlier pass on this PR: patch width now comes from prepared metadata instead of a lookup table keyed on patches_per_feature, the duplicated pixel-width table in conditioned.rs is gone, atomic spans are emitted by the layout that builds the envelope rather than by the prompt dispatcher, and the Gemma 4 envelope test no longer shells out to Python. Seven nits remain, all recorded below with fixes; the only one with structural risk is nit 1 (per-profile patch width authored twice, in two matches keyed on different enums, linked only by a test).
Rules applied: docs/design-review.md:31-52 (principle 3 — shared input packing and frontend processing, model-dependent behaviour expressed through prepared metadata, no enum or metadata field acting as a model allowlist), :25-26 and principle 13 (append, do not renumber, prepared contract requires approval), and AGENTS.md:31-36 (read design-review before reviewing). The charter line "Keep the runtime small and model-agnostic" (read_charter) is the same requirement stated at project level.
What closed since the previous pass (verified in code, not just in the reply)
patches_per_feature → patch widthtable removed.helios/src/frontend/images/packing.rs:16-32now hasbracketed_patch_features(&VisionCapabilities)(prepared metadata;0means the legacy1176) plussquare_merge_side(patches_per_feature)usingisqrtand rejecting non-squares.tensor_layouttakes&VisionCapabilities(packing.rs:34-39) and theBracketedarm reads width from it (packing.rs:49-56);bracketed()derives the merge stride the same way. This is the metadata route principle 3 asks for, and it removes the model-identity encoding (DeepSeek already usespatches_per_feature = 9with588floats, so the old key was ambiguous).- Second width table in
conditioned.rsremoved.mod.rs:459-471ImageProcessor::patch_features()is now the single per-profile authority, andconditioned.rs:187calls it. ThePaddedGrid = 1200/PatchMerge = 1176cache-validation path is covered by the profile loop. - Atomic spans moved into the layout.
layouts/bracketed.rs:52-111buildsspansfrommm_token_type_idsruns and returns them inPromptData, mirroringlayouts/deepseek.rs:149;model/prompt.rs:52-65now passes only anatomic_spansbool derived fromimage_tokens.span. The former generic span-filling block inmodel/prompt.rsis gone. - Gemma 4 span coverage exists.
model/prompt.rs:1171-1256bracketed_layout_emits_atomic_spans_only_when_contract_declares_them(two spans, marker assertions, 64-aligned chunk rejection, no-span case), plus server-side bounds atserver/config.rs:935-1021. - Test no longer duplicates the template machinery.
gemma4.rs:394-402writes the{% mark %}{{ messages[0].content }}template inline, matchingmodel/prompt.rs:428,patch_merge.rs:266,server/config.rs:613; the live-parity test is#[ignore]d with hard assertions (gemma4.rs:522-531). - New tag has a round-trip test.
runtime_core/protobuf.rs:812-860serialized_gemma4_profile_selects_only_image_preparation, next to the GLM and padded-grid equivalents.
Nits (severity: nit — none block merge)
Nit 1 — Per-profile patch width still authored twice, in two matches over different enums
Files: helios/src/frontend/images/packing.rs:41-100, helios/src/frontend/images/mod.rs:459-471, test packing.rs:695-824.
tensor_layout maps ImageLayoutKind → pixel width (Qwen|Mimo → 1536, Bracketed → bracketed_patch_features(vision), Radio → 768, …), while ImageProcessor::patch_features() maps Profile → the same widths (mod.rs:461-469). Nothing links the two at compile time; only processor_patch_features_match_tensor_layout_for_every_profile (packing.rs:695, 11 cases to packing.rs:808-823) notices a drift, and it can only enumerate profiles someone remembered to add. Why it matters: a new profile (or a changed default) that is added to one table and not the other produces a silently wrong upload buffer extent, caught only if a test case is also added. Fix: make one delegate to the other, e.g. tensor_layout takes the ImageProcessor (or a patch_features value derived from the profile) instead of re-deriving it from capabilities, so a single match is authoritative. Graded nit because the duplication is bounded to two tables over the same 11 profiles and is test-covered today.
Nit 2 — patch_features() accessor bypassed inside process
File: helios/src/frontend/images/gemma4.rs:54-56 vs gemma4.rs:132.
Processor::patch_features() computes 3 * self.patch_size * self.patch_size, and process re-inlines exactly that expression when sizing the pixel buffer: let patch_features = 3 * self.patch_size * self.patch_size; (:132). Why it matters: the value the loader validates against vision.patch_features (server/config.rs:448-463) and the value used to size the buffer must agree; two spellings invite a one-sided edit. Fix: let patch_features = self.patch_features();. Pre-existing analogue: patches.rs:89 does the same inlining, so this is consistency with the wrong neighbour rather than a regression.
Nit 3 — Soft-token allowlist duplicated across the language boundary
Files: helios/src/frontend/images/gemma4.rs:13 (SUPPORTED_SOFT_TOKENS: [70, 140, 280, 560, 1120]) and ignition/preparation/frontend.py:132 (max_soft_tokens not in (70, 140, 280, 560, 1120)).
Both sites cite defence-in-depth deliberately (the Rust comment at gemma4.rs:11-12 says so), and no neighbouring profile enumerates an allowlist (deepseek_row_major.rs:14 (not opened) validates a range), so there is no in-repo precedent to follow. Why it matters: adding a Gemma 4 soft-token budget requires editing two files in two languages with no test asserting they match. Fix: accept as-is, or have Ignition emit the allowed set in Gemma4ImageSettings so Helios validates against prepared metadata (which principle 3 prefers).
Nit 4 — Shared Envelope still homed in patch_merge
File: helios/src/frontend/images/patch_merge.rs:10-17; imported at gemma4.rs:8.
The doc comment now says it is "shared by PatchMerge and Gemma4 image preparation profiles", i.e. the type has become a general frontend construct but lives in one profile's module. Why it matters: the next enveloped profile imports from super::patch_merge::Envelope, which reads as depending on the PatchMerge profile. Fix: move it to frontend/images/envelope.rs (not opened) (or next to ImageGeometry in mod.rs) with patch_merge re-exporting or importing.
Nit 5 — server::config reaches into image-packing internals
File: helios/src/server/config.rs:456-464.
validate_loaded_image_processor calls crate::frontend::images::packing::bracketed_patch_features(vision) to compute the legacy-default expectation for the Bracketed mismatch error. The rule ("patch_features == 0 means 1176") is packing knowledge, restated in the server layer. Why it matters: layering — server::config otherwise talks to ImageProcessor/VisionCapabilities accessors (compare processor.patch_features() and processor.max_image_envelope_tokens() on the lines above and below). Fix: add VisionCapabilities::bracketed_patch_features() (or an ImageProcessor accessor) and call that.
Nit 6 — Fixture generator copies helpers from the GLM generator
Files: tests/frontend/generate_gemma4_image_fixtures.py:17-25 vs tests/frontend/generate_glm_image_fixtures.py:18-25 (pattern and digest are byte-identical apart from the comment).
Every generator in tests/frontend/ is written standalone, so this matches the existing convention; the duplication is real but consistent. Fix: optional shared helper module; not worth a change on its own.
Nit 7 — Marker-presence check partially duplicated with validate_prompt_data
File: helios/src/frontend/images/layouts/bracketed.rs:57-65 vs helios/src/model.rs:441-456.
flush_span rejects start == 0 || end >= len ("missing envelope markers"), while validate_prompt_data already asserts tokens[s.start] == span.start_token && tokens[s.end-1] == span.end_token for every declared span. The layout check only proves a marker slot exists, not that it is the declared marker, so the stronger check lives one layer away. Why it matters: two places encode the same invariant with different strength; a reader must check both to know what is guaranteed. Fix: none required (the layout check yields a clearer per-request error); if touched, express it as the same predicate as model.rs or drop it and rely on validate_prompt_data.
Precedents that hold (checked, no finding)
- Proto:
ImageSettings.profiletag 11 andGemma4ImageSettingsmirrorPatchMergeImageSettings(helios/proto/runtime_core.proto:278-281,446-451,582-603);VisionCapacity.patch_featurestag 6 with#[serde(default)]follows the additive-tag convention. Enum value appended, not renumbered — the design-review principle-13 requirement. - Contract enum:
contract_enum!addsGemma4 = 11atmodel/contract.rs:68, appended; wire ids preserved. - Runtime-core rendering:
describe.rs:451-452andprotobuf.rs:168-172add arms adjacent to their PatchMerge arms rather than introducing a new dispatch shape. - Image preparation:
ImageSettings::Gemma4/Gemma4ImageSettingsand theProfile::Gemma4arms inmod.rs(load, geometry,resized_rgb,process,expand_prompt,preparation_kind) mirror thePaddedGrid/PatchMergearms;gemma4.rsreusesresize::resize(uint8 antialiased bicubic) likepatch_mergeandqweninstead of adding a kernel. - Ignition: the
gemma4branch (ignition/preparation/frontend.py:114-173) mirrors theglmbranch (:174+) —_expectedfor required fields, filtered_expectedfor optional ones, and the same atomic-token single-vocabulary check used by_native_image_placeholder(frontend.py:270-275). - Genuine de-duplication: the
Envelopeextraction (patch_merge.rs:10-81) removes a second copy of the start/feature/end expansion logic that Gemma 4 would otherwise have had.
Open questions and limits
- Not a finding, checked and dismissed: the regenerated
ignition/preparation/runtime_core_pb2.pyheader readsProtobuf Python Version: 7.36.1(:5) whilepyproject.toml:34pinsprotobuf>=7.36.2,<8. The same7.36.1header is already onmain(runtime_core_pb2.py:5atmain), so the PR preserves the existing state; the author's description claims it matchesorigin/main, which is true. Left as an observation only. - Coverage: every changed file was read at
pr/483in context, or — for the mechanical additions — seen via diff:flare-cli/tests/unverified_payload.rs(not opened),helios/tests/deepseek_requests.rs(not opened),server/{models,protocol/decode,request,runtime}.rs,scheduler/{boundary_tests,cache_memory,vision_window_tests}.rsare one-linepatch_features: 0struct fills;tests/frontend/gemma4_images.json(not opened) is consumed only through the Rust fixture reader atgemma4.rs:277-333; the regenerated descriptor blob inruntime_core_pb2.pywas checked at its header and version lines only. - Limits: no build or test was run in this environment, so behavioural claims come from reading code and callers; the author's test counts are their own evidence. Numerical parity with the Hugging Face processor, load-path cost, serving behaviour, and partial-span prefix-cache behaviour are outside this lens and are covered by other reviewers.