Skip to content

The agent that grows with you

fix(desktop): identify unsafe update blockers

Ryan Hartc32dd7580a25
diff --git a/apps/desktop/src/app/updates-overlay.blockers.test.tsx b/apps/desktop/src/app/updates-overlay.blockers.test.tsx
index edf2a11910f..de475664710 100644
--- a/apps/desktop/src/app/updates-overlay.blockers.test.tsx
+++ b/apps/desktop/src/app/updates-overlay.blockers.test.tsx
@@ -2,9 +2,17 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { Dialog, DialogContent } from '@/components/ui/dialog'
+import type { DesktopUpdateStatus } from '@/global'
import { I18nProvider } from '@/i18n/context'
+import {
+ $updateApply,
+ $updateOverlayOpen,
+ $updateOverlayTarget,
+ $updateStatus,
+ resetUpdateApplyState
+} from '@/store/updates'
-import { BlockerView } from './updates-overlay'
+import { BlockerView, formatBlockerCommandLine, UpdatesOverlay } from './updates-overlay'
async function renderWithI18n(ui: React.ReactNode) {
await act(async () => {
@@ -18,8 +26,160 @@ async function renderWithI18n(ui: React.ReactNode) {
})
}
+async function renderUpdatesOverlay() {
+ await act(async () => {
+ render(
+ <I18nProvider configClient={{ getConfig: async () => ({}), saveConfig: async () => ({ ok: true }) }}>
+ <UpdatesOverlay />
+ </I18nProvider>
+ )
+ })
+}
+
+describe('formatBlockerCommandLine', () => {
+ it('redacts the full ambiguous tail after a sensitive CLI, environment, or header marker', () => {
+ const secretParts = ['first-part', 'second-part']
+ const secret = secretParts.join(' ')
+
+ const commands = [
+ `python.exe watcher.py --token ${secret} --mode inspect`,
+ ['python.exe watcher.py --password="', secret, '" --mode inspect'].join(''),
+ `AUTH_TOKEN=${secret} python.exe watcher.py --mode inspect`,
+ `python.exe watcher.py Authorization: Bearer ${secret} --mode inspect`
+ ]
+
+ for (const commandLine of commands) {
+ const formatted = formatBlockerCommandLine(commandLine)
+
+ expect(formatted).not.toContain(secretParts[0])
+ expect(formatted).not.toContain(secretParts[1])
+ expect(formatted).not.toContain('--mode inspect')
+ expect(formatted.endsWith('[REDACTED]')).toBe(true)
+ }
+ })
+
+ it('redacts a sensitive query value and bounds the remaining diagnostic output', () => {
+ const queryValue = ['private', 'value'].join('-')
+
+ const commandLine =
+ `python.exe watcher.py https://example.test/?api_key=${queryValue}&mode=inspect ` + 'x'.repeat(600)
+
+ const formatted = formatBlockerCommandLine(commandLine)
+
+ expect(formatted).not.toContain(queryValue)
+ expect(formatted).toContain('api_key=[REDACTED]&mode=inspect')
+ expect(Array.from(formatted).length).toBeLessThanOrEqual(500)
+ expect(formatted.endsWith('…')).toBe(true)
+ })
+})
+
describe('BlockerView', () => {
- afterEach(cleanup)
+ afterEach(() => {
+ cleanup()
+ $updateOverlayOpen.set(false)
+ $updateOverlayTarget.set('client')
+ $updateStatus.set(null)
+ resetUpdateApplyState()
+ })
+
+ it('uses the blocker view for a foreign process instead of the generic update error', async () => {
+ $updateOverlayTarget.set('client')
+ $updateOverlayOpen.set(true)
+ $updateStatus.set({
+ supported: true,
+ updateAvailable: true,
+ behind: 1,
+ commits: []
+ } as DesktopUpdateStatus)
+ $updateApply.set({
+ applying: false,
+ stage: 'error',
+ message: 'Update aborted: another Hermes process is using this installation.',
+ percent: null,
+ error: 'venv-blocked',
+ command: null,
+ blockers: [
+ {
+ pid: 58636,
+ name: 'python.exe',
+ cmdline: 'python.exe fenbi_session_refresh.py',
+ kind: 'other',
+ safeToStop: false
+ }
+ ],
+ log: []
+ })
+
+ await renderUpdatesOverlay()
+
+ expect(screen.getByText('Close other processes to update Hermes')).toBeTruthy()
+ expect(screen.getByText('python.exe')).toBeTruthy()
+ expect(screen.queryByText('Update didn’t finish')).toBeNull()
+ })
+
+ it('identifies foreign blockers without offering automatic termination', async () => {
+ const onStopAndUpdate = vi.fn()
+
+ await renderWithI18n(
+ <BlockerView
+ blockers={[
+ {
+ pid: 58636,
+ name: 'python.exe',
+ cmdline: 'python.exe fenbi_session_refresh.py',
+ kind: 'other',
+ safeToStop: false
+ }
+ ]}
+ onDismiss={() => {}}
+ onStopAndUpdate={onStopAndUpdate}
+ />
+ )
+
+ expect(screen.getByText('Close other processes to update Hermes')).toBeTruthy()
+ expect(screen.getByText('python.exe')).toBeTruthy()
+ expect(screen.getByText('PID 58636')).toBeTruthy()
+ expect(screen.getByText(/can’t safely close these processes automatically/i)).toBeTruthy()
+ expect(screen.getByText(/python.exe fenbi_session_refresh\.py/i)).toBeTruthy()
+ expect(screen.queryByRole('button', { name: /close previews/i })).toBeNull()
+ expect(onStopAndUpdate).not.toHaveBeenCalled()
+ })
+
+ it('keeps mixed blocker cleanup limited to safe previews', async () => {
+ const onStopAndUpdate = vi.fn()
+
+ await renderWithI18n(
+ <BlockerView
+ blockers={[
+ {
+ pid: 47484,
+ name: 'python.exe',
+ cmdline: 'python.exe -m http.server 8766',
+ kind: 'local-preview',
+ safeToStop: true,
+ label: 'Example Preview',
+ port: 8766
+ },
+ {
+ pid: 58636,
+ name: 'python.exe',
+ cmdline: 'python.exe fenbi_session_refresh.py',
+ kind: 'other',
+ safeToStop: false
+ }
+ ]}
+ onDismiss={() => {}}
+ onStopAndUpdate={onStopAndUpdate}
+ />
+ )
+
+ expect(screen.getByText(/can close the local previews listed below/i)).toBeTruthy()
+ expect(screen.getByText('Example Preview')).toBeTruthy()
+ expect(screen.getByText('python.exe')).toBeTruthy()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Close previews and check again' }))
+ expect(onStopAndUpdate).toHaveBeenCalledTimes(1)
+ })
it('explains safe local previews and offers one-click close-and-update', async () => {
const onStopAndUpdate = vi.fn()
diff --git a/apps/desktop/src/app/updates-overlay.tsx b/apps/desktop/src/app/updates-overlay.tsx
index c616c642ad1..b797a4f031a 100644
--- a/apps/desktop/src/app/updates-overlay.tsx
+++ b/apps/desktop/src/app/updates-overlay.tsx
@@ -14,12 +14,7 @@ import {
import { ErrorIcon, ErrorState } from '@/components/ui/error-state'
import { Loader } from '@/components/ui/loader'
import { Progress } from '@/components/ui/progress'
-import type {
- DesktopUpdateBlocker,
- DesktopUpdateCommit,
- DesktopUpdateStage,
- DesktopUpdateStatus
-} from '@/global'
+import type { DesktopUpdateBlocker, DesktopUpdateCommit, DesktopUpdateStage, DesktopUpdateStatus } from '@/global'
import { useI18n } from '@/i18n'
import { buildCommitChangelog, type CommitGroup } from '@/lib/commit-changelog'
import { AlertCircle, Check, Copy, Terminal } from '@/lib/icons'
@@ -85,13 +80,7 @@ export function UpdatesOverlay() {
? 'error'
: 'idle'
- const safeBlockers =
- !isBackend &&
- apply.error === 'venv-blocked' &&
- apply.blockers?.length &&
- apply.blockers.every(blocker => blocker.kind === 'local-preview' && blocker.safeToStop)
- ? apply.blockers
- : null
+ const updateBlockers = !isBackend && apply.error === 'venv-blocked' && apply.blockers?.length ? apply.blockers : null
const handleClose = (next: boolean) => {
if (phase === 'applying') {
@@ -130,15 +119,15 @@ export function UpdatesOverlay() {
{phase === 'guiSkew' && <GuiSkewView message={apply.message} onDone={() => handleClose(false)} />}
- {phase === 'error' && safeBlockers ? (
+ {phase === 'error' && updateBlockers ? (
<BlockerView
- blockers={safeBlockers}
+ blockers={updateBlockers}
onDismiss={() => handleClose(false)}
onStopAndUpdate={() => void applyUpdates({ stopSafeBlockers: true })}
/>
) : null}
- {phase === 'error' && !safeBlockers ? (
+ {phase === 'error' && !updateBlockers ? (
<ErrorView message={apply.message} onDismiss={() => handleClose(false)} onRetry={handleInstall} />
) : null}
@@ -441,6 +430,30 @@ function ApplyingView({ apply, isBackend }: { apply: UpdateApplyState; isBackend
)
}
+const BLOCKER_COMMAND_LINE_LIMIT = 500
+
+const SENSITIVE_ARGUMENT_NAME =
+ '(?:api[-_]?key|access[-_]?token|refresh[-_]?token|auth[-_]?token|x[-_]?plex[-_]?token|token|password|passwd|client[-_]?secret|secret|authorization)'
+
+const SENSITIVE_COMMAND_TAIL = new RegExp(
+ `((?:^|\\s)(?:(?:--?)${SENSITIVE_ARGUMENT_NAME}(?:\\s*=\\s*|\\s+)|${SENSITIVE_ARGUMENT_NAME}\\s*(?:=|:)\\s*)).*$`,
+ 'i'
+)
+
+const SENSITIVE_QUERY_ARGUMENT = new RegExp(`([?&]${SENSITIVE_ARGUMENT_NAME}=)[^&#\\s]+`, 'gi')
+
+export function formatBlockerCommandLine(commandLine: string): string {
+ const redacted = commandLine
+ .replace(SENSITIVE_QUERY_ARGUMENT, '$1[REDACTED]')
+ .replace(SENSITIVE_COMMAND_TAIL, '$1[REDACTED]')
+
+ const characters = Array.from(redacted)
+
+ return characters.length > BLOCKER_COMMAND_LINE_LIMIT
+ ? `${characters.slice(0, BLOCKER_COMMAND_LINE_LIMIT - 1).join('')}…`
+ : redacted
+}
+
export function BlockerView({
blockers,
onDismiss,
@@ -453,25 +466,43 @@ export function BlockerView({
const { t } = useI18n()
const u = t.updates
+ const safeBlockers = blockers.filter(blocker => blocker.kind === 'local-preview' && blocker.safeToStop)
+ const hasForeignBlockers = safeBlockers.length !== blockers.length
+ const title = hasForeignBlockers ? u.foreignBlockerTitle : u.blockerTitle
+
+ const body = hasForeignBlockers
+ ? safeBlockers.length > 0
+ ? u.mixedBlockerBody
+ : u.foreignBlockerBody
+ : u.blockerBody
+
return (
<div className="grid gap-5 px-6 pb-6 pt-7 pr-8">
<div className="flex flex-col items-center gap-3 text-center">
<div className="grid size-12 place-items-center rounded-full bg-warning/15 text-warning">
<AlertCircle aria-hidden className="size-6" />
</div>
- <DialogTitle className="text-center text-xl font-semibold tracking-tight">{u.blockerTitle}</DialogTitle>
+ <DialogTitle className="text-center text-xl font-semibold tracking-tight">{title}</DialogTitle>
<DialogDescription className="max-w-prose text-center text-sm leading-5 text-muted-foreground">
- {u.blockerBody}
+ {body}
</DialogDescription>
</div>
<div className="grid gap-2">
- {blockers.map(blocker => (
- <div className="rounded-lg border border-border/70 bg-muted/35 px-3 py-2.5" key={blocker.pid}>
- <div className="text-sm font-medium">{blocker.label || u.localPreview}</div>
- {blocker.port ? <div className="text-xs text-muted-foreground">{u.portLabel(blocker.port)}</div> : null}
- </div>
- ))}
+ {blockers.map(blocker => {
+ const isSafePreview = blocker.kind === 'local-preview' && blocker.safeToStop
+
+ return (
+ <div className="rounded-lg border border-border/70 bg-muted/35 px-3 py-2.5" key={blocker.pid}>
+ <div className="text-sm font-medium">
+ {isSafePreview ? blocker.label || u.localPreview : blocker.name}
+ </div>
+ <div className="text-xs text-muted-foreground">
+ {isSafePreview && blocker.port ? u.portLabel(blocker.port) : u.pidLabel(blocker.pid)}
+ </div>
+ </div>
+ )
+ })}
</div>
<details className="rounded-md border border-border/60 px-3 py-2 text-xs text-muted-foreground">
@@ -479,16 +510,18 @@ export function BlockerView({
<div className="mt-2 grid gap-2 font-mono text-[11px] leading-4">
{blockers.map(blocker => (
<div className="break-all" key={blocker.pid}>
- PID {blocker.pid} · {blocker.cmdline}
+ PID {blocker.pid} · {formatBlockerCommandLine(blocker.cmdline)}
</div>
))}
</div>
</details>
<div className="grid gap-1">
- <Button className="font-semibold" onClick={onStopAndUpdate} size="lg">
- {u.closePreviewsAndUpdate}
- </Button>
+ {safeBlockers.length > 0 ? (
+ <Button className="font-semibold" onClick={onStopAndUpdate} size="lg">
+ {hasForeignBlockers ? u.closePreviewsAndCheckAgain : u.closePreviewsAndUpdate}
+ </Button>
+ ) : null}
<Button onClick={onDismiss} variant="text">
{u.notNow}
</Button>
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 7b06448c4f6..7b77fa7d88a 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -1903,9 +1903,16 @@ export const ar = defineLocale({
errorBody: 'لا داعي للقلق — لم يُفقد شيء. يمكنك إعادة المحاولة الآن.',
blockerTitle: 'إغلاق المعاينات المحلية لتحديث Hermes؟',
blockerBody: 'يحتاج Hermes إلى إيقاف هذه المعاينات المحلية قبل التحديث. لن يؤدي ذلك إلى تعديل ملفاتك أو حذفها.',
+ foreignBlockerTitle: 'أغلق العمليات الأخرى لتحديث Hermes',
+ foreignBlockerBody:
+ 'لا يمكن لـ Hermes إغلاق هذه العمليات تلقائيًا بأمان. أغلق التطبيق أو الطرفية أو الخدمة التي تشغّل كل عملية، ثم حاول التحديث مرة أخرى.',
+ mixedBlockerBody:
+ 'يمكن لـ Hermes إغلاق المعاينات المحلية المدرجة أدناه. يجب إغلاق العمليات الأخرى يدويًا قبل متابعة التحديث.',
closePreviewsAndUpdate: 'إغلاق المعاينات والتحديث',
+ closePreviewsAndCheckAgain: 'إغلاق المعاينات والتحقق مجددًا',
localPreview: 'معاينة محلية',
portLabel: port => `المنفذ ${port}`,
+ pidLabel: pid => `معرّف العملية ${pid}`,
technicalDetails: 'التفاصيل التقنية',
notNow: 'ليس الآن',
applyStatus: {
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 7169ad85b79..8c3d0a13973 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2379,9 +2379,16 @@ export const en: Translations = {
blockerTitle: 'Close local previews to update Hermes?',
blockerBody:
'Hermes needs to stop these local previews before updating. This will not modify or delete your files.',
+ foreignBlockerTitle: 'Close other processes to update Hermes',
+ foreignBlockerBody:
+ 'Hermes can’t safely close these processes automatically. Close the app, terminal, or service that owns each one, then try the update again.',
+ mixedBlockerBody:
+ 'Hermes can close the local previews listed below. Other processes must be closed manually before the update can continue.',
closePreviewsAndUpdate: 'Close previews and update',
+ closePreviewsAndCheckAgain: 'Close previews and check again',
localPreview: 'Local preview',
portLabel: port => `Port ${port}`,
+ pidLabel: pid => `PID ${pid}`,
technicalDetails: 'Technical details',
notNow: 'Not now',
applyStatus: {
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index a6a075bb1c2..45528c7d9bc 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2097,10 +2097,18 @@ export const ja = defineLocale({
errorTitle: '更新が完了しませんでした',
errorBody: 'ご安心ください。何も失われていません。今すぐ再試行できます。',
blockerTitle: 'Hermes を更新するためにローカルプレビューを閉じますか?',
- blockerBody: '更新する前に、これらのローカルプレビューを停止する必要があります。ファイルが変更または削除されることはありません。',
+ blockerBody:
+ '更新する前に、これらのローカルプレビューを停止する必要があります。ファイルが変更または削除されることはありません。',
+ foreignBlockerTitle: '他のプロセスを閉じて Hermes を更新',
+ foreignBlockerBody:
+ 'Hermes はこれらのプロセスを安全に自動終了できません。各プロセスを所有するアプリ、ターミナル、またはサービスを閉じてから、もう一度更新してください。',
+ mixedBlockerBody:
+ 'Hermes は以下のローカルプレビューを閉じることができます。更新を続けるには、他のプロセスを手動で閉じる必要があります。',
closePreviewsAndUpdate: 'プレビューを閉じて更新',
+ closePreviewsAndCheckAgain: 'プレビューを閉じて再確認',
localPreview: 'ローカルプレビュー',
portLabel: port => `ポート ${port}`,
+ pidLabel: pid => `PID ${pid}`,
technicalDetails: '技術的な詳細',
notNow: '今は後で',
applyStatus: {
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index d4c7dfbbf87..16802354e91 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -1997,9 +1997,14 @@ export interface Translations {
errorBody: string
blockerTitle: string
blockerBody: string
+ foreignBlockerTitle: string
+ foreignBlockerBody: string
+ mixedBlockerBody: string
closePreviewsAndUpdate: string
+ closePreviewsAndCheckAgain: string
localPreview: string
portLabel: (port: number) => string
+ pidLabel: (pid: number) => string
technicalDetails: string
notNow: string
applyStatus: {
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index e25d5268bd4..eb6f8ef6621 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2036,9 +2036,15 @@ export const zhHant = defineLocale({
errorBody: '沒有資料遺失。您可以現在重試。',
blockerTitle: '關閉本機預覽以更新 Hermes?',
blockerBody: 'Hermes 需要在更新前停止這些本機預覽。這不會修改或刪除您的檔案。',
+ foreignBlockerTitle: '關閉其他處理程序以更新 Hermes',
+ foreignBlockerBody:
+ 'Hermes 無法安全地自動關閉這些處理程序。請關閉擁有這些處理程序的應用程式、終端機或服務,然後重試更新。',
+ mixedBlockerBody: 'Hermes 可以關閉下方列出的本機預覽。其他處理程序必須手動關閉,更新才能繼續。',
closePreviewsAndUpdate: '關閉預覽並更新',
+ closePreviewsAndCheckAgain: '關閉預覽並重新檢查',
localPreview: '本機預覽',
portLabel: port => `連接埠 ${port}`,
+ pidLabel: pid => `PID ${pid}`,
technicalDetails: '技術詳細資料',
notNow: '暫不',
applyStatus: {
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index a270e68f9df..7ce1d30df9b 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -2563,9 +2563,14 @@ export const zh: Translations = {
errorBody: '没有数据丢失。你可以现在重试。',
blockerTitle: '关闭本地预览以更新 Hermes?',
blockerBody: 'Hermes 需要在更新前停止这些本地预览。这不会修改或删除你的文件。',
+ foreignBlockerTitle: '关闭其他进程以更新 Hermes',
+ foreignBlockerBody: 'Hermes 无法安全地自动关闭这些进程。请关闭拥有这些进程的应用、终端或服务,然后重试更新。',
+ mixedBlockerBody: 'Hermes 可以关闭下方列出的本地预览。其他进程必须手动关闭,更新才能继续。',
closePreviewsAndUpdate: '关闭预览并更新',
+ closePreviewsAndCheckAgain: '关闭预览并重新检查',
localPreview: '本地预览',
portLabel: port => `端口 ${port}`,
+ pidLabel: pid => `PID ${pid}`,
technicalDetails: '技术详情',
notNow: '暂不',
applyStatus: {