[Bug]: Integers outside the Long range from the LLM become Double and lose precision

Open
#83 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
backend

Research direction

The conversion lives in JsonElement.toPrimitive() in the agent module's domain/JsonExtensions.kt, which tries toLongOrNull() then toDoubleOrNull(). Start there and reproduce with a number above Long.MAX_VALUE sent for a String parameter. Done when the literal digits reach the app function unchanged and existing number conversions still pass their tests.

Written by the indexing model from the issue text.

Description

Steps to Reproduce
  1. Have the model send an integer above Long.MAX_VALUE (e.g. an ID such as 12345678901234567890)
    for a String or string-array parameter.
Expected

The value reaches the app function exactly as the digits the model sent ("12345678901234567890").

Observed

"1.2345678901234567E19".

Root cause

JsonElement.toPrimitive() (agent/.../domain/JsonExtensions.kt) tries toLongOrNull() and then
toDoubleOrNull(), so big integers become Double. The raw JSON content is then lost before
type-aware conversion.

Suggested fix

Keep the raw JSON content for numbers that don't fit Long, for example as a String or BigDecimal. Or
convert with the parameter's metadata, so string parameters receive the literal digits.

Found during review of the #62 fix.

Dominant language
Kotlin
Stars
222
Forks
54
Avg merge
1d 11h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/appfunctions

All issues in android/appfunctions

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.