Skip to content

fix(pi): eliminate full-fixture residual — Pi is now fully lossless (#412) - #449

Open
hai-pilgrim wants to merge 1 commit into
heiervang-technologies:mainfrom
hai-pilgrim:fix/pi-usage-lossless-v2
Open

fix(pi): eliminate full-fixture residual — Pi is now fully lossless (#412)#449
hai-pilgrim wants to merge 1 commit into
heiervang-technologies:mainfrom
hai-pilgrim:fix/pi-usage-lossless-v2

Conversation

@hai-pilgrim

Copy link
Copy Markdown
Contributor

Closes #412

Summary

Resolve all four residual gaps tracked by #412, making the Pi converter fully lossless for the entire all-content-types fixture. The diagnostic_pi_hermes test now reports LOSSLESS for 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_stash during from_hub, keyed by their content index. The to_hub leg 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 (carrying encrypted_data/encryption_format) are treated as non-native.
  • Tool-role messages (toolResult) are excluded from content stashing since Pi handles them natively at the message-role level.

Unconditional extensions preservation

Pi's to_hub collapses foreign-originated messages with an empty pi_sidecar to extensions: null, losing the original {} vs null distinction. A _ucf_hub.ext: {} marker is now unconditionally attached for messages with empty-object extensions.

Already on main (verified working)

  • Reasoning/tool token counts via _ucf_hub.pi_usage passthrough
  • Cost None vs 0.0 via cost_present flag
  • Conditional usage_raw stash via synthesize_pi_usage guard

Test Results

  • 785 passed, 0 failed, 4 ignored
  • pi_full_fixture_residual_is_pinned: empty residual ✅
  • diagnostic_pi_hermes: Pi LOSSLESS + IDEMPOTENT on all-content-types ✅
  • All 11 Pi unit tests pass ✅
  • All 12 cross-CLI lossless tests pass ✅

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pi converter: strict-lossless residual (reasoning tokens, cost None-vs-0.0, image, redundant usage_raw)

2 participants