{"record":{"id":"29d0d5f187c17adb","repo":"ruby/ruby","slug":"cannot-set-ractor-local-storage-for-non-current-ra","errorCode":null,"errorMessage":"Cannot set ractor local storage for non-current ractor","messagePattern":"Cannot set ractor local storage for non-current ractor","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"ractor.rb","lineNumber":487,"sourceCode":"        rb_ractor_make_shareable(obj);\n      }\n    end\n  end\n\n  # Gets a value from ractor-local storage for the current Ractor.\n  # Obsolete, use Ractor.[] instead.\n  def [](sym)\n    if (self != Ractor.current)\n      raise RuntimeError, \"Cannot get ractor local storage for non-current ractor\"\n    end\n    Primitive.ractor_local_value(sym)\n  end\n\n  # Sets a value in ractor-local storage for the current Ractor.\n  # Obsolete, use Ractor.[]= instead.\n  def []=(sym, val)\n    if (self != Ractor.current)\n      raise RuntimeError, \"Cannot set ractor local storage for non-current ractor\"\n    end\n    Primitive.ractor_local_value_set(sym, val)\n  end\n\n  # Gets a value from ractor-local storage for the current Ractor.\n  def self.[](sym)\n    Primitive.ractor_local_value(sym)\n  end\n\n  # Sets a value in ractor-local storage for the current Ractor.\n  def self.[]=(sym, val)\n    Primitive.ractor_local_value_set(sym, val)\n  end\n\n  # call-seq:\n  #   Ractor.store_if_absent(key){ init_block }\n  #\n  # If the corresponding ractor-local value is not set, yields a value with","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/ractor.rb#L469-L505","documentation":"Obsolete instance-level Ractor#[]= writes ractor-local storage and carries the same restriction as []: only the current ractor may touch its own storage. other_ractor[:key] = value raises RuntimeError 'Cannot set ractor local storage for non-current ractor' before the primitive runs. Use the class form Ractor[:key] = value, or set storage inside the owning ractor's own code.","triggerScenarios":"Parent code trying to 'seed' a spawned ractor via child_ractor[:init] = data before/after spawn; generic obj[key] = assignment helpers that receive a Ractor; Thread#[]= muscle memory applied to Ractor instances.","commonSituations":"Seeding configuration into workers; code ported from Ruby 3.0 Ractor previews; job frameworks treating ractors as hash-configurable targets.","solutions":["Set storage inside the ractor that owns it: Ractor.new { Ractor[:cfg] = load_cfg; ... }","Pass initial data as Ractor.new(args) block parameters instead of storage writes from outside","Use the class form Ractor[:key] = value for the current ractor's storage"],"exampleFix":"# before\nr = Ractor.new { work }\nr[:mode] = :fast # RuntimeError: Cannot set ractor local storage for non-current ractor\n\n# after\nRactor[:mode] = :fast # sets MAIN ractor's storage\nr = Ractor.new(:fast) { |mode| work(mode) } # child gets data via arguments","handlingStrategy":"validation","validationCode":"# set storage only on the current ractor\nr[sym] = val if r == Ractor.current\n# to initialize a child's storage, set it inside the child's own block:\nRactor.new { Ractor[:mode] = :fast; work }","typeGuard":"def own_ractor?(r)\n  r == Ractor.current\nend","tryCatchPattern":"begin\n  r[sym] = val\nrescue RuntimeError => e\n  raise unless e.message.include?('ractor local storage')\n  Ractor[sym] = val # write the calling ractor's storage instead\nend","preventionTips":["Seed ractors via constructor arguments or messages, never via storage writes from outside","Use the class form Ractor[:key] = value everywhere for current-ractor storage","Treat the obsolete instance []/[]= as removed during upgrades"],"tags":["ractor","ruby","runtimeerror","ractor-local-storage","obsolete-api"],"backgroundTag":"ractor-local-storage-access","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}