mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 02:27:43 +00:00
* refactor(runtime): split OrcaRuntimeService into focused modules
* test(runtime): cover admission tiers and strict worktree reconciliation
* fix(runtime): preserve owner and structured session visibility
* fix(runtime): port post-extraction compatibility fixes
* fix(runtime): preserve skill-share cancellation barrier
* test(runtime): update identity inventory after extraction
* fix(runtime): preserve hook transport environment cleanup
* fix(runtime): consolidate idle probe imports
* test(runtime): retire split file process allowlist entry
* fix(runtime): route child process types through shared boundary
* test(runtime): preserve worktree host metadata precedence
* fix(runtime): update extracted test seams
* fix(runtime): gate the split's ts-nocheck set and restore the stop-confirmed contract
Audit follow-ups for the OrcaRuntimeService split:
- Freeze the 171 @ts-nocheck files behind a ratchet so no new file can disable
type checking. The split's linear mixin chain cannot express forward
references yet, so the existing suppressions are grandfathered; the baseline
may only shrink.
- Drop the stray @ts-nocheck at the end of orca-runtime-get-status.ts. It sat
after the first statement, where TypeScript ignores it, so the module was
already checked.
- Restore `retireRejectedPty(ptyId, stopConfirmed: boolean)` as a required
argument. The split widened it to optional and patched the resulting error
with `stopConfirmed === true`; an omitted argument would have silently taken
the unverified-stop path instead of failing to compile.
- Guard that every orca-runtime-tests fragment is imported by the compatibility
entrypoint. The fragments are .spec.ts, which no Vitest include glob matches,
so one left out of the list would silently stop running.
* fix(runtime): restore four behaviors the OrcaRuntimeService split dropped
Audit findings against the refactor's true base (ad5ba2572e):
- retirePtyAgentLaunchAuthority collected pane keys after deleting the
restored-authority receipt instead of before it. collectPaneKeysForPty reads
that receipt, so a receipt-only pane lost its key and never had its agent-hook
compatibility authority retired. on-pty-exit.ts already carried a comment
naming this exact invariant.
- The PTY-exit path kept orchestrationMailboxNotifications.retirePty but lost
the loop that schedules a debounced mail-pointer repoint for the dead pty's
terminal handle and any run bound to its panes. Restores the schedule call
count to 7, matching base.
- subscribeToPtyExit lost isPtyKnownExited's leaf fallback and its
post-registration lifecycle-generation recheck. leavesByPtyId is rebuilt from
the renderer graph independently of ptysById, so a leaf can outlive its pty
record; without the fallback a caller waiting on an already-dead pty never
gets released.
- The chain root declared `[key: string]: unknown`, which base had nowhere. It
leaked through the exported runtime type into every consumer, so any misspelled
member access typechecked as unknown instead of erroring, and it accounted for
957 of the suppressed errors. Removing it costs zero type errors.
* fix(runtime): restore escalation prose and unscoped automation publication
Two more behaviors the split dropped, each with a regression test that fails
against the pre-fix code:
- The worker-exit escalation stopped deriving its title through
buildOrchestrationTaskDisplayMetadata and inlined `task.spec` instead. That
ignored an explicit task_title, dropped the single-line normalization and the
80-character bound, and turned the no-spec case into a quoted, duplicated id.
A multi-paragraph spec landed verbatim in the coordinator's banner. The
existing 11 tests all use short single-line specs, where the derived title and
the raw spec are identical, so none of them could see it.
Also reverts an added `if (!handle) return` guard: the dispatch lookup is
deliberately keyed on the pane as well, because a reminted handle no longer
matches the row while the pane identity outlives the remint.
- updateAutomation stopped going through automationChangePublications and
published `source` unconditionally while gating the fallback on a non-null
destination. A destination the store can no longer name then published only
the stale source, so subscribers scoped elsewhere kept rendering a row that
had left them — the exact case the helper documents. The helper had been left
with zero callers; all three sites use it again.
* fix(skills): stop swallowing lookup errors and hard-erroring on non-ssh hosts
Follow-ups from auditing the skill install path against the refactor's base:
- resolveWorktree wrapped showManagedWorktree in `.catch(() => null)`, so a
transient git or IO failure surfaced to the user as
skill-install-workspace-not-found with the real cause discarded. Errors
propagate again; a genuine id mismatch still returns null.
- resolveSkillSshTarget threw skill-install-workspace-host-unavailable when the
execution host was neither local nor ssh, on both the repo and folder
branches. Base gated these on connectionId, so a runtime-owned repo simply
was not an SSH install and fell through to the local path. Both return null
again, and the error code the split invented is now unreferenced.
- listManagedSkillInstalls awaited the receipt walk and the worktree resolve in
sequence. They are independent and either can hit disk, WSL, or an SSH scan,
so Promise.all is restored.
Deliberately unchanged: resolving the worktree through listResolvedWorktrees
rather than showManagedWorktree, which disambiguates a worktree id colliding
across hosts and is covered by its own test, and the SSH-folder
skill-install-ssh-dispatch-required throw, which matches the repo branch.
* fix(runtime): merge duplicate worktree-logic imports
The #17448 port added a third import from ../ipc/worktree-logic, which the
code-quality oxlint config rejects under --deny-warnings. Plain oxlint does not
flag it, so it only surfaced in CI's static analysis job.
* ci: run the ts-nocheck ratchet in PR checks
pr-workflow-lint-parity requires every leaf command in `pnpm lint` to have a
matching step in pr.yml. The ratchet was wired into lint but not the workflow,
so PR CI would not have enforced it.
* Merge remote-tracking branch 'origin/main' and retry the paired-host launch evaluate
main advanced 9 commits; none touch the orca-runtime.ts this branch splits, so
nothing needed porting.
CI failed twice on `Execution context was destroyed` thrown from
headless-paired-runtime-host's first `evaluate` after launch — a different spec
each run, which is the signature of the flake #17780 describes rather than a
regression. That commit added retryTransientMainEvaluate and adopted it in five
helpers but not this call site, even though its docblock names exactly this
case: the first evaluate after electron.launch() resolves, before the app is
ready. Wrapped it the same way.
191 lines
7.9 KiB
TypeScript
191 lines
7.9 KiB
TypeScript
// @ts-nocheck -- mechanically split class members.
|
|
import { RuntimeBrowserCommandsWithBrowserProfileImportFromBrowser } from './runtime-browser-commands-browser-profile-import-from-browser'
|
|
import { closeRuntimeBrowserClientPage } from './runtime-browser-client-page-creation'
|
|
import { BrowserError } from '../browser/browser-error'
|
|
import { randomUUID } from 'node:crypto'
|
|
import { ipcMain } from 'electron'
|
|
import type { BrowserTabListResult } from '../../shared/runtime-types'
|
|
import { browserManager } from '../browser/browser-manager'
|
|
import { browserSessionRegistry } from '../browser/browser-session-registry'
|
|
|
|
export class RuntimeBrowserCommandsWithBrowserTabClose extends RuntimeBrowserCommandsWithBrowserProfileImportFromBrowser {
|
|
async browserTabClose(params: {
|
|
index?: number
|
|
page?: string
|
|
worktree?: string
|
|
}): Promise<{ closed: boolean }> {
|
|
const pages = this.host.getRuntimeBrowserPageRegistry()
|
|
let clientPage = params.page ? pages.getPage(params.page) : undefined
|
|
if (clientPage) {
|
|
await this.assertClientPageWorkspace(clientPage, params.worktree)
|
|
} else if (!params.page) {
|
|
const workspaceId = params.worktree
|
|
? (await this.host.resolveBrowserWorkspace(params.worktree)).id
|
|
: undefined
|
|
if (pages.listPages(workspaceId).length > 0) {
|
|
const tab =
|
|
params.index !== undefined
|
|
? (await this.browserTabList({ worktree: params.worktree })).tabs[params.index]
|
|
: (await this.browserTabCurrent({ worktree: params.worktree })).tab
|
|
clientPage = tab ? pages.getPage(tab.browserPageId) : undefined
|
|
}
|
|
}
|
|
if (clientPage) {
|
|
const authority = this.host.getBrowserHostLeaseRegistry()
|
|
// Why: a retained page whose host quit has no placement left to command, and asking the
|
|
// absent host first would refuse the close and strand the tab with no way to dismiss it.
|
|
if (authority.getPlacement(clientPage.browserPageId)) {
|
|
await closeRuntimeBrowserClientPage(authority, {
|
|
browserPageId: clientPage.browserPageId,
|
|
placement: clientPage.placement
|
|
})
|
|
}
|
|
if (!pages.retirePage(clientPage.browserPageId, clientPage.placement)) {
|
|
throw new Error('browser_page_placement_stale')
|
|
}
|
|
if (this.host.retireRuntimeOwnedBrowserSessionTab) {
|
|
this.host.retireRuntimeOwnedBrowserSessionTab(
|
|
clientPage.workspaceId,
|
|
clientPage.browserPageId
|
|
)
|
|
} else {
|
|
this.host.notifyHeadlessBrowserSessionTabsChanged?.(clientPage.workspaceId)
|
|
}
|
|
return { closed: true }
|
|
}
|
|
const namedPageId =
|
|
typeof params.page === 'string' && params.page.length > 0 ? params.page : null
|
|
const explicitPage = namedPageId !== null
|
|
const bridge = this.host.getAgentBrowserBridge()
|
|
if (!bridge) {
|
|
// Why before the refusal: a runtime with no browser session cannot be holding this page
|
|
// either, but it can still be carrying the session row that names it.
|
|
if (
|
|
namedPageId &&
|
|
params.worktree &&
|
|
this.retireGhostBrowserSessionRow(
|
|
(await this.host.resolveWorktreeSelector(params.worktree)).id,
|
|
namedPageId
|
|
)
|
|
) {
|
|
return { closed: true }
|
|
}
|
|
throw new BrowserError('browser_no_tab', 'No browser session is active')
|
|
}
|
|
const worktreeId = explicitPage
|
|
? params.worktree
|
|
? (await this.host.resolveWorktreeSelector(params.worktree)).id
|
|
: undefined
|
|
: await this.resolveBrowserWorktreeId(params.worktree)
|
|
|
|
let tabId: string | null = null
|
|
if (namedPageId !== null) {
|
|
tabId = namedPageId
|
|
} else if (params.index !== undefined) {
|
|
const tabs = bridge.getRegisteredTabs(worktreeId)
|
|
const entries = [...tabs.entries()]
|
|
if (params.index < 0 || params.index >= entries.length) {
|
|
throw new Error(`Tab index ${params.index} out of range (0-${entries.length - 1})`)
|
|
}
|
|
tabId = entries[params.index][0]
|
|
} else {
|
|
// Why: try the bridge first; fall back to the renderer for tabs whose webview hasn't mounted yet (e.g. just created).
|
|
const tabs = bridge.getRegisteredTabs(worktreeId)
|
|
const entries = [...tabs.entries()]
|
|
const activeEntry = entries.find(([, wcId]) => wcId === bridge.getActiveWebContentsId())
|
|
if (activeEntry) {
|
|
tabId = activeEntry[0]
|
|
}
|
|
}
|
|
|
|
// Why: headless serve has no renderer to ask, so destroy the offscreen page directly.
|
|
const authoritativeWindow = this.host.getAvailableAuthoritativeWindow()
|
|
const offscreen = authoritativeWindow ? null : this.host.getOffscreenBrowserBackend()
|
|
if (offscreen) {
|
|
// Why: resolve the active page for implicit close so we don't report success while closing nothing.
|
|
const resolvedTabId = tabId ?? bridge.getActivePageId(worktreeId)
|
|
if (!resolvedTabId) {
|
|
return { closed: false }
|
|
}
|
|
if (explicitPage && !bridge.getRegisteredTabs(worktreeId).has(resolvedTabId)) {
|
|
if (this.retireGhostBrowserSessionRow(worktreeId, resolvedTabId)) {
|
|
return { closed: true }
|
|
}
|
|
const scope = worktreeId ? ' in this worktree' : ''
|
|
throw new BrowserError(
|
|
'browser_tab_not_found',
|
|
`Browser page ${resolvedTabId} was not found${scope}`
|
|
)
|
|
}
|
|
await offscreen.closeTab(resolvedTabId)
|
|
// Why: closeTab only destroys the guest; without retirement, paired clients keep a
|
|
// dead session tab until an unrelated republish (closeMobileSessionTab already retires).
|
|
if (worktreeId) {
|
|
if (this.host.retireRuntimeOwnedBrowserSessionTab) {
|
|
this.host.retireRuntimeOwnedBrowserSessionTab(worktreeId, resolvedTabId)
|
|
} else {
|
|
this.host.notifyHeadlessBrowserSessionTabsChanged?.(worktreeId)
|
|
}
|
|
}
|
|
return { closed: true }
|
|
}
|
|
|
|
if (!authoritativeWindow && tabId && !bridge.getRegisteredTabs(worktreeId).has(tabId)) {
|
|
if (this.retireGhostBrowserSessionRow(worktreeId, tabId)) {
|
|
return { closed: true }
|
|
}
|
|
const scope = worktreeId ? ' in this worktree' : ''
|
|
throw new BrowserError('browser_tab_not_found', `Browser page ${tabId} was not found${scope}`)
|
|
}
|
|
|
|
const win = authoritativeWindow ?? this.host.getAuthoritativeWindow()
|
|
const requestId = randomUUID()
|
|
await new Promise<void>((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
ipcMain.removeListener('browser:tabCloseReply', handler)
|
|
reject(new Error('Tab close timed out'))
|
|
}, 10_000)
|
|
|
|
const handler = (
|
|
_event: Electron.IpcMainEvent,
|
|
reply: { requestId: string; error?: string; code?: 'browser_tab_not_found' }
|
|
): void => {
|
|
if (reply.requestId !== requestId) {
|
|
return
|
|
}
|
|
clearTimeout(timer)
|
|
ipcMain.removeListener('browser:tabCloseReply', handler)
|
|
if (reply.error) {
|
|
reject(
|
|
reply.code === 'browser_tab_not_found'
|
|
? new BrowserError('browser_tab_not_found', reply.error)
|
|
: new Error(reply.error)
|
|
)
|
|
} else {
|
|
resolve()
|
|
}
|
|
}
|
|
ipcMain.on('browser:tabCloseReply', handler)
|
|
// Why: pass worktreeId so the renderer scopes the close correctly instead of falling back to the globally active tab in the wrong worktree.
|
|
win.webContents.send('browser:requestTabClose', { requestId, tabId, worktreeId })
|
|
})
|
|
|
|
return { closed: true }
|
|
}
|
|
|
|
protected enrichBrowserTabInfo(
|
|
tab: BrowserTabListResult['tabs'][number]
|
|
): BrowserTabListResult['tabs'][number] {
|
|
const rawProfileId = browserManager.getSessionProfileIdForTab(tab.browserPageId)
|
|
const profile =
|
|
browserSessionRegistry.getProfile(rawProfileId ?? 'default') ??
|
|
browserSessionRegistry.getDefaultProfile()
|
|
return {
|
|
...tab,
|
|
worktreeId: browserManager.getWorktreeIdForTab(tab.browserPageId) ?? null,
|
|
profileId: profile.id,
|
|
profileLabel: profile.label
|
|
}
|
|
}
|
|
}
|