Skip to content

Fix: keep a newer same-run TensorMap entry when its predecessor is consumed - #1485

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1480-ownership-aware-tensormap-erase
Jul 26, 2026
Merged

ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1480-ownership-aware-tensormap-erase

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1480

Problem

TensorMap::erase_task_outputs(run_id, keys) erased every key unconditionally.
Orchestrator::on_consumed calls it with the consumed task's output_keys, so
the cleanup could drop a mapping that a later task in the same run already
owns.

Two OUTPUT / OUTPUT_EXISTING writers of one key carry no edge between them —
that path inserts without looking up — so the first can reach CONSUMED while
the second is still running:

  1. A: OUTPUT K → insert(run, K, A)
  2. B: OUTPUT K → insert(run, K, B) (overwrites; A and B unordered)
  3. A consumed → erase_task_outputs(run, [K]) removes the entry pointing at B
  4. C: INPUT K → lookup returns INVALID_SLOT → no dependency on B

C can then be dispatched and read K before B has written it.

INOUT is unaffected: it looks up before inserting, so B depends on A and A
cannot reach CONSUMED until B has released its reference.

Fix

erase_task_outputs takes the consumed slot and drops a key only while it still
maps to that slot. This mirrors how the L2 TensorMap reclaims a retired task's
entries — pto_tensormap.h::cleanup_retired, "Only remove if this entry belongs
to the retiring task (slot may have been reused by a newer task)".

Tests

  • OrchestratorFixture.ConsumingASupersededProducerKeepsTheNewerMapping — the
    end-to-end repro. Verified failing on the pre-fix code: C came back with
    fanin_producers.size() == 0 and fanin_count == 0.
  • TensorMap.EraseKeepsNewerSameRunProducer — same-run WAW at the map level,
    alongside the existing cross-run isolation test. Also asserts the owning
    slot's erase still removes the entry.

Existing erase_task_outputs call sites in test_tensormap.cpp take the owner
slot argument.

Verification

  • ctest --test-dir tests/ut/cpp/build -LE requires_hardware — 60/60 passed
  • pytest tests/ut/py — 824 passed, 2 skipped
  • pytest tests/st/worker --platform a2a3sim --device 0-3 (level-3 collectives,
    the hierarchical orchestrator's ST coverage) — 18/18 passed
  • pre-commit run on the touched files — all hooks pass

Host-only change; no hardware run required.

Left open

Whether two unordered OUTPUT writers of one key should be a diagnosed error
rather than a silently unordered WAW — raised in the issue, deliberately not
decided here.

🤖 Generated with Claude Code

…nsumed

Fixes hw-native-sys#1480

`TensorMap::erase_task_outputs` erased every key unconditionally, so a
consumed task's cleanup could drop a mapping that a later same-run task
already owns.

Two `OUTPUT` / `OUTPUT_EXISTING` writers of one key carry no edge between
them — that path inserts without looking up — so the first writer can reach
CONSUMED while the second is still running. Its cleanup then removed the
entry pointing at the second writer, and a subsequent `INPUT` consumer looked
up an empty slot, inferred no dependency, and could be dispatched before the
second writer had written the buffer. `INOUT` is unaffected: it looks up
before inserting, so the writers are ordered and the erase is harmless.

The erase now takes the consumed slot and drops a key only while it still
maps to that slot, matching how the L2 TensorMap reclaims a retired task's
entries (`pto_tensormap.h::cleanup_retired`).

Whether two unordered `OUTPUT` writers of one key should instead be a
diagnosed error is left open.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@ChaoWao, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 488e2837-d69c-4c8f-9f9d-7ca34f771e2f

📥 Commits

Reviewing files that changed from the base of the PR and between e568310 and d0d4a9b.

📒 Files selected for processing (6)
  • docs/orchestrator.md
  • src/common/hierarchical/orchestrator.cpp
  • src/common/hierarchical/tensormap.cpp
  • src/common/hierarchical/tensormap.h
  • tests/ut/cpp/hierarchical/test_orchestrator.cpp
  • tests/ut/cpp/hierarchical/test_tensormap.cpp

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.

@ChaoWao
ChaoWao merged commit bddd321 into hw-native-sys:main Jul 26, 2026
16 checks passed
@ChaoWao
ChaoWao deleted the fix/issue-1480-ownership-aware-tensormap-erase branch July 27, 2026 07:02
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.

[Code Health] Consuming a producer erases a newer same-run TensorMap mapping for the same key

1 participant