{"record":{"id":"c4de2bf030669ff8","repo":"vxcontrol/pentagi","slug":"failed-to-get-container-d-w","errorCode":null,"errorMessage":"failed to get container %d: %w","messagePattern":"failed to get container (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/tools.go","lineNumber":843,"sourceCode":"\tif cfg.Installer == nil {\n\t\treturn nil, fmt.Errorf(\"installer handler is required\")\n\t}\n\n\tif cfg.Memorist == nil {\n\t\treturn nil, fmt.Errorf(\"memorist handler is required\")\n\t}\n\n\tif cfg.Pentester == nil {\n\t\treturn nil, fmt.Errorf(\"pentester handler is required\")\n\t}\n\n\tif cfg.Searcher == nil {\n\t\treturn nil, fmt.Errorf(\"searcher handler is required\")\n\t}\n\n\tcontainer, err := fte.db.GetFlowPrimaryContainer(context.Background(), fte.flowID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get container %d: %w\", fte.flowID, err)\n\t}\n\n\tterm := NewTerminalTool(\n\t\tfte.flowID, nil, nil,\n\t\tcontainer.ID,\n\t\tcontainer.LocalID.String,\n\t\tfte.cfg.TenantPrefix(),\n\t\tfte.docker,\n\t\tfte.tlp,\n\t\ttime.Duration(fte.cfg.TerminalToolTimeout)*time.Second,\n\t)\n\n\tdefinitions := []llms.FunctionDefinition{\n\t\tregistryDefinitions[TerminalToolName],\n\t\tregistryDefinitions[FileToolName],\n\t}\n\thandlers := map[string]ExecutorHandler{\n\t\tTerminalToolName: term.Handle,","sourceCodeStart":825,"sourceCodeEnd":861,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/tools.go#L825-L861","documentation":"After handler validation, GetAssistantExecutor fetches the flow's primary container via fte.db.GetFlowPrimaryContainer. This error wraps any database failure (connection error, no row, query error) while resolving that container, and is needed because terminal/exec tools are bound to the container ID.","triggerScenarios":"Calling GetAssistantExecutor when the flow has no primary container row in the database, or the DB is unreachable/failing — the sqlc/GORM error from GetFlowPrimaryContainer is wrapped with flow ID %d.","commonSituations":"Flow created but its Docker container never registered in the DB; container record deleted while the flow still exists; PostgreSQL down or connection pool exhausted; using a flow ID that was never started.","solutions":["Inspect the wrapped cause (%w) to distinguish 'no rows' from a DB connectivity error.","If no rows: ensure the flow's primary container was created and recorded (start the flow / re-run container provisioning).","If connectivity: verify PostgreSQL is up, credentials and DATABASE_URL are correct, and the pool is not exhausted.","Confirm the flow ID passed to flowToolsExecutor matches an existing flow."],"exampleFix":"// before\ncontainer, err := fte.db.GetFlowPrimaryContainer(ctx, fte.flowID)\nif err != nil { return nil, fmt.Errorf(\"failed to get container %d: %w\", fte.flowID, err) }\n// after — handle 'not found' distinctly upstream\ncfg.ContainerID = container.ID // ensure flow provisioning ran:\n// 1) create flow  2) start primary container  3) then call GetAssistantExecutor","handlingStrategy":"try-catch","validationCode":"var count int64\ndb.Model(&models.Flow{}).Where(\"id = ?\", flowID).Count(&count)\nif count == 0 {\n    return errors.New(\"flow does not exist\")\n}\n// optionally: check a primary container row exists before calling GetAssistantExecutor","typeGuard":null,"tryCatchPattern":"executor, err := fte.GetAssistantExecutor(cfg)\nif err != nil {\n    var noRows sql.ErrNoRows\n    if errors.As(err, &noRows) || strings.Contains(err.Error(), \"failed to get container\") {\n        // check DB connectivity and that the flow's primary container was provisioned\n    }\n    return err\n}","preventionTips":["Always create the flow's primary container before constructing executors.","Monitor PostgreSQL health; wrap GetFlowPrimaryContainer failures with flow ID context.","Delete flows together with their container records to avoid orphaned flows."],"tags":["database","container","flow"],"backgroundTag":"database-record-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}