-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
[Bug]: Anthropic SDK path missing large-integer precision guard (tool_use input) #47229
Copy link
Copy link
Closed
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.Channel message delivery can be lost, duplicated, or misrouted.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.Channel message delivery can be lost, duplicated, or misrouted.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
The
quoteUnsafeIntegerLiteralsfix from #23170 only covers Ollama/llama.cpp JSON parsing paths. The Anthropic Messages API streaming path has the same precision loss bug for tool_useinputarguments containing large integers (e.g., Discord snowflake IDs).Root Cause
When streaming Anthropic responses, tool_use
inputis built by incrementally appendinginput_json_deltafragments into a buffer (jsonBuf), then parsed via the vendored partial-json-parser:The final line:
The
tokenize()step correctly identifies large numbers astype: "number"tokens, andgenerate()outputs them verbatim. But the finalJSON.parse()converts them to IEEE 754 doubles, losing precision for integers >Number.MAX_SAFE_INTEGER.Example:
{"to": 1481220477346119781}tokenize()→{type: "number", value: "1481220477346119781"}generate()→{"to": 1481220477346119781}(string, precision intact)JSON.parse()→{to: 1481220477346119700}← precision lostImpact
quoteUnsafeIntegerLiteralsin OpenClaw's own JSON parsing paths does NOT help here because the Anthropic SDK parses tool input internally before OpenClaw sees itSuggested Fix
Apply the same
quoteUnsafeIntegerLiteralstreatment to the Anthropic SDK's tool_use input parsing path. Options:generate()beforeJSON.parse()MessageStreamemits them — walk the parsedinputobject looking for rounded numbers and cross-reference with the rawjsonBufstringcontentBlockevent — before the parsed input is used, re-parse the raw JSON buffer usingparseJsonPreservingUnsafeIntegersOption 3 seems cleanest since
jsonBuf(stored asJSON_BUF_PROPERTY) still contains the original string with full precision.Version
Related