Skip to content

sheets append: numeric JSON input is rounded before sending the request #1331

Closed

Description

@pkyIntelligence

sheets append --values-json decodes numbers through float64 before serializing its request. An integer that JSON can represent exactly is changed before it reaches the API. For example, 9007199254740993 becomes 9007199254740992 even with --input=RAW.

Reproduced at current main e8428c36dd31db13eecba55fcef6f4ee75951188 (after v0.48.0). SheetsAppendCmd.Run uses sheetsvalues.Decode, which calls json.Unmarshal into interface values. The same package already has DecodeStrict, using json.Decoder.UseNumber.

Credential-free reproduction from that checkout, with Go dependencies available. The test calls the production CLI dispatcher and captures the request at a loopback fake service; it never contacts Google:

cat > internal/cmd/sheets_append_precision_probe_test.go <<'GO'
package cmd

import (
    "io"
    "net/http"
    "net/http/httptest"
    "strings"
    "testing"
)

func TestSheetsAppendJSONPrecisionProbe(t *testing.T) {
    var body string
    srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        data, _ := io.ReadAll(r.Body)
        body = string(data)
        w.Header().Set("Content-Type", "application/json")
        io.WriteString(w, `{"updates":{"updatedRows":1}}`)
    }))
    defer srv.Close()
    svc := newSheetsServiceFromServer(t, srv)
    result := executeWithSheetsTestService(t, []string{
        "--home=" + t.TempDir(), "--account=synthetic@example.invalid", "--json",
        "sheets", "append", "--input=RAW", "--values-json=[[9007199254740993]]",
        "--", "synthetic-sheet", "A:A",
    }, svc)
    if result.err != nil { t.Fatal(result.err) }
    if !strings.Contains(body, "9007199254740993") {
        t.Fatalf("input number changed in request: %s", body)
    }
}
GO
DBUS_SESSION_BUS_ADDRESS=disabled: GOG_KEYRING_BACKEND=file go test -vet=off -count=1 ./internal/cmd -run '^TestSheetsAppendJSONPrecisionProbe$' -v
rm internal/cmd/sheets_append_precision_probe_test.go

Observed:

input number changed in request: {"values":[[9007199254740992]]}
--- FAIL: TestSheetsAppendJSONPrecisionProbe

Expected: preserve 9007199254740993 in the outgoing JSON. This is separate from whatever numeric precision the Google Sheets server supports; no server storage claim is made by this reproduction.

Would you like a small fix using the existing number-preserving decoder for append, with a request-payload regression? A downstream callsite change passes this case.

Investigated and reproduced with AI assistance (the Astrarch agent team); the reproduction was verified on a real host.

Activity

  1. added
    P2Normal priority bug or improvement with limited blast radius.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    impact:data-lossThis issue is about lost, corrupted, or silently dropped user/session/config data.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    no-staleExempts this issue from stale automation.
    on Nov 11, 2026
  2. clawsweeper commented on Nov 11, 2026

    @clawsweeper
    Contributor

    Codex review: this still needs some work.

    Summary
    This issue establishes a current client-side precision bug: append rounds numeric JSON input before constructing its API request.

    Reproducibility: Current source establishes the float64 conversion and direct request handoff, corroborating the reporter's captured payload; this read-only review did not execute the reproduction.

    Next step
    Fix append's numeric decoding after establishing a failing dispatcher-level regression that captures 9007199254740993 exactly in the outgoing RAW request.

    Review details

    Best possible solution:

    Use the existing number-preserving decoder for append and verify exact numeric tokens in outgoing requests.

    Do we have a high-confidence way to reproduce the issue?

    Current source establishes the float64 conversion and direct request handoff, corroborating the reporter's captured payload; this read-only review did not execute the reproduction.

    Is this the best way to solve the issue?

    Switching append to DecodeStrict is a focused repair that follows update's existing approach without changing shared Decode semantics for other callers.

    AGENTS.md: found and applied where relevant.

    Codex review notes: model internal, reasoning medium; reviewed against e8428c36dd31.

    Label changes

    Label changes:

    • add P2: A bounded numeric-input bug silently changes append payloads, with no evidence of an urgent widespread regression.
    • add impact:data-loss: Numeric user data is silently corrupted before transmission, independently of server-side storage precision.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P2: A bounded numeric-input bug silently changes append payloads, with no evidence of an urgent widespread regression.
    • impact:data-loss: Numeric user data is silently corrupted before transmission, independently of server-side storage precision.
    Evidence reviewed

    Acceptance criteria:

    • Establish that TestSheetsAppendJSONPrecision fails on current main by inspecting the raw outgoing request body.
    • go test ./internal/cmd -run '^TestSheetsAppendJSONPrecision$' -count=1
    • go test ./internal/sheetsvalues ./internal/cmd -run 'TestDecode|TestSheetsAppend|TestSheetsCommands' -count=1
    • make ci

    What I checked:

    • Current default branch: GitHub main and the review checkout both resolve to e8428c3. (e8428c36dd31)
    • Lossy append request path: Append calls sheetsvalues.Decode, then assigns the resulting matrix directly to ValueRange.Values before invoking Append; RAW only selects the API input option after decoding. (internal/cmd/sheets.go:562, e8428c36dd31)
    • Existing number-preserving alternative: Decode unmarshals interface values through float64; DecodeStrict uses UseNumber and rejects trailing content. Existing tests explicitly verify preservation of 9007199254740993 in DecodeStrict and float64 output from Decode. (internal/sheetsvalues/values.go:19, e8428c36dd31)
    • Reporter reproduction and discussion: The complete issue supplies a production-dispatcher request-recorder reproduction showing 9007199254740993 sent as 9007199254740992; the only comment is automated review status.
    • Feature history across extracted helpers: The value-parsing extraction preserved the earlier distinction between number-preserving update decoding and json.Unmarshal-based append decoding; it did not introduce that distinction. (internal/sheetsvalues/values.go:37, 47cb3c6b3058)
    • Related work does not fix append: Searches for precision, rounding, numeric values, and append found no competing fix. fix(raw): preserve canonical Google JSON across readers #1158 preserves raw reader responses; feat(sheets): upsert rows by key while preserving human columns #1230 adds key-based upserts and does not claim this repair.
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 11, 2026, 3:02 PM ET / 20:02 UTC.

  3. steipete commented on Nov 14, 2026

    @steipete
    Collaborator

    Fixed in #1336. Sheets append now preserves numeric JSON tokens, including integers above 2^53 and long fractional values, using the existing strict decoder.

    The regression failed against the previous main and passes with the fix. Full make ci, independent P0–P2 review, and exact-head GitHub CI passed. A built CLI also verified the outgoing request against a synthetic HTTP endpoint.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossThis issue is about lost, corrupted, or silently dropped user/session/config data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExempts this issue from stale automation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions