Skip to content

[linter-miner] Add JSON unmarshal byte conversion linter - #75919

Merged
pelikhan merged 4 commits into
mainfrom
copilot/linter-minerjson-unmarshal-bytes-conversion
Nov 8, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/linter-minerjson-unmarshal-bytes-conversion

Conversation

Copilot AI commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

json.Unmarshal([]byte(s), ...) copies string data into a byte slice. Add a custom analyzer to flag this conversion and suggest streaming from a string reader.

  • Analyzer: Detects string-to-[]byte conversions passed to encoding/json.Unmarshal, including parenthesized conversions. Skips generated files, honors nolint, and supports hot-path coverage gating.
  • Integration: Registers and documents the analyzer; leaves CI enforcement deferred pending review of existing findings.
json.Unmarshal([]byte(data), &value)
// Consider: json.NewDecoder(strings.NewReader(data)).Decode(&value)

Copilot AI changed the title [WIP] Add JSON unmarshal byte conversion linter [linter-miner] Add JSON unmarshal byte conversion linter Nov 8, 2026
Copilot AI requested a review from gh-aw-bot November 8, 2026 17:02
@pelikhan
pelikhan marked this pull request as ready for review November 8, 2026 17:08
Copilot AI adaptive review requested due to automatic review settings November 8, 2026 17:08
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75919

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #75919

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-08T17:11:18Z
review_event: REQUEST_CHANGES
top_themes:
  - semantic regression in prescribed json.Decoder rewrite
files_reviewed:
  - pkg/linters/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion.go
  - pkg/linters/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion_test.go
  - pkg/linters/jsonunmarshalbytesconversion/testdata/src/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion.go
  - pkg/linters/registry.go
  - pkg/linters/spec_test.go
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~2 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Request changes: the analyzer's prescribed replacement can silently accept trailing non-whitespace input that json.Unmarshal rejects. The inline comment describes the semantic regression and required guard.

The specialist pass was unavailable because its file-read tool access was denied; this review is based on the pre-fetched diff and independent analysis.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review to run again

!coverage.ShouldApply(pass, call.Pos(), *hotThreshold) {
return
}
pass.ReportRangef(call, "json.Unmarshal([]byte(s), ...) copies the string; use json.NewDecoder(strings.NewReader(s)).Decode(...) to avoid the conversion copy")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diagnostic recommends a rewrite that changes json.Unmarshal semantics by accepting a valid first value followed by non-whitespace trailing data, which json.Unmarshal rejects.

💡 Preserve Unmarshal's complete-input validation

For example, json.NewDecoder(strings.NewReader(s)).Decode(&v) succeeds on {} garbage, whereas json.Unmarshal([]byte(s), &v) returns an error. Either avoid prescribing this rewrite generally or require an explicit EOF/second-decode check (and add a regression fixture) before suggesting it.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Warning

The push_to_pull_request_branch operation failed: Cannot verify branch protection rules for "copilot/linter-minerjson-unmarshal-bytes-conversion": Resource not accessible by integration - https://docs.github.com/rest/branches/branch-protection\#get-branch-protection. Reading classic branch protection requires a GitHub App installation token or fine-grained PAT with Administration: read repository permission; GITHUB_TOKEN cannot provide this permission. Push blocked to prevent accidental writes to protected branches.. The code changes were not applied.

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (>100 new lines in business-logic directories; the pre-fetched gate summary counted 164 new lines) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/75919-add-json-unmarshal-byte-conversion-linter.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR evidence.

  2. Complete or correct the rationale and trade-offs, including any context the draft could not infer.

  3. Commit the finalized ADR to docs/adr/.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-75919: Add a JSON Unmarshal Byte-Conversion Linter (link unavailable: invalid HTTPS URL)

The PR adds and registers jsonunmarshalbytesconversion, updates analyzer documentation and synchronization tests, and adds fixtures. Its evidence reports approximately 125 existing matching conversions and explicitly defers CI enforcement pending review. No linked ADR containing all four required sections — Context, Decision, Alternatives Considered, and Consequences — was found in the PR body or linked issue.

Once the ADR is linked in the PR body, this gate will re-run and verify that the implementation matches the decision.

❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does and make significant trade-offs explicit for future contributors.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What was decided and why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs, both positive and negative?

All records are stored in docs/adr/ and the draft uses the PR number as its identifier.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: gpt56 max · ~3 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The linter recommends a single Decode that can accept trailing input rejected by Unmarshal, potentially weakening whole-document validation unless the advice is explicitly limited to stream semantics.

1 open issue
1 file not reviewed
  • pkg/linters/jsonunmarshalbytesconversion/testdata/src/jsonunmarshalbytesconversion/generated.go: Generated file
What changed in this PR

Adds jsonunmarshalbytesconversion to gh-aw’s custom Go analyzers to flag string-to-byte conversions passed to json.Unmarshal, addressing #75205.

Changes:

  • Detects conversions, including parenthesized forms, with generated-file skipping, nolint support, and coverage-based gating.
  • Adds analyzer tests and fixtures.
  • Registers and documents the analyzer while deferring CI enforcement pending review of existing findings.
