Channel settings serialises nested config structs with Go field names and a raw nanosecond Duration #514

Closed
opened 2026-10-27 13:36:37 +00:00 by sam · 0 comments
Owner

Found while correcting my own citations of [chat.rate_limit] (commit 0ca733f7). The channel-settings resource is Web-UI-owned and applied (boot.loadRuntimeConfig -> boot.startRateLimiter, restart-required), but two of its nested values are not usable from the Web UI as rendered.

EVIDENCE

internal/app/controlplane/channel_settings.go puts two internal/config structs straight into the resource:
RateLimit config.RateLimitConfig json:"rate_limit"
Email config.EmailConfig json:"email"

Neither struct carries a json tag, so encoding/json falls back to the Go field names, and RateLimitConfig.Window is a bare time.Duration, which encoding/json encodes as int64 nanoseconds. Verified by marshalling:

RateLimitConfig{Window: time.Minute, MaxRequests: 20} -> {"Window":60000000000,"MaxRequests":20}
EmailConfig{...} -> {"ListenAddr":"127.0.0.1:2525","RelayAddr":"smtp.example.com:587"}

The Web UI renders this resource with StructuredResourceCard -> StructuredValueEditor, which recurses into nested objects and labels each key by replacing underscores and capitalising the first letter. So the operator sees "Window", "MaxRequests", "ListenAddr", "RelayAddr" -- inconsistent with the kind's own top-level snake_case keys (show_tool_calls, webhook_addr, unrestricted_filesystem) -- and must enter 60000000000 to mean the "1m" the file example shows as window = "1m". A number Input receiving "1m" yields NaN, which fails json.Marshal, so the save errors rather than storing a plausible wrong value; a cleared field stores 0, which silently disables rate limiting.

IN-REPO PRECEDENT

The sibling resource in the same file already solves exactly this: operational_settings.go builds scheduling-policy with PollInterval: cfg.PollInterval.Std().String(), a deliberate human-readable string, while channel-settings passes the raw Duration through. tool_settings.go and the other kinds are worth checking for the same pattern.

FIX DIRECTION

Give the channel-settings document its own wire shape (snake_case json tags, Duration rendered as a string the way scheduling-policy already does) and map to/from config.RateLimitConfig and config.EmailConfig at the resource boundary, so the resource stops being a JSON projection of an internal struct whose tags belong to a different file format. Check the other operational kinds for the same leak before fixing only this one.

Notes

FIX COMMITTED, NOT YET LANDED: 092194cd 'fix(controlplane): give the channel document its own shape'.

What it does: channel_settings.go now defines the document (emailSettings, rateLimitSettings with explicit snake_case tags, and channelDuration, which writes the string the file accepts and reads that, a nanosecond count, and the Go-cased keys an existing store holds). The tolerance stays strict -- decodeRenamingLegacyKeys renames the four known legacy keys and keeps DisallowUnknownFields, because an unknown key decodes as 'unset' and an unset rate limit is off, so a misspelling is refused. normalizeChannels (the Definition.Normalize hook schedules already uses) rewrites a legacy document into the current shape on write, so a store converges on its next save while reads tolerate it until then.

Verified by me: controlplane, messaging and configuration suites, archied (the loadRuntimeConfig consumer), go vet, go build ./..., golangci-lint run ./... (0 issues), docs:check, docs:prds. The FULL task check has NOT run on this commit: the shared checkout is contended and the merge train owns that gate. It is gating 092194cd now and will report.

Left open deliberately until that gate reports green, per the tracker convention of closing when work lands rather than when it commits.

Sibling found by the same audit and filed separately rather than folded in: archie-core-q4og (container-runtime-policies embeds config.ContainerConfig, 7 fields, zero json tags). Audit of every other seeded/mirrored type: Repo 12/12, Provider 4/4, ToolPolicy 2/2, WebFetchConfig 4/4, MinimaxConfig 3/3, Dispatch 3/3, SecretRef 2/2, cronstore.JobSpec 4/4 -- all fully tagged, so q4og is the last instance of this class.

Close reason

Fixed in 092194cd: the channel-settings document has its own snake_case shape, and rate_limit.window is a duration string.


Imported from beads archie-core-02rm · GitHub #1172 · type bug · priority P3 · created 2026-09-21 · closed 2026-09-26

