Skip to content

Select task FU-P13-T11: Preserve JSON-RPC numeric request ID fidelity in broker transport#86

Merged
SoundBlaster merged 6 commits into
mainfrom
claude/implement-flow-specs-Ry4XN
Feb 19, 2026
Merged

Select task FU-P13-T11: Preserve JSON-RPC numeric request ID fidelity in broker transport#86
SoundBlaster merged 6 commits into
mainfrom
claude/implement-flow-specs-Ry4XN

Conversation

@SoundBlaster
Copy link
Copy Markdown
Owner

@SoundBlaster SoundBlaster commented Feb 19, 2026

Description

Replace lossy 20-bit integer ID masking in broker/transport.py with a reversible per-session counter mapping so all valid JSON-RPC request IDs (large, negative, concurrent) round-trip exactly to clients.

Root cause: _process_client_line applied original_id & 0xFFFFF to integer IDs before encoding them into the composite broker_id. This silently truncated IDs > 1,048,575, mangled negative IDs, and could alias two distinct IDs that shared the same lower 20 bits.

Fix: A shared monotonic counter (_alloc_local_id) assigns a unique local alias to every incoming ID (integer or string). A reverse map (id_restore) enables O(1) restoration on the response path, replacing the previous O(n) linear scan of string_id_map.

Changes:

  • broker/types.py — added int_id_map, id_restore, _next_local_id fields to ClientSession
  • broker/transport.py — added _alloc_local_id() helper; updated _process_client_line, route_upstream_response, _drain_session; updated module docstring
  • tests/unit/test_broker_transport.py — fixed 3 existing tests; added 5 new TestIntegerIDFidelity tests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • CI/CD improvement

This is a bug fix — integer ID fidelity was silently broken for IDs outside the 20-bit range.


Quality Gates

Check Result
make test 526 passed, 9 skipped (≥90% coverage)
make lint ruff check src/ — all checks passed
make format No format issues
make typecheck mypy src/mcpbridge_wrapper/broker/ — success, no issues in 5 source files
make doccheck N/A (no docs/ changes)

Documentation Sync

  • Documentation changes are synced with DocC catalog — N/A (no docs/ files modified)

Testing

  • Added/updated tests for new functionality
    • TestIntegerIDFidelity::test_large_integer_id_round_trips (ID = 2²¹)
    • TestIntegerIDFidelity::test_negative_integer_id_round_trips (ID = -1)
    • TestIntegerIDFidelity::test_concurrent_int_ids_no_collision (IDs 1 and 1+2²⁰)
    • TestIntegerIDFidelity::test_integer_id_reuses_existing_mapping
    • TestIntegerIDFidelity::test_int_and_string_id_no_collision
  • All tests pass locally
  • Manually tested the changes — N/A (broker requires macOS + Xcode)

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • Comments added for complex code (updated module docstring in transport.py)
  • Documentation updated (if needed) — N/A
  • No new warnings generated
  • PR title is descriptive

…oker transport

Replace lossy 20-bit bitmask with a shared monotonic counter (_alloc_local_id)
and reverse map (id_restore) so large, negative, and concurrent integer request
IDs round-trip exactly. Update 3 existing tests and add 5 new tests covering
these edge cases. O(1) restore replaces previous O(n) string_id_map scan.
@SoundBlaster SoundBlaster merged commit 4973950 into main Feb 19, 2026
9 checks passed
@SoundBlaster SoundBlaster deleted the claude/implement-flow-specs-Ry4XN branch February 19, 2026 18:03
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.

2 participants