feat(spawner): propagate parent_job_id via task-local for external spawners#78
Draft
HonestMajority wants to merge 2 commits intomainfrom
Draft
feat(spawner): propagate parent_job_id via task-local for external spawners#78HonestMajority wants to merge 2 commits intomainfrom
HonestMajority wants to merge 2 commits intomainfrom
Conversation
…awners Use tokio::task_local to hold the currently executing job's ID in the dispatcher. When a spawner's parent_job_id is None, it falls back to the task-local value. This lets external spawners (not from init()) inherit the parent automatically — matching the pattern used in lana-bank. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address PR #78 review feedback: - Add doc comment on CURRENT_EXECUTING_JOB_ID explaining tokio::spawn limitation - Add test proving explicit with_parent() takes priority over task-local - Add nested A→B→C test proving multi-level task-local propagation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tokio::task_local!(CURRENT_EXECUTING_JOB_ID) in the dispatcher that holds the running job's ID duringrunner.run()resolve_parent_job_id()toJobSpawner— prefers explicitwith_parent()value, falls back to task-localinit()) to automatically inherit the parent job ID — matching the pattern used in lana-bank where initializers discard the init-injected spawnerMotivation
PR #75 added auto-propagation via the init()-injected spawner. However, in lana-bank initializers discard that spawner because they spawn different job types using externally-held spawners. Those external spawners had
parent_job_id = None, so all child jobs ended up withparent_job_id = NULL.The task-local approach fixes this: any spawner called within a job runner's
run()method automatically gets the parent from the task-local context.Changes
src/dispatcher.rs: DeclareCURRENT_EXECUTING_JOB_IDtask-local; wrapdispatch_job()in.scope(job_id, ...)src/spawner.rs: Addresolve_parent_job_id()helper; use it increate_job_internal(),spawn_all_in_op(), andspawn_unique()tests/job.rs: New integration test proving external spawners get parent_job_id via task-localBackward Compatibility
with_parent()still takes priority (no behavior change)parent_job_id = None(task-local not set)Test plan
cargo fmtcleancargo clippy --all-targets -- -D warningscleancargo nextest run— 56/56 tests passnix flake checkpassestest_task_local_parent_propagation_with_external_spawnervalidates the exact lana-bank pattern🤖 Generated with Claude Code