api: raise the docs page bound and make truncation visible - #810
Conversation
docsfetch cut every MCP-served page at 10,000 bytes, which truncates 12 of the 27 reachable docs slugs — including the kalshi runbook, so an agent driving it loses the tail of the procedure. The cut was silent: a bare marker in the content string and no signal anywhere else. Raise the bound to 64 KiB (largest real page is ~34 KB) and report truncation as data on both tool outputs, with the marker naming the source so an agent can point the user at the rest.
A cut runbook index yields a short catalog, so get_onboarding_runbook would answer "unknown runbook" for a runbook that exists. Refuse it instead. Also log truncation at WARN, since the in-band marker is visible to the model but not to an operator.
nikw9944
left a comment
There was a problem hiding this comment.
Nothing blocking. Two things worth folding in: the chat agent keeps its own docs fetch still bounded at 10,000 bytes with the old silent marker, so the pages this PR unblocks stay truncated on the web and Slack paths; and the new truncated-index refusal takes get_onboarding_runbook down for every caller while logging nothing, making it the one truncation case with no operator signal.
The agent had its own copy of the docs fetch with the old 10,000-byte bound, so the pages this branch unblocks stayed truncated on the web and Slack paths. Routing it through docsfetch.Client.Read collapses the duplicate and picks up the slug validation it never had. The truncated-index refusal was the one truncation case with no operator signal; log it at WARN like the other two.
|
Both folded in — thanks, the agent copy was a real miss. The duplicate fetch. Routed The index refusal. Now logs WARN before returning, so all three truncation cases have a line. I kept the refusal itself: One thing I could not verify: the four new |
nikw9944
left a comment
There was a problem hiding this comment.
Both round-1 findings verified fixed in 814bb2c: the agent's duplicate docs fetch now routes through docsfetch.Client.Read (one bound, one marker, error wording preserved), and the truncated-index refusal logs WARN before returning. Nothing new in that commit. lgtm.
docsfetchcut every MCP-served docs page atMaxPageBytes = 10000. Measured againstmalbeclabs/docs@751d45b, that truncates 12 of the 27 MCP-reachable slugs:The bound arrived in #770 as a defensive constant, not a measured one. It was also silent — a bare
... (truncated)appended to the content string and no signal anywhere else — which is why this went unnoticed. Forget_onboarding_runbookit means an agent walks a user through a procedure with the tail of the runbook missing.Raises the bound to 64 KiB (~2x the largest real page), makes the marker name the byte count and the source URL so an agent can point the user at the rest, and reports
truncatedon both tool outputs.Three things worth a reviewer's attention:
The chat agent had its own copy of the fetch, still bounded at 10,000 with the old silent marker, so the raised bound would not have reached web or Slack users.
readDocsinagent/pkg/workflow/v3/pipeline.gonow callsdocsfetch.Client.Read— a net −55 lines, and it picks up two things it never had: theValidPageslug guard (it previously interpolated the page straight into a raw.githubusercontent URL) and a request timeout.A truncated runbook index is a hard error, not a short catalog.
loadRunbookCatalogparsesrunbooks.mdinto the list of known services; a cut index silently drops entries, andget_onboarding_runbookthen answersunknown runbook "kalshi"for a runbook that exists. That is a confident wrong answer rather than a degraded one, so it fails instead. It is the onlyReadcall site whose result the handler branches on.All three truncation cases now log at WARN. The in-band marker reaches the model but not an operator; the index refusal takes the tool down for every caller, so it is the one that most needed a line.
read_docsalso advertises three pages that no longer exist and one that is an HTML redirect stub — in both the MCP and agent tool descriptions. Real, but a separate change.Testing Verification
TestRead_LargestRealPageIsNotTruncatedpins a 34,000-byte page reading back whole; red-checked against the old constant, where it fails. The marker's wording is asserted indocsfetch, which runs without containers.No test here can catch a docs page crossing the bound — nothing in lake knows those sizes, they are fetched at runtime from another repo. Loud truncation is the mitigation chosen over a cross-repo CI size check.
Two gaps, both environmental: the four new
api/handlerstests and the eval suite were not executed locally, since both packages'TestMainstarts containers and Docker was unavailable. Both compile and vet clean. No eval referencesread_docs, so the agent change is unexercised by that suite either way;agent/pkg/workflow/v3unit tests pass.make lintandgo build ./...fail identically onmain(dev/controlcenterneeds a built UI bundle). Both clean when scoped to the touched packages.Blocks
malbeclabs/docs#200 — its new
## Teardownsection lands past the old cut onkalshi-runbook.md(11,086 bytes). The alternative offered there, trimming the page under 10,000, is not the fix taken.