{"record":{"id":"3a07cfe574fc919d","repo":"vxcontrol/pentagi","slug":"failed-to-get-flow-d-containers-w","errorCode":null,"errorMessage":"failed to get flow %d containers: %w","messagePattern":"failed to get flow (.+?) containers: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/pkg/controller/flow.go","lineNumber":552,"sourceCode":"\tif err != nil {\n\t\treturn database.FlowStatusFailed, err\n\t}\n\n\treturn flow.Status, nil\n}\n\nfunc (fw *flowWorker) SetStatus(ctx context.Context, status database.FlowStatus) error {\n\tflow, err := fw.flowCtx.DB.UpdateFlowStatus(ctx, database.UpdateFlowStatusParams{\n\t\tStatus: status,\n\t\tID:     fw.flowCtx.FlowID,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set flow %d status: %w\", fw.flowCtx.FlowID, err)\n\t}\n\n\tcontainers, err := fw.flowCtx.DB.GetFlowContainers(ctx, fw.flowCtx.FlowID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get flow %d containers: %w\", fw.flowCtx.FlowID, err)\n\t}\n\n\tfw.flowCtx.Publisher.FlowUpdated(ctx, flow, containers)\n\n\treturn nil\n}\n\n// InvalidateTaskSubtasks drops stale workers after direct DB deletion,\n// preventing delayed ErrNoRows failures.\nfunc (fw *flowWorker) InvalidateTaskSubtasks(ctx context.Context, taskID int64, subtaskIDs []int64) {\n\ttask, err := fw.tc.GetTask(ctx, taskID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\ttask.InvalidateSubtasks(subtaskIDs)\n}\n","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flow.go#L534-L570","documentation":"After successfully updating flow status, SetStatus fetches the flow's containers with GetFlowContainers so it can publish a FlowUpdated event. If that SELECT fails, the error is wrapped as 'failed to get flow %d containers'. The status update has already been committed at this point; only the notification path fails.","triggerScenarios":"GetFlowContainers errors: DB connectivity loss right after the status UPDATE, context cancelled mid-query, or a schema/query mismatch in the containers table.","commonSituations":"Transient Postgres hiccup between the two queries; shutdown cancelling ctx between update and read; containers table missing after partial migration/restore.","solutions":["Check the wrapped cause; if context.Canceled, re-run with context.WithoutCancel(ctx) so the event isn't dropped.","Verify Postgres health and pool limits if this recurs under load.","Since status was already updated, it is safe to retry only the container fetch + publish, not the whole SetStatus.","Confirm the containers table exists and matches the SQLC query after any migration work.","Note the inconsistency risk: status changed but subscribers not notified — trigger FlowUpdated manually if needed."],"exampleFix":"// before\nerr := fw.SetStatus(ctx, database.FlowStatusWaiting) // ctx cancelled after UPDATE, no event published\n// after\nerr := fw.SetStatus(context.WithoutCancel(ctx), database.FlowStatusWaiting)\nif err != nil {\n    log.WithError(err).Warn(\"status updated but containers fetch failed; retry publish\")\n}","handlingStrategy":"retry","validationCode":"if err := ctx.Err(); err != nil {\n    // ctx already cancelled: run SetStatus with context.WithoutCancel(ctx)\n    ctx = context.WithoutCancel(ctx)\n}","typeGuard":null,"tryCatchPattern":"err := fw.SetStatus(ctx, database.FlowStatusWaiting)\nif err != nil && strings.Contains(err.Error(), \"containers\") {\n    // status already updated; only retry the publish side\n    log.WithError(err).Warn(\"status persisted, FlowUpdated event may be missed\")\n}","preventionTips":["Pass a live (non-cancelled) context into SetStatus","Remember status is already committed when this error fires — don't re-update","Verify containers table schema after migrations/restores","Monitor Postgres for transient failures between adjacent queries"],"tags":["go","database","containers","event-publish"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}