{"record":{"id":"606ef3d16f1f21f2","repo":"grafana/k6","slug":"default-stack-configured-but-the-default-project-i","errorCode":null,"errorMessage":"default stack configured but the default project ID is not available - please run `k6 cloud login` to refresh your configuration","messagePattern":"default stack configured but the default project ID is not available - please run `k6 cloud login` to refresh your configuration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":577,"sourceCode":"\nfunc resolveDefaultProjectID(\n\tgs *state.GlobalState,\n\tcloudConfig *cloudapi.Config,\n) (int64, error) {\n\t// Priority: projectID -> default stack from config\n\tif cloudConfig.ProjectID.Valid && cloudConfig.ProjectID.Int64 > 0 {\n\t\treturn cloudConfig.ProjectID.Int64, nil\n\t}\n\tif cloudConfig.StackID.Valid && cloudConfig.StackID.Int64 != 0 {\n\t\tif cloudConfig.DefaultProjectID.Valid && cloudConfig.DefaultProjectID.Int64 > 0 {\n\t\t\tstackName := cloudConfig.StackURL.String\n\t\t\tif !cloudConfig.StackURL.Valid {\n\t\t\t\tstackName = fmt.Sprintf(\"stack-%d\", cloudConfig.StackID.Int64)\n\t\t\t}\n\t\t\tgs.Logger.Warnf(\"No projectID specified, using default project of the %s stack\\n\", stackName)\n\t\t\treturn cloudConfig.DefaultProjectID.Int64, nil\n\t\t}\n\t\treturn 0, fmt.Errorf(\n\t\t\t\"default stack configured but the default project ID is not available - \" +\n\t\t\t\t\"please run `k6 cloud login` to refresh your configuration\")\n\t}\n\n\t// Return 0 to let the backend pick the project (old behavior)\n\treturn 0, nil\n}\n\nfunc resolveAndSetProjectID(\n\tgs *state.GlobalState,\n\tcloudConfig *cloudapi.Config,\n\ttmpCloudConfig map[string]any,\n\tarc *lib.Archive,\n) error {\n\tprojectID, err := resolveDefaultProjectID(gs, cloudConfig)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L559-L595","documentation":"resolveProjectID found a configured stack (StackID valid and non-zero) but no usable default project: DefaultProjectID is unset or ≤ 0, so it cannot infer which project the test belongs to. The config in this state is stale — the stack block exists without the default-project field that a completed `k6 cloud login` writes — and the error tells you to refresh the configuration rather than guess.","triggerScenarios":"Config file written by an older k6 version or by hand (stack_id present, default_project_id missing), a partially updated login, or programmatic config assembly that copies StackID but not DefaultProjectID. Only reached when --project-id and K6_CLOUD_PROJECT_ID are absent and ProjectID in config is unset/0.","commonSituations":"Upgrading k6 across versions where the login config schema gained default_project_id, sharing a config file between machines with different logins, or `k6 cloud login` interrupted mid-write.","solutions":["Run `k6 cloud login` again — it rewrites the config including the default project","Or bypass inference: pass --project-id <id> on the command","Or set K6_CLOUD_PROJECT_ID in the environment","Find the numeric project ID in the Grafana Cloud k6 app URL/project picker if unsure"],"exampleFix":"# before\nk6 cloud run script.js\n# ERR: default stack configured but the default project ID is not available\n\n# after\nk6 cloud login            # refreshes token, stack, and default project\nk6 cloud run script.js\n# or: k6 cloud run --project-id 123 script.js","handlingStrategy":"validation","validationCode":"if conf.StackID.Valid && conf.StackID.Int64 != 0 &&\n    (!conf.DefaultProjectID.Valid || conf.DefaultProjectID.Int64 <= 0) {\n    return fmt.Errorf(\"stale login config: default project missing; re-run `k6 cloud login` or pass --project-id\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-run `k6 cloud login` after every k6 upgrade that touches cloud config","Pass --project-id explicitly in CI so inference never matters","Treat missing-but-expected config fields as stale state, not defaults"],"tags":["config","project-id","cloud-api","migration","cli"],"backgroundTag":"stale-configuration","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}