{"record":{"id":"59b01794b71241a3","repo":"grafana/k6","slug":"testrunid-is-required","errorCode":null,"errorMessage":"TestRunID is required","messagePattern":"TestRunID is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/cloud/output.go","lineNumber":471,"sourceCode":"\t\t\t// result_status variable, which signifies whether the thresholds\n\t\t\t// passed or failed (failure also called \"tainted\" in some places of\n\t\t\t// the API here). The run_status signifies whether the test run\n\t\t\t// finished normally and has a few fixed failures values.\n\t\t\t//\n\t\t\t// So, this specific k6 error will be communicated to the cloud only\n\t\t\t// via result_status, while the run_status will appear normal.\n\t\t\treturn cloudapi.RunStatusFinished\n\t\t}\n\t}\n\n\t// By default, the catch-all error is \"aborted by system\", but let's log that\n\tout.logger.WithError(testErr).Debug(\"unknown test error classified as 'aborted by system'\")\n\treturn cloudapi.RunStatusAbortedSystem\n}\n\nfunc (out *Output) startVersionedOutput() error {\n\tif out.testRunID == \"\" {\n\t\treturn errors.New(\"TestRunID is required\")\n\t}\n\tvar err error\n\n\tusageErr := out.usage.Strings(\"cloud/test_run_id\", out.testRunID)\n\tif usageErr != nil {\n\t\tout.logger.Warning(\"Couldn't report test run id to usage as part of writing to k6 cloud\")\n\t}\n\n\t// TODO: move here the creation of a new cloudapi.Client\n\t// so in the case the config has been overwritten the client uses the correct\n\t// value.\n\t//\n\t// This logic is handled individually by each single output, it has the downside\n\t// that we could break the logic and not catch easly it.\n\n\tswitch out.config.APIVersion.Int64 {\n\tcase int64(apiVersion1):\n\t\terr = errors.New(\"v1 is not supported anymore\")","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/cloud/output.go#L453-L489","documentation":"Output.startVersionedOutput requires an established cloud test run id before it can start pushing. testRunID is populated from config.PushRefID or by creating a test run during output start; if it is empty at this point the invariant fails with 'TestRunID is required'. In the standard flow this should not be reachable — it indicates the run-creation step was skipped, failed earlier, or the output was constructed/assembled programmatically without a run.","triggerScenarios":"Programmatic use of the cloud output that calls Start without going through the provisioning/create-run path and without PushRefID; an earlier failure in the start sequence that left testRunID unset; a hand-built Config that sets push-mode flags but no ref id.","commonSituations":"Embedding k6 as a library and wiring outputs manually; forks/wrappers that reorder output initialization; upgrading across k6 versions where the start sequence changed.","solutions":["If pushing to a pre-provisioned run, set the run reference (K6_CLOUD_PUSH_REF_ID / config push ref id) so testRunID is non-empty","Check earlier log lines — a failed test-run creation (auth, network, token scope) usually precedes this error; fix that first","Verify you are not mixing provisioning modes (PushRefID + scoped credentials vs. normal cloud token)","If this reproduces with a plain k6 run -o cloud script.js, report it as a k6 bug with the config and logs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Go — programmatic use: ensure a run reference before Start\nif cfg.PushRefID.Valid && cfg.PushRefID.String != \"\" {\n    // direct-push mode carries its own testRunID\n} else if tokenNotConfigured(cfg) {\n    return errors.New(\"cloud output needs a token (K6_CLOUD_TOKEN) to create a test run\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When embedding k6's cloud output, always go through NewOutput + the normal start path rather than calling Start on a partially configured output","Check startup logs for a failed test-run creation before assuming an output bug","Keep cloud credentials valid and scoped so run creation succeeds before versioned start"],"tags":["cloud","internal-invariant","configuration","k6"],"backgroundTag":"missing-required-config","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}