Skip to content

Decomposed process.ts, Audited and fixed 3 small pre-existing bugs - #1355

Merged
reachrazamair merged 1 commit into
rcfrom
refactoring
Aug 6, 2026
Merged

Decomposed process.ts, Audited and fixed 3 small pre-existing bugs#1355
reachrazamair merged 1 commit into
rcfrom
refactoring

Conversation

@reachrazamair

@reachrazamair reachrazamair commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Expanded remote controls for sessions, tabs, commands, groups, Git, playbooks, queues, settings, notifications, group chat, and auto-run workflows.
    • Added remote browser, terminal, AI-tab, Cadenza, movement, context, gist, and Cue operations.
    • Added reliable listener cleanup and response acknowledgments for remote actions.
  • Bug Fixes

    • Improved web-server response-channel uniqueness and timeout handling.
    • Standardized settings snapshots.
  • Tests

    • Added coverage for remote operations, callbacks, acknowledgments, and settings behavior.
  • Documentation

    • Updated IPC reference documentation.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The monolithic preload process bridge is split into core and per-domain IPC factories. New remote APIs cover process, tabs, commands, automation, sessions, groups, context, settings, and related operations. Tests and web-server callbacks validate the extracted APIs and response-channel behavior.

Changes

Preload IPC modularization

