Skip to content

Fix: expose host buffers to L3 subworkers - #1390

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:codex/fix-l3-subworker-host-buffer
Jul 17, 2026
Merged

Fix: expose host buffers to L3 subworkers#1390
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:codex/fix-l3-subworker-host-buffer

Conversation

@puddingfjz

Copy link
Copy Markdown
Contributor

Summary

  • Broadcast post-fork host-buffer MAP and UNMAP controls to L3 SubWorkers
  • Map shared host buffers and rewrite parent virtual addresses before SubWorker task decoding
  • Add focused regression coverage and update host-buffer visibility documentation

Testing

  • pytest tests/ut -m "not requires_hardware" -q — 575 passed, 13 skipped, 10 deselected
  • ruff check and ruff format --check
  • pyright — 0 errors
  • markdownlint-cli2 — 0 errors

Hardware tests were not run because this change is limited to the Python host control path.

@coderabbitai

coderabbitai Bot commented Jul 17, 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

Run ID: 545853c9-5c32-4f7f-b4b4-67dc9671757f

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

Host-buffer zero-copy support now maps buffers into local L3 children, rewrites task host pointers there, and broadcasts registration changes to both NEXT_LEVEL and SUB workers. Documentation and unit tests cover the updated visibility and control paths.

Changes

Local L3 host-buffer flow

Layer / File(s) Summary
Local L3 child mapping and rewriting
python/simpler/worker.py
Sub-workers track host mappings, handle map/unmap controls, rewrite host pointers before task execution, and clean up mappings during shutdown.
Parent host-buffer broadcast
python/simpler/worker.py
create_host_buffer and free_host_buffer propagate controls to both NEXT_LEVEL and SUB children and report consolidated failures.
Visibility documentation and validation
docs/comm-domain.md, tests/ut/py/test_worker/test_host_buffer_registration.py
Documentation describes local L3 dereferencing and valid shared-memory sources; tests verify propagation, mapping, and pointer rewriting.

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

Sequence Diagram(s)

sequenceDiagram
  participant Worker
  participant L3Children
  participant SubWorker
  participant Task
  Worker->>L3Children: create_host_buffer control
  L3Children->>SubWorker: Map shared-memory buffer
  Task->>SubWorker: Ready task with host pointer
  SubWorker->>Task: Rewrite pointer to mapped child address
  Worker->>L3Children: free_host_buffer control
Loading

Possibly related PRs

Poem

A rabbit hops where shared pages flow,
L3 children map the buffers below.
Pointers are rewritten, tasks run bright,
NEXT_LEVEL and SUB keep addresses right.
Unmap, clean up, and onward we go!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% 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 clearly and concisely summarizes the main change: exposing host buffers to L3 subworkers.
Description check ✅ Passed The description directly matches the changeset and summarizes the control propagation, mapping, tests, and docs updates.
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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the host buffer registration mechanism to support broadcasting control commands (such as mapping and unmapping host buffers) to both next-level and sub-workers (local L3 children). It updates the sub-worker loop to handle these control commands, rewrite host addresses in task arguments, and clean up shared memory on shutdown. Additionally, the documentation has been updated to reflect these changes, and new unit tests have been added to verify the behavior. There are no review comments to address, and the changes look solid.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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: 2

🧹 Nitpick comments (1)
python/simpler/worker.py (1)

963-966: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Log exception instead of silently ignoring it.

Silently swallowing exceptions during shutdown reduces observability and can make debugging resource leaks difficult. Based on learnings, treat this as a diagnostic-consistency best practice. Consider logging the exception to sys.stderr instead of using pass.

💡 Proposed refactor to log the exception
     for host_shm, _lo, _hi, _base in host_buf_table.values():
         try:
             host_shm.close()
-        except Exception:  # noqa: BLE001
-            pass
+        except Exception as e:  # noqa: BLE001
+            import sys
+            sys.stderr.write(f"sub_worker: failed to close host_shm: {e}\n")
🤖 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 `@python/simpler/worker.py` around lines 963 - 966, Update the host_shm.close
cleanup in the worker shutdown path to log caught exceptions to sys.stderr
instead of silently executing pass. Preserve the existing broad exception
handling and continue shutdown after logging the failure.

Source: Learnings

🤖 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/comm-domain.md`:
- Around line 153-159: Update the explanation in the “Two sources are legal”
section of docs/comm-domain.md to state that fork-inherited mappings retain
their virtual addresses, while post-fork attachment may map the memory at a
different address and therefore requires pointer rewriting. Preserve the
existing born-shared and worker-allocation requirements.

In `@tests/ut/py/test_worker/test_host_buffer_registration.py`:
- Around line 130-137: Update the assertions in the host-buffer registration
test around create_host_buffer to verify the complete broadcast records,
including each map and unmap command value, rather than only comparing
WorkerType. Ensure both initial registration calls and cleanup calls assert the
expected command values.

---

Nitpick comments:
In `@python/simpler/worker.py`:
- Around line 963-966: Update the host_shm.close cleanup in the worker shutdown
path to log caught exceptions to sys.stderr instead of silently executing pass.
Preserve the existing broad exception handling and continue shutdown after
logging the failure.
🪄 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: 9fdc5495-b1c8-439e-b2a5-c1b9ac3c0195

📥 Commits

Reviewing files that changed from the base of the PR and between 6cea23a and 946d0da.

📒 Files selected for processing (3)
  • docs/comm-domain.md
  • python/simpler/worker.py
  • tests/ut/py/test_worker/test_host_buffer_registration.py

Comment thread docs/comm-domain.md Outdated
Comment thread tests/ut/py/test_worker/test_host_buffer_registration.py Outdated
@puddingfjz
puddingfjz force-pushed the codex/fix-l3-subworker-host-buffer branch 3 times, most recently from 7144dfc to 98c3dab Compare July 17, 2026 08:53
@ChaoWao
ChaoWao force-pushed the codex/fix-l3-subworker-host-buffer branch from 98c3dab to c748e48 Compare July 17, 2026 10:53
- Broadcast host-buffer map and unmap controls to subworkers
- Rewrite parent host addresses before SubWorker task decoding
- Add focused regression coverage for post-fork visibility
@ChaoWao
ChaoWao merged commit 470a84d into hw-native-sys:main Jul 17, 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