Repository navigation
fix(workspace): a restored workspace paints before its terminals reconnect #22293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
922c1c2
fix(workspace): a restored workspace paints before its terminals reco…
brennanb2025 3fd421c
fix(workspace): track the startup terminal hold explicitly and keep i…
brennanb2025 4eb6b10
fix(native-chat): start the startup readable sweep once the local PTY…
brennanb2025 8284ab2
fix(native-chat): open a visible chat's journal on its first read
brennanb2025 52e3599
fix(native-chat): a restored chat reads before its host is built and …
brennanb2025 b7bd3af
test(native-chat): an on-demand read skips the task queue once the ch…
brennanb2025 4b09688
fix(native-chat): a read already past its visibility check cannot reo…
brennanb2025 23ba0dc
Merge remote-tracking branch 'origin/main' into brennanb2025/fix-nati…
brennanb2025 11a1204
test(wire): the cross-version host stub answers the read that opens a…
brennanb2025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/main/native-chat/agent-session-wire/structured-agent-session-readable-on-demand.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /** | ||
| * Reading a persisted chat before the startup sweep reaches it. | ||
| * | ||
| * A restored chat pane subscribes as soon as its workspace paints, which can be long before the | ||
| * startup sweep runs. The read opens the journal itself; the sweep still owns the handoff recovery. | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import type { AgentSessionRecord } from '../../../shared/agent-session-record' | ||
| import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' | ||
| import { | ||
| agentSessionLeaseFixture, | ||
| agentSessionRecordFixture | ||
| } from '../../../shared/agent-session-record.test-fixture' | ||
| import { StructuredAgentSessionReadableRestorer } from './structured-agent-session-readable-restorer' | ||
| import * as readRestore from './structured-agent-session-read-restore' | ||
| import { StructuredAgentSessionTaskQueue } from './structured-agent-session-task-queue' | ||
|
|
||
| const readable = { journal: {}, params: {}, fence: 1 } as never | ||
|
|
||
| function harness(options: { | ||
| records: AgentSessionRecord[] | ||
| visible?: { present: boolean; sessionIds: string[] } | ||
| supports?: (record: AgentSessionRecord) => boolean | ||
| reconcile?: (live: Map<string, unknown>) => Promise<null> | ||
| }) { | ||
| const live = new Map<string, unknown>() | ||
| const tasks = new StructuredAgentSessionTaskQueue() | ||
| const onReadable = vi.fn((sessionId: string, restored: unknown) => live.set(sessionId, restored)) | ||
| const restoreHandoff = vi.fn(async () => undefined) | ||
| const restorer = new StructuredAgentSessionReadableRestorer({ | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the restorer reads only these three store methods. | ||
| store: { | ||
| getRecord: (sessionId: string) => | ||
| options.records.find((record) => record.sessionId === sessionId) ?? null, | ||
| listRecords: () => options.records, | ||
| getVisibleSessionTabIndex: () => | ||
| options.visible ?? { | ||
| present: true, | ||
| sessionIds: options.records.map((record) => record.sessionId) | ||
| } | ||
| } as unknown as AgentSessionRecordStore, | ||
| journalRoot: '/journals', | ||
| supportsRecord: options.supports ?? (() => true), | ||
| reconcile: async () => (options.reconcile ? options.reconcile(live) : null), | ||
| resolveRecovery: async () => undefined, | ||
| serialize: (sessionId, task) => tasks.serialize(sessionId, task), | ||
| hasSession: (sessionId) => live.has(sessionId), | ||
| onReadable, | ||
| retrySettlement: async () => true, | ||
| restoreHandoff | ||
| }) | ||
| return { restorer, live, tasks, onReadable, restoreHandoff } | ||
| } | ||
|
|
||
| function record(sessionId: string): AgentSessionRecord { | ||
| return agentSessionRecordFixture(agentSessionLeaseFixture({ sessionId })) | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| describe('an on-demand read of a persisted chat', () => { | ||
| beforeEach(() => { | ||
| vi.spyOn(readRestore, 'restoreStructuredAgentSessionRead').mockResolvedValue(readable) | ||
| }) | ||
|
|
||
| it('opens a visible chat without running the handoff recovery', async () => { | ||
| const { restorer, live, restoreHandoff } = harness({ records: [record('session-1')] }) | ||
|
|
||
| await expect(restorer.ensureReadable('session-1')).resolves.toBe(true) | ||
|
|
||
| expect(live.has('session-1')).toBe(true) | ||
| expect(restoreHandoff).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('leaves the handoff to the startup sweep, which runs it exactly once', async () => { | ||
| const { restorer, onReadable, restoreHandoff } = harness({ records: [record('session-1')] }) | ||
|
|
||
| await restorer.ensureReadable('session-1') | ||
| await restorer.restore(['session-1']) | ||
|
|
||
| expect(onReadable).toHaveBeenCalledOnce() | ||
| expect(restoreHandoff).toHaveBeenCalledOnce() | ||
| expect(readRestore.restoreStructuredAgentSessionRead).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('opens the journal once when a read races the startup sweep', async () => { | ||
| const opened = Promise.withResolvers<void>() | ||
| vi.mocked(readRestore.restoreStructuredAgentSessionRead).mockImplementation(async () => { | ||
| await opened.promise | ||
| return readable | ||
| }) | ||
| const { restorer, onReadable, restoreHandoff } = harness({ records: [record('session-1')] }) | ||
|
|
||
| const sweep = restorer.restore(['session-1']) | ||
| const read = restorer.ensureReadable('session-1') | ||
| opened.resolve() | ||
|
|
||
| await expect(read).resolves.toBe(true) | ||
| await sweep | ||
| expect(readRestore.restoreStructuredAgentSessionRead).toHaveBeenCalledOnce() | ||
| expect(onReadable).toHaveBeenCalledOnce() | ||
| expect(restoreHandoff).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('does not queue behind a provider start once another surface made the chat readable', async () => { | ||
| // A hold opens the chat, then keeps the task queue for its whole provider start. A read that | ||
| // saw the chat closed at its first check must not then wait that start out. | ||
| const providerStart = Promise.withResolvers<void>() | ||
| const { restorer, live, tasks } = harness({ | ||
| records: [record('session-1')], | ||
| reconcile: async (sessions) => { | ||
| sessions.set('session-1', readable) | ||
| void tasks.serialize('session-1', () => providerStart.promise) | ||
| return null | ||
| } | ||
| }) | ||
|
|
||
| try { | ||
| await expect(restorer.ensureReadable('session-1')).resolves.toBe(true) | ||
| expect(live.has('session-1')).toBe(true) | ||
| expect(readRestore.restoreStructuredAgentSessionRead).not.toHaveBeenCalled() | ||
| } finally { | ||
| providerStart.resolve() | ||
| } | ||
| }) | ||
|
|
||
| it('does not reopen a chat the user closed', async () => { | ||
| // Close hides the tab before it drops the session, so a read retry landing after it must not | ||
| // bring the chat back. | ||
| const { restorer, live } = harness({ | ||
| records: [record('session-closed')], | ||
| visible: { present: true, sessionIds: [] } | ||
| }) | ||
|
|
||
| await expect(restorer.ensureReadable('session-closed')).resolves.toBe(false) | ||
|
|
||
| expect(live.size).toBe(0) | ||
| expect(readRestore.restoreStructuredAgentSessionRead).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('reads any supported record when the store keeps no visible-tab index', async () => { | ||
| const { restorer } = harness({ | ||
| records: [record('session-1')], | ||
| visible: { present: false, sessionIds: [] } | ||
| }) | ||
|
|
||
| await expect(restorer.ensureReadable('session-1')).resolves.toBe(true) | ||
| }) | ||
|
|
||
| it('answers a live session without reopening it', async () => { | ||
| const { restorer, live } = harness({ records: [], visible: { present: true, sessionIds: [] } }) | ||
| live.set('session-live', readable) | ||
|
|
||
| await expect(restorer.ensureReadable('session-live')).resolves.toBe(true) | ||
| expect(readRestore.restoreStructuredAgentSessionRead).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('refuses a record no adapter supports, and one this host has no record for', async () => { | ||
| const { restorer } = harness({ records: [record('session-1')], supports: () => false }) | ||
|
|
||
| await expect(restorer.ensureReadable('session-1')).resolves.toBe(false) | ||
| await expect(restorer.ensureReadable('session-absent')).resolves.toBe(false) | ||
| expect(readRestore.restoreStructuredAgentSessionRead).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: stablyai/orca
Length of output: 41768
Do not attach when
makeReadablereturnsfalse.ensureReadablereturnsfalsewhen the persisted session is no longer visible. The hold path discards that result and still callsresumeHeldStructuredAgentSession, which can attach the provider for the released record. This violates the hold/close contract: a closed or hidden session can regain a provider without a readable surface.Return after the readability check, while preserving error reporting.
Suggested fix
📝 Committable suggestion