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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews