perf(pi): skip rewriting current managed extensions on every terminal spawn (#38481)

Each local terminal spawn with a Pi agent home rewrote three Orca-owned
extension files (~54 KB) synchronously on the main thread even when their
contents were already current. Compare the read we already do for the
ownership check and write only when the content differs.

Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
OrcaWin
2026-11-05 03:04:29 -08:00
committed by GitHub
co-authored by m4air
parent ccacb35bc0
commit 646e2efa27
2 changed files with 25 additions and 9 deletions
@@ -10,7 +10,9 @@ import {
readFileSync,
readdirSync,
rmSync,
statSync,
symlinkSync,
utimesSync,
writeFileSync
} from 'node:fs'
import { tmpdir } from 'node:os'
@@ -512,6 +514,19 @@ describe('PiTitlebarExtensionService', () => {
)
})
it('leaves current Orca-owned extensions untouched on later spawns', () => {
const svc = new PiTitlebarExtensionService()
svc.buildPtyEnv('pty-current-1', piHome, 'pi')
const installed = ['orca-titlebar-spinner.ts', 'orca-prefill.ts', 'orca-agent-status.ts'].map(
(name) => join(piHome, 'extensions', name)
)
installed.forEach((path) => utimesSync(path, 0, 0))
svc.buildPtyEnv('pty-current-2', piHome, 'pi')
expect(installed.map((path) => statSync(path).mtimeMs)).toEqual([0, 0, 0])
})
it("does not overwrite a user's same-named Orca extension file", () => {
const userStatusExtension = 'user-owned status extension'
writeFileSync(join(piHome, 'extensions', 'orca-agent-status.ts'), userStatusExtension, 'utf-8')
+10 -9
View File
@@ -87,16 +87,17 @@ export class PiTitlebarExtensionService {
safeRemoveOverlay(overlayDir, this.getOverlayRoot(kind))
}
private canOverwriteManagedExtension(path: string): boolean {
try {
return readFileSync(path, 'utf8').includes(ORCA_MANAGED_EXTENSION_MARKER)
} catch {
return true
}
}
private writeManagedExtension(path: string, source: string): ManagedExtensionWriteResult {
if (existsSync(path) && !this.canOverwriteManagedExtension(path)) {
let installed: string | undefined
try {
installed = readFileSync(path, 'utf8')
} catch {
installed = undefined
}
if (installed === source) {
return 'written'
}
if (installed !== undefined && !installed.includes(ORCA_MANAGED_EXTENSION_MARKER)) {
return 'skipped-user-owned'
}