Skip to content

Update: simplify NEXT_LEVEL scheduling with explicit targets#1436

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:codex/directed-scheduling-pr1
Jul 23, 2026
Merged

Update: simplify NEXT_LEVEL scheduling with explicit targets#1436
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:codex/directed-scheduling-pr1

Conversation

@puddingfjz

@puddingfjz puddingfjz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Require exact submit-time worker IDs for single and group NEXT_LEVEL tasks.
  • Route READY single tasks through per-worker FIFOs.
  • Dispatch group tasks only to their exact target worker set.
  • Remove free NEXT_LEVEL worker selection from the scheduler.
  • Reject booleans, floats, numeric strings, and other coercible non-integer worker IDs.
  • Update maintained call sites, scheduler documentation, tests, and the consolidated implementation plan.

Scheduling contract

  • submit_next_level(..., worker=id) targets exactly one stable NEXT_LEVEL worker.
  • submit_next_level_group(..., workers=[...]) requires one unique worker ID per group member.
  • A group remains READY until all of its specified workers are available; no partial worker reservation is performed.
  • Task dependencies are resolved before READY queue routing.
  • SUB task placement remains shared and unchanged; SUB APIs do not accept worker IDs.

Validation

  • Focused Python tests: 104 passed, 13 skipped.
  • Relevant C++ orchestrator tests: 18 passed.
  • Relevant C++ scheduler tests: 21 passed.
  • CI pre-commit checks passed.
  • Full no-hardware Python run: 758 passed and 13 skipped. Two socket tests blocked by the sandbox passed when rerun outside it; one pre-existing session-timeout test remains failing.

Out of scope

  • SUB worker-ID selection.
  • Orchestrator heap-buffer ownership and allocation API changes.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 537d40da-595d-4ebd-81ca-26db68557fd6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

NEXT_LEVEL submissions now require explicit stable worker IDs. The orchestrator validates and stores targets, directed queues route READY work, the scheduler dispatches exact workers, and tests/examples/documentation adopt the new contract.

Changes

Directed NEXT_LEVEL scheduling

