{"record":{"id":"cc7c6ea8fadf92c2","repo":"vxcontrol/pentagi","slug":"failed-to-create-flow-worker-w","errorCode":null,"errorMessage":"failed to create flow worker: %w","messagePattern":"failed to create flow worker: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/flows.go","lineNumber":189,"sourceCode":"\t\t\tdb:     fc.db,\n\t\t\tcfg:    fc.cfg,\n\t\t\tdocker: fc.docker,\n\t\t\tprovs:  fc.provs,\n\t\t\tsubs:   fc.subs,\n\t\t\tflowProviderControllers: flowProviderControllers{\n\t\t\t\tmlc:  fc.mlc,\n\t\t\t\taslc: fc.aslc,\n\t\t\t\talc:  fc.alc,\n\t\t\t\tslc:  fc.slc,\n\t\t\t\ttlc:  fc.tlc,\n\t\t\t\tvslc: fc.vslc,\n\t\t\t\ttclc: fc.tclc,\n\t\t\t\tsc:   fc.sc,\n\t\t\t},\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create flow worker: %w\", err)\n\t}\n\n\tfc.flows[fw.GetFlowID()] = fw\n\n\treturn fw, nil\n}\n\nfunc (fc *flowController) CreateAssistant(\n\tctx context.Context,\n\tuserID int64,\n\tflowID int64,\n\tinput string,\n\tuseAgents bool,\n\tprvname provider.ProviderName,\n\tprvtype provider.ProviderType,\n\tfunctions *tools.Functions,\n\tresources []database.UserResource,\n) (AssistantWorker, error) {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flows.go#L171-L207","documentation":"CreateFlow wraps a failure of LoadFlowWorker (which assembles flowProviderWorkers and spins up the worker) with this message. The flow row may have been created in the DB, but the in-memory worker could not be constructed, so no worker is registered in fc.flows.","triggerScenarios":"Calling CreateFlow when any component of flowWorkerCtx fails to initialize its worker — e.g., any of the log fetchers (msg/agent/search/term/vector-store/tool-call/screenshot) errors for the freshly created flowID.","commonSituations":"DB degraded right after flow insert; storage components misconfigured (screenshots/vector store); resource exhaustion (goroutines/connections) under heavy flow creation load.","solutions":["Check the wrapped cause from LoadFlowWorker logs to find which component failed.","Delete or clean up the orphaned flow row if the worker cannot be created, then retry CreateFlow.","Verify all storage backends (DB, screenshot store, vector store) are healthy.","Reduce creation concurrency or scale the DB connection pool if under load."],"exampleFix":"// before\nfw, err := LoadFlowWorker(ctx, flow, flowWorkerCtx{...})\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to create flow worker: %w\", err)\n}\n// after\nfw, err := LoadFlowWorker(ctx, flow, flowWorkerCtx{...})\nif err != nil {\n\t_ = fc.db.DeleteFlow(ctx, flow.GetFlowID()) // avoid orphaned flow rows\n\treturn nil, fmt.Errorf(\"failed to create flow worker: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure backing stores are healthy before creating flows\nif err := db.PingContext(ctx); err != nil { /* abort flow creation */ }\n// storage/vector/screenshot services health-checked at boot","typeGuard":"func isCreateWorkerError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"failed to create flow worker\")\n}","tryCatchPattern":"fw, err := LoadFlowWorker(ctx, flow, flowWorkerCtx{...})\nif err != nil {\n\t// roll back the persisted flow row to avoid orphans\n\t_ = fc.db.DeleteFlow(ctx, flow.GetFlowID())\n\treturn nil, fmt.Errorf(\"failed to create flow worker: %w\", err)\n}","preventionTips":["Health-check all worker dependencies (DB, screenshot store, vector store) before accepting flow creation.","Roll back the DB flow row when worker creation fails.","Unwrap and log the root cause to identify the failing component quickly.","Limit concurrent flow creation to avoid resource exhaustion."],"tags":["flow-creation","worker-init","error-wrapping"],"backgroundTag":"worker-initialization-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}