fix(taskstore): make page tokens unambiguous for task IDs containing underscores - #402
Open
ez-lbz wants to merge 2 commits into
Open
fix(taskstore): make page tokens unambiguous for task IDs containing underscores#402ez-lbz wants to merge 2 commits into
ez-lbz wants to merge 2 commits into
Conversation
…underscores Page tokens were encoded as "<time>_<taskID>" and decoded by splitting on "_"; a client-supplied task ID containing "_" produced more than two parts and the token failed to decode, breaking pagination. Encode the token as "<time>_<length>_<taskID>" with the ID length prefix so fields can be split unambiguously; the decoder still accepts legacy tokens (two parts) for backward compatibility and rejects corrupted length prefixes. Add regression tests for underscore IDs, legacy tokens and corrupted prefixes.
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.
What changed
1. Make task page tokens unambiguous for IDs containing underscores
Problem:
Page tokens were encoded as
<time>_<taskID>and decoded withstrings.Split(decoded, "_"). The task ID is client-controlled and may itself contain_, so such tokens produced more than two parts and pagination broke for those tasks.Fix (a2asrv/taskstore/inmemory.go, a2asrv/taskstore/store_test.go):
<time>_<length>_<taskID>, where<length>is the byte length of the task ID; decoding usesSplitN(_, 3)plus a length check.<time>_<taskID>tokens are still accepted for backward compatibility.a2a.ErrParseError.TestInMemoryTaskStore_List_PageTokenWithUnderscoreIDsandTestPageTokenRoundTrip.Testing
go test ./a2asrv/... ./internal/...— all pass.Behavior change: the token format is now
<time>_<length>_<taskID>; tokens produced by older versions still decode.