{"record":{"id":"1dda34d04d3761ae","repo":"bazelbuild/bazel","slug":"starlark-computation-cancelled-too-many-steps","errorCode":null,"errorMessage":"Starlark computation cancelled: too many steps","messagePattern":"Starlark computation cancelled: too many steps","errorType":"exception","errorClass":"EvalException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/Eval.java","lineNumber":326,"sourceCode":"    // Assign a value to the type alias identifier only if type tagging is enabled.\n    if (typeTable != null) {\n      TypeConstructor typeConstructor =\n          checkNotNull(typeTable.getTypeConstructor(node.getIdentifier().getBinding()));\n      assignIdentifier(fr, node.getIdentifier(), TypeConstructorValue.of(typeConstructor));\n    }\n    return TokenKind.PASS;\n  }\n\n  private static TokenKind exec(StarlarkThread.Frame fr, Statement st)\n      throws EvalException, InterruptedException {\n    if (fr.dbg != null) {\n      Location loc = st.getStartLocation(); // not very precise\n      fr.setLocation(loc);\n      fr.dbg.before(fr.thread, loc); // location is now redundant since it's in the thread\n    }\n\n    if (++fr.thread.steps >= fr.thread.stepLimit) {\n      throw new EvalException(\"Starlark computation cancelled: too many steps\");\n    }\n\n    switch (st.kind()) {\n      case ASSIGNMENT:\n        execAssignment(fr, (AssignmentStatement) st);\n        return TokenKind.PASS;\n      case EXPRESSION:\n        eval(fr, ((ExpressionStatement) st).getExpression());\n        return TokenKind.PASS;\n      case FLOW:\n        return ((FlowStatement) st).getFlowKind();\n      case FOR:\n        return execFor(fr, (ForStatement) st);\n      case DEF:\n        DefStatement def = (DefStatement) st;\n        StarlarkFunction fn = newFunction(fr, def.getResolvedFunction());\n        assignIdentifier(fr, def.getIdentifier(), fn);\n        return TokenKind.PASS;","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/Eval.java#L308-L344","documentation":"Starlark executes scripts within a step budget: every executed statement increments a counter, and when it reaches the thread's stepLimit the interpreter aborts with EvalException 'Starlark computation cancelled: too many steps'. This is a safety valve against infinite loops, since Starlark has no other resource control for unbounded loops. This instance is the check in statement execution (exec).","triggerScenarios":"A script with an unbounded or huge loop (while True:, for over an enormous range/list), runaway recursion expressed iteratively, or a legitimately long computation whose step count exceeds the configured limit; StarlarkThread.stepLimit set low or left at default.","commonSituations":"BUILD/.bzl or macro logic with a loop over all targets that grows with the repository; regression where a loop condition never becomes false; evaluators (REPL, tests) running with a small stepLimit for fast failure.","solutions":["Fix the script: ensure loop termination conditions actually progress (bump the counter/index, correct the break condition).","If the computation is legitimately large, raise the budget: StarlarkThread.setStepLimit(n) (or the host application's configured limit) before evaluation.","Reproduce locally with a debug print/log every N iterations to find the non-terminating loop.","Move the heavy computation into a native (Java) Starlark builtin instead of a Starlark loop."],"exampleFix":"# before\ndef collect(items):\n    out = []\n    i = 0\n    while i < len(items):   # i never incremented -> infinite\n        out.append(items[i])\n    return out\n\n# after\ndef collect(items):\n    return list(items)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  Starlark.execFile(thread, parsedFile);\n} catch (EvalException e) {\n  if (e.getMessage().contains(\"too many steps\")) {\n    // script exceeded budget: fix the loop or raise setStepLimit\n  } else {\n    throw e;\n  }\n}","preventionTips":["Set an explicit, generous stepLimit with StarlarkThread.setStepLimit() sized to the workload.","Review every while-loop and large for-loop in scripts for guaranteed progress.","Log loop iteration counts during development to catch growth before the limit does."],"tags":["starlark","interpreter","resource-limit","infinite-loop"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}