fix(mcp-common): make outcome optional in observability event schema - #419
Open
arimu1 wants to merge 1 commit into
Open
fix(mcp-common): make outcome optional in observability event schema#419arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
zCloudflareMiniEvent required outcome on every event, but outcome only describes an invocation and is absent on console.log lines emitted inside one. query_worker_observability validates the whole event array in a single .parse(), so any response containing one of these non-invocation events was rejected outright and no logs were returned. Fixes cloudflare#418
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.
Fixes #418
zCloudflareMiniEventinpackages/mcp-common/src/types/workers-logs.types.tsdeclaresoutcome: z.string(), butoutcome(ok/exception/canceled) only describes a whole invocation.console.loglines emitted inside an invocation ($metadata.type = "cf-worker") legitimately don't have it — only the invocation-summary line ($metadata.type = "cf-worker-event") does.query_worker_observabilityvalidates the whole event array with a single.parse()inpackages/mcp-common/src/cloudflare-api.ts, so one non-invocation event in the response threw away the entire batch and the tool returned no logs at all.The issue reporter measured this against real production data: 46% of all events and 86% of cron events were missing
outcomeand getting the whole response discarded as a result.The fix makes
outcomeoptional, matching how the other non-invocation-only fields on this schema are already handled.I scoped this to the one-line schema change rather than also switching
cloudflare-api.ts's.parse()to per-event.safeParse()(also suggested in the issue) — that helper is shared by several unrelated endpoints (workers-builds, IAM integrations, KV keys/values), and changing its error-swallowing behavior generically felt like a separate, riskier change from the actual bug here.Added a regression test in
packages/mcp-common/src/types/workers-logs.types.spec.tsthat reproduces the issue's minimal repro shape (a cron event with nooutcome) and asserts an event array containing one such event still parses. Confirmed it fails with the sameinvalid_union/path: ["outcome"]Zod error described in the issue when run against the old schema, and passes with the fix.