Skip to content

Refuse an unreadable send_token identifier instead of throwing on it - #133

Open
BeeHiveTeam wants to merge 1 commit into
portdeveloper:mainfrom
BeeHiveTeam:fix/send-token-unreadable
Open

BeeHiveTeam wants to merge 1 commit into
portdeveloper:mainfrom
BeeHiveTeam:fix/send-token-unreadable

Conversation

@BeeHiveTeam

Copy link
Copy Markdown
Contributor

Closes #130

What was wrong

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 (src/nativeToolLoop.mjs:76), so {"toString": null} as the token made the loop report Error: Cannot convert object to primitive value where every other bad value gets a Refused: with a reason.

The change

The empty check is 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 #123. Blank strings are still no token specified. Nothing else in the send path changes.

Verified

Through prepareTokenSend, in test/send-token.test.mjs, with a getMetadata seam 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 still no token specified.
  • "USDC" still prepares.

Red, then green:

  • On main (3027c41): the two unreadable cases fail (they throw); the blank and USDC cases pass, as they should.
  • Mutations: treating the unreadable object as blank fails both unreadable cases; dropping the blank check fails the blank case; rewriting !String(input).trim() as String(input).trim() === "" passes.
  • End to end, send_token through dispatchNativeCall and the loop's own catch: {"toString": null} → Refused: invalid token "<unprintable>": … (was Error: Cannot convert object to primitive value); {} and "USDC" unchanged.

npm test 633/633 and npm run build on Node 22. One of eight full runs had a single failure that did not reproduce in the other seven; it was not in send-token.test.mjs, whose cases are pure and ran green in every run.

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
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.

send_token answers an unreadable token identifier with a JavaScript error instead of a refusal

1 participant