Layer / File(s) Summary
Placement contract and documentation
docs/..., examples/workers/l3/*, docs/task-flow.md
NEXT_LEVEL APIs, worker identity, eligibility, queue topology, and dispatch examples now describe explicit stable targets.
Python target validation and provenance
python/simpler/*, python/bindings/worker_bind.h, tests/ut/py/*
Python and binding APIs require worker targets, validate group IDs, and check child provenance against the selected worker.
Orchestrator state and READY routing
src/common/hierarchical/orchestrator.*, src/common/hierarchical/types.*, src/common/hierarchical/worker*
Task slots store target IDs; READY work routes through per-worker and group queues; WorkerManager resolves stable IDs and retains SUB idle selection.
Directed scheduler dispatch
src/common/hierarchical/scheduler.*
Scheduler dispatch is split between NEXT_LEVEL groups, NEXT_LEVEL singles, and SUB work, with completion-first processing and aggregate group completion.
Scheduler behavior coverage
tests/ut/cpp/hierarchical/test_scheduler.cpp
Tests cover directed queues, group ordering, blocked groups, dependency release, eligibility validation, queue isolation, and exact dispatch counts.
Orchestrator and integration coverage
tests/ut/cpp/hierarchical/test_orchestrator.cpp, tests/st/a2a3/..., tests/ut/py/test_worker/*
Tests migrate local, remote, dynamic-registration, group, and recursive-worker submissions to explicit stable targets.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ParentOrchestrator
  participant NextLevelReadyQueues
  participant Scheduler
  participant WorkerManager
  participant TargetWorker
  ParentOrchestrator->>NextLevelReadyQueues: enqueue READY task for target worker
  Scheduler->>NextLevelReadyQueues: pop target FIFO
  Scheduler->>WorkerManager: resolve stable worker ID
  WorkerManager-->>Scheduler: return TargetWorker
  Scheduler->>TargetWorker: dispatch task
Loading

Possibly related PRs

Poem

A rabbit pins a worker bright,
No wandering queue through day or night.
Groups hop in an orderly line,
Stable IDs make dispatch shine.
“Ready!” thumps the scheduler’s drum—
Exact little targets, here we come! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change by describing explicit NEXT_LEVEL targets and simplified scheduling.
Description check ✅ Passed The description accurately summarizes the explicit-target NEXT_LEVEL scheduling changes and updated call sites, tests, and docs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/ut/py/test_worker/test_child_addr_guard.py (1)

341-351: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make this test reach the owner-resolution path.

workers=[0, 0] is rejected by the public duplicate-worker check before _child_dispatch_candidates or _child_prov_check_dispatch runs, so this does not test the “same owner” behavior its name describes. Rename it to cover duplicate explicit worker IDs, or construct a case with distinct requested IDs that reaches the owner-resolution check. The supplied orchestrator flow validates duplicates first, and tests/ut/py/test_callable_identity.py already covers that validation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ut/py/test_worker/test_child_addr_guard.py` around lines 341 - 351,
Update test_group_two_child_members_same_owner_rejected so it does not use
workers=[0, 0], which is rejected by the public duplicate-worker validation
before owner resolution. Either rename the test to reflect duplicate explicit
worker IDs and align its assertions, or use distinct requested worker IDs that
reach _child_dispatch_candidates/_child_prov_check_dispatch and genuinely verify
same-owner rejection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/callable-identity-registration.md`:
- Line 345: Update the sentence describing orch.submit_next_level_group(...,
workers=...) to use correct subject–verb agreement by changing “require” to
“requires,” or rewrite it as “The API requires exact submit-time placement.”

In `@docs/orchestrator.md`:
- Around line 37-43: Update the submit_next_level_group usage example to pass
the required workers vector alongside callable, args_list, and config, and show
that the vector contains one worker ID for each group member. Ensure the example
propagates the worker assignments consistently from group construction through
the submission call.

In `@python/simpler/orchestrator.py`:
- Around line 194-195: Validate worker IDs as non-boolean integers before
coercion in both submission paths: update the single-worker handling around the
existing cpp_worker_id check at python/simpler/orchestrator.py lines 194-195,
and validate every workers entry before length, sign, and duplicate checks at
lines 261-264. Reject floats, numeric strings, booleans, and other non-integer
values while preserving non-negative ID validation.

---

Nitpick comments:
In `@tests/ut/py/test_worker/test_child_addr_guard.py`:
- Around line 341-351: Update test_group_two_child_members_same_owner_rejected
so it does not use workers=[0, 0], which is rejected by the public
duplicate-worker validation before owner resolution. Either rename the test to
reflect duplicate explicit worker IDs and align its assertions, or use distinct
requested worker IDs that reach
_child_dispatch_candidates/_child_prov_check_dispatch and genuinely verify
same-owner rejection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1cca16a5-d170-40ef-b8a7-4b7b8ccaa739

📥 Commits

Reviewing files that changed from the base of the PR and between 56919a7 and a25c6b9.

📒 Files selected for processing (25)
  • docs/callable-identity-registration.md
  • docs/directed-next-level-scheduling/pr1-explicit-placement-contract.md
  • docs/hierarchical_level_runtime.md
  • docs/orchestrator.md
  • docs/remote-l3-worker-design.md
  • docs/scheduler.md
  • docs/task-flow.md
  • examples/workers/l3/README.md
  • examples/workers/l3/per_task_runtime_env/README.md
  • examples/workers/l3/per_task_runtime_env/main.py
  • python/bindings/worker_bind.h
  • python/simpler/orchestrator.py
  • python/simpler/worker.py
  • src/common/hierarchical/orchestrator.cpp
  • src/common/hierarchical/orchestrator.h
  • tests/st/a2a3/tensormap_and_ringbuffer/dynamic_register/test_dynamic_register.py
  • tests/st/a2a3/tensormap_and_ringbuffer/test_l3_dependency.py
  • tests/st/a2a3/tensormap_and_ringbuffer/test_l3_group.py
  • tests/ut/cpp/hierarchical/test_orchestrator.cpp
  • tests/ut/cpp/hierarchical/test_scheduler.cpp
  • tests/ut/py/test_callable_identity.py
  • tests/ut/py/test_worker/test_child_addr_guard.py
  • tests/ut/py/test_worker/test_error_propagation.py
  • tests/ut/py/test_worker/test_l4_recursive.py
  • tests/ut/py/test_worker/test_startup_readiness.py

Comment thread docs/callable-identity-registration.md
Comment thread docs/orchestrator.md
Comment thread python/simpler/orchestrator.py Outdated
@puddingfjz
puddingfjz force-pushed the codex/directed-scheduling-pr1 branch 2 times, most recently from 636672f to a8c9b19 Compare July 22, 2026 07:04
@puddingfjz puddingfjz changed the title Update: require explicit NEXT_LEVEL placement Update: simplify NEXT_LEVEL scheduling with explicit targets Jul 22, 2026
@puddingfjz

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/st/a2a3/tensormap_and_ringbuffer/dynamic_register/test_dynamic_register.py (1)

235-245: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exercise both workers in the parallel-broadcast test.

device_ids contains two workers, but both submissions are pinned to worker 0. The assertions therefore cannot detect a registration or execution failure on worker 1. Use separate per-worker argument bundles with submit_next_level_group(..., workers=[0, 1]) (or submit one task to each worker).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@tests/st/a2a3/tensormap_and_ringbuffer/dynamic_register/test_dynamic_register.py`
around lines 235 - 245, Update the parallel-broadcast flow in orch_post to
exercise both workers instead of pinning submission to worker 0. Use separate
per-worker argument bundles and submit them through submit_next_level_group with
workers [0, 1], preserving the existing post_handle and broadcast behavior so
assertions cover worker 1 as well.
🧹 Nitpick comments (1)
src/common/hierarchical/scheduler.cpp (1)

411-419: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the group-state reset into a helper.

This reset block is duplicated in dispatch_sub_ready (Lines 357-364), differing only by the initial group_member_states value (RUNNING vs NOT_DISPATCHED). Extracting a helper such as reset_group_state(s, group_size, initial_member_state) removes the risk of the two sites diverging when a group-state field is added or renamed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common/hierarchical/scheduler.cpp` around lines 411 - 419, Extract the
duplicated group-state initialization into a helper such as reset_group_state,
parameterized by s, group_size, and the initial GroupMemberState. Replace the
reset blocks in dispatch_sub_ready and the current group setup with this helper,
preserving RUNNING at this site and NOT_DISPATCHED at the other while resetting
all shared state fields consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/callable-identity-registration.md`:
- Around line 345-349: Update the placement API sentence in the callable
identity registration documentation to name both submit-time APIs: retain
orch.submit_next_level_group(..., workers=...) and add
orch.submit_next_level(..., worker=...). Ensure the following “they” reference
clearly applies to both APIs without changing the placement or worker-ID
guidance.

In `@docs/hierarchical_level_runtime.md`:
- Around line 145-150: Update the runtime diagram around the READY routing steps
and the associated channel table to show READY work being enqueued directly into
the directed/shared ready queues, followed by waking the Scheduler. Remove
references to routing READY work through the obsolete wiring_queue path, while
preserving the completion_queue, fanout/fanin, and target-resolution flow.

In `@docs/task-flow.md`:
- Around line 345-348: Update the task-flow documentation around Scheduler
dispatch and WorkerThread mailbox encoding to scope the shared-memory mailbox
description to local worker endpoints only. Clarify that remote NEXT_LEVEL
dispatch through RemoteL3Endpoint sends a framed TASK instead, while preserving
the local SUB-worker mailbox flow.

In `@examples/workers/l3/per_task_runtime_env/README.md`:
- Line 25: Update the example’s orch.submit_next_level call to construct the
per-task configuration from the existing _cfg CallConfig, preserving
harness-injected diagnostics while applying task-specific settings; do not
create a fresh standalone CallConfig.

In `@tests/ut/cpp/hierarchical/test_orchestrator.cpp`:
- Around line 355-362: Update the test around submit_next_level and
try_pop_single to assert that worker 3’s queue pop succeeds and that the
retrieved TaskSlot corresponds to producer before submitting the consumer. Use
the existing producer and ready symbols to validate both queue routing and slot
identity.

---

Outside diff comments:
In
`@tests/st/a2a3/tensormap_and_ringbuffer/dynamic_register/test_dynamic_register.py`:
- Around line 235-245: Update the parallel-broadcast flow in orch_post to
exercise both workers instead of pinning submission to worker 0. Use separate
per-worker argument bundles and submit them through submit_next_level_group with
workers [0, 1], preserving the existing post_handle and broadcast behavior so
assertions cover worker 1 as well.

---

Nitpick comments:
In `@src/common/hierarchical/scheduler.cpp`:
- Around line 411-419: Extract the duplicated group-state initialization into a
helper such as reset_group_state, parameterized by s, group_size, and the
initial GroupMemberState. Replace the reset blocks in dispatch_sub_ready and the
current group setup with this helper, preserving RUNNING at this site and
NOT_DISPATCHED at the other while resetting all shared state fields
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 69dbf5a4-b037-4e7e-b199-c8d9c9b5645c

📥 Commits

Reviewing files that changed from the base of the PR and between 56919a7 and a8c9b19.

📒 Files selected for processing (37)
  • docs/callable-identity-registration.md
  • docs/directed-next-level-scheduling/implementation-plan.md
  • docs/hierarchical_level_runtime.md
  • docs/orchestrator.md
  • docs/remote-l3-worker-design.md
  • docs/remote-l3-worker-design/implementation-plan.md
  • docs/remote-l3-worker-design/pr-split-and-audit-artifacts.md
  • docs/remote-l3-worker-design/pr-split-and-audit-plan.md
  • docs/scheduler.md
  • docs/task-flow.md
  • docs/worker-manager.md
  • examples/workers/l3/README.md
  • examples/workers/l3/per_task_runtime_env/README.md
  • examples/workers/l3/per_task_runtime_env/main.py
  • python/bindings/worker_bind.h
  • python/simpler/orchestrator.py
  • python/simpler/worker.py
  • src/common/hierarchical/orchestrator.cpp
  • src/common/hierarchical/orchestrator.h
  • src/common/hierarchical/scheduler.cpp
  • src/common/hierarchical/scheduler.h
  • src/common/hierarchical/types.cpp
  • src/common/hierarchical/types.h
  • src/common/hierarchical/worker.cpp
  • src/common/hierarchical/worker.h
  • src/common/hierarchical/worker_manager.cpp
  • src/common/hierarchical/worker_manager.h
  • tests/st/a2a3/tensormap_and_ringbuffer/dynamic_register/test_dynamic_register.py
  • tests/st/a2a3/tensormap_and_ringbuffer/test_l3_dependency.py
  • tests/st/a2a3/tensormap_and_ringbuffer/test_l3_group.py
  • tests/ut/cpp/hierarchical/test_orchestrator.cpp
  • tests/ut/cpp/hierarchical/test_scheduler.cpp
  • tests/ut/py/test_callable_identity.py
  • tests/ut/py/test_worker/test_child_addr_guard.py
  • tests/ut/py/test_worker/test_error_propagation.py
  • tests/ut/py/test_worker/test_l4_recursive.py
  • tests/ut/py/test_worker/test_startup_readiness.py

Comment thread docs/callable-identity-registration.md
Comment thread docs/hierarchical_level_runtime.md
Comment thread docs/task-flow.md Outdated
Comment thread examples/workers/l3/per_task_runtime_env/README.md
Comment thread tests/ut/cpp/hierarchical/test_orchestrator.cpp
@puddingfjz
puddingfjz force-pushed the codex/directed-scheduling-pr1 branch from a8c9b19 to ed7d4ba Compare July 22, 2026 08:02
@puddingfjz

Copy link
Copy Markdown
Contributor Author

Addressed the remaining full-review items in ed7d4ba:

  • The parallel dynamic-registration test now dispatches a group to workers [0, 1] and validates both outputs.
  • Shared group-state initialization is centralized in reset_group_state, while preserving the different SUB and NEXT_LEVEL initial member states.

@puddingfjz

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 17 minutes.

@puddingfjz
puddingfjz force-pushed the codex/directed-scheduling-pr1 branch 3 times, most recently from 03d2358 to 6ba0b38 Compare July 22, 2026 09:03
@ChaoWao
ChaoWao force-pushed the codex/directed-scheduling-pr1 branch from 6ba0b38 to a18f08e Compare July 23, 2026 01:11
ChaoWao
ChaoWao previously approved these changes Jul 23, 2026
Replace unconstrained NEXT_LEVEL scheduling with explicit placement: every
NEXT_LEVEL task names its exact worker at submit time and the Scheduler
dispatches only to that worker. The runtime no longer selects a NEXT_LEVEL
worker on the caller's behalf.

- submit_next_level requires a stable worker id; submit_next_level_group
  requires one distinct id per member. Booleans, floats, numeric strings, and
  other coercible non-integers are rejected.
- READY singles route through a per-worker FIFO; groups use one shared FIFO
  whose head launches only when every target worker is idle (all-or-nothing,
  no partial reservation). SUB placement is unchanged and takes no worker id.
- A local (LOCAL_PYTHON / LOCAL_CHIP) callable is rejected when pinned to a
  remote worker id: a remote endpoint installs only its own dispatcher
  callables, so a local digest would fail asynchronously as an unknown hashid.
- Remove the shared NEXT_LEVEL queue, idle-pool fallback selection, and the
  queue wait/shutdown/condition-variable state; retain idle-worker selection
  only for SUB.

Docs: rewrite scheduler.md for the directed model, add
directed-next-level-scheduling.md as the placement-contract reference, and
refresh the maintained call sites and API summaries for the required worker
argument.

Tests: cover required/malformed target rejection, per-worker FIFO routing,
exact member-to-worker mapping (including reversed target order), group-first
dispatch, blocked-group non-reservation, and the local-callable remote-target
guard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChaoWao
ChaoWao merged commit fee284e into hw-native-sys:main Jul 23, 2026
16 checks passed
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.

2 participants