{"record":{"id":"30c8d5620ad0193f","repo":"apache/beam","slug":"not-currently-processing-a-bundle","errorCode":null,"errorMessage":"Not currently processing a bundle.","messagePattern":"Not currently processing a bundle\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/worker/worker.ts","lineNumber":442,"sourceCode":"      if (typeof this.getStateChannel === \"function\") {\n        this.stateProvider = new CachingStateProvider(\n          new GrpcStateProvider(\n            this.getStateChannel(\n              this.descriptor.stateApiServiceDescriptor!.url,\n            ),\n            this.getBundleId(),\n          ),\n        );\n      } else {\n        this.stateProvider = this.getStateChannel;\n      }\n    }\n    return this.stateProvider;\n  }\n\n  getBundleId() {\n    if (this.currentBundleId === null || this.currentBundleId === undefined) {\n      throw new Error(\"Not currently processing a bundle.\");\n    }\n    return this.currentBundleId!;\n  }\n\n  // Put this on a worker thread...\n  async process(instructionId: string) {\n    console.debug(\"Processing \", this.descriptor.id, \"for\", instructionId);\n    this.metricsContainer.reset();\n    this.currentBundleId = instructionId;\n    this.loggingStageInfo.instructionId = instructionId;\n    loggingLocalStorage.enterWith(this.loggingStageInfo);\n    // We must await these in reverse topological order.\n    for (const o of this.topologicallyOrderedOperators.slice().reverse()) {\n      this.loggingStageInfo.transformId = o.transformId;\n      await o.startBundle();\n    }\n    this.loggingStageInfo.transformId = undefined;\n    // Now finish bundles all the bundles.","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/worker/worker.ts#L424-L460","documentation":"Worker.getBundleId() returns the id of the bundle currently being processed. When no bundle is active (currentBundleId is null/undefined) it throws, because callers like getStateProvider need an active bundle context to be valid.","triggerScenarios":"Calling worker.getBundleId() or obtaining a state provider between bundles, before process(instructionId) starts, or after a bundle completes and the id is reset to null.","commonSituations":"Custom runner/driver code probing the worker outside a process() call; callbacks invoked after the bundle finished; unit tests instantiating Worker and calling getBundleId directly.","solutions":["Call getBundleId()/getStateProvider only inside bundle processing (i.e. from within DoFn setup/process invocations during process(instructionId)).","Track the currentBundleId yourself or guard the call: if (worker.currentBundleId != null) ... .","Pass the instruction id explicitly instead of relying on ambient bundle state.","In tests, start a fake bundle via process() or set up the id before asserting."],"exampleFix":"// before\n// const provider = worker.getStateProvider(); // outside process()\n// after\n// async process: within process(instructionId) { const id = worker.getBundleId(); ... }","handlingStrategy":"type-guard","validationCode":"// check before calling\nif (worker.currentBundleId == null) {\n  throw new Error('No active bundle; cannot get state provider');\n}","typeGuard":"const hasActiveBundle = (w: {currentBundleId: string | null | undefined}): w is {currentBundleId: string} =>\n  w.currentBundleId != null;","tryCatchPattern":"let bundleId: string;\ntry {\n  bundleId = worker.getBundleId();\n} catch (e) {\n  if (e.message === 'Not currently processing a bundle.') {\n    throw new Error('Call getBundleId only during process()');\n  }\n  throw e;\n}","preventionTips":["Access bundle-scoped APIs only inside process(instructionId)","Pass instruction ids explicitly to helpers instead of relying on ambient state","In tests, simulate an active bundle before asserting"],"tags":["beam","worker","lifecycle","bundle"],"backgroundTag":"invalid-state-transition","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}