fix(pi): eliminate full-fixture residual — Pi is now fully lossless (#412) - #449
Open
hai-pilgrim wants to merge 1 commit into
Open
fix(pi): eliminate full-fixture residual — Pi is now fully lossless (#412)#449hai-pilgrim wants to merge 1 commit into
hai-pilgrim wants to merge 1 commit into
Conversation
…eiervang-technologies#412) Resolve all four residual gaps tracked by heiervang-technologies#412: 1. Reasoning/tool token counts: preserved via _ucf_hub.pi_usage passthrough (already on main, verified working). 2. Cost None-vs-0.0: cost_present flag prevents spurious cost synthesis (already on main, verified working). 3. Redundant usage_raw: conditional stash via synthesize_pi_usage guard (already on main, verified working). 4. Image + ToolResult + encrypted Thinking content degradation: NEW content_stash passthrough in _ucf_hub preserves non-native hub content blocks through the Pi round-trip. Blocks that Pi cannot natively represent (Image, encrypted Thinking) are stashed as JSON in _ucf_hub.content_stash and restored by to_hub at their original content indices. Additionally fixes the {} vs null extensions distinction: an unconditional _ucf_hub.ext passthrough preserves empty-object extensions that would otherwise collapse to null through Pi's foreign-originated code path. The pi_full_fixture_residual_is_pinned test now asserts an empty residual, and the diagnostic_pi_hermes test reports LOSSLESS for all-content-types. Implementation: - is_pi_native_content(): classify which ContentBlock variants Pi models natively (text, non-encrypted thinking, toolCall). Encrypted thinking and everything else gets stashed. - hub_message_to_pi (from_hub): attach _ucf_hub.content_stash for non-native blocks; unconditionally attach _ucf_hub.ext for {} extensions. Skip content_stash for toolResult role (Pi handles tool results natively at the message-role level). - pi_message_to_hub (to_hub): restore content blocks from _ucf_hub.content_stash at their stashed indices. Test results: 785 passed, 0 failed, 4 ignored.
This was referenced Aug 13, 2026
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.
Closes #412
Summary
Resolve all four residual gaps tracked by #412, making the Pi converter fully lossless for the entire
all-content-typesfixture. Thediagnostic_pi_hermestest now reportsLOSSLESSfor Pi on all content types, and the pinned residual test asserts an empty diff.Changes
Content stash passthrough (
_ucf_hub.content_stash)Non-native hub content blocks (Image, encrypted Thinking) that Pi degrades to text placeholders are now stashed as JSON in
_ucf_hub.content_stashduringfrom_hub, keyed by their content index. Theto_hubleg restores the original blocks at those indices instead of the degraded placeholders.is_pi_native_content(): classifies which ContentBlock variants Pi models natively (text, non-encrypted thinking, toolCall). Encrypted thinking blocks (carryingencrypted_data/encryption_format) are treated as non-native.toolResult) are excluded from content stashing since Pi handles them natively at the message-role level.Unconditional extensions preservation
Pi's
to_hubcollapses foreign-originated messages with an emptypi_sidecartoextensions: null, losing the original{}vsnulldistinction. A_ucf_hub.ext: {}marker is now unconditionally attached for messages with empty-object extensions.Already on main (verified working)
_ucf_hub.pi_usagepassthroughNonevs0.0viacost_presentflagusage_rawstash viasynthesize_pi_usageguardTest Results
pi_full_fixture_residual_is_pinned: empty residual ✅diagnostic_pi_hermes: Pi LOSSLESS + IDEMPOTENT on all-content-types ✅