File Description
pkg/​linters/​spec_test.go Adds the analyzer to documentation synchronization checks.
pkg/​linters/​registry.go Registers the analyzer with the shared runner.
pkg/​linters/​README.md Documents detection and recommended alternatives.
pkg/​linters/​jsonunmarshalbytesconversion/​testdata/​src/​jsonunmarshalbytesconversion/​jsonunmarshalbytesconversion.go Covers detection, suppression, and non-matching calls.
pkg/​linters/​jsonunmarshalbytesconversion/​testdata/​src/​jsonunmarshalbytesconversion/​generated.go Provides a generated-file exclusion fixture.
pkg/​linters/​jsonunmarshalbytesconversion/​jsonunmarshalbytesconversion.go Implements detection, filtering, and diagnostics.
pkg/​linters/​jsonunmarshalbytesconversion/​jsonunmarshalbytesconversion_test.go Runs the analyzer against its fixtures.
pkg/​linters/​doc.go Updates the analyzer inventory and count.
pkg/​linters/​doc_sync_test.go Records deferred CI enforcement.

Review effort: Balanced (auto)

!coverage.ShouldApply(pass, call.Pos(), *hotThreshold) {
return
}
pass.ReportRangef(call, "json.Unmarshal([]byte(s), ...) copies the string; use json.NewDecoder(strings.NewReader(s)).Decode(...) to avoid the conversion copy")

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /grill-with-docs and /tdd. Requesting changes: the analyzer’s replacement advice is not behaviour-preserving, and the new analyzer has no test that would catch that.

📋 Key Themes & Highlights

Key Themes

  • Incorrect replacement advice: json.NewDecoder(strings.NewReader(s)).Decode(...) accepts trailing data (for example {"a":1} xyz) that json.Unmarshal rejects. It also allocates more than json.Unmarshal in a 64 KiB benchmark (326 KB/16 allocs vs 139 KB/7 allocs), so it does not avoid the copy. A behaviour-preserving pattern is in the inline comment on the analyzer.
  • Docs drift: the README bullet and analyzer message repeat the same advice, and the README Dependencies list is missing the new analyzer.
  • Test gap: analysistest checks diagnostic text only, so no test covers the semantics that the advice depends on.

Positive Highlights

  • ✅ Clean analyzer shape: it reuses the shared astutil, nolint, filecheck, and coverage helpers, and skips generated files.
  • ✅ Handles parenthesised conversions and named string types, and has a nolint suppression case.
  • ✅ Registry, doc.go, spec_test.go, and the README Subpackages table are updated consistently.
  • ✅ Local checks pass: go test ./pkg/linters/... exits 0 (99 packages), including the README/doc sync tests.

Uncertainty

I did not review the wider repository for other json.Unmarshal call sites, so the impact of enabling this in CI is not assessed. The CI enforcement deferral in notYetEnforced is left as-is.

@copilot please address the review comments above.

Comments that could not be inline-anchored

pkg/linters/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion.go:57

**[/grill-with-docs]** The suggested replacement is not behaviour-preserving, and it does not avoid the copy this message claims to avoid. `Decode` silently accepts trailing data, for example `{"a":1} xyz`, which `json.Unmarshal` rejects. Do not recommend it as written. <details> <summary>💡 Behaviour-preserving alternative and measurements</summary> This pattern matches `json.Unmarshal` error behaviour on every input I tried, including trailing data, a second value, and an extra closing brace...

pkg/linters/README.md:45

**[/grill-with-docs]** This bullet repeats the replacement advice from the analyzer message, which is not behaviour-preserving and does not avoid the copy (see the comment on jsonunmarshalbytesconversion.go line 57). Update it in the same commit as the message. `doc_sync_test.go` only checks analyzer names, so it will not catch wording drift. @copilot please address this.

pkg/linters/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion_test.go:13

**[/tdd]** Nothing pins the behaviour that the advice depends on. `analysistest` only checks the diagnostic text, so the wrong rewrite passed CI. <details> <summary>💡 Suggested test</summary> If the advice stays, add a table-driven runtime test next to `TestAnalyzer`. It should check that the recommended rewrite returns an error for trailing data such as `{"a":1} xyz`, and that its error behaviour matches `json.Unmarshal` on the same inputs. A future rewrite that changes semantics would then ...

pkg/linters/README.md:380

**[/grill-with-docs]** The **Dependencies** list has no entry for `jsonunmarshalbytesconversion`, but every sibling analyzer has one (for example `jsonmarshalignoredeerror` on this line). The doc-sync tests only parse the Subpackages table, so this gap is not caught. Add the matching bullet here. @copilot please address this.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/jsonunmarshalbytesconversion/jsonunmarshalbytesconversion.go:57): This diagnostic recommends a rewrite that changes json.Unmarshal semantics by accepting a valid first value followed by non-whitespace trailing data, which json.Unmarshal rejects. - [linter-miner] Add JSON unmarshal byte conversion linter #75919 (comment)
  3. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42503441288/job/128802556286.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: b021c25
Sous-chef requested-work: 88b2768431594954bf9d6882fb3a4ea53757082cec35eb5aa6749eed7b9b7faf c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: c4bd459f786fedec25fc0f84e67f8e8c89349386bc316708c2630669c5049edf

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~8 AIC · ⌖ ~15 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Assignment started. I’m merging the latest main, correcting the diagnostic so decoder advice preserves whole-document validation, and investigating the reported safe_outputs failure.

Sous-chef requested-head: b021c25
Sous-chef requested-work: 88b2768431594954bf9d6882fb3a4ea53757082cec35eb5aa6749eed7b9b7faf c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: c4bd459f786fedec25fc0f84e67f8e8c89349386bc316708c2630669c5049edf

…son-unmarshal-bytes-conversion

Co-authored-by: gh-aw-bot <[email protected]>
@pelikhan
pelikhan merged commit ac0cfba into main Nov 8, 2026
46 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minerjson-unmarshal-bytes-conversion branch November 8, 2026 18:25
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[linter-miner] Add JSON unmarshal byte conversion linter

4 participants