Skip to content

refactor: migrate JSON from sonic to encoding/json/v2 - #253

Merged
yusing merged 3 commits into
mainfrom
feat/json-v2
Aug 20, 2026
Merged

refactor: migrate JSON from sonic to encoding/json/v2#253
yusing merged 3 commits into
mainfrom
feat/json-v2

Conversation

@yusing

@yusing yusing commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

Stacked on #252 (feat/go1.27).

Replace bytedance/sonic with Go 1.27 encoding/json/v2 as the JSON backend wired into strutils. Drop USE_SONIC_JSON and the SIGILL workaround.

Changes

  • internal/serialization always registers encoding/json/v2 + encoding/json/jsontext on strutils (setupJSONV2())
  • time.Duration keeps v1 nanosecond numbers via encoding/json.FormatDurationAsNano, so health/timeout JSON still round-trips
  • Agent proxy cache keys use json/v2 instead of sonic.Marshal
  • Remove USE_SONIC_JSON from .env.example, rootless env, agent compose template, install script, agent logs, and user-facing wiki

Not dropped

Gin still lists github.com/bytedance/sonic as an indirect module because gin/codec/json has a //go:build sonic file. Default gin builds do not use that codec.

Docs

Wiki and webui submodule branches:

Summary by CodeRabbit

  • Improvements

    • Standardized JSON handling for more consistent serialization and validation.
    • Removed the optional high-performance JSON backend and related configuration settings.
    • Simplified startup messaging and generated environment configuration.
  • Documentation

    • Updated configuration and integration documentation to reflect current JSON behavior and serialization utilities.
  • Maintenance

    • Refreshed supporting components and streamlined dependency management.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2c65b3db-8c54-4bd2-a957-dee3e37213f7

📥 Commits

Reviewing files that changed from the base of the PR and between 3dd1bf9 and 340c957.

⛔ Files ignored due to path filters (1)
  • internal/dnsproviders/go.sum is excluded by !**/*.sum
📒 Files selected for processing (20)
  • .env.example
  • agent/cmd/main.go
  • agent/go.mod
  • agent/pkg/agent/templates/agent.compose.yml.tmpl
  • agent/pkg/handler/proxy_http.go
  • go.mod
  • goutils
  • internal/dnsproviders/go.mod
  • internal/homepage/integrations/qbittorrent/README.md
  • internal/homepage/override_config_test.go
  • internal/jsonstore/README.md
  • internal/metrics/README.md
  • internal/metrics/period/README.md
  • internal/metrics/uptime/README.md
  • internal/notif/webhook.go
  • internal/serialization/README.md
  • internal/serialization/serialization.go
  • rootless.env.example
  • scripts/install-agent.sh
  • webui

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting


📝 Walkthrough

Walkthrough

The change removes optional Sonic JSON initialization and configuration. Proxy caching and webhook validation use goutils/strings. Module requirements, documentation, generated environment files, startup messages, and submodule references are updated.

Changes

Sonic JSON removal

Layer / File(s) Summary
Serialization path and documentation
internal/serialization/serialization.go, agent/pkg/handler/proxy_http.go, internal/notif/webhook.go, internal/serialization/README.md, internal/jsonstore/README.md, internal/metrics/**, internal/homepage/**
YAML-only initialization remains. Proxy cache keys use strutils.MarshalString. Webhook validation uses strutils.ValidJSONString. Documentation identifies encoding/json/v2 as the JSON implementation.
Configuration and startup cleanup
agent/cmd/main.go, agent/pkg/agent/templates/agent.compose.yml.tmpl, rootless.env.example, scripts/install-agent.sh
Startup messages and generated configuration no longer include Sonic status, USE_SONIC_JSON, or SIGILL guidance.
Dependency graph and submodule updates
go.mod, agent/go.mod, internal/dnsproviders/go.mod, goutils, webui
Sonic moves from direct to indirect requirements. Obsolete DNS-provider dependencies are removed. The goutils and webui submodule references are updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with a tidy JSON nest,
Sonic hopped out; the helpers do the rest.
YAML stays where it belongs,
Config tips no longer sing their songs.
Dependencies shed a few old leaves—
Clean paths grow beneath my paws and sleeves.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: replacing Sonic with encoding/json/v2 for JSON serialization.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • ✅ Committed to branch successfully - (🔄 Check to regenerate)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/json-v2
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/json-v2

Comment @coderabbitai help to get the list of available commands.

yusing added 2 commits August 20, 2026 20:30
Wire encoding/json/v2 into strutils, drop USE_SONIC_JSON, and keep
time.Duration as nanosecond numbers so existing API JSON still round-trips.
Remove the local JSON v2 registration and tests, and use goutils string
helpers for proxy cache keys and webhook validation. Update related
documentation to reflect the centralized backend.

Submodule updates:
- refactor(strings): migrate JSON serialization to encoding/json/v2
- chore: update Go base image and wiki documentation
- chore(deps): update wiki submodule for json/v2 docs (#18)
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Note

Docstrings generation - SUCCESS
Generated docstrings and committed to branch feat/json-v2 (commit: 014add97d520a0578e6ab55a715fea532d2e0ba1)

Docstrings generation was requested by @yusing.

The following files were modified:

* `agent/pkg/handler/proxy_http.go`
* `internal/notif/webhook.go`

These files were kept as they were:
* `agent/cmd/main.go`
* `internal/serialization/serialization.go`

These files were ignored:
* `internal/homepage/override_config_test.go`

These file types are not supported:
* `.env.example`
* `agent/go.mod`
* `agent/pkg/agent/templates/agent.compose.yml.tmpl`
* `go.mod`
* `goutils`
* `internal/dnsproviders/go.mod`
* `internal/homepage/integrations/qbittorrent/README.md`
* `internal/jsonstore/README.md`
* `internal/metrics/README.md`
* `internal/metrics/period/README.md`
* `internal/metrics/uptime/README.md`
* `internal/serialization/README.md`
* `rootless.env.example`
* `webui`
@sonarqubecloud

Copy link
Copy Markdown

@yusing
yusing merged commit 5d91817 into main Aug 20, 2026
14 of 16 checks passed
@yusing
yusing deleted the feat/json-v2 branch August 20, 2026 12:53
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.

1 participant