Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/chat-swarm-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,36 +323,38 @@ test("OpenCLI provisioning fails closed when the authenticated peer probe is mal
);
});

test("OpenCLI wake reopens the exact conversation", async () => {
test("OpenCLI continuation uses send and confirms delivery by exact prompt readback", async () => {
const driver = openCliDriverForTest();
const calls: string[][] = [];
let sent = false;
(driver as any).runJson = async (args: string[]) => {
calls.push(args);
if (args[1] === "detail") {
return [
{ Role: "User", Text: "init", Generating: false },
{ Role: "Assistant", Text: "READY_FOR_BOOTSTRAP", Generating: false },
...(sent ? [{ Role: "User", Text: "@devspace wake", Generating: false }] : []),
];
}
return [{
conversationId: "opencli-managed-02",
conversationUrl: "https://chatgpt.com/g/g-p-runtime-test/c/opencli-managed-02",
response: "",
}];
if (args[1] === "send") {
sent = true;
return [{ Status: "Success", InjectedText: "@devspace wake" }];
}
throw new Error(`unexpected OpenCLI command: ${args[1]}`);
};
const result = await driver.sendPrompt(
"https://chatgpt.com/g/g-p-runtime-test/c/opencli-managed-02",
"@devspace wake",
new Date(Date.now() + 1_000).toISOString(),
);
assert.deepEqual(result, { delivered: true, remoteMayContinue: true });
const ask = calls.find((args) => args[1] === "ask")!;
assert.equal(ask[ask.indexOf("--conversation") + 1], "opencli-managed-02");
assert.equal(ask[ask.indexOf("--wait") + 1], "false");
assert.equal(ask[ask.indexOf("--site-session") + 1], "ephemeral");
const send = calls.find((args) => args[1] === "send")!;
assert.equal(send[send.indexOf("--conversation") + 1], "opencli-managed-02");
assert.equal(send.includes("--wait"), false);
assert.equal(send[send.indexOf("--site-session") + 1], "ephemeral");
});

test("OpenCLI wake fails closed when the returned conversation identity drifts", async () => {
test("OpenCLI continuation fails closed when send acknowledgement has no prompt readback", async () => {
const driver = openCliDriverForTest();
(driver as any).runJson = async (args: string[]) => {
if (args[1] === "detail") {
Expand All @@ -361,11 +363,10 @@ test("OpenCLI wake fails closed when the returned conversation identity drifts",
{ Role: "Assistant", Text: "READY_FOR_BOOTSTRAP", Generating: false },
];
}
return [{
conversationId: "opencli-managed-wrong",
conversationUrl: "https://chatgpt.com/g/g-p-runtime-test/c/opencli-managed-wrong",
response: "",
}];
if (args[1] === "send") {
return [{ Status: "Success", InjectedText: "@devspace wake" }];
}
throw new Error(`unexpected OpenCLI command: ${args[1]}`);
};
const result = await driver.sendPrompt(
"https://chatgpt.com/g/g-p-runtime-test/c/opencli-managed-02",
Expand All @@ -375,7 +376,7 @@ test("OpenCLI wake fails closed when the returned conversation identity drifts",
assert.deepEqual(result, {
delivered: false,
remoteMayContinue: true,
blocker: "OPENCLI_CONVERSATION_IDENTITY_DRIFT",
blocker: "OPENCLI_PROMPT_NOT_OBSERVED",
});
});

Expand Down
37 changes: 19 additions & 18 deletions src/chat-swarm-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export interface ChatSwarmManagedCarrierAdapter extends ChatSwarmCarrierAdapter
}): Promise<{
disposition: "DELIVERED" | "UNKNOWN" | "SETUP_REQUIRED";
remoteMayContinue: boolean;
blocker?: string;
}>;
recover(slot: ManagedCarrierSlot): Promise<{ ready: boolean; blocker?: string }>;
stop(slot: ManagedCarrierSlot): Promise<void>;
Expand Down Expand Up @@ -1464,15 +1465,13 @@ export class OpenCliMacWebDriver implements MacWebDriver {
}

try {
const rows = await this.runJson<OpenCliConversationRow[]>(
const rows = await this.runJson<Array<{ Status?: string; InjectedText?: string }>>(
[
"chatgpt",
"ask",
"send",
prompt,
"--conversation",
conversationIdFromUrl(conversationUrl),
"--wait",
"false",
"--site-session",
"ephemeral",
"--keep-tab",
Expand All @@ -1482,19 +1481,20 @@ export class OpenCliMacWebDriver implements MacWebDriver {
],
deadlineAt,
);
const observedUrl = rows[0]?.conversationUrl?.trim();
if (
!observedUrl ||
conversationFingerprintFromUrl(observedUrl) !==
conversationFingerprintFromUrl(conversationUrl)
) {
return {
delivered: false,
remoteMayContinue: true,
blocker: "OPENCLI_CONVERSATION_IDENTITY_DRIFT",
};
}
return { delivered: true, remoteMayContinue: true };
const acknowledged =
rows[0]?.Status === "Success" && rows[0]?.InjectedText === prompt;
const observed = acknowledged
? await this.promptObserved(conversationUrl, prompt, deadlineAt).catch(() => false)
: false;
return observed
? { delivered: true, remoteMayContinue: true }
: {
delivered: false,
remoteMayContinue: true,
blocker: acknowledged
? "OPENCLI_PROMPT_NOT_OBSERVED"
: "OPENCLI_SEND_NOT_ACKNOWLEDGED",
};
} catch (error) {
const observed = await this.promptObserved(
conversationUrl,
Expand Down Expand Up @@ -2061,6 +2061,7 @@ export class MacWebChatCarrierAdapter implements ChatSwarmManagedCarrierAdapter
? ("SETUP_REQUIRED" as const)
: ("UNKNOWN" as const),
remoteMayContinue: sent.remoteMayContinue,
blocker: sent.blocker,
};
}
return { disposition: "DELIVERED" as const, remoteMayContinue: true };
Expand Down Expand Up @@ -2369,7 +2370,7 @@ export class ChatSwarmRuntimeManager {
operation.operationId,
delivered.disposition === "SETUP_REQUIRED"
? "HOST_APP_BINDING_SETUP_REQUIRED"
: "BOOTSTRAP_DELIVERY_UNKNOWN",
: delivered.blocker ?? "BOOTSTRAP_DELIVERY_UNKNOWN",
);
}
continue;
Expand Down
Loading