mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
* Revert "fix terminal attribution shim removal edge cases (#14187)"
This reverts 585dd6d3a9. Re-landed in the next commit without the host capability gate. Nothing shipped with it, so no migration constraint.
* rm git shim: neutralize stale wrappers without a host gate
Re-lands the cleanup half of #14187: pass-through tombstones for retained wrapper paths, env/PATH scrubbing at every spawn owner, and the retired setting drop.
Only writes tombstones when the legacy directory already exists, so a clean install no longer has it created. Leaves out the terminal.attribution-removed.v1 capability gate: the tombstone neutralizes each host locally, so refusing terminal create/split against older hosts denied service without adding cleanup.
* rm git shim: surface neutralization failures and fix rollback marker
Readiness review follow-ups: warn on each failed attempt and on give-up (was silent and undiagnosable); write a VERSION marker distinct from the retired shim's '7' so a rolled-back build rewrites its own wrappers; clear a captured ORCA_REAL_* path that no longer exists so the cmd wrapper's where.exe fallback can run; stop a locked temp file masking the real error. Adds retry-exhaustion coverage.
* rm git shim: pin the cmd fallback order and correct the give-up count
Round-2 review follow-ups: string-pin that a stale ORCA_REAL_* is cleared before the where.exe fallback, and count the initial attempt in the give-up warning so it agrees with the per-attempt line.
* rm git shim: keep the split-failure toast
The revert took a toast that #14187 added alongside the gate but which stands on its own: without it a failed remote split only reaches the console and the pane silently never appears. Also pins attempt ordinals in the retry-exhaustion test.
144 lines
4.9 KiB
TypeScript
144 lines
4.9 KiB
TypeScript
import { randomUUID } from 'node:crypto'
|
|
import type { RuntimeRpcResponse } from './runtime-rpc-envelope'
|
|
import { getCleanupRequest, getSubscriptionId } from './remote-runtime-shared-control-protocol'
|
|
import {
|
|
finishSharedControlSubscription,
|
|
handleSharedControlSubscriptionResponse
|
|
} from './remote-runtime-shared-control-state'
|
|
import type {
|
|
SharedControlLogicalSubscription,
|
|
SharedControlSubscriptionCallbacks
|
|
} from './remote-runtime-shared-control-types'
|
|
|
|
export function createSharedControlSubscription<TResult>(args: {
|
|
requestId: string
|
|
method: string
|
|
params: unknown
|
|
retainedParamsBytes: number
|
|
callbacks: SharedControlSubscriptionCallbacks<TResult>
|
|
}): SharedControlLogicalSubscription<TResult> {
|
|
return {
|
|
requestId: args.requestId,
|
|
method: args.method,
|
|
params: args.params,
|
|
retainedParamsBytes: args.retainedParamsBytes,
|
|
callbacks: args.callbacks,
|
|
sent: false,
|
|
closed: false,
|
|
closeAfterReady: false,
|
|
remoteSubscriptionId: null
|
|
}
|
|
}
|
|
|
|
export function handleSharedControlLogicalResponse(args: {
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
subscription: SharedControlLogicalSubscription<unknown>
|
|
response: RuntimeRpcResponse<unknown>
|
|
request: (method: string, params: unknown) => void
|
|
}): void {
|
|
if (!args.subscription.closeAfterReady) {
|
|
handleSharedControlSubscriptionResponse(args.subscriptions, args.subscription, args.response)
|
|
return
|
|
}
|
|
if (args.response.ok) {
|
|
const subscriptionId = getSubscriptionId(args.response.result)
|
|
if (subscriptionId) {
|
|
args.subscription.remoteSubscriptionId = subscriptionId
|
|
}
|
|
const cleanup = getCleanupRequest(args.subscription)
|
|
if (cleanup) {
|
|
args.request(cleanup.method, cleanup.params)
|
|
}
|
|
}
|
|
finishSharedControlSubscription(args.subscriptions, args.subscription, false)
|
|
}
|
|
|
|
export function closeSharedControlLogicalSubscription(args: {
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
subscription?: SharedControlLogicalSubscription<unknown>
|
|
request: (method: string, params: unknown) => void
|
|
}): void {
|
|
if (!args.subscription) {
|
|
return
|
|
}
|
|
const cleanup = getCleanupRequest(args.subscription)
|
|
if (cleanup) {
|
|
finishSharedControlSubscription(args.subscriptions, args.subscription, false)
|
|
args.request(cleanup.method, cleanup.params)
|
|
return
|
|
}
|
|
if (
|
|
(args.subscription.sent || args.subscription.awaitingResubscribe) &&
|
|
cleanupNeedsRemoteSubscriptionId(args.subscription.method)
|
|
) {
|
|
// Why: id-scoped server subscriptions can only be cleaned up after the
|
|
// server returns its concrete subscription id in the ready response. This
|
|
// also covers the reconnect replay window (sent===false, id cleared) where
|
|
// a resubscribe is in flight — finishing locally there would leak it.
|
|
args.subscription.closeAfterReady = true
|
|
return
|
|
}
|
|
finishSharedControlSubscription(args.subscriptions, args.subscription, false)
|
|
}
|
|
|
|
export function sendSharedControlCleanupRequest(args: {
|
|
deviceToken: string
|
|
method: string
|
|
params: unknown
|
|
send: (payload: unknown) => boolean
|
|
}): string | null {
|
|
// Why: cleanup is best-effort and often runs during teardown; send it
|
|
// synchronously so close() cannot race the async request path.
|
|
const requestId = randomUUID()
|
|
const sent = args.send({
|
|
id: requestId,
|
|
deviceToken: args.deviceToken,
|
|
method: args.method,
|
|
params: args.params
|
|
})
|
|
return sent ? requestId : null
|
|
}
|
|
|
|
export function replaySharedControlSubscriptions(args: {
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
send: (subscription: SharedControlLogicalSubscription<unknown>) => void
|
|
// Why: true only for a reconnect of a previously-ready connection; first
|
|
// connects deliver their initial snapshot through the normal gated path.
|
|
tagReplayedResponses?: boolean
|
|
}): void {
|
|
for (const subscription of args.subscriptions.values()) {
|
|
if (subscription.closeAfterReady) {
|
|
continue
|
|
}
|
|
subscription.sent = false
|
|
subscription.remoteSubscriptionId = null
|
|
// Why: mark the id-less window so a close() racing this resubscribe defers
|
|
// to closeAfterReady instead of finishing locally and leaking the server
|
|
// subscription the resubscribe is about to create.
|
|
subscription.awaitingResubscribe = true
|
|
if (args.tagReplayedResponses) {
|
|
subscription.pendingReplayTag = true
|
|
}
|
|
args.send(subscription)
|
|
}
|
|
}
|
|
|
|
export function finishCloseAfterReadySubscriptions(
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
): void {
|
|
for (const subscription of Array.from(subscriptions.values())) {
|
|
if (subscription.closeAfterReady) {
|
|
finishSharedControlSubscription(subscriptions, subscription, false)
|
|
}
|
|
}
|
|
}
|
|
|
|
function cleanupNeedsRemoteSubscriptionId(method: string): boolean {
|
|
return (
|
|
method === 'accounts.subscribe' ||
|
|
method === 'notifications.subscribe' ||
|
|
method === 'runtime.clientEvents.subscribe' ||
|
|
method === 'files.watch'
|
|
)
|
|
}
|