fix: reuse runtime processes across project sessions
Multiple projects could spawn duplicate heavyweight runtimes, while settings changes and remote reconnection could cancel or strand native conversations. Share compatible local OpenCode and DeepSeek Harness process owners and Agent-owned ACP connections, retaining workspace routing, per-session modes, model attribution, question ownership, targeted cancellation and idle cleanup. Restore remote pending questions and terminal task projections across reconnect and desktop restart, and preserve accepted ordinary requests during settings replacement while cancelling expert-team parents with their replaced scheduler. Extend regression coverage and Agent type checks. Record measured resource and real-model validation results, including failures and limitations. Also include the conversation media-generation design drafts (not an implemented feature), documentation entry links and dedicated Linux test-directory guidance. Desktop and Agent changes must be delivered together for shared process results. Validation: typecheck and lint passed; staged content and documentation links checked. Prior full regression and live-model evidence are recorded in progress notes; no new full test suite or model calls were run for this commit. Release note: 多项目会话现在复用兼容的 OpenCode 和 DeepSeek Harness 进程,减少重复启动并保持工作区、工具和取消隔离。修复远端问答在断线、重启及配置更新后的恢复与状态同步问题,Desktop 与 Agent 需配套更新。
This commit is contained in:
@@ -1436,6 +1436,19 @@ function persistedTerminalStateOverridesLocal(
|
||||
return persisted.state !== "streaming" && local.state !== "complete";
|
||||
}
|
||||
|
||||
function withRecoveredQuestions(conversation: Conversation): Conversation {
|
||||
const active = conversation.activeRequest;
|
||||
if (!active) return conversation;
|
||||
return {
|
||||
...conversation,
|
||||
messages: conversation.messages.map(message =>
|
||||
message.id === active.messageId && message.state === "streaming"
|
||||
? { ...message, pendingQuestions: active.questions }
|
||||
: message,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function mergePersistedConversations(
|
||||
current: readonly Conversation[],
|
||||
incoming: readonly ConversationSnapshot[],
|
||||
@@ -1454,7 +1467,7 @@ function mergePersistedConversations(
|
||||
const local = currentById.get(conversation.id);
|
||||
if (!local || local.remote) {
|
||||
persistedLocal.set(conversation.id, conversation);
|
||||
return conversation;
|
||||
return withRecoveredQuestions(conversation);
|
||||
}
|
||||
const localMessageById = new Map(
|
||||
local.messages.map((message) => [message.id, message]),
|
||||
@@ -1466,6 +1479,9 @@ function mergePersistedConversations(
|
||||
const messages = [
|
||||
...conversation.messages.map((message) => {
|
||||
const localMessage = localMessageById.get(message.id);
|
||||
if (!conversation.activeRequest && local.activeRequest?.messageId === message.id) {
|
||||
return { ...message, pendingQuestions: undefined };
|
||||
}
|
||||
if (!localIsNewer) {
|
||||
// Pending prompts are live-only and are omitted from persisted messages.
|
||||
if (localMessage?.state === "streaming" && message.state === "streaming") {
|
||||
@@ -1484,10 +1500,10 @@ function mergePersistedConversations(
|
||||
...local.messages.filter((message) => !serverMessageIds.has(message.id)),
|
||||
];
|
||||
const next = localIsNewer
|
||||
? { ...local, messages }
|
||||
? { ...local, messages, activeRequest: conversation.activeRequest }
|
||||
: { ...conversation, messages };
|
||||
persistedLocal.set(conversation.id, conversation);
|
||||
return next;
|
||||
return withRecoveredQuestions(next);
|
||||
});
|
||||
for (const conversation of current) {
|
||||
if (!incomingById.has(conversation.id)) {
|
||||
@@ -5579,7 +5595,7 @@ function App(): React.JSX.Element {
|
||||
)
|
||||
: [];
|
||||
let nextConversations: Conversation[] = [
|
||||
...persistedConversations,
|
||||
...persistedConversations.map(withRecoveredQuestions),
|
||||
...migratedLocalConversations,
|
||||
];
|
||||
let projectConversation = nextConversations.find(
|
||||
@@ -7404,7 +7420,9 @@ function App(): React.JSX.Element {
|
||||
const stop = async (): Promise<void> => {
|
||||
const requestId = [...activeRuns.current.entries()].find(
|
||||
([, run]) => run.conversationId === activeId,
|
||||
)?.[0];
|
||||
)?.[0] ?? conversationsRef.current.find(
|
||||
conversation => conversation.id === activeId,
|
||||
)?.activeRequest?.requestId;
|
||||
if (requestId) {
|
||||
try {
|
||||
await window.goodbuddy.agent.cancel(requestId);
|
||||
@@ -7503,8 +7521,7 @@ function App(): React.JSX.Element {
|
||||
if (!question || question.questionId !== questionId) {
|
||||
return;
|
||||
}
|
||||
const taskId = pendingMessage.task?.id ?? [...activeRuns.current.entries()]
|
||||
.find(([, run]) => run.conversationId === conversationId && run.messageId === messageId)?.[0];
|
||||
const taskId = question.requestId;
|
||||
await window.goodbuddy.agent.respondQuestion(questionId, answers);
|
||||
updateMessage(conversationId, messageId, (message) => {
|
||||
const pendingQuestions = message.pendingQuestions?.filter((item) => item.questionId !== questionId);
|
||||
|
||||
Reference in New Issue
Block a user