Skip to content

fix(ios,nsh): harden iOS reload subscriptions and carry remaining NSH/CI fixes - #7352

Open
me2seeks wants to merge 1 commit into
chore/nsh-sync-latestfrom
fix/ios-bridge-reload-and-nsh-fixes
Open

me2seeks wants to merge 1 commit into
chore/nsh-sync-latestfrom
fix/ios-bridge-reload-and-nsh-fixes

Conversation

@me2seeks

@me2seeks me2seeks commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #7368, which carries the upstream sync, scoped keymap implementation, and Metal submission ordering. This PR adds the following on top.

  • Reject a replaced app's late iOS subscription registration under the lock so it cannot replace the new app's stream with the same ID. The existing caller-close path still handles active subscriptions.
  • Record the inherited keymap focus override and the new shader frame lifetime behavior in third-party/nsh/SOURCE.md.
  • Retire stale shared frames when a shader unmounts or collapses, even if a prior resize swapped the pool. Geometry changes wake hosted/static shaders where needed; ordinary nsh.time shaders stay idle at zero size.
  • Finish AppKit and UIKit view/screen transitions on collapse, clear their output and release child masks without waiting for another render tick. Don't let an ended transition present over its children on expansion. Replace the overlapping AppKit state test with a native Metal test for both view and screen transitions.
  • The central macOS NSH suite runs the engine's shader-enabled library tests and AppKit resize regressions.

Verification

Rerun on the stacked commit.

  • Native AppKit resize subset: five passes on Metal, including hidden resize after a pool swap, root collapse/restore, and unmasking on collapse for both transition roles. With the prior AppKit shader implementation, the new case failed at “collapsed transition still masks its child”.
  • Shader-enabled nsh-engine library: 111 passed, one ignored. Both queue-ordering regressions from chore(nsh): sync upstream through 3b2fd5876 and use nsh-system-controls 0.1.0 #7368 ran on Metal without the no-GPU skip. iOS bridge: 11 passed. UIKit shader code compiled for aarch64-apple-ios-sim; this was a compile check, not a native UIKit run.
  • CI routing: 31 passed. Root and vendored Rust formatting, ASF headers, and whitespace checks passed.

Linux/Windows behavior and AppKit independent windows were not rerun for this revision. PR Check is scoped; the full hosted matrix runs on main pushes, schedules or manual dispatch.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool and scope: Maka assisted with the NSH/bridge changes, AppKit regression and verification. Retain Generated-by: Maka on the squash commit.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally (with platform gaps noted above)

Breaking change or persisted-data migration?

  • Yes
  • No

Change in behavior?

  • Yes — described under Summary above
  • No

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

English

