fix(pi): keep active runs alive during background sleep
This commit is contained in:
@@ -47,6 +47,7 @@ export interface CreateCodingCompositionOptions {
|
||||
browser: AgentBrowserModule;
|
||||
paths: CodingCompositionPaths;
|
||||
getLocalProxyCredential?(): string | undefined;
|
||||
acquireBackgroundLease?(lease: { id: string; kind: 'coding-run' }): () => void;
|
||||
}
|
||||
|
||||
export function resolveCodingPiRuntimePaths(input: {
|
||||
@@ -158,6 +159,9 @@ export function createCodingComposition(
|
||||
mimeType: record.mime,
|
||||
};
|
||||
})),
|
||||
...(options.acquireBackgroundLease
|
||||
? { acquireBackgroundLease: options.acquireBackgroundLease }
|
||||
: {}),
|
||||
});
|
||||
const projects = new CodingProjectService(projectStore, {
|
||||
migration: {
|
||||
@@ -174,13 +178,13 @@ export function createCodingComposition(
|
||||
.catch(() => []);
|
||||
for (const conversation of conversations) registry.forget(conversation.id);
|
||||
},
|
||||
onProjectDeactivated: async (project) => {
|
||||
onProjectDeactivated: async (project, reason) => {
|
||||
const conversations = await conversationStoreForProject(project.path).read()
|
||||
.then((file) => file.conversations)
|
||||
.catch(() => []);
|
||||
await Promise.allSettled([
|
||||
options.browser.close(project.path),
|
||||
...conversations.map(({ id }) => runtime.dispose(id)),
|
||||
...conversations.map(({ id }) => runtime.dispose(id, reason)),
|
||||
]);
|
||||
},
|
||||
});
|
||||
@@ -205,9 +209,12 @@ export function createCodingComposition(
|
||||
conversations,
|
||||
runtime,
|
||||
host,
|
||||
async sleep() {
|
||||
async sleep(reason) {
|
||||
if (reason === 'background_sleep' && runtime.hasActiveWork()) return;
|
||||
const conversationIds = runtime.getDiagnostics().workers.map((worker) => worker.conversationId);
|
||||
await Promise.allSettled(conversationIds.map((conversationId) => runtime.dispose(conversationId)));
|
||||
await Promise.allSettled(conversationIds.map((conversationId) => (
|
||||
runtime.dispose(conversationId, reason)
|
||||
)));
|
||||
},
|
||||
async shutdown() {
|
||||
await subagents.close();
|
||||
|
||||
@@ -40,7 +40,7 @@ export interface CodingProductComposition {
|
||||
conversations: CodingConversationService;
|
||||
runtime: CodingConversationRuntime;
|
||||
host: CodingProductHost;
|
||||
sleep(): Promise<void>;
|
||||
sleep(reason: 'background_sleep' | 'auth_cleanup'): Promise<void>;
|
||||
shutdown(): Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user