Layer / File(s) Summary
Core process API and composition
src/main/preload/process.ts, src/main/preload/process/core.ts, src/__tests__/main/preload/process/core.test.ts, docs/agent-guides/IPC-PATTERNS.md
Process types and lifecycle handlers moved into createProcessCoreApi. createProcessApi now composes the core API with domain factories.
Command, tab, browser, and movement APIs
src/main/preload/process/{commandRemote,tabRemote,browserTabRemote,cadenzaMovementRemote}.ts, src/__tests__/main/preload/process/*Remote.test.ts, src/main/web-server/callbacks/{cadenzaMovementCallbacks,tabCallbacks}.ts
Added typed remote handlers, response senders, listener cleanup, movement IPC methods, focused tests, timeout ordering, and UUID response channels.
Automation, queue, and playbook APIs
src/main/preload/process/{autoRunConfigRemote,autoRunControlRemote,queueRemote,playbookRemote}.ts
Added remote Auto Run, queue, and playbook subscriptions with response forwarding and fallback responses.
Session, group, context, and settings APIs
src/main/preload/process/{sessionCrudRemote,groupCrudRemote,groupChatRemote,contextOpsRemote,settingsRemote}.ts, src/main/web-server/callbacks/settingsCallbacks.ts, src/__tests__/main/web-server/web-server-factory.test.ts
Added remote session, group, context, and settings APIs. Settings callbacks now use the shared snapshot builder.
Supporting remote APIs and callback wiring
src/main/preload/process/{cueRemote,gistRemote,gitRemote,notificationRemote}.ts
Added remote Cue, gist, Git, toast, and center-flash IPC handlers with cleanup and response behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: runmaestro.ai

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the process.ts decomposition and the three related bug fixes included in the changeset.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactoring

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.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown

Greptile Summary

The PR decomposes the large process preload bridge into focused per-domain factories while preserving the existing window.maestro.process API. It also fixes response timing, response-channel uniqueness, and web settings snapshot consistency.

  • Moves process lifecycle and remote integration methods into 18 composable preload factories.
  • Initializes Cadenza movement timeouts before requests that can receive immediate replies.
  • Uses UUID response channels for concurrent new-tab requests.
  • Reuses the canonical web settings snapshot builder for reads and broadcasts.
  • Adds focused preload and web-server regression tests.

Confidence Score: 5/5

The PR appears safe to merge, with the decomposed preload API retaining its existing contracts and the three targeted fixes addressing reachable pre-existing failures.

All prior process API properties remain represented exactly once with matching IPC channels and argument shapes, while the callback changes safely fix timer ordering, response-channel collisions, and settings snapshot drift.

Important Files Changed

Filename Overview
src/main/preload/process.ts Replaces the monolithic implementation with a thin composer while preserving every prior process API property exactly once.
src/main/preload/process/core.ts Moves process lifecycle methods, process events, permission relay, and exported types without changing their IPC contracts.
src/main/preload/process/cadenzaMovementRemote.ts Extracts Cadenza and movement IPC methods with response-channel and revision forwarding preserved.
src/main/web-server/callbacks/cadenzaMovementCallbacks.ts Initializes the timeout before dispatch so immediate movement replies cannot access an uninitialized timer.
src/main/web-server/callbacks/tabCallbacks.ts Uses random UUIDs to prevent overlapping new-tab requests from sharing a response channel.
src/main/web-server/callbacks/settingsCallbacks.ts Uses the shared settings snapshot builder for both initial reads and settings broadcasts.
src/tests/main/web-server/web-server-factory.test.ts Adds regression coverage for settings snapshot parity and distinct concurrent new-tab response channels.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Composer["createProcessApi()"] --> Core["Process core"]
    Composer --> Commands["Command and queue remotes"]
    Composer --> Tabs["Tab and browser remotes"]
    Composer --> Automation["Auto Run, Cue, and playbook remotes"]
    Composer --> Data["Session, group, git, settings, and context remotes"]
    Composer --> Cadenza["Cadenza and movement remotes"]
    Core --> IPC["ipcRenderer channels"]
    Commands --> IPC
    Tabs --> IPC
    Automation --> IPC
    Data --> IPC
    Cadenza --> IPC
    IPC --> Main["Electron main process"]
    Main --> Web["Web server callbacks"]
Loading

Reviews (1): Last reviewed commit: "Decomposed process.ts, Audited and fixed..." | Re-trigger Greptile

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

🧹 Nitpick comments (4)
src/main/preload/process/sessionCrudRemote.ts (1)

61-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract one request-response registration helper for the domain factories. Each factory hand-rolls the same ipcRenderer.on + forward + removeListener shape, and the direct-forward handlers send no ack when the callback throws or rejects. The caller then waits for its 5000 ms timeout instead of receiving an immediate error. A single helper that wraps the callback in Promise.resolve(...), acks a caller-supplied fallback, and rethrows would fix all sites at once and match the pattern already used in autoRunControlRemote.ts and playbookRemote.ts.

  • src/main/preload/process/sessionCrudRemote.ts#L61-L72: route onRemoteCreateSession through the shared helper with a { success: false, error } fallback, then apply it to lines 97-104, 119-126, 143-158, and 176-191.
  • src/main/preload/process/contextOpsRemote.ts#L12-L20: route onRemoteMergeContext through the shared helper with a false fallback, then apply it to lines 36-44 and 60-64.
  • src/main/preload/process/groupCrudRemote.ts#L17-L25: route onRemoteCreateGroup through the shared helper with a null fallback, then apply it to lines 47-48 and 76-81.
  • src/main/preload/process/groupChatRemote.ts#L29-L37: route onRemoteStartGroupChat through the shared helper with a null fallback, then apply it to lines 10, 56-57, 76-77, and 96-97.

Check docs/agent-guides/IPC-PATTERNS.md first. If a canonical helper already exists there, extend it instead of adding a new one.

Based on learnings from the coding guidelines: "Before creating a new utility, helper, hook, component, type, or constant, check the relevant guide in docs/agent-guides/ and reuse or extend the canonical implementation instead of duplicating it."

🤖 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 `@src/main/preload/process/sessionCrudRemote.ts` around lines 61 - 72, Extract
or extend the canonical request-response registration helper described in
docs/agent-guides/IPC-PATTERNS.md so it wraps callbacks with Promise.resolve,
acknowledges failures using the supplied fallback, and rethrows errors. Apply it
to sessionCrudRemote.ts lines 61-72, 97-104, 119-126, 143-158, and 176-191;
contextOpsRemote.ts lines 12-20, 36-44, and 60-64; groupCrudRemote.ts lines
17-25, 47-48, and 76-81; and groupChatRemote.ts lines 29-37, 10, 56-57, 76-77,
and 96-97, using fallbacks { success: false, error }, false, null, and null
respectively.

Source: Coding guidelines

src/main/preload/process/tabRemote.ts (1)

17-24: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider acking a failure when the new-tab callback throws.

onRemoteNewTab uses the request-response pattern with responseChannel. If the callback throws synchronously, nothing is ever sent on that channel, so the caller waits for its full response timeout. browserTabRemote.ts lines 14-21 solve the same problem by sending a failure value first and then rethrowing for Sentry.

This behavior is unchanged from the previous monolithic module. Aligning it makes the request-response factories consistent.

♻️ Proposed change
 			const handler = (_: unknown, sessionId: string, responseChannel: string) =>
-				callback(sessionId, responseChannel);
+			{
+				try {
+					callback(sessionId, responseChannel);
+				} catch (error) {
+					ipcRenderer.send(responseChannel, null);
+					throw error;
+				}
+			};
 			ipcRenderer.on('remote:newTab', handler);
🤖 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 `@src/main/preload/process/tabRemote.ts` around lines 17 - 24, Update
onRemoteNewTab so its IPC handler catches synchronous errors from callback,
sends a failure response through responseChannel before rethrowing the error for
Sentry, and preserves the existing success callback behavior and listener
cleanup.
src/__tests__/main/preload/process/commandRemote.test.ts (1)

30-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extend coverage to the remaining factory methods and the error path.

createCommandRemoteApi exposes four methods. These tests cover only onRemoteCommand. Consider adding cases for:

  • The returned unsubscribe function. Assert that it calls removeListener with the same channel and handler reference.
  • The catch path at commandRemote.ts lines 49-59. If the rethrow fix in the other comment is applied, a test here locks in that behavior.
  • onRemoteSwitchMode, onRemoteInterrupt, and onRemoteSelectSession.

The mockOn.mockImplementation block is repeated in both tests. A small captureHandler(channel) helper would remove that duplication.

🤖 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 `@src/__tests__/main/preload/process/commandRemote.test.ts` around lines 30 -
97, Expand coverage for createCommandRemoteApi beyond onRemoteCommand: add tests
for the unsubscribe function verifying removeListener receives the same channel
and handler, the commandRemote.ts catch path preserving the rethrow behavior,
and the onRemoteSwitchMode, onRemoteInterrupt, and onRemoteSelectSession
methods. Extract the repeated mockOn handler-capture setup into a small
captureHandler(channel) helper and reuse it in the existing tests.
src/main/preload/process/commandRemote.ts (1)

40-48: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Consider dropping the command preview from the debug log.

commandPreview forwards the first 50 characters of the user prompt to the main-process logger. Prompt text can contain credentials, tokens, or personal data. The log is written to the persisted log buffer through logger:log. Logging the command length instead of the content keeps the diagnostic value without retaining user content.

This behavior is carried over from the previous monolithic module, so it is not a regression in this PR.

🔒 Proposed change
 				log('Received remote:executeCommand IPC', {
 					sessionId,
-					commandPreview: command?.substring(0, 50),
+					commandLength: command?.length ?? 0,
 					inputMode,
 					tabId,
 					force,
 					imageCount: images?.length ?? 0,
 					background,
 				});
🤖 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 `@src/main/preload/process/commandRemote.ts` around lines 40 - 48, Update the
remote:executeCommand debug log to remove commandPreview and log only the
command’s length instead. Preserve the existing sessionId, inputMode, tabId,
force, imageCount, and background fields while ensuring no user prompt content
is passed to log.
🤖 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/agent-guides/IPC-PATTERNS.md`:
- Line 38: Update the process row in the IPC patterns table to identify the
main-process handler file consistently with the other rows, rather than listing
preload modules in the Handler File column. Correct the preload factory count to
18, and move the `core.ts` plus 17 `*Remote.ts` module breakdown into the
explanatory text below the table or a separate column.

In `@src/__tests__/main/web-server/web-server-factory.test.ts`:
- Around line 2106-2107: Update the test around registerTabCallbacks so both
callback promises returned by callback('session-1') are retained and settled
before the test completes. Invoke the corresponding response handlers, or use
fake timers to trigger the five-second fallback cleanup, ensuring both IPC
listeners and timeout resources are released.

In `@src/main/preload/process/autoRunConfigRemote.ts`:
- Around line 20-35: Update the error handlers in onRemoteConfigureAutoRun,
onRemoteGetAutoRunDocs, onRemoteGetAutoRunDocContent, and onRemoteSaveAutoRunDoc
to rethrow the caught error after sending their fallback acknowledgement,
matching the existing pattern in onRemoteSetAutoRunFolder. Preserve each
handler’s current fallback response while ensuring the original error reaches
the global error handler.

In `@src/main/preload/process/commandRemote.ts`:
- Around line 49-59: Update the catch block surrounding the remote command
callback invocation to rethrow the captured error after logging it. Preserve the
existing logging behavior and do not add an acknowledgement, since
remote:executeCommand has no response channel.

In `@src/main/preload/process/cueRemote.ts`:
- Around line 23-33: Handle only known recoverable errors in the Cue and Git
remote callbacks. In src/main/preload/process/cueRemote.ts:23-33, preserve the
failure acknowledgment, report unexpected callback failures through the project
Sentry utility, and rethrow them; in src/main/preload/process/gitRemote.ts:13-19
and 45-51, replace empty status/diff fallbacks for unexpected failures with
Sentry reporting and rethrowing, while retaining existing behavior for known
recoverable errors.

In `@src/main/preload/process/gistRemote.ts`:
- Around line 26-34: Update the callback invocation in the remote gist process
to handle both synchronous throws and rejected Promise results by wrapping the
returned value in a Promise chain. On failure, send the unsuccessful IPC
response, call captureException with context "remoteCreateGist", and rethrow
unexpected errors.

In `@src/main/preload/process/queueRemote.ts`:
- Around line 32-37: Update the callback invocation in onRemoteEnqueueCommand,
onRemoteListQueue, and onRemoteRemoveQueueItem to use Promise.resolve(...)
within the existing try/catch so rejected promises reach the fallback
ipcRenderer.send(responseChannel, { success: false }) acknowledgement. Preserve
rethrowing the error after sending the acknowledgement and match the established
sibling-factory pattern.

In `@src/main/preload/process/sessionCrudRemote.ts`:
- Around line 20-31: Add throw error after each fallback ipcRenderer.send in the
Promise rejection and synchronous catch branches of the session CRUD callback
flow, preserving the failure acknowledgement while rethrowing the original
exception for Sentry capture. Match the behavior used by
autoRunControlRemote.ts.

---

Nitpick comments:
In `@src/__tests__/main/preload/process/commandRemote.test.ts`:
- Around line 30-97: Expand coverage for createCommandRemoteApi beyond
onRemoteCommand: add tests for the unsubscribe function verifying removeListener
receives the same channel and handler, the commandRemote.ts catch path
preserving the rethrow behavior, and the onRemoteSwitchMode, onRemoteInterrupt,
and onRemoteSelectSession methods. Extract the repeated mockOn handler-capture
setup into a small captureHandler(channel) helper and reuse it in the existing
tests.

In `@src/main/preload/process/commandRemote.ts`:
- Around line 40-48: Update the remote:executeCommand debug log to remove
commandPreview and log only the command’s length instead. Preserve the existing
sessionId, inputMode, tabId, force, imageCount, and background fields while
ensuring no user prompt content is passed to log.

In `@src/main/preload/process/sessionCrudRemote.ts`:
- Around line 61-72: Extract or extend the canonical request-response
registration helper described in docs/agent-guides/IPC-PATTERNS.md so it wraps
callbacks with Promise.resolve, acknowledges failures using the supplied
fallback, and rethrows errors. Apply it to sessionCrudRemote.ts lines 61-72,
97-104, 119-126, 143-158, and 176-191; contextOpsRemote.ts lines 12-20, 36-44,
and 60-64; groupCrudRemote.ts lines 17-25, 47-48, and 76-81; and
groupChatRemote.ts lines 29-37, 10, 56-57, 76-77, and 96-97, using fallbacks {
success: false, error }, false, null, and null respectively.

In `@src/main/preload/process/tabRemote.ts`:
- Around line 17-24: Update onRemoteNewTab so its IPC handler catches
synchronous errors from callback, sends a failure response through
responseChannel before rethrowing the error for Sentry, and preserves the
existing success callback behavior and listener cleanup.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e943c177-5156-4d6b-b074-9f2fb6272c64

📥 Commits

Reviewing files that changed from the base of the PR and between 3cf55dc and ac6021b.

📒 Files selected for processing (29)
  • docs/agent-guides/IPC-PATTERNS.md
  • src/__tests__/main/preload/process/cadenzaMovementRemote.test.ts
  • src/__tests__/main/preload/process/commandRemote.test.ts
  • src/__tests__/main/preload/process/core.test.ts
  • src/__tests__/main/preload/process/groupCrudRemote.test.ts
  • src/__tests__/main/preload/process/tabRemote.test.ts
  • src/__tests__/main/web-server/web-server-factory.test.ts
  • src/main/preload/process.ts
  • src/main/preload/process/autoRunConfigRemote.ts
  • src/main/preload/process/autoRunControlRemote.ts
  • src/main/preload/process/browserTabRemote.ts
  • src/main/preload/process/cadenzaMovementRemote.ts
  • src/main/preload/process/commandRemote.ts
  • src/main/preload/process/contextOpsRemote.ts
  • src/main/preload/process/core.ts
  • src/main/preload/process/cueRemote.ts
  • src/main/preload/process/gistRemote.ts
  • src/main/preload/process/gitRemote.ts
  • src/main/preload/process/groupChatRemote.ts
  • src/main/preload/process/groupCrudRemote.ts
  • src/main/preload/process/notificationRemote.ts
  • src/main/preload/process/playbookRemote.ts
  • src/main/preload/process/queueRemote.ts
  • src/main/preload/process/sessionCrudRemote.ts
  • src/main/preload/process/settingsRemote.ts
  • src/main/preload/process/tabRemote.ts
  • src/main/web-server/callbacks/cadenzaMovementCallbacks.ts
  • src/main/web-server/callbacks/settingsCallbacks.ts
  • src/main/web-server/callbacks/tabCallbacks.ts

Comment thread docs/agent-guides/IPC-PATTERNS.md
Comment thread src/__tests__/main/web-server/web-server-factory.test.ts
Comment thread src/main/preload/process/autoRunConfigRemote.ts
Comment thread src/main/preload/process/commandRemote.ts
Comment thread src/main/preload/process/cueRemote.ts
Comment thread src/main/preload/process/gistRemote.ts
Comment thread src/main/preload/process/queueRemote.ts
Comment thread src/main/preload/process/sessionCrudRemote.ts
@reachrazamair
reachrazamair merged commit b953f65 into rc Aug 6, 2026
3 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.

1 participant