Repository navigation
Refuse an unreadable send_token identifier instead of throwing on it - #133
Open
BeeHiveTeam wants to merge 1 commit into
Open
BeeHiveTeam wants to merge 1 commit into
BeeHiveTeam wants to merge 1 commit into
Conversation
prepareTokenSend checked for an empty token with `String(input).trim()`, and String()
throws on an object that cannot become text. Native tool calling passes the model's
arguments to handleAction as parsed JSON, so `{"toString": null}` as the token made
the loop report `Error: Cannot convert object to primitive value` where every other
bad value gets a refusal with a reason.
The empty check is now total: an identifier that cannot be read is not blank, so it
reaches resolveToken, whose existing catch refuses it as `invalid token
"<unprintable>": Cannot convert object to primitive value` — the reason the read
path has given since portdeveloper#123. Blank strings are still "no token specified".
Tests go through prepareTokenSend with a getMetadata seam that fails if called, for
two unreadable shapes, blank strings and "USDC". On main the two unreadable cases
fail; treating the object as blank fails both, dropping the blank check fails the
blank case, and an equivalent rewrite of the check passes. Through
dispatchNativeCall the answer is now `Refused: invalid token "<unprintable>": …`.
Closes portdeveloper#130
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 #130
What was wrong
prepareTokenSendchecked for an empty token withString(input).trim(), andString()throws on an object that cannot become text. Native tool calling passes the model's arguments tohandleActionas parsed JSON (src/nativeToolLoop.mjs:76), so{"toString": null}as the token made the loop reportError: Cannot convert object to primitive valuewhere every other bad value gets aRefused:with a reason.The change
The empty check is total. An identifier that cannot be read is not blank, so it reaches
resolveToken, whose existingcatchrefuses it asinvalid token "<unprintable>": Cannot convert object to primitive value— the reason the read path has given since #123. Blank strings are stillno token specified. Nothing else in the send path changes.Verified
Through
prepareTokenSend, intest/send-token.test.mjs, with agetMetadataseam that fails the test if it is called:{"toString": null}and an object with no prototype are refused with the read path's exact reason.""and" "are stillno token specified."USDC"still prepares.Red, then green:
main(3027c41): the two unreadable cases fail (they throw); the blank andUSDCcases pass, as they should.!String(input).trim()asString(input).trim() === ""passes.send_tokenthroughdispatchNativeCalland the loop's own catch:{"toString": null}→Refused: invalid token "<unprintable>": …(wasError: Cannot convert object to primitive value);{}and"USDC"unchanged.npm test633/633 andnpm run buildon Node 22. One of eight full runs had a single failure that did not reproduce in the other seven; it was not insend-token.test.mjs, whose cases are pure and ran green in every run.