Thanks for splitting these follow-ups out of #7338! The underlying fixes are real, and a few cleanups would make this much sharper and avoid leaving peer paths behind:

  1. FrameTarget::clear_layer() leaves two zero-size peer paths broken (third-party/nsh/crates/nsh-engine/src/{frames,shader,gpu}.rs)

    • Adding a separate clear_layer(&mut self) only updates ShaderView::set_layer(None), while leaving clear_frame(&mut self) -> bool untouched.
    • There are only three callers of clear_frame() in nsh-engine: ShaderView::set_layer(None), ShaderView::render on width == 0 || height == 0 (shader.rs:1024), and GpuView render on width == 0 || height == 0 (gpu.rs:603).
    • With show_on_surfaces(true) on Apple/Windows, self.frame.width is always 0 and frames live in self.surfaces / self.previous. Leaving clear_frame() as-is means collapsing a ShaderView or GpuView to 0×0 still retains stale IOSurface/SharedTexture frames and returns false from clear_frame(), so macOS (display_frame) and Windows (view.redraw()) don't repaint to clear the old frame.
    • Suggestion: Drop clear_layer() and fix clear_frame(&mut self) -> bool directly—take() both self.surfaces (Apple/Windows) and self.previous (Windows), folding shown_texture().is_some() into the returned had flag. That fixes all three call sites in one place and keeps shader.rs production code untouched (smaller vendored diff). Extending the shader.rs test with a 0×0 resize check would cover both paths.
  2. Avoid the curried closure signature on pub fn Keymap::gives_way (third-party/nsh/crates/nsh-core/src/keymap.rs, nsh-platform-linux/src/keymap.rs)

    • Returning impl Fn(&KeyBinding) -> bool makes single-binding call sites awkward (!table.gives_way(binding.keystroke, eligible)(binding) in Linux) and introduces an implicit contract on a pub method: the returned closure silently assumes every binding passed to it has binding.keystroke == key.
    • Suggestion: Keep gives_way as a plain predicate—pub fn gives_way(&self, binding: &KeyBinding, eligible: impl Fn(&KeyBinding) -> bool) -> bool (matching upstream's signature plus eligible)—and extract a small private helper (or explicit private policy enum) shared by gives_way and find_eligible so find_eligible still computes the pointer-override check once in O(N).
  3. products/maka/ios-shell/src/bridge.rs: redundant inner tokio::select! and heavy test boilerplate

    • Keeping if sender.is_closed() under the state lock in register_subscription is genuinely needed (when calls.subscribe().await resolves and state.lock().await is uncontended, the outer select! doesn't get another poll before insertion). The MutationProgress::emit fast path, moving drop(subscription) before locking, and typing outcome as Option<Result<(), RemoteClientError>> are all clean improvements.
    • However, the new inner tokio::select! { biased; _ = sender.closed() => ..., result = calls.subscribe(...) => ... } inside open_subscription duplicates the outer tokio::select! { biased; _ = caller.closed() => return, ... } in HostBridge::attach. It registers a second HostSenderClosed waker on Caller::waiting and adds an Err branch that production never reaches (and tests don't exercise). Please remove the inner select!.
    • For the two new tests (~149 lines vs. ~47 lines of production changes): the scenarios are worth covering, but both duplicate nearly identical HostChannel / HostBridge::attach / Bundle::source / Headless::start setup, and the first test reaches into connections["root"].subscriptions["stream"].1 to spin in a while !task.is_finished() { yield_now().await; } loop. Extracting a shared setup helper would tighten them up nicely.
  4. Drop nsh-gpu from the nsh CI suite (scripts/ci/suites.mjs)

    • nsh-platform-macos, nsh-platform-linux, and nsh-platform-windows all depend directly on nsh-gpu (with shader enabled by default), so scripts/ci/plan.mjs already routes nsh-gpu changes to macos-nsh, linux-nsh, and windows-nsh via reverse dependencies (no outside maintained suites gap).
    • Meanwhile, the cross-platform nsh suite currently builds without wgpu (nsh-engine runs without shader). Adding -p nsh-gpu pulls the entire wgpu / wgpu-core / wgpu-hal / naga build graph into the lightweight nsh suite just to run 2 in-memory registry unit tests in a vendored crate. Best to drop this change from suites.mjs (or, if we really want those 2 tests run explicitly, attach nsh-gpu to a platform suite that already compiles wgpu).
中文

感谢把 #7338 里剩下的修复单独拆出来!底层要修的问题都是真实的,有 4 处收拾一下会更干净,也能避免漏掉同源路径:

  1. FrameTarget::clear_layer() 漏修了两个 0×0 尺寸同源路径(third-party/nsh/crates/nsh-engine/src/{frames,shader,gpu}.rs)

    • 另加一个 clear_layer(&mut self) 只改了 ShaderView::set_layer(None),把 clear_frame(&mut self) -> bool 原样留着没动。
    • 整个 nsh-engine 里 clear_frame() 一共只有 3 处调用:ShaderView::set_layer(None)、ShaderView::render 的 width == 0 || height == 0 分支(shader.rs:1024),以及 GpuView render 的 width == 0 || height == 0 分支(gpu.rs:603)。
    • 在 Apple / Windows 开启 show_on_surfaces(true) 时,self.frame.width 始终为 0,帧存放在 self.surfaces / self.previous 中。不修 clear_frame() 会导致 ShaderView 或 GpuView 缩成 0×0 时旧的 IOSurface / SharedTexture 仍不释放,且 clear_frame() 错误返回 false,使 macOS(display_frame)和 Windows(view.redraw())连重绘清帧都不会触发。
    • 建议:删掉 clear_layer(),直接修 clear_frame(&mut self) -> bool——同时 take() 清掉 self.surfaces(Apple/Windows)和 self.previous(Windows),并把 shown_texture().is_some() 折进返回值 had。这样 3 个调用点一次全修,shader.rs 生产代码一行不用动(vendored diff 更小);测试里顺手补一个 0×0 缩放断言即可同时覆盖两条路径。
  2. pub fn Keymap::gives_way 不建议改成柯里化闭包(third-party/nsh/crates/nsh-core/src/keymap.rs、nsh-platform-linux/src/keymap.rs)

    • 返回 impl Fn(&KeyBinding) -> bool 让单绑定调用点很别扭(Linux 端写成 !table.gives_way(binding.keystroke, eligible)(binding)),还给公开 API 埋了隐式前提:返回的闭包默认调用方传入的 binding 一定满足 binding.keystroke == key,传错键会静默套错规则。
    • 建议:保持 gives_way 为直白的布尔谓词 pub fn gives_way(&self, binding: &KeyBinding, eligible: impl Fn(&KeyBinding) -> bool) -> bool(与上游原签名只差一个 eligible 参数),内部抽一个小私有 helper(或显式私有枚举)供 gives_way 和 find_eligible 共用,既保留 find_eligible 的 O(N) 单次扫描,也消除隐式契约。
  3. products/maka/ios-shell/src/bridge.rs:open_subscription 里有冗余的 tokio::select!,新增测试样板偏重

    • register_subscription 锁内的 if sender.is_closed() 是真正必要的(calls.subscribe().await 返回后若 state.lock().await 无竞争不会挂起,外层 select! 没有机会重新 poll);MutationProgress::emit 的 is_closed() 快速路径、把 drop(subscription) 提前到加锁之前、以及 outcome 改用 Option<Result<(), RemoteClientError>> 也都很干净。
    • 但 open_subscription 里在 calls.subscribe(...) 外新套的那层 tokio::select! { biased; _ = sender.closed() => ..., ... } 与 HostBridge::attach 外层的 tokio::select! { biased; _ = caller.closed() => return, ... } 完全重复,多往 Caller::waiting 挂了一个无用 waker,且多出一条生产路径走不到(测试也没覆盖)的 Err 分支,建议直接删掉。
    • 两个新增测试(约 149 行 vs 约 47 行生产改动)测的场景有价值,但重复搭了两遍几乎一样的 HostChannel / HostBridge::attach / Bundle::source / Headless::start 样板,且第一个测试直接窥探内部 connections["root"].subscriptions["stream"].1 做 while !task.is_finished() { yield_now().await; } 忙等;建议抽公共 setup helper 把体积收紧。
  4. 建议撤回 scripts/ci/suites.mjs 中把 nsh-gpu 加进 nsh suite 的改动

    • nsh-platform-macos、nsh-platform-linux、nsh-platform-windows 全部直接依赖 nsh-gpu(且默认开启 shader),scripts/ci/plan.mjs 会通过反向依赖自动把 nsh-gpu 的改动路由到 macos-nsh / linux-nsh / windows-nsh,不会触发 outside maintained suites。
    • 而跨平台轻量 nsh suite 目前不含任何 wgpu 依赖(nsh-engine 默认不开 shader)。把 -p nsh-gpu 塞进 nsh 会强行拉入整套 wgpu / wgpu-core / wgpu-hal / naga 编译依赖,只为跑 vendored crate 里 2 个纯内存注册表单元测试。建议直接删掉这 3 行(若确实想显式跑那 2 个单测,挂在本来就编 wgpu 的平台 suite 里更合适)。

@YongGoose YongGoose left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The in-lock sender.is_closed() check in register_subscription is the real fix here, and it holds: HostChannel::attach closes the replaced caller before the new engine runs any JS, so a late registration from the old app always sees it closed and can no longer overwrite or abort the new app's same-ID stream. The keymap eligibility scoping and the shader clear_layer change look right to me across the platform callers. Could you fill in the template's AI use section and checklist? The commit carries Generated-by: Maka, and that trailer needs to survive the squash. Also, the summary line about tearing down stale subscriptions on reload describes behavior main already has; the change is the late-registration guard.

Comment on lines +1454 to +1455
assert!(view.surface().is_none(), "the cleared layer has no surface");
assert!(!view.collect_frame(&renderer), "no stale frame can show");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This assertion never runs in CI. No suite builds nsh-engine's own tests with the shader feature: the nsh suite tests -p nsh-engine without it, so shader.rs is swapped for shader_off.rs and frames.rs is cfg'd out, while macos-nsh only compiles nsh-engine/shader as a dependency and runs -p nsh-platform-apple -p nsh-platform-macos --lib. If set_layer(None) went back to clear_frame(), every job would stay green and a stale IOSurface would show again after the layer is cleared.

Since this PR already touches the nsh routing, could macos-nsh also run -p nsh-engine --features nsh-engine/shader --lib (or a filter narrowed to these tests)? One caveat: these tests return early with no GPU: skipped when Renderer::new returns None, so it's worth confirming the macOS runner actually gets a Metal device, otherwise the routed test still passes without checking anything.

Comment thread products/maka/ios-shell/src/bridge.rs Outdated
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn replacing_the_app_closes_and_unregisters_its_live_subscription() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this test passes against main's bridge.rs unchanged. main's loop already does select! { biased; _ = caller.closed() => break None, next = subscription.next() => next }; dropping the pending next() drops the channel it took out of the RemoteSubscription, so the RPC stream closes, and the task then removes its own entry, so ios.unsubscribe returns cancelled:false. The final try_recv().is_err() can't fail either, since the server never sends an item after the replacement starts. detached_engine_subscriptions_do_not_reach_the_replacement_engine in tests/ios_shell_behaviors.rs already covers no events reaching the replacement and cancelled:false.

I'd drop this one, or move the one new assertion (the remote stream closes on reload) into that integration test. a_late_subscription_registration_cannot_replace_the_new_apps_stream is the test that fails without this change.

Comment thread products/maka/ios-shell/src/bridge.rs Outdated
Comment on lines +1481 to +1485
let subscription = tokio::select! {
biased;
_ = sender.closed() => return Err("app closed during subscription setup".into()),
result = calls.subscribe(&rpc.endpoint, &rpc.method, rpc.input) => result.map_err(error)?,
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this select duplicates the biased caller.closed() => return arm in the ios.subscribe handler, the only production caller. That arm watches the same Caller, is polled first, and drops this whole future when the app closes. The check that actually closes the race is the one under the lock in register_subscription.

Suggested change
let subscription = tokio::select! {
biased;
_ = sender.closed() => return Err("app closed during subscription setup".into()),
result = calls.subscribe(&rpc.endpoint, &rpc.method, rpc.input) => result.map_err(error)?,
};
let subscription = calls
.subscribe(&rpc.endpoint, &rpc.method, rpc.input)
.await
.map_err(error)?;

Comment thread products/maka/ios-shell/src/bridge.rs Outdated
impl MutationProgress<'_> {
async fn emit(&self, bridge: &Bridge, root: &str, generation: u64, value: Value) {
if self.stalled.load(Ordering::Relaxed) {
if self.sender.is_closed() || self.stalled.load(Ordering::Relaxed) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: the closed case is already handled below. HostSender::send returns Ok(false) for a closed caller, so sent doesn't advance, and the full-window path returns on self.sender.closed(). This only skips one lock acquisition, so I'd leave the original condition.

Suggested change
if self.sender.is_closed() || self.stalled.load(Ordering::Relaxed) {
if self.stalled.load(Ordering::Relaxed) {

let over = self.pointer_focus
/// opening its list). `eligible` must account for the current window,
/// focus scope and dispatch phase, also when GTK matches the keys itself.
pub fn gives_way(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this changes the public Keymap::gives_way signature, and upstream longbridge/nsh still has gives_way(&self, binding: &KeyBinding) -> bool and no FrameTarget::clear_layer. Neither patch is recorded in third-party/nsh/SOURCE.md (#7338 listed the scoped gives_way() among the preserved patches). If they aren't recorded, the next three-way sync can take upstream's versions, and both bugs come back without a conflict to flag them. Could you note both under "Retained local capabilities"? Both bugs also exist upstream (the window-scope part and the stale surface), so sending the fixes upstream would remove the divergence altogether.

@me2seeks

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @M4n5ter! Rebased onto latest main (82d53dc2c5) and addressed all 4 items in 621127385e:

  1. FrameTarget::clear_frame(&mut self) -> bool (dropped clear_layer()): Updated clear_frame() directly to take() both self.surfaces (Apple/Windows) and self.previous (Windows) and fold shown_texture().is_some() into the return value, leaving shader.rs production code untouched. Also fixed GpuView zero-size collapse (including hidden and consecutive resize A→B→0×0 before B is collected) to notify GpuViews::tick so native layers drop stale CALayer.contents, and fixed macOS static ShaderView collapse→re-expand to call set_size() before scheduling checks (with Metal & AppKit regression tests).
  2. Keymap::gives_way restored to plain bool predicate: Signature is now pub fn gives_way(&self, binding: &KeyBinding, eligible: impl Fn(&KeyBinding) -> bool) -> bool, sharing a private helper (overrides_control) with find_eligible to preserve single-pass O(N) scan and clean Linux call sites.
  3. products/maka/ios-shell/src/bridge.rs: Removed the redundant inner tokio::select! in open_subscription (relying on the outer attach select!), while keeping the locked sender.is_closed() check, MutationProgress::emit fast path, pre-lock drop(subscription), and Option<Result<_, _>> outcome. Extracted a shared test setup helper and replaced internal subscription table polling with real WebSocket disconnect observation.
  4. scripts/ci/suites.mjs: Reverted the nsh-gpu addition to the lightweight nsh suite (suites.mjs is now unchanged from main).

Verified with nsh-core keymap (19/19), nsh-engine --features shader (102/102, real Apple IOSurface), macOS --features shader --all-targets + AppKit static-fill collapse/re-expand regression, and check ios.

@me2seeks
me2seeks force-pushed the fix/ios-bridge-reload-and-nsh-fixes branch from d532ae0 to 6211273 Compare November 27, 2026 11:57
@me2seeks
me2seeks requested a review from M4n5ter November 27, 2026 12:59

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated Review · Reviewed at 621127385e using Magpie codex/gpt-6.2-sol (xhigh)

English

Verdict: Request Changes

The iOS bridge reload regressions pass, but a verified stale-frame bug remains on regular ShaderView resize-then-collapse before merge. Keep #7352 for finishing these remaining fixes on top of #7325.

Verified Findings

  • Blocker — Regular ShaderView still leaves a stale frame on A → B → 0.
    After size A has presented, a non-zero resize to B replaces the Apple surface pool. If the view collapses to 0 before B finishes its first frame, clear_frame() sees no presented frame in the new pool, render() returns false, and AppKit skips display_frame(). Reproduced with real Metal + CALayer (render_changed=false, layer_has_old_surface=true), which can leave stale content visible for effects with overflow.
    Fix: Mirror GpuViews::Presentation by having ShaderView explicitly track whether a frame has been presented to the platform, use that state when collapsing to schedule and emit the clear notification, and assert CALayer.contents is cleared on the same sequence.
    (frames.rs:118, shader.rs:1022, macos shader.rs:1543)

  • Important — New rendering regressions are not wired into central CI execution.
    Checked via plan --base HEAD^ and each suite's Cargo feature graph: Linux nsh selects nsh-engine without the shader feature; macos-nsh enables shader, but only builds nsh-engine as a dependency and runs only the menu branch of native tests. Wire the engine shader/GPU tests and AppKit resize test into a Metal-capable macOS job.
    (suites.mjs:238, run.mjs:629)

  • Nit — Stale PR description.
    scripts/ci/suites.mjs is unchanged from main (per the earlier comment removing the nsh-gpu suite edit). Remove that bullet from the PR body, update clear_layer() to clear_frame(), and describe the bridge fix accurately (a late registration from a closed app cannot overwrite/abort a reloaded app's same-ID subscription).

Test Quality & Local Verification

  • Tests make up 332/568 added lines (58.5%). Keep the late-registration bridge test and the AppKit collapse-clear / re-expand redraw test. Merge the plain reload-disconnect test into the same reload scenario to drop redundant fixture setup. In the GPU consecutive-resize test, drop the internal with_surface()-empty assertion and verify the platform clear notification directly.
  • Verified locally: iOS bridge bridge::tests (12/12 passed), nsh-core / nsh-engine / nsh-gpu with nsh-engine/shader (2078 / 102 / 2 passed; serial GPU rerun 5/5), AppKit collapse/expand + standalone Metal repro, nsh-platform-ios simulator cargo check, CI routing (30/30), and iOS packaging (11/11). Full iOS Shell simulator build, GTK native keymap, and Windows GPU paths were not executed.
中文

结论:Request Changes

Bridge 的两个 reload 回归均已通过,但普通 ShaderView 在连续 resize 后折叠的残帧问题仍未闭合,需补齐后再合入。建议继续在 #7352 上收尾(保留已合入的 #7325)。

已验证的问题

  • Blocker — 普通 ShaderView 在 A → B → 0 时仍会留下旧帧。
    A 尺寸已上屏后,非零 resize 到 B 会先替换 Apple surface pool;B 的首帧尚未完成即折叠到 0 时,clear_frame() 从新 pool 查不到已显示帧,render() 返回 false,AppKit 随之跳过 display_frame()。已用真实 Metal + CALayer 复现(render_changed=false, layer_has_old_surface=true),带 overflow 的 effect 在零尺寸下仍可能露出旧内容。
    建议改法: 沿用 GpuViews::Presentation 的思路,让 ShaderView 显式记录已交付给平台的帧状态,折叠时据此决定调度并发出清屏通知,并在同一时序下断言 CALayer.contents 已清空。
    (frames.rs:118, shader.rs:1022, macos shader.rs:1543)

  • Important — 新增的渲染回归未接入中央 CI 执行路径。
    实测 plan --base HEAD^ 与各 suite 的 feature graph:Linux nsh 选中了 nsh-engine 但未开启 shader;macos-nsh 开启了 shader,但 nsh-engine 仅作为依赖编译,且 native 测试只跑菜单分支。建议将 engine 的 shader/GPU 用例与 AppKit resize 用例接入具备 Metal 的 macOS job。
    (suites.mjs:238, run.mjs:629)

  • Nit — PR 正文残留旧版说明。
    scripts/ci/suites.mjs 与 main 一致(nsh-gpu 已按先前评论撤出)。建议正文删掉该条 CI 变更,将 clear_layer() 更新为 clear_frame(),并准确描述 bridge 修复点(旧 app 的迟到注册无法覆盖或中止新 app 的同 ID 订阅)。

测试质量与本地验证

  • 测试占新增 332/568 行(58.5%)。建议保留迟到注册后新流正常收消息的 bridge 用例,以及 AppKit 折叠清屏/展开重绘用例;普通 reload 断开可并入同一 reload 场景减少重复 fixture;GPU 连续 resize 用例建议删掉「换 pool 后 with_surface() 为空」的内部实现断言,直接验证平台收到清屏通知。
  • 本地实测:iOS bridge bridge::tests 12/12 通过;nsh-core / nsh-engine / nsh-gpu(含 nsh-engine/shader)2078 / 102 / 2 通过(GPU 串行复跑 5/5);AppKit 折叠/展开及独立 Metal 复现完成;nsh-platform-ios simulator cargo check、CI 路由 30/30、iOS 打包 11/11 通过。完整 iOS Shell simulator 构建、GTK 原生按键与 Windows GPU 路径未实测。

@me2seeks
me2seeks force-pushed the fix/ios-bridge-reload-and-nsh-fixes branch from 6211273 to c965795 Compare November 27, 2026 21:11

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated Re-Review · Reviewed at c965795294 using Magpie codex/gpt-6.2-sol (xhigh)

English

Verdict: Request Changes

c965795294 fixes the previous A → B → 0 stale-frame blocker and wires the shader/GPU and AppKit resize suites into central CI cleanly. However, stopping scheduling at zero size introduces a verified AppKit transition regression that needs to be fixed before merge.

Verified Findings

  • Important — Collapsed transitions stay masked after their duration expires.
    Reproduced in an isolated AppKit instance: starting a 600 ms ScreenTransition, letting its first frame present, and collapsing the host clears CALayer.contents, but pumping another 900 ms leaves the empty child mask stuck in place (PR base 92a4ba0d1f unmasks on schedule). Reproduced on regular ShaderTransition as well—with the window at normal size and only the transition container collapsed to zero width, overflowing child subtrees still within the window remain masked.
    Root cause: Clearing the frame makes wants_frame() return false, stopping AppKit ticks, while unmasking only runs inside show_frame() when a subsequent tick observes transition completion.
    Fix: Separate "GPU still has frames to render" from "transition still owes a completion cleanup"—either finish the transition and remove its mask upon entering zero area, or wake once at the original deadline to finalize cleanup (regular nsh.time shaders can stay GPU-idle at zero size).
    (shader.rs:931, macos shader.rs:1822)

  • Nit — PR description implies full CI matrix runs on PR checks.
    This SHA only ran PR Check / test (run 46068627892); the full matrix runs on main push, schedule, or manual dispatch (ci.yml:20). Clarify local verification vs. full CI trigger conditions.

Test Quality & Local Verification

  • Tests make up 731/1127 added lines (64.9%). Keep the native AppKit hidden-resize clear, root-resize redraw, and engine nsh.time idle/wake tests. Remove the redundant AppKit unit tests constructing ShaderState to assert internal needs_tick() and IOSurface pointers (macos shader.rs:2757), which duplicate the real native Metal coverage (shader_content.rs:206), and use that budget for a behavioral test verifying transition expiry unmasks subtrees.
  • Verified locally: nsh-engine --features shader --lib (103/103), macos-nsh rendering subset (38/38), NSH_SHADER_CONTENT_CHECK_ONLY=resize (3/3, including real Metal A → B pool swap → hidden → 0), node --test scripts/ci.test.mjs (31/31) + plan --base HEAD^ / Cargo feature graph checks (suites.mjs:305, run.mjs:629), plus AppKit --no-default-features, iOS Simulator shader, and Windows ARM64 shader cargo check. GTK/Xvfb, Windows/iOS native runs, AppKit independent windows, and bridge tests on this commit were not re-executed locally.
中文

结论:Request Changes

最新提交 c965795294 已修掉上一轮的 A → B → 0 残帧 Blocker,也已将 shader/GPU 与 AppKit resize 测试干净接入中央 CI。但零尺寸停表引入了一个已实测复现的 AppKit transition 回归,需修复后再合入。

已验证的问题

  • Important — 折叠中的 transition 到期后仍持续遮住子树。
    独立 AppKit 实例复现:启动 600 ms 的 ScreenTransition,首帧呈现后折叠宿主,CALayer.contents 确实清空了,但继续泵 900 ms 后 children 的空 mask 仍然残留(PR base 92a4ba0d1f 会按期解除)。普通 ShaderTransition 同样复现——窗口保持正常尺寸、仅 transition 容器缩到零宽时,仍在窗口范围内的溢出子树继续被遮住。
    根因: 清帧后 wants_frame() 返回 false,AppKit 停止调度,而解除 mask 仅在下一次 show_frame() 发现 transition 到期时执行。
    建议改法: 拆开「GPU 是否还有帧要画」与「transition 是否还欠一次收尾」——在进入零面积时结束 transition 并解除 mask,或按原 deadline 单次唤醒做收尾(普通 nsh.time shader 仍保持零尺寸 GPU idle)。
    (shader.rs:931, macos shader.rs:1822)

  • Nit — PR 正文把完整 CI 矩阵写成了 PR 上会跑的检查。
    当前 SHA 仅触发了 PR Check / test (run 46068627892),完整 CI 在 main push、定时或手动时触发 (ci.yml:20),建议写清本地实测与完整 CI 的触发条件。

测试质量与本地验证

  • 测试占新增 731/1127 行(64.9%)。保留原生 AppKit 的 hidden resize 清帧、root resize 重绘和 engine 的 nsh.time 停表/恢复用例;建议删掉重复构造 ShaderState 并断言内部 needs_tick() 与 IOSurface 指针的 AppKit 单测 (macos shader.rs:2757),这些已被真实原生 Metal 用例覆盖 (shader_content.rs:206),把覆盖留给“transition 到期恢复子树”的行为回归。
  • 本地验证:nsh-engine --features shader --lib 103/103、macos-nsh 渲染子集 38/38、NSH_SHADER_CONTENT_CHECK_ONLY=resize 3/3(真 Metal 跑通 A → B 换池 → hidden → 0)、node --test scripts/ci.test.mjs 31/31 + plan --base HEAD^ / feature graph 核验 (suites.mjs:305, run.mjs:629),以及 AppKit --no-default-features、iOS Simulator shader、Windows ARM64 shader cargo check 全过。GTK/Xvfb、Windows/iOS 原生运行、AppKit 独立窗口与本提交下的 bridge 用例未在本地复跑。

@github-actions github-actions Bot added effort/XL Under 2500 readable lines and removed effort/M Under 500 readable lines labels Nov 28, 2026
@me2seeks
me2seeks force-pushed the fix/ios-bridge-reload-and-nsh-fixes branch from c965795 to 4f063db Compare November 28, 2026 04:59
Reject subscriptions registered by a replaced caller under the lock.

Retire shared shader frames on collapse even when a resize replaced
the pool. Keep zero-size animations idle, and finish collapsed AppKit
and UIKit transitions so their masks do not outlive their frames.
Wake hosted shaders on resize and run the shader and AppKit regressions
in the central macOS suite.

Generated-by: Maka
@me2seeks
me2seeks force-pushed the fix/ios-bridge-reload-and-nsh-fixes branch from 4f063db to 8d92f82 Compare November 28, 2026 05:53
@me2seeks
me2seeks changed the base branch from main to chore/nsh-sync-latest November 28, 2026 05:53
@me2seeks
me2seeks added this pull request to stack #7393 November 28, 2026 05:53

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated Re-Review · Reviewed at 8d92f828e3 using Magpie codex/gpt-6.2-sol (xhigh)

English

Verdict: Request Changes — Please split this PR and fix the underlying state ownership instead of patching platform by platform

8d92f828e3 fixes the AppKit transition cases and local UIKit ShaderTransition, but testing on an isolated iOS 27.2 Simulator immediately hit another Blocker on UIKit ScreenTransition. More importantly, three rounds of back-and-forth on what started as a small fix point to two structural problems with this PR itself.

1. Why this PR keeps bouncing (Root Problems)

  • Catch-all PR scope: This PR bundles three unrelated concerns—the iOS bridge reload subscription race (products/maka/ios-shell/src/bridge.rs), cross-platform NSH shader/transition lifecycle changes across AppKit/UIKit/GTK/Windows, and central CI suite wiring—on top of an unmerged stack (#7368). bridge.rs has been clean and ready since round 1 with zero dependency on #7368 or NSH shaders, yet it keeps getting blocked by NSH churn while the diff keeps expanding (now 16 files, +901/-114, 66.9% tests).
  • Per-platform whack-a-mole instead of closing the state machine in nsh-engine:
    • Round 1 tied "frame presented" to surface-pool lifetime → broke A → B → 0 after a pool swap.
    • Round 2 stopped ticking at zero size (wants_frame() == false) while transition unmasking still relied on the next tick → locked AppKit child masks in place, while expanding changes across 4 platforms.
    • Round 3 kept the collapse-ends-transition rule out of ShaderView::set_size() and copy-pasted if w <= 0 || h <= 0 { finish_transition(); setContents(None); sync_mask(); } into platform layout() hooks instead. Because UIKit was only compile-checked rather than run on a Simulator, missing the UIKit root layout path broke ScreenTransition immediately. As long as each platform duplicates collapse/transition rules and only macOS Metal is actually executed, fixing one platform just exposes the next gap (UIKit today, GTK/Windows/independent windows next).

2. Verified Finding in 8d92f828e3

  • Blocker — UIKit root collapse never notifies ScreenTransition to finish and unmask.
    Reproduced on an isolated iOS 27.2 Simulator: shrinking a playing ScreenTransition's host from 402 pt → 0 and restoring it before the original duration expires leaves the 402 pt output layer, contents, and child mask stuck both while collapsed and after re-expansion.
    Root cause: RootView::layout_subviews returns early on zero size (surface.rs:192), while ScreenTransition is hosted on the root view but indexed by its declared node ID (mount.rs:1713). layout_shader(id) only tracks declared-node layout, so root collapse never reaches the new finish_transition() path (shader.rs:455).

3. Concrete Path Forward

  1. Split products/maka/ios-shell/src/bridge.rs into its own standalone PR against main so the verified iOS reload subscription fix can merge immediately without waiting on #7368 or NSH shader work.
  2. Consolidate the shader collapse/transition contract in nsh-engine (e.g. handle zero-area transition retirement inside ShaderView::set_size rather than duplicating collapse rules in every platform's layout()), then wire uniform root/node geometry forwarding (including UIKit RootView::layout_subviews) and verify each touched platform rather than relying on compile-only checks.
  3. Stack / merge order: Since this repo is squash-merge only with auto-deleted branches, once #7368 merges, rebase the remaining NSH/CI commit onto the new main (do not just retarget the base).
  4. Tests (603/901 added lines, 66.9%): Dropping the redundant internal ShaderState test was the right call. Extend the shared AppKit native transition test (shader_content.rs:369) to assert post-expansion visibility as well, and add a UIKit root-resize behavioral check.

Local Verification Summary

  • AppKit Metal NSH_SHADER_CONTENT_CHECK_ONLY=resize (5/5) + temporary re-expand probe passed.
  • Isolated iOS 27.2 Simulator: local ShaderTransition collapse/expand passed; ScreenTransition reproduced the Blocker above.
  • nsh-engine --features shader --lib (111 passed, 1 ignored), CI routing (31/31), plan --base HEAD^, and git diff --check passed. Bridge, GTK, and Windows native runs were not re-executed in this pass.
中文

结论:Request Changes — 建议先拆 PR、把状态机收口回 nsh-engine,不要再按平台打地鼠

8d92f828e3 修好了 AppKit 的两种 transition 和 UIKit 的局部 ShaderTransition,但在独立 iOS 27.2 Simulator 上一实测又立刻抓出 UIKit ScreenTransition 的新 Blocker。比这个单点 bug 更值得正视的是:一个小修复来回打回三轮,暴露出这个 PR 本身的两个根本问题。

1. 为什么会反复打回(根本问题)

  • “拾遗垃圾桶”式的 PR 范围: 这个 PR 把三件互不相干的事硬捆在一起——products/maka/ios-shell/src/bridge.rs 的 iOS reload 订阅竞态、NSH 跨四端(AppKit/UIKit/GTK/Windows)的 shader/transition 生命周期改动、以及中央 CI 接线,还 stack 在尚未合入的 #7368 上。bridge.rs 从第一轮开始就是干净可合的,跟 #7368 和 NSH 毫无依赖,结果一直被 NSH 拖着陪跑;而 PR 反而越改越胖(当前 16 文件,+901/-114,测试占 66.9%)。
  • 状态机没收口在 nsh-engine,而是在各平台 layout() 里逐个打补丁:
    • 第 1 轮把“已上屏帧”偷懒挂在 surface pool 生命周期上 → A → B → 0 换池漏清帧;
    • 第 2 轮加了零尺寸停表(wants_frame() == false),却忘了 transition 解 mask 依赖下一次 tick → 锁死 AppKit 子树 mask,同时顺手把改动扩到四端;
    • 第 3 轮仍未把“零尺寸结束 transition”收口到 ShaderView::set_size(),而是把 if w <= 0 || h <= 0 { finish_transition(); setContents(None); sync_mask(); } 复制粘贴进 AppKit 和 UIKit 各自的 layout(),且 UIKit 只做 compile check 没跑 Simulator,结果漏接 UIKit root 布局入口立刻炸掉。只要规则分散在四端且只实跑 macOS Metal,修完一端就必然在下一端(今天是 UIKit,明天可能是 GTK / Windows / 独立窗口)继续露馅。

2. 8d92f828e3 上已验证的新 Blocker

  • Blocker — UIKit 的 root 折叠没有通知 ScreenTransition 收尾并解除 mask。
    在独立 iOS 27.2 Simulator 上复现:播放中的 ScreenTransition 宿主从 402 pt → 0 并在原动画到期前恢复,折叠时输出层仍宽 402 pt、contents 与子树 mask 都在,展开后依然未清、继续遮住子树。
    根因: RootView::layout_subviews 遇零尺寸直接返回 (surface.rs:192),而 ScreenTransition 挂在 root 上却按声明节点 ID 登记 (mount.rs:1713);layout_shader(id) 只跟声明节点走,导致 root 折叠从未走到新增的 finish_transition() (shader.rs:455)。

3. 建议的收尾方式

  1. 先把 products/maka/ios-shell/src/bridge.rs 独立拆 PR 基于 main 合掉,不要再被 #7368 和 NSH shader 绑架。
  2. 把零尺寸收尾 transition 的状态转换收口到 nsh-engine(如 ShaderView::set_size 内部),平台侧只负责把 root/node 的几何变化(含 UIKit RootView::layout_subviews)无遗漏地传给引擎并同步清帧/mask,且改到哪端就实跑验证哪端,不要仅靠 compile check。
  3. Stack 与合入顺序: 仓库只允许 squash merge 且自动删分支,#7368 合入后请将剩余 NSH/CI 提交 rebase 到新 main 再核对 diff 合入,不要直接改 base。
  4. 测试(603/901 新增行,66.9%): 删掉重复的内部 ShaderState 单测方向是对的;建议在现有 AppKit 原生用例 (shader_content.rs:369) 里补上展开后的可见性断言,并补一条 UIKit root resize 行为覆盖。

本地验证记录

  • AppKit Metal NSH_SHADER_CONTENT_CHECK_ONLY=resize 5/5 + 展开恢复探针通过。
  • 独立 iOS 27.2 Simulator:局部 ShaderTransition 折叠/展开通过,ScreenTransition 复现上述 Blocker。
  • nsh-engine --features shader --lib 111 通过(1 ignored)、CI 路由 31/31、plan --base HEAD^ 与 git diff --check 通过。本轮未重跑 bridge、GTK 和 Windows 原生运行。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XL Under 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants