Skip to content

fix(sessions): keep SQLite session state numbers exact across updates - #7426

Closed
donggyun112 wants to merge 1 commit into
google:mainfrom
donggyun112:fix/sqlite-state-number-precision
Closed

donggyun112 wants to merge 1 commit into
google:mainfrom
donggyun112:fix/sqlite-state-number-precision

Conversation

@donggyun112

Copy link
Copy Markdown
Contributor

SqliteSessionService merges a state delta in SQL by rebuilding the row from json_each values (_MERGE_STATE_SQL), and json_group_object writes every REAL back with 15 significant digits. Every key in the row is rewritten on each merge, not just the delta's: 0.1 + 0.2 reads back as 0.3 and a time.time() value loses its last digits. adk web uses this service by default; the in-memory and database services keep the values exact.

Write a REAL with 17 significant digits when 15 do not read back as the same value. Floats round-trip, and values that already fit in 15 digits, such as 19.99, are stored as before. The merge stays a single linear pass. Integers beyond 64 bits are still parsed as REAL by SQLite and are not covered here.

Testing Plan

Unit tests

New contract tests run on every backend: floats stored earlier and floats written by a delta read back unchanged in session, user: and app: state. On main they fail for sqlite and per_agent_database only.

$ pytest tests/unittests/sessions tests/unittests/cli -q
1920 passed, 5 skipped, 4 xfailed

Manual E2E

adk api_server with the default local store and an agent that saves a charged amount (1.05 * 1.1) to state, then refunds against the gateway amount on the next turn. On main the state holds 1.155 and the refund fails the amount check; with this change it holds 1.1550000000000002 and the refund goes through.

SqliteSessionService merges a state delta by rebuilding the row from
json_each values, and json_group_object writes every REAL with 15
significant digits. Each merge rewrote every key in the row, so floats such
as 0.1 + 0.2 or a time.time() value were rounded even when the delta never
touched them.

Write a REAL with 17 digits when 15 do not read back as the same value, so
floats round-trip while short values such as 19.99 keep their form.
copybara-service Bot pushed a commit that referenced this pull request Oct 8, 2026
@adk-bot

adk-bot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Thank you @donggyun112 for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 13787a5.

Closing this PR as the changes are now in the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants