From ba424bd82f53a9c711c5e225f9ae8054820a3b77 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sat, 18 Apr 2026 15:55:01 -0700 Subject: [PATCH] Trace infrastructure outlier prefix classes --- crates/rrt-runtime/src/smp.rs | 343 ++++++++++++++++++++++++++++++++-- 1 file changed, 327 insertions(+), 16 deletions(-) diff --git a/crates/rrt-runtime/src/smp.rs b/crates/rrt-runtime/src/smp.rs index 0ae90fd..ae9fd3d 100644 --- a/crates/rrt-runtime/src/smp.rs +++ b/crates/rrt-runtime/src/smp.rs @@ -2242,6 +2242,42 @@ pub struct SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanCorrelat #[serde(default)] pub mode_family_counts: Vec, + #[serde(default)] + pub compact_prefix_pattern_summaries: + Vec, + #[serde(default)] + pub sample_rows: Vec, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + pub prefix_leading_dword: u32, + pub prefix_leading_dword_hex: String, + pub prefix_trailing_word: u16, + pub prefix_trailing_word_hex: String, + pub prefix_separator_byte: u8, + pub prefix_separator_byte_hex: String, + pub count: usize, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanSample { + pub sample_index: usize, + pub name_tag_relative_offset: usize, + #[serde(default)] + pub primary_name: Option, + #[serde(default)] + pub secondary_name: Option, + pub prefix_leading_dword: u32, + pub prefix_leading_dword_hex: String, + pub prefix_trailing_word: u16, + pub prefix_trailing_word_hex: String, + pub prefix_separator_byte: u8, + pub prefix_separator_byte_hex: String, + pub child_count_candidate: u16, + pub child_count_candidate_hex: String, + pub saved_primary_child_byte_candidate: u8, + pub saved_primary_child_byte_candidate_hex: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -4687,7 +4723,7 @@ fn build_infrastructure_asset_trace_report( }) .map(|correlation| { format!( - "current save-side probe now also shows the short 0x03-byte post-profile gaps collapsing cleanly to the next-record prelude: dominant candidate pattern is {}/{} x{} across {} rows", + "current save-side probe now also shows the short 0x03-byte post-profile gaps collapsing cleanly to the next-record prelude: dominant candidate pattern is {}/{} x{} across {} rows, mode counts={:?}, prefix counts={:?}", correlation .dominant_candidate_pattern .as_ref() @@ -4703,12 +4739,74 @@ fn build_infrastructure_asset_trace_report( .as_ref() .map(|pattern| pattern.count) .unwrap_or_default(), - correlation.row_count + correlation.row_count, + correlation + .mode_family_counts + .iter() + .map(|mode| format!("{}:{}", mode.mode_family, mode.count)) + .collect::>(), + correlation + .compact_prefix_pattern_summaries + .iter() + .map(|prefix| format!( + "{}/{}/{}:{}", + prefix.prefix_leading_dword_hex, + prefix.prefix_trailing_word_hex, + prefix.prefix_separator_byte_hex, + prefix.count + )) + .collect::>() ) }) .unwrap_or_else(|| { "no grounded 0x03-byte post-profile span correlation was available for the prelude candidates".to_string() }), + side_buffer + .and_then(|probe| probe.payload_envelope_summary.as_ref()) + .and_then(|summary| summary.name_prelude_candidate_summary.as_ref()) + .and_then(|summary| { + summary + .profile_span_correlations + .iter() + .find(|row| row.previous_profile_chunk_len_to_next_name_or_end == 0x27) + }) + .map(|correlation| { + format!( + "the sparse 0x27 post-profile outlier is now explicit too: mode counts={:?}, prefix counts={:?}, sample rows={:?}", + correlation + .mode_family_counts + .iter() + .map(|mode| format!("{}:{}", mode.mode_family, mode.count)) + .collect::>(), + correlation + .compact_prefix_pattern_summaries + .iter() + .map(|prefix| format!( + "{}/{}/{}:{}", + prefix.prefix_leading_dword_hex, + prefix.prefix_trailing_word_hex, + prefix.prefix_separator_byte_hex, + prefix.count + )) + .collect::>(), + correlation + .sample_rows + .iter() + .map(|sample| format!( + "{}:{:?}/{:?}@{}/{}/{}", + sample.name_tag_relative_offset, + sample.primary_name, + sample.secondary_name, + sample.prefix_leading_dword_hex, + sample.prefix_trailing_word_hex, + sample.prefix_separator_byte_hex + )) + .collect::>() + ) + }) + .unwrap_or_else(|| { + "no grounded 0x27 post-profile outlier correlation was available for the prelude candidates".to_string() + }), side_buffer .and_then(|probe| probe.payload_envelope_summary.as_ref()) .and_then(|summary| summary.name_prelude_candidate_summary.as_ref()) @@ -4769,7 +4867,7 @@ fn build_infrastructure_asset_trace_report( "the smaller attach primitive 0x00490a3c no longer looks like the semantic fork by itself: it just allocates one literal Infrastructure child, seeds it through 0x455b70 with caller-provided stem input, attaches it through 0x5395d0, seeds position lanes through 0x539530/0x53a5b0, and optionally caches it as primary child".to_string(), ], blockers: vec![ - "how the remaining compact-prefix regimes subdivide the tiny residual outlier spans inside the dominant mixed 0x0001/0xff class, now that the new mode-family correlations already narrow grounded q.gms to bridge:62 / track_cap:21 / tunnel:19 overall and further split the prior 0x55f3 spans as 0x06 -> pure bridge, 0x03 -> mostly tunnel with a small track-cap residue, 0x0f/0x2d/0x33 -> track_cap, 0x36 -> tunnel, leaving only sparse mixed outliers such as 0x27".to_string(), + "how the exact residual compact-prefix patterns map back onto constructor semantics now that the mixed 0x0001/0xff class is narrowed to concrete outliers: span 0x03 stays entirely on 0x000055f3/0x0001/0xff but still mixes tunnel with a tiny track-cap residue, while span 0x27 splits cleanly between 0xff0000ff/0x0001/0xff tunnel residue and 0xff0000ff/0x0002/0xff bridge residue".to_string(), "how the payload streams reached through 0x00518380 -> 0x00518140 align with the embedded 0x55f1 name-pair groups and compact-prefix regimes surfaced by the save-side probe".to_string(), "how the observed 0x55f3-to-next-0x55f1 gaps partition between the two 0x52ebd0 flag bytes and the next-record prelude now that 0x0048a6c0 is grounded as the writer for the outer child-count / primary-child prelude".to_string(), "which fields written through the grounded 0x00490960 -> 0x004559d0 -> slot +0x4c -> 0x52ec50 chain retain the 0x38a5 embedded name-pair semantics before route/local-runtime follow-ons take over".to_string(), @@ -4884,7 +4982,7 @@ fn build_infrastructure_asset_trace_report( ), ]; let notes = vec![ - "Infrastructure asset trace now makes the side-buffer-versus-triplet split explicit: owner seam identity is grounded, the pure bridge-only 0x0002/0xff candidate class is grounded save-side, the upstream chooser above the child attach path is grounded as paired DT/ST siblings at 0x004a2c80 and 0x004a34e0 with decoded Bridge/Tunnel/BallastCap/Overpass families, grounded top-level branch meaning, grounded bridge/tunnel material selector roles, a concrete child-construction/write-side chain through 0x00490960, 0x00491c60, 0x0048a6c0, 0x00455a40, and 0x004559d0, and stable 0x00490960 mode families for BallastCap, TrackCap, Overpass, Tunnel, and Bridge branches. The current save-side name corpus already maps BallastCap, TrackCap, Tunnel, and Bridge rows onto those families directly, the candidate-pattern correlation narrows the dominant mixed 0x0001/0xff class to bridge:62 / track_cap:21 / tunnel:19, and the profile-span correlation further splits most of that mixed class by prior 0x55f3 span, leaving only sparse outlier spans such as 0x27 and the small track-cap residue inside 0x03 as the remaining unknown.".to_string(), + "Infrastructure asset trace now makes the side-buffer-versus-triplet split explicit: owner seam identity is grounded, the pure bridge-only 0x0002/0xff candidate class is grounded save-side, the upstream chooser above the child attach path is grounded as paired DT/ST siblings at 0x004a2c80 and 0x004a34e0 with decoded Bridge/Tunnel/BallastCap/Overpass families, grounded top-level branch meaning, grounded bridge/tunnel material selector roles, a concrete child-construction/write-side chain through 0x00490960, 0x00491c60, 0x0048a6c0, 0x00455a40, and 0x004559d0, and stable 0x00490960 mode families for BallastCap, TrackCap, Overpass, Tunnel, and Bridge branches. The current save-side name corpus already maps BallastCap, TrackCap, Tunnel, and Bridge rows onto those families directly, the candidate-pattern correlation narrows the dominant mixed 0x0001/0xff class to bridge:62 / track_cap:21 / tunnel:19, and the profile-span/prefix correlation now pins the remaining outliers down to exact residual prefix patterns: 0x03 is a 0x000055f3/0x0001/0xff tunnel-dominant class with a tiny track-cap residue, while 0x27 splits between 0xff0000ff/0x0001/0xff tunnel residue and 0xff0000ff/0x0002/0xff bridge residue.".to_string(), if st_only_name_pair_corpus { "The current save-side side-buffer corpus is ST-only, so this trace directly exercises the ST chooser sibling while the DT sibling remains grounded statically but unexercised in this save.".to_string() } else { @@ -13537,10 +13635,12 @@ fn parse_save_placed_structure_dynamic_side_buffer_probe( ) .take(8) .collect::>(); - let mut name_prelude_profile_span_groups = - BTreeMap::, Option)>>::new(); + let mut name_prelude_profile_span_groups = BTreeMap::< + usize, + Vec<(usize, Option, Option, u32, u16, u8, u16, u8)>, + >::new(); for ( - _, + name_tag_relative_offset, primary_name, secondary_name, child_count_candidate, @@ -13549,14 +13649,26 @@ fn parse_save_placed_structure_dynamic_side_buffer_probe( ) in &name_prelude_candidate_rows { if let Some(previous_span) = previous_span { + let Some(row) = embedded_name_rows.get( + payload_envelope_rows + .iter() + .position(|row| row.name_tag_relative_offset == *name_tag_relative_offset) + .unwrap_or(usize::MAX), + ) else { + continue; + }; name_prelude_profile_span_groups .entry(*previous_span) .or_default() .push(( - *child_count_candidate, - *saved_primary_child_byte_candidate, + *name_tag_relative_offset, primary_name.clone(), secondary_name.clone(), + row.prefix_leading_dword, + row.prefix_trailing_word, + row.prefix_separator_byte, + *child_count_candidate, + *saved_primary_child_byte_candidate, )); } } @@ -13567,11 +13679,16 @@ fn parse_save_placed_structure_dynamic_side_buffer_probe( let mut child_count_counts = BTreeMap::::new(); let mut saved_primary_counts = BTreeMap::::new(); let mut mode_family_counts = BTreeMap::::new(); + let mut prefix_counts = BTreeMap::<(u32, u16, u8), usize>::new(); for ( - child_count_candidate, - saved_primary_child_byte_candidate, + _name_tag_relative_offset, primary_name, secondary_name, + prefix_leading_dword, + prefix_trailing_word, + prefix_separator_byte, + child_count_candidate, + saved_primary_child_byte_candidate, ) in &rows { *pattern_counts @@ -13583,6 +13700,13 @@ fn parse_save_placed_structure_dynamic_side_buffer_probe( *saved_primary_counts .entry(*saved_primary_child_byte_candidate) .or_default() += 1; + *prefix_counts + .entry(( + *prefix_leading_dword, + *prefix_trailing_word, + *prefix_separator_byte, + )) + .or_default() += 1; *mode_family_counts .entry( classify_side_buffer_mode_family( @@ -13668,6 +13792,79 @@ fn parse_save_placed_structure_dynamic_side_buffer_probe( } }) .collect(), + compact_prefix_pattern_summaries: prefix_counts + .into_iter() + .map( + |( + (prefix_leading_dword, prefix_trailing_word, prefix_separator_byte), + count, + )| { + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + prefix_leading_dword, + prefix_leading_dword_hex: format!( + "0x{prefix_leading_dword:08x}" + ), + prefix_trailing_word, + prefix_trailing_word_hex: format!( + "0x{prefix_trailing_word:04x}" + ), + prefix_separator_byte, + prefix_separator_byte_hex: format!( + "0x{prefix_separator_byte:02x}" + ), + count, + } + }, + ) + .collect(), + sample_rows: rows + .iter() + .take(8) + .enumerate() + .map( + |( + sample_index, + ( + name_tag_relative_offset, + primary_name, + secondary_name, + prefix_leading_dword, + prefix_trailing_word, + prefix_separator_byte, + child_count_candidate, + saved_primary_child_byte_candidate, + ), + )| { + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanSample { + sample_index, + name_tag_relative_offset: *name_tag_relative_offset, + primary_name: primary_name.clone(), + secondary_name: secondary_name.clone(), + prefix_leading_dword: *prefix_leading_dword, + prefix_leading_dword_hex: format!( + "0x{prefix_leading_dword:08x}" + ), + prefix_trailing_word: *prefix_trailing_word, + prefix_trailing_word_hex: format!( + "0x{prefix_trailing_word:04x}" + ), + prefix_separator_byte: *prefix_separator_byte, + prefix_separator_byte_hex: format!( + "0x{prefix_separator_byte:02x}" + ), + child_count_candidate: *child_count_candidate, + child_count_candidate_hex: format!( + "0x{child_count_candidate:04x}" + ), + saved_primary_child_byte_candidate: + *saved_primary_child_byte_candidate, + saved_primary_child_byte_candidate_hex: format!( + "0x{saved_primary_child_byte_candidate:02x}" + ), + } + }, + ) + .collect(), } }) .take(8) @@ -24563,6 +24760,35 @@ mod tests { count: 15, }, ], + compact_prefix_pattern_summaries: vec![ + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + prefix_leading_dword: 0x0000_55f3, + prefix_leading_dword_hex: "0x000055f3".to_string(), + prefix_trailing_word: 0x0001, + prefix_trailing_word_hex: "0x0001".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + count: 17, + }, + ], + sample_rows: vec![ + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanSample { + sample_index: 0, + name_tag_relative_offset: 1200, + primary_name: Some("TunnelSTBrick_Section.3dp".to_string()), + secondary_name: Some("Infrastructure".to_string()), + prefix_leading_dword: 0x0000_55f3, + prefix_leading_dword_hex: "0x000055f3".to_string(), + prefix_trailing_word: 0x0001, + prefix_trailing_word_hex: "0x0001".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + child_count_candidate: 1, + child_count_candidate_hex: "0x0001".to_string(), + saved_primary_child_byte_candidate: 0xff, + saved_primary_child_byte_candidate_hex: "0xff".to_string(), + }, + ], }, SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanCorrelation { previous_profile_chunk_len_to_next_name_or_end: 6, @@ -24592,6 +24818,18 @@ mod tests { count: 72, }, ], + compact_prefix_pattern_summaries: vec![ + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + prefix_leading_dword: 0xff00_0000, + prefix_leading_dword_hex: "0xff000000".to_string(), + prefix_trailing_word: 0x0001, + prefix_trailing_word_hex: "0x0001".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + count: 72, + }, + ], + sample_rows: vec![], }, SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanCorrelation { previous_profile_chunk_len_to_next_name_or_end: 0x27, @@ -24625,6 +24863,60 @@ mod tests { count: 1, }, ], + compact_prefix_pattern_summaries: vec![ + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + prefix_leading_dword: 0xff00_00ff, + prefix_leading_dword_hex: "0xff0000ff".to_string(), + prefix_trailing_word: 0x0001, + prefix_trailing_word_hex: "0x0001".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + count: 1, + }, + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanPrefixSummary { + prefix_leading_dword: 0xff00_00ff, + prefix_leading_dword_hex: "0xff0000ff".to_string(), + prefix_trailing_word: 0x0002, + prefix_trailing_word_hex: "0x0002".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + count: 2, + }, + ], + sample_rows: vec![ + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanSample { + sample_index: 0, + name_tag_relative_offset: 2805, + primary_name: Some("TunnelSTBrick_Section.3dp".to_string()), + secondary_name: Some("Infrastructure".to_string()), + prefix_leading_dword: 0xff00_00ff, + prefix_leading_dword_hex: "0xff0000ff".to_string(), + prefix_trailing_word: 0x0001, + prefix_trailing_word_hex: "0x0001".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + child_count_candidate: 1, + child_count_candidate_hex: "0x0001".to_string(), + saved_primary_child_byte_candidate: 0xff, + saved_primary_child_byte_candidate_hex: "0xff".to_string(), + }, + SmpSavePlacedStructureDynamicSideBufferNamePreludeProfileSpanSample { + sample_index: 1, + name_tag_relative_offset: 3764, + primary_name: Some("BridgeSTWood_Section.3dp".to_string()), + secondary_name: Some("Infrastructure".to_string()), + prefix_leading_dword: 0xff00_00ff, + prefix_leading_dword_hex: "0xff0000ff".to_string(), + prefix_trailing_word: 0x0002, + prefix_trailing_word_hex: "0x0002".to_string(), + prefix_separator_byte: 0xff, + prefix_separator_byte_hex: "0xff".to_string(), + child_count_candidate: 1, + child_count_candidate_hex: "0x0001".to_string(), + saved_primary_child_byte_candidate: 0xff, + saved_primary_child_byte_candidate_hex: "0xff".to_string(), + }, + ], }, ], sample_rows: Vec::new(), @@ -24788,11 +25080,11 @@ mod tests { trace.candidate_consumer_hypotheses[0] .blockers .iter() - .any(|line| line.contains("compact-prefix regimes subdivide") - && line.contains("bridge:62 / track_cap:21 / tunnel:19") - && line.contains("0x06 -> pure bridge") - && line.contains("0x03 -> mostly tunnel") - && line.contains("0x27")) + .any(|line| line.contains("exact residual compact-prefix patterns") + && line.contains("span 0x03") + && line.contains("0x000055f3/0x0001/0xff") + && line.contains("span 0x27") + && line.contains("0xff0000ff/0x0002/0xff")) ); assert!( trace.candidate_consumer_hypotheses[0] @@ -24804,6 +25096,25 @@ mod tests { && line.contains("span=0x3 rows=17") && line.contains("span=0x27 rows=3")) ); + assert!( + trace.candidate_consumer_hypotheses[0] + .evidence + .iter() + .any(|line| line.contains("short 0x03-byte post-profile gaps") + && line.contains("track_cap:2") + && line.contains("tunnel:15") + && line.contains("0x000055f3/0x0001/0xff:17")) + ); + assert!( + trace.candidate_consumer_hypotheses[0] + .evidence + .iter() + .any(|line| line.contains("sparse 0x27 post-profile outlier") + && line.contains("0xff0000ff/0x0001/0xff:1") + && line.contains("0xff0000ff/0x0002/0xff:2") + && line.contains("TunnelSTBrick_Section.3dp") + && line.contains("BridgeSTWood_Section.3dp")) + ); assert!( trace.candidate_consumer_hypotheses[0] .evidence