Skip to content

feat(ipc): add opt-in complete workspace state and monitor-targeted switching - #118

Open
Mihir-Null wants to merge 10 commits into
jcardama:mainfrom
Mihir-Null:feat/workspace-ipc
Open

Mihir-Null wants to merge 10 commits into
jcardama:mainfrom
Mihir-Null:feat/workspace-ipc

Conversation

@Mihir-Null

@Mihir-Null Mihir-Null commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Status bars need complete workspace membership and monitor-targeted switching. This extends the existing IPC commands and subscription transport so consumers can render every monitor's workspaces, including inactive/empty slots and floating windows.

Interface Behavior
lwm subscribe --events workspace_state Explicit opt-in to complete initial and replacement snapshots; can be combined with legacy event filters.
Plain lwm subscribe / empty wire filter Preserves the legacy event set for older typed clients.
lwm query workspaces Prints one complete snapshot using bounded NDJSON frames, then exits.
lwm workspace N --monitor DEVICE Validates and switches an explicit monitor and transfers focus to it. Omitting the monitor preserves focused-monitor behavior.

Contract and implementation

  • IPC v3 remains the hotkey-query extension from feat: export hotkeys to PowerToys Shortcut Guide #110; v4 adds workspace state and monitor-targeted switching. Consumers also verify workspace_state in the acknowledged filter.
  • Snapshots include all connected monitors, all nine slots, names, active/focused identity, and authoritative tiled/floating HWND membership. Command indexes are 1-based; snapshot indexes are 0-based.
  • Initial snapshot capture and receiver installation are atomic under the state lock. Session IDs and semantic revisions identify complete begin/chunk/end replacement transactions; geometry-only changes do not advance revisions.
  • Frames stay within 64 KiB including the newline. Workspace-enabled clients use a separate 256-frame broadcaster, including requested legacy events, so workspace traffic cannot evict legacy-only clients' events. Transactions stay contiguous.
  • Ordinary workspace projection runs only while a workspace-enabled receiver exists. Query/subscription handoffs still capture fresh state. Lag or incomplete/error transactions require reconnecting for a fresh snapshot.
  • Server writes have ten-second deadlines. One-shot CLI queries have five-second acknowledgment and per-frame read deadlines, with no query deadline imposed on long-lived subscriptions.
  • The maintained contract is in agent_docs/ipc-events.md; the original proposal is marked historical.

Review 5225970035

  • Restore remembered floating focus when an explicitly targeted workspace is already active, using the same membership-checked restoration as normal switching. Regression tests cover floating-only targets, stale remembered HWNDs, and preserving current tiled/floating focus when the target monitor is already focused.
  • Isolate workspace snapshot traffic from legacy-only buffers and gate publication on workspace-enabled receivers. Regression tests cover legacy-only clients, simultaneous mixed subscriptions, more than 256 snapshot frames, last-receiver disconnect, and fresh later capture.
  • Implement the optional query timeout. Tests cover stalled acknowledgment, stalled/partial frames, deadlines resetting between frames, and subscriptions remaining alive beyond the query timeout.
  • Preserve the maintainer's merge of current main at ed0aa13, including chore(deps): bump wry from 0.56.1 to 0.57.0 #120's wry update and chore(deps): bump toml from 1.1.5+spec-1.1.0 to 1.1.6+spec-1.1.0 #121's toml update.

Validation

  • Formatting and git diff --check: passed. Full-workspace formatting was checked before the final follow-up; daemon and CLI module trees were checked again on the final changes.
  • Windows CI run 415 passed on 233491dd2e22d39ff16f486f9e8bc3d7e468f59d: release MSVC build, GUI-subsystem verification, cargo test --all (1,549 passed, 0 failed, 13 ignored, including both CLI binaries and doc tests), 26 offline desktop acceptance helper tests, and cargo clippy --all -- -D warnings.
  • Independent source review found no remaining issues in these fixes. All three threads from review 5225970035 have implementation replies and are resolved.
  • No live Windows desktop test was run during this revision. Previously reported live testing applies to the earlier implementation, not these fixes.
  • Companion consumer: amnweb/yasb#1112. It was not modified or revalidated in this revision.

AI assistance

Implementation, regression tests, and documentation updates were developed with OpenAI Codex assistance. Automated checks and source review do not substitute for maintainer review or live-desktop verification.

