{"record":{"id":"d1ae85c5553cafe4","repo":"vxcontrol/pentagi","slug":"failed-to-create-flow-term-log-w","errorCode":null,"errorMessage":"failed to create flow term log: %w","messagePattern":"failed to create flow term log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/flow.go","lineNumber":1184,"sourceCode":") (*flowProviderWorkers, error) {\n\talw, err := cnts.alc.NewFlowAgentLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow agent log: %w\", err)\n\t}\n\n\tmlw, err := cnts.mlc.NewFlowMsgLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow msg log: %w\", err)\n\t}\n\n\tslw, err := cnts.slc.NewFlowSearchLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow search log: %w\", err)\n\t}\n\n\ttlw, err := cnts.tlc.NewFlowTermLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow term log: %w\", err)\n\t}\n\n\tvslw, err := cnts.vslc.NewFlowVectorStoreLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow vector store log: %w\", err)\n\t}\n\n\ttclw, err := cnts.tclc.NewFlowToolCallLog(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow tool call log: %w\", err)\n\t}\n\n\tsw, err := cnts.sc.NewFlowScreenshot(ctx, flowID, pub)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow screenshot: %w\", err)\n\t}\n\n\treturn &flowProviderWorkers{","sourceCodeStart":1166,"sourceCodeEnd":1202,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flow.go#L1166-L1202","documentation":"Fourth step of newFlowProviderWorkers: the terminal log worker is created via cnts.tlc.NewFlowTermLog(ctx, flowID, pub). An error is wrapped with this message and flow startup aborts, since terminal command/session output cannot be persisted without it.","triggerScenarios":"NewFlowTermLog fails during flow startup — DB error initializing terminal log storage for the flow, nonexistent flowID, or context cancellation before this step.","commonSituations":"PostgreSQL unreachable or restarting during flow creation; terminal_logs table missing from an incomplete migration; concurrent flow deletion; ctx deadline exceeded after earlier slow worker-creation steps.","solutions":["Check the wrapped cause and Postgres server logs","Apply pending migrations so the terminal-log schema is present","Verify DB connectivity and retry flow creation","Confirm the flow still exists in the DB"],"exampleFix":"// before: retries absent; transient DB blip kills flow start\ntlw, err := cnts.tlc.NewFlowTermLog(ctx, flowID, pub)\nif err != nil { return nil, fmt.Errorf(\"failed to create flow term log: %w\", err) }\n// after: bounded retry for transient DB errors\nvar tlw *termlog.Worker\ngofmt // pseudo: retry helper\nerr = retry(3, time.Second, func() error {\n    var e error\n    tlw, e = cnts.tlc.NewFlowTermLog(ctx, flowID, pub)\n    return e\n})\nif err != nil { return nil, fmt.Errorf(\"failed to create flow term log: %w\", err) }","handlingStrategy":"retry","validationCode":"var t int\nif err := db.QueryRowContext(ctx, `SELECT COUNT(1) FROM information_schema.tables WHERE table_name='terminal_logs'`).Scan(&t); err != nil || t == 0 {\n    return errors.New(\"terminal log schema missing: run migrations\")\n}","typeGuard":"func hasValidFlowID(flowID int64) bool { return flowID > 0 }","tryCatchPattern":"tlw, err := cnts.tlc.NewFlowTermLog(ctx, flowID, pub)\nif err != nil {\n    if isTransientDBError(err) { /* retry up to 3x */ }\n    return nil, fmt.Errorf(\"failed to create flow term log (flow=%d): %w\", flowID, err)\n}","preventionTips":["Verify migrations ran at boot before accepting flow creation","Bounce detection: alert on Postgres restarts","Bound worker-creation time with a dedicated context timeout","Confirm the flow row exists before each creation step"],"tags":["go","database","flow-startup","terminal"],"backgroundTag":"database-write-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}