mirror of
https://github.com/stablyai/orca.git
synced 2026-10-07 00:02:29 +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.
231 lines
9.0 KiB
JavaScript
231 lines
9.0 KiB
JavaScript
import { execFileSync } from 'node:child_process'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import process from 'node:process'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
// Ratchet gate for the `@ts-nocheck` directive.
|
|
//
|
|
// TypeScript only honours `@ts-nocheck` in a comment before the first statement, and
|
|
// once present it disables type checking for the ENTIRE file. PR #17605 split a single
|
|
// 43,928-line class into ~172 modules whose linear mixin-inheritance chain cannot yet
|
|
// express forward references, so each carries a grandfathered `@ts-nocheck` header. This
|
|
// check freezes that set (the baseline) and fails CI when a NEW file adds the directive —
|
|
// the existing files are grandfathered; new ones must fix their types instead. The
|
|
// baseline may only shrink.
|
|
|
|
const BASELINE_PATH = 'config/ts-nocheck-baseline.txt'
|
|
// These two files legitimately contain the directive text as data (regex, fixtures),
|
|
// so scanning them would self-flag. The ratchet does not police itself.
|
|
const SELF_FILES = new Set([
|
|
'config/scripts/check-ts-nocheck-ratchet.mjs',
|
|
'config/scripts/check-ts-nocheck-ratchet.test.mjs'
|
|
])
|
|
|
|
// True if `@ts-nocheck` appears in a comment before the first statement, matching the
|
|
// TypeScript rule. Limitation: only the leading run of blank lines / line comments /
|
|
// block comments at the top of the file is scanned, so a directive-looking string deeper
|
|
// in a block comment that itself starts at the top is still checked — but anything after
|
|
// real code (or inside a string literal, which never opens the leading comment run) is not.
|
|
export function hasTsNoCheck(sourceText) {
|
|
let i = 0
|
|
const n = sourceText.length
|
|
while (i < n) {
|
|
const rest = sourceText.slice(i)
|
|
const blank = /^[ \t]*\r?\n/.exec(rest)
|
|
if (blank) {
|
|
i += blank[0].length
|
|
continue
|
|
}
|
|
if (rest.startsWith('//')) {
|
|
const end = sourceText.indexOf('\n', i)
|
|
const line = end === -1 ? sourceText.slice(i) : sourceText.slice(i, end)
|
|
if (/^\/\/\s*@ts-nocheck\b/.test(line)) {
|
|
return true
|
|
}
|
|
i = end === -1 ? n : end + 1
|
|
continue
|
|
}
|
|
if (rest.startsWith('/*')) {
|
|
const end = sourceText.indexOf('*/', i + 2)
|
|
const block = end === -1 ? sourceText.slice(i) : sourceText.slice(i, end + 2)
|
|
if (/^\/\*\s*@ts-nocheck\b/.test(block)) {
|
|
return true
|
|
}
|
|
i = end === -1 ? n : end + 2
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function parseBaseline(text) {
|
|
return new Set(
|
|
text
|
|
.split('\n')
|
|
.map((l) => l.trim())
|
|
.filter((l) => l && !l.startsWith('#'))
|
|
)
|
|
}
|
|
|
|
export function diffBaseline(current, baseline) {
|
|
const cur = new Set(current)
|
|
const base = baseline instanceof Set ? baseline : new Set(baseline)
|
|
const added = [...cur].filter((e) => !base.has(e)).sort()
|
|
const stale = [...base].filter((e) => !cur.has(e)).sort()
|
|
return { added, stale }
|
|
}
|
|
|
|
// Collect every currently tracked file that carries a `@ts-nocheck` header.
|
|
export function collectCurrentTsNoCheckFiles(root = process.cwd()) {
|
|
const tracked = execFileSync('git', ['ls-files', '*.ts', '*.tsx', '*.mts', '*.cts'], {
|
|
cwd: root,
|
|
encoding: 'utf8',
|
|
maxBuffer: 64 * 1024 * 1024
|
|
})
|
|
.split('\n')
|
|
.filter(Boolean)
|
|
.filter((f) => !SELF_FILES.has(f))
|
|
|
|
const entries = []
|
|
for (const rel of tracked) {
|
|
let src
|
|
try {
|
|
src = fs.readFileSync(path.join(root, rel), 'utf8')
|
|
} catch {
|
|
continue
|
|
}
|
|
if (hasTsNoCheck(src)) {
|
|
entries.push(rel)
|
|
}
|
|
}
|
|
|
|
return entries.sort()
|
|
}
|
|
|
|
function printAddedFailure(added) {
|
|
for (const entry of added) {
|
|
console.error(`::error::New @ts-nocheck not allowed: ${entry}`)
|
|
}
|
|
console.error('')
|
|
console.error('╭────────────────────────────────────────────────────────────────────────────╮')
|
|
console.error('│ ❌ ts-nocheck ratchet failed — a NEW file adds a @ts-nocheck directive. │')
|
|
console.error('╰────────────────────────────────────────────────────────────────────────────╯')
|
|
console.error('')
|
|
console.error(` ${added.length} file(s) newly add a \`@ts-nocheck\` header:`)
|
|
console.error('')
|
|
for (const entry of added) {
|
|
console.error(` • ${entry}`)
|
|
}
|
|
console.error('')
|
|
console.error(' `@ts-nocheck` disables ALL type checking for the whole file, not just one line.')
|
|
console.error(
|
|
' The grandfathered entries exist only because the split runtime mixin chain cannot'
|
|
)
|
|
console.error(' express forward references yet — that is not a general license to suppress.')
|
|
console.error('')
|
|
console.error(' ✅ Fix it: fix the types instead of suppressing the whole file.')
|
|
console.error('')
|
|
console.error(' (If you are intentionally, with reviewer sign-off, adding an unavoidable')
|
|
console.error(` exception, add the exact line(s) above to ${BASELINE_PATH}.)`)
|
|
console.error('')
|
|
}
|
|
|
|
function printStaleFailure(stale) {
|
|
for (const entry of stale) {
|
|
console.error(`::error::Stale ts-nocheck baseline entry (prune it): ${entry}`)
|
|
}
|
|
console.error('')
|
|
console.error('╭────────────────────────────────────────────────────────────────────────────╮')
|
|
console.error('│ ⚠️ ts-nocheck baseline is out of date — nice work removing a suppression! │')
|
|
console.error('╰────────────────────────────────────────────────────────────────────────────╯')
|
|
console.error('')
|
|
console.error(` ${stale.length} baseline entr(y/ies) no longer have a @ts-nocheck directive.`)
|
|
console.error(
|
|
' The baseline may only shrink, so these must be removed to keep re-adding blocked:'
|
|
)
|
|
console.error('')
|
|
for (const entry of stale) {
|
|
console.error(` • ${entry}`)
|
|
}
|
|
console.error('')
|
|
console.error(` ✅ Fix it (one command): pnpm check:ts-nocheck-ratchet --prune`)
|
|
console.error('')
|
|
}
|
|
|
|
export function main(root = process.cwd()) {
|
|
const baselineFile = path.join(root, BASELINE_PATH)
|
|
if (!fs.existsSync(baselineFile)) {
|
|
console.error(
|
|
`::error::Missing ${BASELINE_PATH}. Generate it with: node config/scripts/check-ts-nocheck-ratchet.mjs --init`
|
|
)
|
|
return 1
|
|
}
|
|
const baseline = parseBaseline(fs.readFileSync(baselineFile, 'utf8'))
|
|
const current = collectCurrentTsNoCheckFiles(root)
|
|
const { added, stale } = diffBaseline(current, baseline)
|
|
|
|
if (added.length > 0) {
|
|
printAddedFailure(added)
|
|
if (stale.length > 0) {
|
|
console.error(
|
|
` (Also: ${stale.length} stale baseline entr(y/ies) can be pruned — see below.)`
|
|
)
|
|
printStaleFailure(stale)
|
|
}
|
|
return 1
|
|
}
|
|
if (stale.length > 0) {
|
|
printStaleFailure(stale)
|
|
return 1
|
|
}
|
|
console.log(
|
|
`ts-nocheck ratchet OK — ${current.length} grandfathered file(s), no new suppressions.`
|
|
)
|
|
return 0
|
|
}
|
|
|
|
function writeBaseline(root, entries) {
|
|
const header = [
|
|
'# Files currently allowed to carry a `@ts-nocheck` header.',
|
|
'# This is a RATCHET: the list may only SHRINK. These exist only because the split',
|
|
'# runtime mixin chain cannot express forward references yet — do NOT add entries to',
|
|
'# get CI green; fix the types instead.',
|
|
'# Regenerate/prune: pnpm check:ts-nocheck-ratchet --prune (removes stale entries only)',
|
|
''
|
|
].join('\n')
|
|
fs.writeFileSync(path.join(root, BASELINE_PATH), `${header}${entries.join('\n')}\n`)
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const root = process.cwd()
|
|
const arg = process.argv[2]
|
|
if (arg === '--init') {
|
|
// One-time bootstrap: capture the current @ts-nocheck set as the baseline.
|
|
const entries = collectCurrentTsNoCheckFiles(root)
|
|
writeBaseline(root, entries)
|
|
console.log(`Wrote ${BASELINE_PATH} with ${entries.length} entries.`)
|
|
process.exit(0)
|
|
}
|
|
if (arg === '--prune') {
|
|
// Remove baseline entries whose @ts-nocheck is gone (shrink only; never adds).
|
|
const current = new Set(collectCurrentTsNoCheckFiles(root))
|
|
const baseline = parseBaseline(fs.readFileSync(path.join(root, BASELINE_PATH), 'utf8'))
|
|
const kept = [...baseline].filter((e) => current.has(e)).sort()
|
|
const newlyAdded = [...current].filter((e) => !baseline.has(e))
|
|
writeBaseline(root, kept)
|
|
console.log(
|
|
`Pruned baseline to ${kept.length} entries (removed ${baseline.size - kept.length}).`
|
|
)
|
|
if (newlyAdded.length > 0) {
|
|
console.error(
|
|
`::error::--prune does not add entries; ${newlyAdded.length} new suppression(s) remain — fix those files' types.`
|
|
)
|
|
process.exit(1)
|
|
}
|
|
process.exit(0)
|
|
}
|
|
process.exit(main(root))
|
|
}
|