can1357/oh-my-pi · error · RuntimeError

No session - output artifacts unavailable

Error message

No session - output artifacts unavailable

What it means

The prelude's `output(*ids)` helper reads sub-agent/task artifacts (`<id>.md`) from a artifacts directory taken from PI_ARTIFACTS_DIR, or derived from PI_SESSION_FILE by stripping its extension. If neither env var is set (both nil or empty), there is no way to locate artifacts, so it emits an error status and raises this plain RuntimeError. It means the eval script is running without a session context.

Source

Thrown at packages/coding-agent/src/eval/rb/prelude.rb:174

    tokens.each do |kind, value|
      if kind == :index
        return nil unless current.is_a?(Array) && value < current.length
        current = current[value]
      else
        return nil unless current.is_a?(Hash) && current.key?(value)
        current = current[value]
      end
    end
    current
  end

  def output(*ids, format: "raw", query: nil, offset: nil, limit: nil)
    artifacts_dir = ENV["PI_ARTIFACTS_DIR"]
    if artifacts_dir.nil? || artifacts_dir.empty?
      session_file = ENV["PI_SESSION_FILE"]
      if session_file.nil? || session_file.empty?
        __omp_emit_status("output", "error" => "No session file available")
        raise "No session - output artifacts unavailable"
      end
      artifacts_dir = session_file.sub(/\.[^.]*\z/, "")
    end
    unless File.directory?(artifacts_dir)
      __omp_emit_status("output", "error" => "Artifacts directory not found", "path" => artifacts_dir)
      raise "No artifacts directory found: #{artifacts_dir}"
    end
    raise ArgumentError, "At least one output ID is required" if ids.empty?
    if query && (!offset.nil? || !limit.nil?)
      __omp_emit_status("output", "error" => "query cannot be combined with offset/limit")
      raise ArgumentError, "query cannot be combined with offset/limit"
    end

    results = []
    not_found = []
    ids.each do |output_id|
      path = File.join(artifacts_dir, "#{output_id}.md")
      unless File.exist?(path)

View on GitHub (pinned to 9690622007)

Solutions

  1. Ensure the script is launched through the omp eval host so PI_SESSION_FILE is set; verify with `env['PI_SESSION_FILE']` at the top of the script
  2. Set PI_ARTIFACTS_DIR explicitly to the directory containing `<id>.md` artifacts before calling `output`
  3. If running standalone intentionally, skip `output` and read the artifact files directly with `read`/`File.read`

Example fix

// before
summary = output("step1")
// after
dir = env["PI_ARTIFACTS_DIR"]
raise "set PI_ARTIFACTS_DIR" if dir.nil? || dir.empty?
summary = output("step1")
Defensive patterns

Strategy: validation

Validate before calling

raise "output() requires PI_ARTIFACTS_DIR or PI_SESSION_FILE" if ENV["PI_ARTIFACTS_DIR"].to_s.empty? && ENV["PI_SESSION_FILE"].to_s.empty?
results = output("step1")

Try / catch

begin
  artifacts = output("step1")
rescue RuntimeError => e
  raise unless e.message == "No session - output artifacts unavailable"
  artifacts = nil # run without artifact lookup
end

Prevention

When it happens

Trigger: Calling `output` (with any or no arguments) inside an eval/run script when neither PI_ARTIFACTS_DIR nor PI_SESSION_FILE is present in the process environment — e.g. running the script standalone via the Ruby runner without the coding-agent host session wiring, or a host bug that failed to pass the env through the tool bridge.

Common situations: Executing the prelude-backed script outside `omp` (raw `ruby`/runner invocation); CI jobs that sanitize the environment; a version change where the host stopped exporting PI_SESSION_FILE to eval workers.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/761a0d4e8bd9bd3e. Report an issue: GitHub.