{"record":{"id":"343d1745488164f9","repo":"siyuan-note/siyuan","slug":"validation-exceeded-s","errorCode":null,"errorMessage":"validation exceeded %s","messagePattern":"validation exceeded (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/mcp/tools/validation.go","lineNumber":186,"sourceCode":"\t\treturn ctx.Err()\n\tcase <-timer.C:\n\t\treturn fmt.Errorf(\"validation did not start within %s\", toolValidationTime)\n\t}\n\n\tresult := make(chan error, 1)\n\tgo func() {\n\t\terr := schema.Validate(value)\n\t\t<-validationSlots\n\t\tresult <- err\n\t}()\n\n\tselect {\n\tcase err := <-result:\n\t\treturn err\n\tcase <-ctx.Done():\n\t\treturn ctx.Err()\n\tcase <-timer.C:\n\t\treturn fmt.Errorf(\"validation exceeded %s\", toolValidationTime)\n\t}\n}\n\nfunc validateJSONComplexity(value any, maxDepth, maxNodes int) error {\n\tnodes := 0\n\tvar walk func(any, int) error\n\twalk = func(current any, depth int) error {\n\t\tif depth > maxDepth {\n\t\t\treturn fmt.Errorf(\"JSON depth exceeds %d\", maxDepth)\n\t\t}\n\t\tnodes++\n\t\tif nodes > maxNodes {\n\t\t\treturn fmt.Errorf(\"JSON node count exceeds %d\", maxNodes)\n\t\t}\n\t\tswitch typed := current.(type) {\n\t\tcase map[string]any:\n\t\t\tfor _, child := range typed {\n\t\t\t\tif err := walk(child, depth+1); err != nil {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/tools/validation.go#L168-L204","documentation":"Thrown by validateResolved when schema.Validate(value) does not return within toolValidationTime (2s) after acquiring a slot. Unlike error 365 (could not start), this means validation started but the jsonschema evaluator is taking too long — typically due to catastrophic regex backtracking, exponential $ref combinatorics, or an enormous value against a complex schema.","triggerScenarios":"A single schema.Validate(value) call runs longer than 2s. Common with patterns vulnerable to ReDoS, deeply recursive schemas, or validating a multi-megabyte value against a schema with many constraints.","commonSituations":"A tool schema includes a user-supplied regex that backtracks catastrophically; a schema uses recursive $ref structures that explode against nested data; validating a near-8 MiB value against a schema with many anyOf/oneOf branches.","solutions":["Simplify the schema: replace risky regexes with anchored, linear patterns; flatten or bound recursive $ref definitions; prune redundant anyOf/oneOf branches.","Reduce the value size (see error 364) so validation has less work.","Pre-validate expensive constraints incrementally or cache compiled (Resolved) schemas.","If unavoidable, surface a clear user-facing message and degrade gracefully rather than retrying the same slow validation."],"exampleFix":"// before: regex vulnerable to catastrophic backtracking\n{\"pattern\": \"^(a+)+$\"}\n// after: anchored, linear pattern\n{\"pattern\": \"^a*$\"}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := validator.ValidateInputContext(ctx, args)\nif err != nil && strings.Contains(err.Error(), \"validation exceeded\") {\n    // schema is too slow against this value: simplify schema or shrink value\n}","preventionTips":["Avoid regexes susceptible to catastrophic backtracking in schemas.","Flatten recursive $ref definitions and prune redundant anyOf/oneOf branches.","Profile schema.Validate on representative inputs during development."],"tags":["mcp","validation","timeout","regex","performance"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}