{"record":{"id":"709cd9e27c92df97","repo":"grafana/k6","slug":"starting-test-w","errorCode":null,"errorMessage":"starting test: %w","messagePattern":"starting test: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":303,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\texecutionPlan := test.derivedConfig.Scenarios.GetFullExecutionRequirements(et)\n\t\ttestURL, err := resolveCloudTestURL(cloudConfig.StackURL.String, loadTest.GetId())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tprintExecutionDescription(\n\t\t\tgs, \"cloud\", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil,\n\t\t)\n\t\tmodifyAndPrintBar(gs, progressBar, pb.WithConstLeft(\"Run \"), pb.WithConstProgress(1.0, \"Archived\"))\n\t\tprintCloudTestStatus(gs, \"Archived\")\n\t\treturn nil\n\t}\n\n\trun, err := client.StartTest(globalCtx, loadTest.GetId())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"starting test: %w\", err)\n\t}\n\ttestRunID := run.GetId()\n\n\t// Trap Interrupts, SIGINTs and SIGTERMs.\n\tgracefulStop := func(sig os.Signal) {\n\t\tlogger.WithField(\"sig\", sig).Print(\"Stopping cloud test run in response to signal...\")\n\t\t// Do this in a separate goroutine so that if it blocks, the\n\t\t// second signal can still abort the process execution.\n\t\tgo func() {\n\t\t\tstopErr := client.StopTest(context.WithoutCancel(globalCtx), testRunID)\n\t\t\tif stopErr != nil {\n\t\t\t\tlogger.WithError(stopErr).Error(\"Stop cloud test error\")\n\t\t\t} else {\n\t\t\t\tlogger.Info(\"Successfully sent signal to stop the cloud test, now waiting for it to actually stop...\")\n\t\t\t}\n\t\t\tglobalCancel()\n\t\t}()\n\t}","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L285-L321","documentation":"After a successful upload, `k6 cloud` failed at client.StartTest — the request to actually launch the previously created load test (loadTest.GetId()) was rejected or failed in transport. The 'starting test' prefix identifies the stage; the wrapped ResponseError carries the decisive status code and API message.","triggerScenarios":"409 when a run of the same test is already active, 401/403 on expired or insufficient token permissions, 402/429 on plan or concurrency limits, or 5xx/transport failure contacting /cloud/v6 start endpoint.","commonSituations":"Re-running a test while a previous cloud run is still finishing (its teardown or abort grace period), quota exhaustion near the end of a billing period, or CI retries firing while the first run is starting.","solutions":["Check the Grafana Cloud UI for a still-running instance of the test; stop it, then re-run","If 401/403, refresh auth with `k6 cloud login` and retry","If 429/402, reduce concurrent cloud runs or raise plan limits, then retry with backoff","For 5xx/transport errors, retry after a short delay — the uploaded test remains usable, only the start needs repeating (re-invoking k6 cloud re-uploads)"],"exampleFix":"# before\nk6 cloud run script.js   # 409: test already running\n\n# after\nk6 cloud stop --test <test-id> 2>/dev/null || true\nsleep 5\nk6 cloud run script.js","handlingStrategy":"retry","validationCode":"// ensure no active run before starting\nrun, _, _ := client.GetTestRun(ctx, loadTestID) // or ListTestRuns\nif run != nil && isActive(run.Status) {\n    _ = client.StopTest(ctx, loadTestID)\n    time.Sleep(5 * time.Second)\n}","typeGuard":null,"tryCatchPattern":"run, err := client.StartTest(ctx, loadTest.GetId())\nif err != nil {\n    var re *cloudapiv6.ResponseError\n    if errors.As(err, &re) {\n        if re.Response.StatusCode == 409 { return fmt.Errorf(\"test already running; stop it first: %w\", err) }\n        if re.Response.StatusCode == 429 || re.Response.StatusCode >= 500 { /* retry with backoff */ }\n    }\n    return fmt.Errorf(\"starting test: %w\", err)\n}","preventionTips":["Make CI pipelines idempotent: stop-or-ignore previous runs before starting","Distinguish 409 (state) from 5xx (transient) in retry logic","Keep a small delay between stop and start to let cloud state converge"],"tags":["cloud-api","test-lifecycle","conflict","auth"],"backgroundTag":"api-request-failed","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"}