{"record":{"id":"aeacfbd9a69d042d","repo":"vxcontrol/pentagi","slug":"failed-to-create-search-log-w","errorCode":null,"errorMessage":"failed to create search log: %w","messagePattern":"failed to create search log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/pkg/controller/slog.go","lineNumber":67,"sourceCode":"\tresult string,\n\ttaskID *int64,\n\tsubtaskID *int64,\n) (int64, error) {\n\tslw.mx.Lock()\n\tdefer slw.mx.Unlock()\n\n\tslLog, err := slw.db.CreateSearchLog(ctx, database.CreateSearchLogParams{\n\t\tInitiator: initiator,\n\t\tExecutor:  executor,\n\t\tEngine:    engine,\n\t\tQuery:     query,\n\t\tResult:    result,\n\t\tFlowID:    slw.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 search log: %w\", err)\n\t}\n\n\tslw.pub.SearchLogAdded(ctx, slLog)\n\n\treturn slLog.ID, nil\n}\n\nfunc (slw *flowSearchLogWorker) GetLog(ctx context.Context, msgID int64) (database.Searchlog, error) {\n\tmsg, err := slw.db.GetFlowSearchLog(ctx, database.GetFlowSearchLogParams{\n\t\tID:     msgID,\n\t\tFlowID: slw.flowID,\n\t})\n\tif err != nil {\n\t\treturn database.Searchlog{}, fmt.Errorf(\"failed to get search log: %w\", err)\n\t}\n\n\treturn msg, nil\n}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/slog.go#L49-L85","documentation":"PutLog persists a search-log record (query, engine result, flow/task/subtask IDs) via the database insert CreateSearchLog; on failure it returns \"failed to create search log: %w\". The SearchLogAdded event is published only after a successful insert, so this error means the search was not recorded. The frontend treats engine as an opaque string, but a lost insert means the log is invisible in the UI.","triggerScenarios":"The web_search orchestrator records a search while the INSERT fails: DB unreachable, constraint violation (e.g. invalid engine or flow_id FK), oversized result payload, or context cancellation during the write.","commonSituations":"Large search results exceeding column limits; database restart or failover during an active pentest run; FK failure when the flow/task was deleted while a search was in flight; connection pool exhaustion under heavy tool activity.","solutions":["Unwrap the error to identify the driver/constraint cause.","Check the result payload size against the DB column type/limits.","Verify DB health and that the referenced flow/task rows still exist.","Retry the insert after transient failures; search-log writes are idempotent-safe to reissue for a new record."],"exampleFix":"null","handlingStrategy":"fallback","validationCode":"// bound the stored result size before the insert\nif len(result) > maxSearchLogResultLen {\n    result = result[:maxSearchLogResultLen]\n}","typeGuard":"null","tryCatchPattern":"id, err := slw.PutLog(ctx, taskID, subtaskID, engine, query, result)\nif err != nil {\n    // search logs are observability data — never fail the search itself\n    logger.WithError(err).Warn(\"search log not persisted\")\n    return 0, nil\n}","preventionTips":["Treat search logs as best-effort: don't let log-insert failures break the agent's search flow.","Truncate large result payloads to fit the DB column.","Verify flow/task FK rows still exist when logging from long-running tool calls.","Watch for pool exhaustion during heavy tool activity and size the pool accordingly."],"tags":["database","go","search","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"}