Skip to content

feat(spawner): propagate parent_job_id via task-local for external spawners#78

Draft
HonestMajority wants to merge 2 commits intomainfrom
feat/task-local-parent-propagation
Draft

feat(spawner): propagate parent_job_id via task-local for external spawners#78
HonestMajority wants to merge 2 commits intomainfrom
feat/task-local-parent-propagation

Conversation

@HonestMajority
Copy link
Copy Markdown
Contributor

Summary

  • Declares a tokio::task_local! (CURRENT_EXECUTING_JOB_ID) in the dispatcher that holds the running job's ID during runner.run()
  • Adds resolve_parent_job_id() to JobSpawner — prefers explicit with_parent() value, falls back to task-local
  • Enables external spawners (not from init()) to automatically inherit the parent job ID — matching the pattern used in lana-bank where initializers discard the init-injected spawner

Motivation

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 with parent_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: Declare CURRENT_EXECUTING_JOB_ID task-local; wrap dispatch_job() in .scope(job_id, ...)
  • src/spawner.rs: Add resolve_parent_job_id() helper; use it in create_job_internal(), spawn_all_in_op(), and spawn_unique()
  • tests/job.rs: New integration test proving external spawners get parent_job_id via task-local

Backward Compatibility

Test plan

  • cargo fmt clean
  • cargo clippy --all-targets -- -D warnings clean
  • cargo nextest run — 56/56 tests pass
  • nix flake check passes
  • New test test_task_local_parent_propagation_with_external_spawner validates the exact lana-bank pattern

🤖 Generated with Claude Code

HonestMajority and others added 2 commits April 1, 2026 11:45
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant