Skip to content

omitempty silently erases explicitly-configured zero values on max_result_size_chars, activity_max_size_mb and tracing.sample_rate #1175

Closed

Description

@Dumbris

Summary

Three config fields are tagged omitempty on a numeric type while 0 is a meaningful, documented value. SaveConfig (internal/config/loader.go:392) is json.MarshalIndent, so an operator's explicit 0 is deleted from mcp_config.json on the next save and the field silently reverts to its default.

This was found and fixed for activity_max_response_size while reviewing #1173/#1174. The same shape exists on three more fields that nobody has fixed.

Affected fields

Field Line Default What 0 is documented to mean
max_result_size_chars internal/config/config.go:261 500000 "Set to 0 to disable." — the field's own doc comment
activity_max_size_mb internal/config/config.go:467 256 "0=disabled" — the field's own doc comment
observability.tracing.sample_rate internal/config/config.go:1486 0.1 sample nothing

max_result_size_chars is the sharpest: it is advertised on every tool as _meta.anthropic/maxResultSizeChars and internal/server/mcp_max_result_size.go treats <= 0 as the opt-out. So an operator who deliberately disables the annotation gets it silently re-enabled at 500000 on the next config write.

sample_rate means an operator who turns trace sampling off gets 10% sampling back.

Reproduce

Set the field to 0, save the config through any path that calls SaveConfig — the Web UI raw-config editor (GET /api/v1/config → POST /api/v1/config/apply) is the easy one — then read the file back. The key is gone. Restart and the default is in force.

Verified empirically per field: set on DefaultConfig(), json.MarshalIndent, check whether the key survived.

Suggested fix

activity_max_response_size was fixed by making the field a *int with a single Effective…() reader: nil = absent (default applies), 0 = explicitly disabled, and both round-trip through marshal → decode without loss. Dropping omitempty from the int is not equivalent — it materialises an absent key as an explicit 0, which turns the feature off for every operator who never set it. There is a regression test pinning exactly that distinction (TestActivityMaxResponseSizeAbsentKeyStaysAbsentAndKeepsTheCap).

Worth adding alongside the fixes: a guard test that walks the Config struct by reflection and fails on any numeric field carrying omitempty unless it is on an allowlist with a stated reason. That is what stops this class coming back a fourth time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/storagekind/bugpriority/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions