Repository navigation
feat(server): adaptive TOON output for tool results (spec 084) - #852
Merged
Merged
Conversation
Deploying mcpproxy-docs with
|
| Latest commit: |
5d7ab69
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bdbd68fd.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://084-toon-output.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 29398139119 --repo smart-mcp-proxy/mcpproxy-go
|
Related #175 Adaptive TOON encoding for call_tool_* result payloads: encode only when tabular-uniform AND complete emission beats exact passthrough by >=15% (never-larger by construction). Off by default, per-server override, hot-reload. Security pipeline receives pre-encoding inputs; code_execution and direct mode explicitly out of scope. Gated by spec-083 profiler measurements (TOON listings measured +23.9% worse — excluded). Codex-reviewed: 3 rounds, 13 findings fixed, VERDICT: APPROVE.
Related #175 Planning package: internal/toonenc leaf package (classifier + size-compared encoder, ordered representation for determinism), server seam encodeToonBlocks (contentTrust threaded; off ⇒ empty detection text), truncation guard based on the truncator's actual retained-prefix budget, detection FINDING-parity (spec US3 clarified accordingly), string-only config resolution with per-server override, ASCII marker contract, passthrough-error scoped to true encoder faults. Codex-reviewed: 5 rounds, 14 findings fixed, VERDICT: APPROVE.
Related #175 Implements specs/084-toon-output: opt-in, measured, never-larger-by-construction. - internal/toonenc: v1 tabular classifier (>=4 rows, scalar/null values, >=90% key presence, single-key envelope), ordered-representation encoder (no raw map iteration), complete-emission size comparison vs exact passthrough, ASCII marker + decode hint, Decision records - internal/server: encodeToonBlocks seam (contentTrust + tool identity; off => byte-identical + empty detection text; sanitise before encode; encode before truncate with retained-prefix-aware guard), activity tool_call metadata per text-block, passthrough-error logging + counter - internal/config: toon_output (off/adaptive/always) + per-server override, toon_min_savings_pct (1-90), validation, DetectConfigChanges wiring - Detection FINDING-parity: same detections with feature on/off across the security corpus incl. over-limit fixtures - Regression tests: code_execution, direct mode, retrieve_tools untouched under every mode value - go test ./internal/{toonenc,config,server}/... -race: all green - golangci-lint v2 on touched packages: 0 issues - ./scripts/test-api-e2e.sh: all passed - gofmt: branch-changed files clean (5 flagged files are pre-existing main drift, untouched)
…uous determinism test Related #175 - Number fidelity gate: any json.Number that does not survive toon-go's exact float64 round-trip forces byte-identical passthrough (reason: non-roundtrippable-number) — 2^53+1 and max-uint64 corrupted before this fix; control test proves 2^53 still encodes - FR-012 profiler-arm tasks marked CROSS-BRANCH-BLOCKED on PR #851 - Randomized-key determinism test now requires >=2 distinct serializations ## Testing - go test ./internal/toonenc/... -race: green (incl. 8 new P1 subtests)
Related #175 OutputTokens/TotalTokens now recount from the final agent-facing response whenever any block was TOON-encoded (previously only on truncation), so tool-call history and session stats reflect the savings instead of overreporting pre-encoding sizes. Adds toonEncodedAny helper + test. ## Testing - go test ./internal/server -run 'Toon|TOON|TokenMetrics' -race: green
The Spec 084 FR-005 marker echo appended a verbose two-clause sentence (64 tokens) to each call_tool_read|write|destructive description, pushing the retrieve_tools proxy catalog past the frozen 45-tool corpus baseline in bench.TestComputeReport_SavingsAreReal (1761 vs 1730 tokens), failing unit tests on every platform plus the Windows/macOS binary builds. Trim to the one-line footprint the spec asks for (§137), keeping toonenc.Marker embedded verbatim so T037 / the single-source-of-truth anti-drift guarantee still hold. The marker text is self-describing, so the trailing explanatory clause was redundant. Related #175
docs/features/toon-output.md is published on the Docusaurus site and its links are validated (onBrokenLinks: throw). It linked to ../configuration.md#toon-output-adaptive-result-encoding, but the flat docs/configuration.md is an orphan not in the sidebar, so it has no route and the link 404s the docs build (Documentation + Cloudflare Pages checks). Point at ../configuration/config-file.md, the routed canonical config reference, matching the existing pattern in settings-page.md. Related #175
Bleve returns search hits by score descending but leaves equally-scored ties in an unstable, backend-dependent order. That order flows straight into the retrieve_tools tools array and its JSON, so two otherwise- identical calls could serialize differently. The Spec 084 surface- isolation test (T031) compares retrieve_tools byte-for-byte across toon_output modes and flaked on CI when a tie reordered between calls (three github tools sharing an identical BM25 score). Sort callable results by score desc then full tool name before building the response, making the agent-facing output stable regardless of the search backend. Full internal/index and internal/server suites pass. Related #175
…A5011 Related #175 CI lint upgraded to golangci-lint v2.6.2 whose staticcheck build no longer models t.Fatal as no-return at these sites; explicit returns are version-proof.
Related #175 CI-only SA5011 findings on t.Fatal no-return sites do not reproduce with the identical golangci-lint v2.6.2 + config on a clean run; the action's cross-run analysis cache is the remaining variable. Timeout raised to 10m for cold runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements spec 084 — Adaptive TOON Output for Tool Results: opt-in, per-response-adaptive TOON serialization for
call_tool_*result payloads. Encode only when the payload is tabular-uniform and the complete emission (marker + hint + body) beats the exact passthrough emission by ≥ threshold (default 15%) — never larger by construction. Off by default; byte-identical when off.Grounded in spec-083 profiler measurements (PR #851): TOON is +23.9% worse on tool listings (excluded —
retrieve_toolsuntouched) and wins only on uniform tabular results, hence adaptive instead of blanket.What's new
internal/toonenc(leaf package, bench-importable): v1 tabular classifier (≥4 rows, scalar/null values, ≥90% key presence, single-key envelope), ordered-representation encoder (no map-iteration nondeterminism), complete-emission size comparison, ASCII marker + one-line decode hint, per-block Decision records, number-fidelity gate (anyjson.Numberthat toon-go would round through float64 — e.g. 2^53+1 — forces byte-identical passthrough)encodeToonBlocks): sanitise → encode → truncate ordering;contentTrustthreaded; off ⇒ empty detection text + byte-identical path; retained-prefix-aware truncation guard; token metrics recount from the final response when encoding rantoon_output: off|adaptive|always(+ per-server override),toon_min_savings_pct(1–90), validation, hot-reload viaDetectConfigChangescode_execution, direct mode, andretrieve_toolsbyte-identical under every mode valuetool_callmetadataCross-branch note: the profiler adaptive-results arm (FR-012) is explicitly blocked on #851 merging; it lands as a follow-up after rebase.
Review
Spec: Codex-approved (3 rounds, 13 findings). Plan: Codex-approved (5 rounds, 14 findings). Implementation: Codex-approved (3 rounds — caught a real big-integer corruption bug and a token-metrics overreport, both fixed with tests).
Testing
go test ./internal/{toonenc,config,server}/... -race: green (server suite 502s)golangci-lintv2 on touched packages: 0 issues./scripts/test-api-e2e.sh: all passedRelated #175