{"record":{"id":"17208ad6b60b01fa","repo":"JuliusBrussee/caveman","slug":"rewriter-theta-must-not-be-negative-got-d","errorCode":null,"errorMessage":"rewriter: theta must not be negative, got %d","messagePattern":"rewriter: theta must not be negative, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rewriter/rewriter.go","lineNumber":144,"sourceCode":"// gate was designed for.\nfunc New(cfg Config) (*Client, error) {\n\tprovider := strings.ToLower(strings.TrimSpace(cfg.Provider))\n\tif provider != providerAnthropic && provider != providerOpenAI {\n\t\treturn nil, fmt.Errorf(\"rewriter: unsupported provider %q\", cfg.Provider)\n\t}\n\tmodel := strings.TrimSpace(cfg.Model)\n\tif model == \"\" {\n\t\treturn nil, errors.New(\"rewriter: model is required\")\n\t}\n\tif strings.TrimSpace(cfg.APIKey) == \"\" {\n\t\treturn nil, errors.New(\"rewriter: api key is required\")\n\t}\n\ttheta := cfg.Theta\n\tif theta == 0 {\n\t\ttheta = DefaultTheta\n\t}\n\tif theta < 0 {\n\t\treturn nil, fmt.Errorf(\"rewriter: theta must not be negative, got %d\", theta)\n\t}\n\tdoer := cfg.HTTPDoer\n\tif doer == nil {\n\t\tdoer = http.DefaultClient.Do\n\t}\n\treturn &Client{provider: provider, model: model, apiKey: cfg.APIKey, theta: theta, doer: doer}, nil\n}\n\n// Rewrite condenses req.StepBytes, or explains why it did not.\n//\n// Gate 1 (invocation) skips the API call entirely when the step is at or under\n// θ tokens. Gate 2 (application) plus the fidelity checks in Accept decide\n// whether the completion may replace the original. Only an accepted result\n// carries bytes; every other path returns an empty Rewritten and a reason.\nfunc (c *Client) Rewrite(ctx context.Context, req Request) (Result, error) {\n\toriginalTokens := countTokens(req.StepBytes)\n\tif originalTokens <= c.theta {\n\t\treturn Result{RejectReason: reasonBelowTheta}, nil","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/rewriter/rewriter.go#L126-L162","documentation":"New validated the rewriter theta gate configuration and found a negative Theta value. Theta zero defaults to DefaultTheta, but a negative threshold is nonsensical for the gate (it would invert the accept/reject decision) and is rejected at construction time.","triggerScenarios":"Thrown at rewriter/rewriter.go:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set Theta to a non-negative value (or 0/omit it to use DefaultTheta)","Remove the negative sign — likely a typo in configuration"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}