Skip to content

Give ImportContext's capability rejections the domain-scoped vocabulary - #1782

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:attachment-vocab-unify
Aug 11, 2026
Merged

Give ImportContext's capability rejections the domain-scoped vocabulary#1782
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:attachment-vocab-unify

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • ImportContext/ImportRegistry.materialize() (P1-B's worker-tree capability check) and EndpointRegistry/RegionAccessService (Add: CPU-NPU Comm Endpoint Model #1696's domain-scoped capability engine) are two independent implementations of "can this endpoint reach this backing" — flagged repeatedly in .docs as a naming gap, most recently in the P1-B closure audit (2026-08-11).
  • Investigated two ways to actually unify them and ruled both out (recorded on ImportContext itself so they don't get re-proposed):
    • Routing ImportContext's construction through the live EndpointRegistry object doesn't work across the fork boundary — ImportContext is built inside forked child processes or at L2's same-process point, both of which predate EndpointRegistry's _require_ready_for_region_planning() precondition.
    • Swapping is_host_endpoint: bool for the domain-scoped EndpointDeployment enum (HOST_CPU/DEVICE_AICORE/DEVICE_AICPU) doesn't map onto the chip-fork model — one forked chip process covers both AICore and AICPU roles, and the topology snapshot doesn't track per-chip identity anyway, so the enum wouldn't even close ImportContext's known Worker-grained-not-chip-grained limit.
  • What both mechanisms can share safely: the vocabulary for why a capability check failed. comm_endpoints.py's RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION already names this question. Both of materialize()'s DEVICE-backing rejections now carry it, prose unchanged so existing match= patterns keep matching.
  • No behavior change: same accept/reject logic, only the error-message text (built only on the already-failing path) changed.

Testing

  • New test pins the reason code in both rejection messages — verified against the pre-fix code first (reverted, confirmed it fails on the plain message, restored, confirmed it passes).
  • Two pre-existing tests pass unmodified, confirming the change is additive.
  • pyut: 1319 passed / 13 skipped / 0 failed
  • ruff check/format, pyright: clean
  • Checked buffer.pycomm_endpoints.py for import cycles: none (comm_endpoints.py only imports from _task_interface)

.docs flags this repeatedly: the "can this endpoint reach this backing"
judgment exists in two independent implementations -- the domain-scoped
EndpointRegistry/RegionAccessService capability engine (hw-native-sys#1696) and P1-B's
ImportContext, which only ever raised freeform ValueError strings. The P1-B
closure audit (2026-08-11) recorded this as a naming gap to close via
"AttachmentPlan/TransportPlan 归位", scoped here to something small and safe
rather than a full unification.

Checked two obvious unification approaches and ruled both out, recording why
on ImportContext itself so they don't get re-proposed:

- Routing ImportContext's construction through the live EndpointRegistry
  object doesn't work across the fork boundary. ImportContext is built inside
  forked child processes (_sub_worker_loop, _run_chip_main_loop -- plain
  functions, not Worker methods) or at L2's same-process lazy-materialize
  point. Worker._get_endpoint_registry() walks the entire tree and requires
  _require_ready_for_region_planning(), a precondition that doesn't obviously
  hold at either of those points -- routing through it risks raising where a
  trivial attribute read works fine today.
- Swapping ImportContext.is_host_endpoint: bool for the domain-scoped
  EndpointDeployment enum (HOST_CPU/DEVICE_AICORE/DEVICE_AICPU) doesn't map
  onto the chip-fork model: a forked chip child is one process covering both
  AICore and AICPU roles, and EndpointRegistry's own topology snapshot
  doesn't track per-chip identity anyway (_append_device_endpoint_topology
  passes no owner_instance_id for device entries) -- so adopting the enum
  wouldn't even close ImportContext's known Worker-grained-not-chip-grained
  limitation, it would just force an ill-fitting split for no gain.

What both mechanisms already answer with the same underlying values, and can
share without either problem: the vocabulary naming *why* a capability check
failed. comm_endpoints.py's RegionAccessReasonCode already has
UNSUPPORTED_ENDPOINT_RELATION for exactly this question. ImportRegistry.
materialize()'s two DEVICE-backing rejections (host endpoint attempting a
DEVICE backing; device endpoint attempting a different chip's DEVICE backing)
are both instances of it. Prefixed both raised messages with the reason
code's value, keeping the existing prose intact so the pre-existing test
match= patterns ("host endpoint", "different chip's owner") keep matching
without edits. buffer.py now imports RegionAccessReasonCode from
.comm_endpoints -- checked for cycles: comm_endpoints.py imports only from
_task_interface today, a fresh one-way edge.

No change to ImportContext's fields, materialize()'s accept/reject logic, or
anything on the hot dispatch path beyond the two error-message strings, which
only build when materialize is about to raise anyway. Out of scope, both
deliberately: ImportRegistry.materialize()'s backend_kind switch (the
un-named adapter-selection logic for FORK_SHM/DEVICE_MALLOC/VMM_WINDOW/
POSIX_SHM) is the genuinely large, hot-path-risk piece of "AttachmentPlan/
TransportPlan 归位" and stays untouched; nothing in comm_endpoints.py itself
changes.

New test: both rejection messages carry RegionAccessReasonCode.
UNSUPPORTED_ENDPOINT_RELATION.value, verified against the pre-fix code first
(reverted the prefix, confirmed the new test fails with the plain "on a host
endpoint" message and no reason code, restored the fix and confirmed it
passes). The two pre-existing tests
(test_host_endpoint_materialize_refuses_a_device_tensor_directly,
test_chip_materialization_refuses_a_foreign_chips_device_tensor) pass
unmodified, confirming the change is additive.

Verified: pyut 1319 passed / 13 skipped / 0 failed; ruff check/format and
pyright clean; no circular import between buffer.py and comm_endpoints.py.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 016fc130-26b2-4bd7-b691-b2061f92d49f

📥 Commits

Reviewing files that changed from the base of the PR and between 144319b and c161096.

📒 Files selected for processing (2)
  • python/simpler/buffer.py
  • tests/ut/py/test_worker/test_endpoint_capability.py

📝 Walkthrough

Walkthrough

The change adds UNSUPPORTED_ENDPOINT_RELATION to DEVICE-backing materialization errors. It documents the shared rejection-code vocabulary and tests host-endpoint and foreign-chip rejection cases.

Changes

DEVICE materialization rejection codes

Layer / File(s) Summary
Add endpoint-relation rejection codes
python/simpler/buffer.py
DEVICE materialization errors now include UNSUPPORTED_ENDPOINT_RELATION for host endpoints and descriptors owned by another chip. ImportContext documents the related rejection-code vocabulary and topology constraints.
Test endpoint-relation rejection codes
tests/ut/py/test_worker/test_endpoint_capability.py
Tests verify that host-endpoint and foreign-chip DEVICE materialization raise ValueError messages containing the expected reason code.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A rabbit checks each device path,
And marks the wrong-endpoint wrath.
Host or foreign chip in sight,
UNSUPPORTED_ENDPOINT_RELATION makes it right.
Tests hop gladly through the code.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: using domain-scoped vocabulary for ImportContext capability rejections.
Description check ✅ Passed The description directly explains the reason-code changes, affected rejection paths, compatibility, design rationale, and test results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@ChaoWao
ChaoWao merged commit 9a8b9d0 into hw-native-sys:main Aug 11, 2026
19 checks passed
@ChaoWao
ChaoWao deleted the attachment-vocab-unify branch August 11, 2026 10:43
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