Skip to main content

Module second_instance

Module second_instance 

Source

Enumsยง

ForwardError ๐Ÿ”’
Phase B.6 (post-fix) โ€” forward an open_new_window request to the already-running host and let this launcher exit 0.
Handoff ๐Ÿ”’
What await_running_instance ended with.

Constantsยง

QUITTING_INSTANCE_WAIT ๐Ÿ”’
How long a relaunch keeps at it when the running instanceโ€™s host didnโ€™t take its open_new_window: long enough for an instance that is quitting to let go of the single-instance socket/pipe (its launcher holds on until srv has closed every agent, up to SRV_EXIT_WAIT, via upgrade::quiesce_srv).

Functionsยง

await_running_instance ๐Ÿ”’
A relaunch whose forward failed with first: the running instance is starting (no port file yet) or quitting (its host is gone; a clean exit deletes the port file). Until QUITTING_INSTANCE_WAIT passes, take the socket/pipe as soon as the old launcher lets go of it, or forward as soon as the host answers. Shared by both supervisors.
bind_socket_with_recovery ๐Ÿ”’
Bind the launcherโ€™s IPC socket with single-instance enforcement + crash-safe stale-socket recovery, serialized across concurrent launchers via flock(2).
claim_after_quit ๐Ÿ”’
The socket, once the launcher that held it has exited: unlink its file and bind. None while it still answers. Called under the recovery lock.
forward_for_second_instance ๐Ÿ”’
What a launcher that lost the single-instance race does: open a window in the running instance, unless it was started by a login entry, which only asks that AgentMux be running (SPEC_START_WITH_OS_2026_09_25.md ยง3.6). Not used by the macOS reopen handler, which is a user asking for a window. Returns the forwardโ€™s error, if any, for await_running_instance.
forward_host_body ๐Ÿ”’
forward_host_cmd ๐Ÿ”’
Forward an arbitrary host IPC command over the same authenticated localhost channel forward_open_new_window uses.
forward_host_cmd_impl ๐Ÿ”’
forward_host_cmd_with_args ๐Ÿ”’
forward_host_cmd with an args object โ€” the hostโ€™s /ipc body is {"cmd", "args"} (crates/cef/src/ipc.rs IpcRequest). Used by the notification click path (open_new_window {workspace_id}, focus_window {label}).
forward_open_new_window ๐Ÿ”’
print_dev_instance_collision ๐Ÿ”’
User-facing message for an actual second-instance collision (not a bind-failure, not a stale socket โ€” a real running launcher answered our connect probe). Shared by both call sites in bind_socket_with_recovery (fast-path and post-recovery-lock retry), which previously duplicated this message and both got it wrong the same way โ€” see docs/specs/SPEC_DEV_INSTANCE_ISOLATION_DIAGNOSTICS_2026_09_19.md.