ryanwinchester

ryanwinchester

apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”

Versions: oban_pro 1.7.12, oban 2.24.0, Elixir 1.20.3 / OTP 28, Postgres, Smart engine.
Also reproduced on oban_pro 1.7.8 + oban 2.23.0.

Summary

Inside a process/1 grafting callback (defined via add_graft/4), building a sub-workflow
that mixes add/4 and add_many/4 with deps: between them produces unresolvable
dependency references after apply_graft/2.

Specifically: when an add_many step depends on an add step, the add_many jobs are
inserted with meta.deps entries of the form [<pre-graft workflow id>, <step name>] —
but that workflow id belongs to the transient Workflow.new() built inside the grafter
and is never persisted (the add step’s job is re-homed under grafted_<id>). As soon
as the dependency completes, the add_many jobs are cancelled with:

** (Oban.Pro.WorkflowError) upstream job was deleted, workflow can't complete

The reverse direction works: an add step depending on an add_many sub-workflow gets
its deps correctly rewritten to [[<sub-workflow id>, "*"]].

Reproduction

defmodule Repro.NoopWorker do
  use Oban.Pro.Worker, queue: :default, max_attempts: 1

  @impl Oban.Pro.Worker
  def process(_job), do: :ok
end

defmodule Repro.Graft do
  alias Oban.Pro.Workflow

  def new do
    Workflow.new()
    |> Workflow.add_graft(:rebalance, &__MODULE__.graft/1, queue: :default, max_attempts: 1)
  end

  def graft(_context) do
    sells = Map.new(1..2, &{"sell_#{&1}", Repro.NoopWorker.new(%{"s" => &1})})
    buys = Map.new(1..2, &{"buy_#{&1}", Repro.NoopWorker.new(%{"n" => &1})})

    Workflow.new()
    |> Workflow.add_many(:sells, sells)              # also fails with add_many(:sells, %{})
    |> Workflow.add(:fund, Repro.NoopWorker.new(%{"fund" => true}), deps: :sells)
    |> Workflow.add_many(:buys, buys, deps: :fund)   # <- these jobs cancel
    |> Workflow.apply_graft()
    |> Oban.insert_all()

    :ok
  end
end

Oban.insert_all(Repro.Graft.new())

Observed

Job meta after execution:

step state meta.workflow_id meta.deps
sell_1/2 completed 01…748c (retained sub-workflow id) []
fund completed grafted_01… [["01…748c", "*"]] :white_check_mark: rewritten
buy_1/2 cancelled 01…7073 (retained sub-workflow id) [["01…744c", "fund"]] :cross_mark: pre-graft workflow id

01…744c is the id of the transient Workflow.new() built inside the grafter — no
persisted job carries it, so dependency resolution treats the upstream as deleted and
cancels the buys.

Expected

The buys’ deps should reference the fund job’s post-graft workflow id (grafted_…),
the same way the fund step’s dep on the sells sub-workflow was rewritten.

Notes

  • Possibly related to the v1.7.5 fix “Preserve sub-workflow identity through
    apply_graft/2” — the sub-workflow keeps its identity, but its outward dep
    references aren’t remapped.
  • Workaround: build the graft exclusively with individual Workflow.add/4 calls;
    all jobs then co-home under grafted_<id> and deps resolve as plain name refs.

Showing Posts 1 to 1

sorentwo

sorentwo

Oban Core Team

Thanks for the report. That’s a twisty one!

It’s fixed on main for v1.8, but since you have a workaround we probably won’t backport it to v1.7.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews