Repository navigation
fix(harness): hide unfinished continuation sessions [SAP-3292] #1033
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
ynadge
wants to merge
1
commit into
assistant-terminal-start-controls
from
assistant-pending-child-visibility
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@sapiom/harness": patch | ||
| --- | ||
|
|
||
| Keep unfinished Assistant continuation children out of all public session lists and block direct actions until preparation completes. |
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
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
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 |
|---|---|---|
|
|
@@ -907,6 +907,9 @@ export const startServer = async ( | |
| } satisfies Partial<Record<HarnessKind, HarnessAdapter>>); | ||
|
|
||
| const bus = new EventBus(); | ||
| // Synchronous event projections consult this cache; all public admission reads | ||
| // refresh it from durable receipts, and allocation marks it before publication. | ||
| const hiddenAssistantSessions = new Set<string>(); | ||
| const canvasWatcher = new CanvasWatcherManager({ | ||
| onChange: (harnessSessionId) => | ||
| bus.publish({ type: "canvas.reload", harnessSessionId }), | ||
|
|
@@ -2013,7 +2016,7 @@ export const startServer = async ( | |
| const rescannedOnStart = new Set<string>(); | ||
|
|
||
| sessionManager.onStatusChange((session) => { | ||
| bus.publish({ type: "session.status", session }); | ||
| if (!hiddenAssistantSessions.has(session.id)) bus.publish({ type: "session.status", session }); | ||
| if (session.status === "running") { | ||
| canvasWatcher.start(session.id, session.cwd); | ||
| workspaceWatcher.start(session.id, session.cwd); | ||
|
|
@@ -3555,6 +3558,15 @@ export const startServer = async ( | |
| const assistantSessions = new AssistantSessionStore(statePaths.root); | ||
| const assistantRecords = new AssistantRecordStore(statePaths.root); | ||
| const assistantContinuations = new AssistantContinuationStore(statePaths.root); | ||
| const isAssistantSessionVisible = async (id: string): Promise<boolean> => { | ||
| const visible = await assistantContinuations.canAttach(id); | ||
| if (visible) hiddenAssistantSessions.delete(id); | ||
| else hiddenAssistantSessions.add(id); | ||
| return visible; | ||
| }; | ||
| const restoredSessionIds = sessionManager.list().map((session) => session.id); | ||
| for (let offset = 0; offset < restoredSessionIds.length; offset += 8) | ||
| await Promise.all(restoredSessionIds.slice(offset, offset + 8).map(isAssistantSessionVisible)); | ||
| const recordCaptures = new WeakMap<HostedOpenCode, AssistantRecordCapture>(); | ||
| const authorizeAssistantWorkspace = async (id: string) => { | ||
| const session = sessionManager.get(id); | ||
|
|
@@ -3594,13 +3606,14 @@ export const startServer = async ( | |
| authorize: authorizeAssistantWorkspace, | ||
| }); | ||
| const openCodeAssociations = new OpenCodeAssociations(assistantSessions); | ||
| const assistantLifecycle = new AssistantLifecycleCoordinator({ store: assistantSessions, host: openCodeHost, associations: openCodeAssociations, canAttach: (id) => assistantContinuations.canAttach(id) }); | ||
| const assistantLifecycle = new AssistantLifecycleCoordinator({ store: assistantSessions, host: openCodeHost, associations: openCodeAssociations, canAttach: isAssistantSessionVisible }); | ||
| const assistantEnd = new AssistantEndCoordinator({ store: assistantSessions, lifecycle: assistantLifecycle, sessionManager }); | ||
| // Hydrate lifecycle headers without launching runtimes. A corrupt entry fails | ||
| // closed when selected rather than preventing unrelated sessions from loading. | ||
| await Promise.allSettled(sessionManager.list().map((session) => assistantLifecycle.describe(session.id))); | ||
| const assistantProjection = createAssistantStateProjection(openCodeHost, assistantLifecycle, (snapshot) => | ||
| bus.publish({ type: "assistant.state", snapshot }), | ||
| (id) => !hiddenAssistantSessions.has(id), | ||
| ); | ||
| const getAssistantState = assistantProjection.get; | ||
| const assistantContext = createAssistantContextRuntime({ | ||
|
|
@@ -3623,7 +3636,13 @@ export const startServer = async ( | |
| const assistantContinue = new AssistantContinuation({ | ||
| store: assistantContinuations, | ||
| records: assistantRecords, | ||
| sessions: sessionManager, | ||
| sessions: { | ||
| get: (id) => sessionManager.get(id), | ||
| allocateDormant: async (id, input) => { | ||
| await isAssistantSessionVisible(input.childSessionId); | ||
| return sessionManager.allocateDormant(id, input); | ||
| }, | ||
| }, | ||
| associations: assistantSessions, | ||
| lifecycle: assistantLifecycle, | ||
| native: new AssistantContinuationNative((hosted) => openCodeHost.assertCurrent(hosted)), | ||
|
|
@@ -3673,7 +3692,7 @@ export const startServer = async ( | |
| res.setHeader("Cache-Control", "no-store"); | ||
| res.json(assistantAccess.getBrowserState()); | ||
| }); | ||
| const assistantHistory = new AssistantHistory({ sessions: sessionManager, authorize: authorizeAssistantHistory, records: assistantRecords, lifecycle: assistantLifecycle, isVisible: (id) => assistantContinuations.canAttach(id) }); | ||
| const assistantHistory = new AssistantHistory({ sessions: sessionManager, authorize: authorizeAssistantHistory, records: assistantRecords, lifecycle: assistantLifecycle, isVisible: isAssistantSessionVisible }); | ||
| app.use("/api", createAssistantLifecycleRouter({ | ||
| bootToken: options.bootToken, | ||
| history: assistantHistory, | ||
|
|
@@ -3690,12 +3709,13 @@ export const startServer = async ( | |
| app.use("/api", createAssistantRecordsRouter({ | ||
| bootToken: options.bootToken, | ||
| store: assistantRecords, | ||
| authorize: authorizeAssistantHistory, | ||
| authorize: async (id) => (await isAssistantSessionVisible(id)) ? authorizeAssistantHistory(id) : null, | ||
| history: assistantHistory, | ||
| })); | ||
| app.use( | ||
| "/api", | ||
| createRestRouter({ | ||
| isSessionVisible: isAssistantSessionVisible, | ||
|
Comment on lines
3717
to
+3718
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| getAssistantState, | ||
| endSession: (id) => assistantEnd.end(id), | ||
| sessionManager, | ||
|
|
||
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.
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.
🔍 WebSocket visibility remains implicit
/ws/terminaltrusts internal session rows without checking continuation visibility. Pending children currently lack PTYs, but future runtime changes can bypass the shared boundary.Was this helpful? React with 👍 or 👎 to provide feedback.