The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): cron run rows carry their owning backend so the transcript opens
Austin Pickett90c8598e38bf
diff --git a/apps/desktop/src/api/cron.ts b/apps/desktop/src/api/cron.tsindex b790b033d76..5483ddfb223 100644--- a/apps/desktop/src/api/cron.ts+++ b/apps/desktop/src/api/cron.ts@@ -1,3 +1,4 @@+import { stampRowsWithOwningConnection } from '@/lib/session-owner-stamp'import type {AutomationBlueprint,CronDeliveryTarget,@@ -7,7 +8,13 @@ import type {SessionInfo} from '@/types/hermes'-import { connectionScoped, hermesApi, profileScoped, STARTUP_REQUEST_TIMEOUT_MS } from './client'+import {+ connectionScoped,+ getApiRequestConnection,+ hermesApi,+ profileScoped,+ STARTUP_REQUEST_TIMEOUT_MS+} from './client'// The cron trigger endpoint intentionally waits for the whole job so its// response reflects the persisted execution result. Agent jobs can run far@@ -46,7 +53,16 @@ export async function getCronJobRuns(jobId: string, limit = 20): Promise<Sessionpath: `/api/cron/jobs/${encodeURIComponent(jobId)}/runs?limit=${limit}`})- return runs ?? []+ // Run rows are backend-returned sessions like any other page, so they carry+ // the same ownership contract: tag each with the registry connection that+ // served it so a later resume can name the backend that actually holds the+ // run. Without the tag the row's bare (or backend-only) profile is not an+ // exact owner, and clicking a run — especially over SSH/remote, where the+ // run lives on a host the local pool has never seen — fell to the ambient+ // id-only resume and the transcript never loaded (#82527). The backend+ // stamps `profile` (the job's owning profile); this adds the connection+ // half, exactly as /api/sessions and the sidebar slices do.+ return stampRowsWithOwningConnection(runs ?? [], getApiRequestConnection())}// The single source of truth for cron delivery targets (local + configureddiff --git a/apps/desktop/src/app/chat/sidebar/cron-jobs-section.test.tsx b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.test.tsxnew file mode 100644index 00000000000..5afa63b248a--- /dev/null+++ b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.test.tsx@@ -0,0 +1,80 @@+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import { I18nProvider, TRANSLATIONS } from '@/i18n'+import { fmtDayTime } from '@/lib/time'+import type { CronJob, SessionInfo } from '@/types/hermes'++import { SidebarCronJobsSection } from './cron-jobs-section'++// Hoisted so the vi.mock factory (also hoisted) can close over it.+const { getCronJobRuns } = vi.hoisted(() => ({ getCronJobRuns: vi.fn() }))++vi.mock('@/hermes', async importOriginal => ({+ ...(await importOriginal<object>()),+ getCronJobRuns+}))++// A cron run row as the backend serves it: the job's owning profile plus the+// connection tag the desktop stamps on backend-returned session pages.+const RUN = {+ connection_id: 'gw-tailscale',+ ended_at: null,+ id: 'cron-nightly-1',+ input_tokens: 0,+ is_active: false,+ last_active: 1_700_000_000,+ message_count: 2,+ model: null,+ output_tokens: 0,+ profile: 'research',+ source: 'cron'+} as SessionInfo++const JOB = { enabled: true, id: 'job-1', name: 'nightly', schedule: '* * * * *', state: 'scheduled' } as CronJob++beforeEach(() => {+ getCronJobRuns.mockResolvedValue([RUN])+})++afterEach(() => {+ cleanup()+ getCronJobRuns.mockReset()+})++function renderSection(onOpenRun: (sessionId: string, session?: SessionInfo) => void) {+ return render(+ <I18nProvider configClient={null} initialLocale="en">+ <SidebarCronJobsSection+ jobs={[JOB]}+ label="Cron jobs"+ onManageJob={() => {}}+ onOpenRun={onOpenRun}+ onToggle={() => {}}+ onTriggerJob={async () => {}}+ open+ />+ </I18nProvider>+ )+}++describe('SidebarCronJobsSection run rows', () => {+ // Contract (#82527): clicking a run must hand the open path the run ROW, not+ // its bare id. The row carries the owning (connection, profile); without it+ // the resume cannot name the backend that holds the run and falls to the+ // ambient one — so an SSH/remote run's transcript never loads.+ it('opens a run with the run ROW so the resume can pin its owning backend', async () => {+ const onOpenRun = vi.fn()+ renderSection(onOpenRun)++ fireEvent.click(screen.getByRole('button', { name: TRANSLATIONS.en.cron.showRuns }))++ const runButton = await screen.findByRole('button', {+ name: fmtDayTime.format(new Date(RUN.last_active * 1000))+ })++ fireEvent.click(runButton)++ expect(onOpenRun).toHaveBeenCalledWith(RUN.id, RUN)+ })+})diff --git a/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsxindex 0bc80e8263c..a940ea9fee7 100644--- a/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx+++ b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx@@ -77,8 +77,10 @@ interface SidebarCronJobsSectionProps {jobs: CronJob[]label: stringmax?: number- // Open a run session's chat (1 click to output).- onOpenRun: (sessionId: string) => void+ // Open a run session's chat (1 click to output). The run ROW rides along so+ // the open can pin its owning (connection, profile) — the same owner-aware+ // door every other session-list row uses.+ onOpenRun: (sessionId: string, session?: SessionInfo) => void// Open the full Cron page focused on this job (manage / full history).onManageJob: (jobId: string) => void// Fire the job now.@@ -240,7 +242,7 @@ function CronJobSidebarRow({job: CronJobnowMs: numberonManage: () => void- onOpenRun: (sessionId: string) => void+ onOpenRun: (sessionId: string, session?: SessionInfo) => voidonTogglePeek: () => voidonTrigger: () => void}) {@@ -395,7 +397,13 @@ function CronJobSidebarRow({)}-function CronJobSidebarRuns({ jobId, onOpenRun }: { jobId: string; onOpenRun: (sessionId: string) => void }) {+function CronJobSidebarRuns({+ jobId,+ onOpenRun+}: {+ jobId: string+ onOpenRun: (sessionId: string, session?: SessionInfo) => void+}) {const { t } = useI18n()const c = t.cronconst selectedSessionId = useStore($selectedStoredSessionId)@@ -475,7 +483,7 @@ function CronJobSidebarRuns({ jobId, onOpenRun }: { jobId: string; onOpenRun: (s: 'text-(--ui-text-secondary) hover:bg-(--chrome-action-hover) hover:text-foreground')}key={run.id}- onClick={() => onOpenRun(run.id)}+ onClick={() => onOpenRun(run.id, run)}type="button">{formatRunTime(run.last_active || run.started_at)}diff --git a/apps/desktop/src/app/command-center/index.tsx b/apps/desktop/src/app/command-center/index.tsxindex 0adf6127965..9c05ab44747 100644--- a/apps/desktop/src/app/command-center/index.tsx+++ b/apps/desktop/src/app/command-center/index.tsx@@ -65,7 +65,7 @@ interface CommandCenterViewProps {onDeleteSession: (sessionId: string) => Promise<void>// Accepted for call-site parity; navigation lives in the global Cmd+K palette.onNavigateRoute?: (path: string) => void- onOpenSession: (sessionId: string) => void+ onOpenSession: (sessionId: string, session?: SessionInfo) => void/** Grows the shared session window (bumpSessionsLimit + refetch), same* mechanism as the sidebar's recents "load more". Renders the Sessions* list's bottom-right button when the backend page is capped. */@@ -427,7 +427,7 @@ export function CommandCenterView({<li className="group flex items-center gap-2 py-2" key={session.id}><buttonclassName="min-w-0 flex-1 text-left"- onClick={() => onOpenSession(session.id)}+ onClick={() => onOpenSession(session.id, session)}type="button"><div className="truncate text-[length:var(--conversation-text-font-size)] font-medium text-foreground">diff --git a/apps/desktop/src/app/command-center/open-session.test.tsx b/apps/desktop/src/app/command-center/open-session.test.tsxnew file mode 100644index 00000000000..4a994cb3a91--- /dev/null+++ b/apps/desktop/src/app/command-center/open-session.test.tsx@@ -0,0 +1,69 @@+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { MemoryRouter } from 'react-router'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import type * as HermesApi from '@/hermes'+import type { SessionInfo } from '@/hermes'+import { $sessions } from '@/store/session'++import { CommandCenterView } from './index'++vi.mock('@/hermes', async importOriginal => ({+ ...(await importOriginal<typeof HermesApi>()),+ getActionStatus: vi.fn(() => Promise.resolve({ running: false })),+ getLogs: vi.fn(() => Promise.resolve({ lines: [] })),+ getStatus: vi.fn(() => Promise.resolve({})),+ getUsageAnalytics: vi.fn(() => Promise.resolve({})),+ restartGateway: vi.fn(),+ updateHermes: vi.fn()+}))+vi.mock('@/lib/session-export', () => ({ exportSession: vi.fn() }))+vi.mock('./maintenance', () => ({ MaintenancePanel: () => null }))++afterEach(() => {+ cleanup()+ $sessions.set([])+})++const SESSION = {+ connection_id: 'gw-tailscale',+ ended_at: null,+ id: 'sess-remote',+ input_tokens: 0,+ is_active: false,+ last_active: 1_756_600_000,+ message_count: 3,+ model: null,+ output_tokens: 0,+ profile: 'research',+ started_at: 1_756_500_000,+ title: 'Remote conversation'+} as SessionInfo++// Same open-path contract as the cron run rows (#82527): a list row hands its+// owner (connection, profile) to the open call so a remote/other-profile row+// resumes on the backend that owns it, not the ambient one.+describe('Command Center session open carries the row', () => {+ beforeEach(() => {+ $sessions.set([SESSION])+ })++ it('passes the clicked ROW to onOpenSession, not a bare id', async () => {+ const onOpenSession = vi.fn()+ render(+ <MemoryRouter>+ <CommandCenterView+ initialSection="sessions"+ onClose={() => {}}+ onDeleteSession={() => Promise.resolve()}+ onOpenSession={onOpenSession}+ />+ </MemoryRouter>+ )++ const title = await screen.findByText('Remote conversation')+ fireEvent.click(title.closest('button') as HTMLButtonElement)++ expect(onOpenSession).toHaveBeenCalledWith(SESSION.id, SESSION)+ })+})diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex c9037cc495a..2385e89e3bd 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -93,6 +93,7 @@ import { $titlebarAppActionsSide, titlebarAppActionsClusterCounts } from '@/storimport { armWakeWord, stopClientCapture } from '@/store/wake-word'import { isAuxiliaryWindow, isBrowserWindow, isHudWindow } from '@/store/windows'import { useSkinCommand } from '@/themes/use-skin-command'+import type { SessionInfo } from '@/types/hermes'import { closeWorkspaceTab } from '../chat/close-tab'import { requestComposerInsert } from '../chat/composer/focus'@@ -1095,6 +1096,32 @@ export function ContribWiring({ children }: { children: ReactNode }) {return () => registerPaneCloser('workspace')}, [navigate])+ // One owner-aware door for "open a stored session from a list row" — the+ // sessions sidebar, the Cron page's run history and the command center all+ // funnel here. The clicked ROW is the identity, not its bare id: two+ // profiles can hold twins with the same stored id (#92454), and an id-only+ // resume resolves against whichever cached row is found first — the user+ // clicks a row previewing profile A (or a cron run served by an SSH backend)+ // and the resume dials the ambient backend instead, so the transcript never+ // loads (#82527). Pin the row's own (connection, profile) as the resume owner+ // before navigating; untagged rows (single-profile installs and the legacy+ // primary-SSH path) keep the ambient/id-only path. Clear any stale explicit+ // hint first: older builds incorrectly persisted those rows as `local`,+ // which made a remote session click switch to the Mac backend and fail with+ // "session not found".+ const openStoredSession = (sessionId: string, session?: SessionInfo) => {+ const ownerRoute = sessionOwnerRouteFromRow(session)++ if (ownerRoute) {+ requestSessionResume(sessionId, ownerRoute)+ } else {+ forgetSessionOwnerHintsForSession(sessionId)+ requestSessionResume(sessionId)+ }++ openSession(sessionId, navigate)+ }+// The controller's entire callback surface, gathered into the stable// `actions` bag. `nextActions` is TS-checked against WiringActions each// render; its fields are copied into the ref object so `actions` keeps one@@ -1156,28 +1183,9 @@ export function ContribWiring({ children }: { children: ReactNode }) {onRemoveAttachment: id => void composer.removeAttachment(id),onRestoreToMessage: restoreToMessage,// Already on screen (open tile, or the main session)? Jump to its tab;- // otherwise load it into main. Same door every other session link uses.- // The clicked ROW is the identity, not its bare id: two profiles can hold- // twins with the same stored id (#92454), and an id-only resume resolves- // against whichever cached row is found first — the user clicks a row- // previewing profile A and the resume dials profile B. Pin the row's own- // (connection, profile) as the resume owner before navigating; untagged- // rows (single-profile installs and the legacy primary-SSH path) keep the- // ambient/id-only path. Clear any stale explicit hint first: older builds- // incorrectly persisted those rows as `local`, which made a remote session- // click switch to the Mac backend and fail with "session not found".- onResumeSession: (sessionId, session) => {- const ownerRoute = sessionOwnerRouteFromRow(session)-- if (ownerRoute) {- requestSessionResume(sessionId, ownerRoute)- } else {- forgetSessionOwnerHintsForSession(sessionId)- requestSessionResume(sessionId)- }-- openSession(sessionId, navigate)- },+ // otherwise load it into main. Same owner-aware door every other session+ // link uses (openStoredSession).+ onResumeSession: openStoredSession,onRetryResume: sessionId => void resumeSession(sessionId, true),onSteer: steerPrompt,onSteerHidden: injectHiddenPrompt,@@ -1415,7 +1423,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {onDeleteSession={removeSession}onLoadMoreSessions={loadMoreSessions}onNavigateRoute={path => navigateToWorkspacePage(navigate, path)}- onOpenSession={sessionId => openSession(sessionId, navigate)}+ onOpenSession={openStoredSession}/></Suspense>)}@@ -1428,10 +1436,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {{cronOpen && (<Suspense fallback={null}>- <CronView- onClose={closeOverlayToPreviousRoute}- onOpenSession={sessionId => openSession(sessionId, navigate)}- />+ <CronView onClose={closeOverlayToPreviousRoute} onOpenSession={openStoredSession} /></Suspense>)}diff --git a/apps/desktop/src/app/cron/index.tsx b/apps/desktop/src/app/cron/index.tsxindex 7e0d468f0ac..a8634d9836c 100644--- a/apps/desktop/src/app/cron/index.tsx+++ b/apps/desktop/src/app/cron/index.tsx@@ -295,7 +295,7 @@ function matchesQuery(job: CronJob, q: string): boolean {interface CronViewProps extends React.ComponentProps<'section'> {onClose: () => void- onOpenSession?: (sessionId: string) => void+ onOpenSession?: (sessionId: string, session?: SessionInfo) => voidsetStatusbarItemGroup?: SetStatusbarItemGroup}@@ -794,7 +794,7 @@ interface CronJobDetailProps {c: Translations['cron']job: CronJobonEdit: () => void- onOpenSession?: (sessionId: string) => void+ onOpenSession?: (sessionId: string, session?: SessionInfo) => voidonPauseResume: () => voidonTrigger: () => void}@@ -903,7 +903,7 @@ function CronJobRuns({}: {c: Translations['cron']jobId: string- onOpenSession?: (sessionId: string) => void+ onOpenSession?: (sessionId: string, session?: SessionInfo) => void}) {const [runs, setRuns] = useState<null | SessionInfo[]>(null)const changeEventsAvailable = useStore($changeEventsAvailable)@@ -982,7 +982,7 @@ function CronJobRuns({<buttonclassName="row-hover flex items-center justify-between gap-3 rounded-md px-2 py-1 text-left text-xs focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"key={run.id}- onClick={() => onOpenSession?.(run.id)}+ onClick={() => onOpenSession?.(run.id, run)}type="button"><span className="truncate text-foreground/85">diff --git a/apps/desktop/src/hermes-cron-scope.test.ts b/apps/desktop/src/hermes-cron-scope.test.tsindex c49d5431a27..df76a09861b 100644--- a/apps/desktop/src/hermes-cron-scope.test.ts+++ b/apps/desktop/src/hermes-cron-scope.test.ts@@ -105,3 +105,55 @@ describe('cron helpers are profile-scoped', () => {expect(api.mock.calls.at(-1)?.[0].path).toBe('/api/cron/jobs')})})++// Contract (#82527): the run rows a cron job returns are sessions like any+// other backend page, so they must carry the same ownership tag the session+// lists do — the registry connection that served them. Clicking a run then+// hands the open path a row whose (connection, profile) names the backend+// that actually holds it, instead of the ambient one a bare id resolves to.+describe('cron run rows carry their owning connection', () => {+ const run: { connection_id?: string; id: string; profile: string; source: string } = {+ id: 'cron-nightly-1',+ profile: 'research',+ source: 'cron'+ }++ const api = vi.fn(async () => ({ runs: [{ ...run }] }))++ beforeEach(() => {+ ;(window as { hermesDesktop?: unknown }).hermesDesktop = { api }+ api.mockClear()+ })++ afterEach(() => {+ setApiRequestProfile(null)+ setApiRequestConnection(null)+ delete (window as { hermesDesktop?: unknown }).hermesDesktop+ })++ it('stamps the active registry connection onto every run row', async () => {+ setApiRequestProfile('research')+ setApiRequestConnection('gw-tailscale')++ const rows = await getCronJobRuns('job-1')++ expect(rows[0].connection_id).toBe('gw-tailscale')+ // The backend's owning profile is preserved, not overwritten.+ expect(rows[0].profile).toBe('research')+ })++ it('leaves run rows untagged on a local/single-source window', async () => {+ const rows = await getCronJobRuns('job-1')++ expect(rows[0].connection_id).toBeUndefined()+ })++ it('never clobbers an owner a row already names', async () => {+ setApiRequestConnection('gw-tailscale')+ api.mockResolvedValueOnce({ runs: [{ ...run, connection_id: 'gw-homelab' }] })++ const rows = await getCronJobRuns('job-1')++ expect(rows[0].connection_id).toBe('gw-homelab')+ })+})