{"record":{"id":"afb2d32893f76cfc","repo":"vxcontrol/pentagi","slug":"failed-to-create-screenshot-w","errorCode":null,"errorMessage":"failed to create screenshot: %w","messagePattern":"failed to create screenshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/screenshot.go","lineNumber":47,"sourceCode":"\t\tflowID:     flowID,\n\t\tcontainers: make(map[int64]struct{}),\n\t\tpub:        pub,\n\t}\n}\n\nfunc (sw *flowScreenshotWorker) PutScreenshot(ctx context.Context, name, url string, taskID, subtaskID *int64) (int64, error) {\n\tsw.mx.Lock()\n\tdefer sw.mx.Unlock()\n\n\tscreenshot, err := sw.db.CreateScreenshot(ctx, database.CreateScreenshotParams{\n\t\tName:      database.SanitizeUTF8(name),\n\t\tUrl:       database.SanitizeUTF8(url),\n\t\tFlowID:    sw.flowID,\n\t\tTaskID:    database.Int64ToNullInt64(taskID),\n\t\tSubtaskID: database.Int64ToNullInt64(subtaskID),\n\t})\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to create screenshot: %w\", err)\n\t}\n\n\tsw.pub.ScreenshotAdded(ctx, screenshot)\n\n\treturn screenshot.ID, nil\n}\n\nfunc (sw *flowScreenshotWorker) GetScreenshot(ctx context.Context, screenshotID int64) (database.Screenshot, error) {\n\tscreenshot, err := sw.db.GetScreenshot(ctx, screenshotID)\n\tif err != nil {\n\t\treturn database.Screenshot{}, fmt.Errorf(\"failed to get screenshot: %w\", err)\n\t}\n\n\treturn screenshot, nil\n}\n","sourceCodeStart":29,"sourceCodeEnd":63,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/screenshot.go#L29-L63","documentation":"PutScreenshot persists a screenshot record via the database (CreateScreenshot) with sanitized URL and flow/task/subtask IDs; on DB failure it returns \"failed to create screenshot: %w\". The controller only publishes the ScreenshotAdded event after the insert succeeds, so this error means nothing was stored or broadcast.","triggerScenarios":"An agent/tool calls the screenshot worker's PutScreenshot while the INSERT fails: DB unreachable, NOT NULL/FK violation on flow_id/task_id, oversized data column exceeding limits, or context cancellation mid-insert.","commonSituations":"Screenshot blob exceeding column size limits (e.g. large base64 payloads vs. TEXT/bytea constraints); database restarted mid-run; worker outliving a cancelled context; foreign key mismatch when the parent task was deleted concurrently.","solutions":["Unwrap the error to see the driver/constraint failure.","Check screenshot payload size against the DB column type and Postgres limits.","Verify DB connectivity and that the parent flow/task rows still exist (FK constraints).","Retry the put after transient DB failures — the insert is atomic and leaves no partial state."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// validate payload size and parent existence before inserting\nif len(screenshotData) > maxScreenshotBytes {\n    return fmt.Errorf(\"screenshot too large: %d bytes\", len(screenshotData))\n}\nif _, err := db.GetFlow(ctx, flowID); err != nil {\n    return err // parent row missing would violate FK\n}","typeGuard":"null","tryCatchPattern":"id, err := sw.PutScreenshot(ctx, taskID, subtaskID, url, data)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create screenshot\") {\n        logger.WithError(err).Warn(\"screenshot not persisted\")\n        // degrade gracefully: agent continues without the screenshot record\n        return 0, nil\n    }\n    return 0, err\n}","preventionTips":["Compress/resize screenshots before persisting to stay within column limits.","Ensure the flow/task rows exist before writing child records.","Use contexts that survive the originating tool call's request scope.","Alert on insert failures — the event is only published after a successful insert, so no record means no UI entry."],"tags":["database","go","screenshot","insert"],"backgroundTag":"database-insert-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}