Skip to content

fix(sheets): emit empty arrays for ranges without notes or links - #1314

Closed
saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/sheets-notes-links-empty-json
Closed

saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/sheets-notes-links-empty-json

Conversation

@saariuslystoned

Copy link
Copy Markdown
Contributor

What problem this solves

gog sheets notes and gog sheets links collect their rows in nil slices (var notes []sheetsCellNote, var links []sheetsCellLink). For a range with no notes or no links, the JSON output carries null instead of an empty array, and --results-only gets worse:

$ gog --json sheets notes <id> 'Sheet1!A1:A1'
{"notes":null,"range":"Sheet1!A1:A1","spreadsheetId":"s1"}
$ gog --json --results-only sheets notes <id> 'Sheet1!A1:A1'
null
$ gog --json --results-only sheets links <id> 'Sheet1!A1:A1'
{"links":null,"range":"Sheet1!A1:A1","spreadsheetId":"s1"}

unwrapPrimary only selects array values. Empty notes therefore unwrap to bare null, and empty links fall back to the whole envelope, so jq '.[]' and jq length fail exactly when a range is empty. Other list commands already emit [] for empty results and pin it with tests, for example TestGmailFiltersList_JSONEmptyArray and TestExecute_FormsResponsesList_JSONEmptyArray.

Change

Start both slices empty (notes := []sheetsCellNote{}, links := []sheetsCellLink{}). Non-empty output and text output are unchanged.

Evidence

  • TestSheetsNotesAndLinks_EmptyRangeJSONIsEmptyArray runs gog --json sheets notes|links through the CLI entry point, with and without --results-only, against an httptest Sheets response containing one plain cell. It fails on main (e8428c3) with "notes" = null and passes with this change, as do the existing Sheets tests.

  • A built bin/gog from main and from this branch was run against a local Sheets stand-in through GOG_GOOGLE_API_BASE_URL, with an empty GOG_HOME and the file keyring. The stand-in is not Google:

    main:   notes  -> {"notes":null,...}      --results-only -> null
            links  -> {"links":null,...}      --results-only -> {"links":null,"range":...,"spreadsheetId":...}
    branch: notes  -> {"notes":[],...}        --results-only -> []
            links  -> {"links":[],...}        --results-only -> []
    
  • make ci passed locally (macOS arm64, go1.27.3).

This changes local output only. The Sheets request is unchanged, and no live spreadsheet was used.

🤖 Generated with Claude Code

sheets notes and sheets links built their results in nil slices, so a
range with no notes or links printed "notes": null or "links": null.
Under --results-only, notes unwrapped to null and links fell back to the
whole envelope, because the unwrapper only selects arrays. Start both
slices empty, as other list commands do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Sheets notes and links return empty JSON arrays when a range contains no matching annotations.

Example: Run gog --json --results-only sheets links s1 'Sheet1!A1:A1' for a cell containing plain text.

  • Before: Output is an envelope containing "links": null.
  • After: Output is [].

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Minimal complete fix with supplied shipped-CLI proof, useful regression coverage, and the previous finding resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor supplies built-main and built-branch CLI output against a local Sheets stand-in on macOS arm64, showing empty arrays for both annotation commands with and without results-only; the final revision changes only the changelog reference.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scripts receive null or an envelope instead of an empty collection when a Sheets range has no notes or links.
Reason: Two focused production edits restore consistent collection output without adding options or another implementation path.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main JSON output bug with a minimal change; the earlier changelog finding is resolved and no actionable defects remain.

Priority: P2
Reviewed head: 169f73ffb1361a450aded199a91d0b765007bc46

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Sheets CLI retrieves grid data, collects cell annotations, and passes the resulting collections to shared JSON formatting or table output.

flowchart LR
 CLI[Sheets CLI] --> API[Sheets grid response]
 API --> Collect[Annotation collectors]
 Collect --> Format[JSON formatter]
 Format --> Transform[Optional results only transform]
 Transform --> Output[Standard output]
Loading

Technical review

Best possible solution:

Land the two collector initialization fixes with the focused regression coverage and corrected Unreleased entry.

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

Current-main collectors and shared JSON transformation explain the reported outputs directly, supported by contributor before-and-after CLI output; no target code was run during this read-only review.

Is this the best way to solve the issue?

Initializing empty collections in their existing owners is the smallest complete fix and matches existing empty-list regression contracts elsewhere in the CLI.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Annotation collection initialization changes intended behavior with a stated reason (46345b5: The typed-presentation refactor moved collection types and table formatting while preserving nil initialization from the original commands.)
  • Unreleased changelog placement keeps the original intent (chore(release): open 0.48.1 development cycle #1307: The release closeout opened the next development section while preserving finalized release notes.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main retains the bug: The notes collector initializes a nil slice and passes it directly to WriteJSON when no notes are found; the links collector does the same at line 53. (internal/cmd/sheets_notes.go:43, e8428c36dd31)
  • Smallest complete production fix: The pinned introduced diff changes only the two collector initializers in production, preserving requests, populated results, and text handling. (internal/cmd/sheets_links.go:53, 169f73ffb136)
  • Results-only behavior verified in source: Shared JSON transformation marshals typed collections before selecting array results; empty non-nil collections therefore unwrap correctly for both commands. (internal/outfmt/outfmt.go:168, 169f73ffb136)
  • Focused regression coverage: The added test exercises both shipped command routes with and without results-only against a plain-cell Sheets response, asserting empty arrays. (internal/cmd/sheets_notes_links_empty_test.go:13, 169f73ffb136)
  • Supplied CLI proof: The full PR body supplies before-and-after output from built CLI binaries against a local Sheets stand-in through GOG_GOOGLE_API_BASE_URL on macOS arm64, covering both commands and output modes. (169f73ffb136)
  • Earlier finding resolved: The follow-up commit adds the required PR reference while retaining contributor thanks in the Unreleased entry. (CHANGELOG.md:5, 169f73ffb136)

Likely related people:

  • Andrea Bergonzo: Raw commit c530eb3 adds internal/cmd/sheets_notes.go:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c530eb309d48; files: internal/cmd/sheets_notes.go)
  • Omar Othman: Raw commit ddc1a23 adds internal/cmd/sheets_links.go:59 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ddc1a232e0d2; files: internal/cmd/sheets_links.go)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Change size Production +2/-2 lines; tests +55 lines The test covers four distinct command and output-mode combinations through existing CLI infrastructure.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Empty annotation results disrupt JSON consumers in two Sheets read commands, with limited blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-08T14:55:07.378Z sha 0ab172a :: needs changes before merge. :: [P3] Add the required PR reference to the changelog entry

Reviewed November 8, 2026, 2:18 PM ET / 19:18 UTC (Revision 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@steipete

Copy link
Copy Markdown
Collaborator

Thank you for the fix. I reproduced the claim and consolidated emitting empty Sheets notes and links as arrays into #1336, with regression coverage and your coauthor credit retained. The full make ci gate, built-CLI checks for the new request-validation fixes, and exact-head GitHub CI passed. Closing this PR as superseded by the merged implementation in #1336.

@steipete steipete closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants