{"record":{"id":"cc82c1db68d83d9f","repo":"vxcontrol/pentagi","slug":"failed-to-load-flow-d-w","errorCode":null,"errorMessage":"failed to load flow %d: %w","messagePattern":"failed to load flow (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/flows.go","lineNumber":267,"sourceCode":"\t\tfc.flows[fw.GetFlowID()] = fw\n\t\tflowID = fw.GetFlowID()\n\t\tfw.SetStatus(ctx, database.FlowStatusWaiting)\n\n\t\treturn nil\n\t}\n\n\tloadFlow := func() error {\n\t\tflow, err := fc.db.UpdateFlowStatus(ctx, database.UpdateFlowStatusParams{\n\t\t\tID:     flowID,\n\t\t\tStatus: database.FlowStatusWaiting,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to renew flow %d status: %w\", flowID, err)\n\t\t}\n\n\t\tfw, err = LoadFlowWorker(ctx, flow, flowWorkerCtx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to load flow %d: %w\", flowID, err)\n\t\t}\n\n\t\tfc.flows[flowID] = fw\n\n\t\treturn nil\n\t}\n\n\tif flowID == 0 {\n\t\tif err := newFlow(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t} else if fw, ok = fc.flows[flowID]; ok {\n\t\tstatus, err := fw.GetStatus(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get flow %d status: %w\", flowID, err)\n\t\t}\n\n\t\tswitch status {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flows.go#L249-L285","documentation":"Wrap in the loadFlow closure of CreateAssistant when LoadFlowWorker cannot rebuild an in-memory FlowWorker from the persisted flow record. The DB status update succeeded but reconstructing the worker (rehydrating providers, functions, Docker refs) failed.","triggerScenarios":"CreateAssistant on a flowID that is not in fc.flows (e.g. after backend restart) and LoadFlowWorker errors: the stored provider name/type is no longer valid, provider credentials are missing, the configured container/tools are gone, or required config values are absent.","commonSituations":"Restarting the backend after changing/removing a provider's API key so old flows reference a now-unconfigurable provider; upgrading PentAGI so stored provider types no longer validate; Docker containers from a previous run having been pruned.","solutions":["Inspect the wrapped root cause; it names why LoadFlowWorker failed (provider lookup, config, Docker).","Restore the provider configuration the flow was created with (API key env vars, server URL).","If the flow cannot be rehydrated, start a new flow (flowID=0) instead of resuming this one.","Ensure Docker is reachable and the flow's worker container still exists or can be recreated.","Verify the stored provider type is still supported after an upgrade."],"exampleFix":"// before\nbackend restarted with OPENAI_API_KEY unset -> LoadFlowWorker fails\n// after\nexport OPENAI_API_KEY=... (or configure via Settings) then retry CreateAssistant with the same flowID","handlingStrategy":"retry","validationCode":"// confirm the flow's provider is still configured before resuming\nif os.Getenv(\"OPENAI_API_KEY\") == \"\" && flowUsesProvider(\"openai\") {\n    return fmt.Errorf(\"provider credentials missing; cannot resume flow\")\n}","typeGuard":null,"tryCatchPattern":"fw, err := ctl.GetFlow(ctx, flowID)\nif err != nil { // ErrFlowNotFound -> worker must be rehydrated\n    _, err = ctl.CreateAssistant(ctx, userID, flowID, ...)\n    if err != nil { log.Errorf(\"rehydrate flow %d: %v\", flowID, err) }\n}","preventionTips":["Persist all provider credentials the flows depend on; don't rotate keys without restarting workers.","After backend restarts, verify provider config before resuming old flows.","Keep Docker running and avoid pruning containers belonging to active flows.","Pin application version to migration version to avoid unknown stored provider types."],"tags":["go","flow-worker","state-restoration","wrapped-error"],"backgroundTag":"worker-rehydration-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}