Found while correcting my own citations of [chat.rate_limit] (commit 0ca733f7). The channel-settings resource is Web-UI-owned and applied (boot.loadRuntimeConfig -> boot.startRateLimiter, restart-required), but two of its nested values are not usable from the Web UI as rendered. EVIDENCE internal/app/controlplane/channel_settings.go puts two internal/config structs straight into the resource: RateLimit config.RateLimitConfig `json:"rate_limit"` Email config.EmailConfig `json:"email"` Neither struct carries a json tag, so encoding/json falls back to the Go field names, and RateLimitConfig.Window is a bare time.Duration, which encoding/json encodes as int64 nanoseconds. Verified by marshalling: RateLimitConfig{Window: time.Minute, MaxRequests: 20} -> {"Window":60000000000,"MaxRequests":20} EmailConfig{...} -> {"ListenAddr":"127.0.0.1:2525","RelayAddr":"smtp.example.com:587"} The Web UI renders this resource with StructuredResourceCard -> StructuredValueEditor, which recurses into nested objects and labels each key by replacing underscores and capitalising the first letter. So the operator sees "Window", "MaxRequests", "ListenAddr", "RelayAddr" -- inconsistent with the kind's own top-level snake_case keys (show_tool_calls, webhook_addr, unrestricted_filesystem) -- and must enter 60000000000 to mean the "1m" the file example shows as window = "1m". A number Input receiving "1m" yields NaN, which fails json.Marshal, so the save errors rather than storing a plausible wrong value; a cleared field stores 0, which silently disables rate limiting. IN-REPO PRECEDENT The sibling resource in the same file already solves exactly this: operational_settings.go builds scheduling-policy with PollInterval: cfg.PollInterval.Std().String(), a deliberate human-readable string, while channel-settings passes the raw Duration through. tool_settings.go and the other kinds are worth checking for the same pattern. FIX DIRECTION Give the channel-settings document its own wire shape (snake_case json tags, Duration rendered as a string the way scheduling-policy already does) and map to/from config.RateLimitConfig and config.EmailConfig at the resource boundary, so the resource stops being a JSON projection of an internal struct whose tags belong to a different file format. Check the other operational kinds for the same leak before fixing only this one. ### Notes FIX COMMITTED, NOT YET LANDED: 092194cd 'fix(controlplane): give the channel document its own shape'. What it does: channel_settings.go now defines the document (emailSettings, rateLimitSettings with explicit snake_case tags, and channelDuration, which writes the string the file accepts and reads that, a nanosecond count, and the Go-cased keys an existing store holds). The tolerance stays strict -- decodeRenamingLegacyKeys renames the four known legacy keys and keeps DisallowUnknownFields, because an unknown key decodes as 'unset' and an unset rate limit is off, so a misspelling is refused. normalizeChannels (the Definition.Normalize hook schedules already uses) rewrites a legacy document into the current shape on write, so a store converges on its next save while reads tolerate it until then. Verified by me: controlplane, messaging and configuration suites, archied (the loadRuntimeConfig consumer), go vet, go build ./..., golangci-lint run ./... (0 issues), docs:check, docs:prds. The FULL task check has NOT run on this commit: the shared checkout is contended and the merge train owns that gate. It is gating 092194cd now and will report. Left open deliberately until that gate reports green, per the tracker convention of closing when work lands rather than when it commits. Sibling found by the same audit and filed separately rather than folded in: archie-core-q4og (container-runtime-policies embeds config.ContainerConfig, 7 fields, zero json tags). Audit of every other seeded/mirrored type: Repo 12/12, Provider 4/4, ToolPolicy 2/2, WebFetchConfig 4/4, MinimaxConfig 3/3, Dispatch 3/3, SecretRef 2/2, cronstore.JobSpec 4/4 -- all fully tagged, so q4og is the last instance of this class. ### Close reason Fixed in 092194cd: the channel-settings document has its own snake_case shape, and rate_limit.window is a duration string. --- _Imported from beads `archie-core-02rm` · GitHub #1172 · type bug · priority P3 · created 2026-09-21 · closed 2026-09-26_
sam added the lowbug labels 2026-10-27 13:36:37 +00:00
sam self-assigned this 2026-10-27 13:36:37 +00:00
sam closed this issue 2026-10-27 13:36:37 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#514