Skip to content

host_build_graph: route boot failure through common teardown; fix Level-1 docs - #1518

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:issue-1515-hbg-boot-teardown
Jul 27, 2026
Merged

ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:issue-1515-hbg-boot-teardown

Conversation

@ChaoZheng109

Copy link
Copy Markdown
Collaborator

Summary

Follow-up on unaddressed review feedback from #1452. Fixes the three findings tracked in #1515 — one correctness bug and two stale-doc drifts.

1. (Bug, Major) Boot-thread failure bypasses AICore teardown and the finished-barrier

aicpu_executor.cpp — both boot-failure branches in run() returned -1 directly. Since #1452 made every AICPU thread schedule, the boot thread (thread_idx == aicpu_thread_num_ - 1) now owns a non-empty core slice (handshake_partition assigns it [lo, total) in init()), so an early return skips the common teardown:

  • shutdown(thread_idx) — the boot thread's AICore cores never get their exit signal and spin forever on an unclosed register window.
  • finished_count_ — tops out at aicpu_thread_num_ - 1, so finished_ never publishes and runtime_destroy never runs; the host hangs into the op-execute timeout (507018), masking the real error.

Fix: record the failure in run_rc, leave rt null (the dispatch block already skips on rt == nullptr), publish runtime_init_ready_ once so peers stop spinning, and fall through to the common teardown. Success-path behavior and the task-count-latch-before-release ordering are unchanged.

2 & 3. (Docs) profiling_levels.md Level-1 describes an on-device orchestrator

host_build_graph boots scheduler-only (orchestrator runs on the host), so the device log has no orch_* lines and no "PTO2 total submitted tasks" line. The Level-1 section still listed them, used the count formula N_sched*2 + N_orch*1 + 1, and showed a device-orch example capture; the summary table listed Level-1 = 7.

Fix: rewrite the section scheduler-only (N_sched*2, N_sched == aicpu_thread_num) with a 4-thread example, and correct the summary-table count 7 → 8.

Testing

  • Incremental build of the a2a3 onboard host_build_graph AICPU runtime — aicpu_executor.cpp compiles and libaicpu_kernel.so links cleanly.
  • markdownlint-cli2 passes on profiling_levels.md.
  • The Multi-threaded AICPU Scheduler with Parallel Task Dispatch #1 fix is on the boot-failure (error-injection) path — a natural onboard repro is impractical; verified by inspection against the common-cleanup contract in run().

Fixes #1515.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 27, 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: 8c32a8f8-c68d-4f68-832e-16025e8e58e5

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
📝 Walkthrough

Walkthrough

The runtime boot path now handles attachment failures through shared teardown and publishes initialization readiness in all boot outcomes. Profiling documentation now describes scheduler-only Level 1 execution and updates its log examples and counts.

Changes

Host build graph boot and profiling

Layer / File(s) Summary
Boot failure teardown
src/a2a3/runtime/host_build_graph/aicpu/aicpu_executor.cpp
Boot failures set failure state without returning early, publish runtime_init_ready_, skip runtime dispatch, and continue through scheduler shutdown and completion handling.
Scheduler-only profiling documentation
src/a2a3/runtime/host_build_graph/docs/profiling_levels.md
Level 1 documentation, examples, and LOG_INFO_V9 counts now contain scheduler-only timing and summary output.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BootThread
  participant RuntimeAttachment
  participant WaitingThreads
  participant SchedulerContext
  BootThread->>RuntimeAttachment: Check prebuilt_arena and attach_populated
  RuntimeAttachment-->>BootThread: Runtime or boot failure
  BootThread->>WaitingThreads: Publish runtime_init_ready_
  BootThread->>SchedulerContext: shutdown(thread_idx)
  BootThread->>BootThread: Increment finished_count_
Loading

Possibly related PRs

Poem

A bunny found a boot path bright,
No early exits fled the night.
Schedulers count, the logs now sing,
Readiness wakes each waiting thing.
Teardown hops in tidy flight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: boot-failure teardown routing and Level-1 documentation updates.
Description check ✅ Passed The description is directly about the runtime fix and profiling docs, matching the change set.
Linked Issues check ✅ Passed The code and docs updates match issue #1515's boot-failure teardown and Level-1 profiling requirements.
Out of Scope Changes check ✅ Passed No unrelated code changes are indicated beyond the runtime fix and the documented Level-1 updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@ChaoZheng109
ChaoZheng109 force-pushed the issue-1515-hbg-boot-teardown branch from cf9ec66 to a643c85 Compare July 27, 2026 10:43
…el-1 docs

Since hw-native-sys#1452 the boot thread (aicpu_thread_num_ - 1) owns a non-empty core
slice — handshake_partition assigns it [lo, total) during init(). The two
boot-failure branches in run() (prebuilt_arena null, sm_handle attach failure)
still returned -1 directly, skipping the common teardown that every other
thread reaches:

- shutdown(thread_idx): the boot thread's AICore cores never get their exit
  signal, so they spin forever on an unclosed register window.
- finished_count_: the counter tops out at aicpu_thread_num_ - 1, so
  finished_ never publishes and runtime_destroy never runs — the host hangs
  into the op-execute timeout (507018), masking the real boot error.

Record the failure in run_rc, leave rt null (the dispatch block already skips
on rt == nullptr), publish runtime_init_ready_ at a single point so peers stop
spinning, and fall through to the common teardown. Behavior on success is
unchanged; the task-count latch still precedes the init-ready release.

profiling_levels.md: the Level-1 section still described an on-device
orchestrator (orch_start/orch_end/orch_cost lines, "PTO2 total submitted
tasks" printed by the last orch thread, the N_orch count term, and a
device-orch example capture). host_build_graph boots scheduler-only, so those
lines never appear on device. Rewrite the section scheduler-only (count is
N_sched*2, N_sched == aicpu_thread_num) with a 4-thread example, and correct
the summary-table Level-1 count from 7 to 8.

Fixes hw-native-sys#1515.
@ChaoZheng109
ChaoZheng109 merged commit 6e6fb06 into hw-native-sys:main Jul 27, 2026
15 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.

[Bug] host_build_graph: boot-failure bypasses AICore teardown + stale profiling docs (#1452 follow-up)

1 participant