Select task FU-P13-T11: Preserve JSON-RPC numeric request ID fidelity in broker transport#86
Merged
Merged
Conversation
… in broker transport
…n broker transport
…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.
…y in broker transport (PASS)
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.
Description
Replace lossy 20-bit integer ID masking in
broker/transport.pywith 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_lineappliedoriginal_id & 0xFFFFFto integer IDs before encoding them into the compositebroker_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 ofstring_id_map.Changes:
broker/types.py— addedint_id_map,id_restore,_next_local_idfields toClientSessionbroker/transport.py— added_alloc_local_id()helper; updated_process_client_line,route_upstream_response,_drain_session; updated module docstringtests/unit/test_broker_transport.py— fixed 3 existing tests; added 5 newTestIntegerIDFidelitytestsType of Change
Quality Gates
make testmake lintruff check src/— all checks passedmake formatmake typecheckmypy src/mcpbridge_wrapper/broker/— success, no issues in 5 source filesmake doccheckdocs/changes)Documentation Sync
docs/files modified)Testing
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_mappingTestIntegerIDFidelity::test_int_and_string_id_no_collisionChecklist
transport.py)