Copilot AI lite review requested due to automatic review settings September 14, 2026 03:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jcardama jcardama left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The three suggestions below are nice-to-have improvements, not blockers. The rebase and IPC-version reconciliation noted separately still need to be completed before landing.

The Rust and Python subscription examples in agent_docs/ipc-events.md still describe an empty filter as all event kinds, but it now delivers only legacy kinds. A consumer copying either example will not receive workspace snapshots. I suggest updating both comments to say that workspace_state requires explicit opt-in. The README stream paragraph and the subscription round-trip test comment need the same distinction.

The opt-in design and monitor-targeted command fit the intended integration. Before landing, please rebase onto current main and reconcile the IPC version with #110, which now owns version 3. I recommend version 4 for this addition while retaining the acknowledged-filter capability check and older-client compatibility.

Comment thread crates/daemon/src/main.rs Outdated
Comment thread agent_docs/workspace-ipc-proposal.md Outdated
@jcardama

Copy link
Copy Markdown
Owner

These are my recommendations for this PR. They do not establish a complete policy for future IPC extensions.

1. Opt-in and default behavior

I recommend keeping explicit --events workspace_state opt-in. An empty filter should continue to select only legacy event kinds. This preserves the event stream for existing consumers.

I do not see a need for another default-migration mechanism in this PR. Consumers should check the acknowledged event filter before expecting workspace snapshots. Sending the filter alone does not prove support.

2. Commands and monitor focus

I recommend keeping query workspaces and workspace N --monitor DEVICE.

Keep command indices 1-based. Keep snapshot indices 0-based. Document this distinction in the maintained IPC contract.

An explicit monitor target should switch the workspace on that monitor and transfer focus to it. Omitting --monitor should preserve the existing focused-monitor behavior. Document the focus transfer as part of the command contract.

3. Protocol version and capability detection

#110 has merged with IPC version 3. I recommend rebasing this PR onto current main and assigning IPC version 4 to this addition.

Keep the version history clear: version 3 adds hotkey queries, and version 4 adds the workspace IPC capability. The personal combined build is not part of this review.

Retain the acknowledged-filter capability check alongside the protocol version. Preserve older-client compatibility. For future extensions, document the version change and the capability check together.

4. Snapshot contents and publication

The compact monitor, workspace, and HWND membership model fits this PR. I recommend keeping all nine workspace slots for each connected monitor. I do not propose additional fields or naming changes at this stage.

Keep geometry, titles, and icons outside this snapshot contract. Consumer presentation should remain in YASB.

Complete replacement snapshots are a reasonable starting point. Consumers should apply a snapshot only after they receive its complete begin/chunk/end transaction. They should discard an incomplete transaction and reconnect for a fresh snapshot after lag or a stream failure.

The existing broadcaster and end-of-event publication approach fit this design. Publish a new revision when the represented state changes. Geometry-only changes should not produce a new revision. Keep the 64 KiB frame limit, including the newline.

The separate review notes the cost of building the snapshot after animation-frame events. That is a nonblocking measurement suggestion, not a request to redesign the stream.

Verification limits

This was a source-only review. I did not run the PR or test its integration with current main. I did not review or run the companion YASB PR. These recommendations do not establish end-to-end compatibility.

@Mihir-Null

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and reconciled IPC history: v3 remains hotkey queries and workspace IPC is v4. Documentation now distinguishes legacy empty filters, 1-based commands versus 0-based snapshots, explicit monitor focus transfer, and acknowledged-filter capability detection. The historical proposal links to the maintained contract. I also added a large-membership projection benchmark and skipped end-of-event projection when no stream subscribers exist while preserving forced query/subscription synchronization. CI run 401 passes completely.

@jcardama jcardama left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The protocol-version conflict and documentation comments are resolved. I found two remaining issues: floating-only focus restoration when the target workspace is already active, and workspace snapshot traffic consuming legacy subscribers' buffer capacity. Please fix those before landing. The client timeout suggestion is optional.

CI is green for 1b17a13. This was a source review, not local execution or live-desktop verification. Main has since advanced with #120's wry update, so integration with that newer base still needs verification.

Comment thread crates/daemon/src/command_handler.rs
Comment thread crates/daemon/src/workspace_ipc.rs Outdated
Comment thread crates/cli/src/daemon_cmds.rs
@Mihir-Null
Mihir-Null requested a review from jcardama September 18, 2026 15:33
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.

3 participants