Skip to content
Merged
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
6 changes: 6 additions & 0 deletions extensions/googlechat/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ export async function handleGoogleChatAction({
if (messageNames.length === 0) {
return jsonResult({ ok: true, to: space, ...sent });
}
findGoogleChatProgressActivity({
accountId: account.accountId,
spaceId: space,
threadName: deliveredThread,
sessionKey,
})?.noteSeparatePost?.();
Comment on lines +164 to +168

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark accepted chunks before throwing partial delivery

When a long message-tool answer is chunked and a later sendGoogleChatMessage call fails, the handler throws a partial-delivery error after earlier chunks are already visible. This notification runs only after the whole loop succeeds, so the activity is never marked; settlement then preserves folded progress alongside the partial answer. Notify the matching activity before throwing whenever acceptedText is nonempty.

Useful? React with 👍 / 👎.

// Only Chat's confirmed thread proves a source reply when the send inherited it.
const receipt = createMessageReceiptFromOutboundResults({
results: messageNames.map((messageId) => ({
Expand Down
77 changes: 77 additions & 0 deletions extensions/googlechat/src/monitor.reply-target.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GoogleChatApiError } from "./api.js";
import type { GoogleChatIngressLifecycle } from "./monitor-ingress.js";
import type { GoogleChatCoreRuntime, GoogleChatRuntimeEnv } from "./monitor-types.js";
import "./monitor.js";
import { findGoogleChatProgressActivity } from "./progress-activity.js";
import type { GoogleChatEvent } from "./types.js";

const apiMocks = vi.hoisted(() => ({
Expand Down Expand Up @@ -345,6 +346,82 @@ describe("Google Chat automatic reply target reconciliation", () => {
});
});

it("keeps folded progress visible when the turn ends without an answer", async () => {
const account = createAccount({ replyToMode: "all" });
const core = createCore({
run: async () => {
const activity = findGoogleChatProgressActivity({
accountId: account.accountId,
spaceId: SPACE,
threadName: THREAD,
});
expect(await activity?.update("Checking the calendar next.", {})).toBe(true);
},
});
apiMocks.sendGoogleChatMessage.mockResolvedValueOnce({
messageName: TYPING,
threadName: THREAD,
});

await processEvent({ account, core });

expect(apiMocks.deleteGoogleChatMessage).not.toHaveBeenCalled();
expect(apiMocks.updateGoogleChatMessage).toHaveBeenLastCalledWith({
account,
messageName: TYPING,
text: "Checking the calendar next.",
});
});

it("keeps an automatic status notice visible when the turn ends without an answer", async () => {
const account = createAccount({ replyToMode: "all" });
const core = createCore({
run: async (delivery) => {
const notice = { text: "I’m continuing this work.", isStatusNotice: true };
await delivery.deliver(notice, { kind: "block" });
},
});
apiMocks.sendGoogleChatMessage.mockResolvedValueOnce({
messageName: TYPING,
threadName: THREAD,
});

await processEvent({ account, core });

expect(apiMocks.deleteGoogleChatMessage).not.toHaveBeenCalled();
expect(apiMocks.updateGoogleChatMessage).toHaveBeenLastCalledWith({
account,
messageName: TYPING,
text: "I’m continuing this work.",
});
});

it("removes folded progress once an answer is posted separately", async () => {
const account = createAccount({ replyToMode: "all" });
const core = createCore({
run: async () => {
const activity = findGoogleChatProgressActivity({
accountId: account.accountId,
spaceId: SPACE,
threadName: THREAD,
});
await activity?.update("Checking the calendar next.", {});
activity?.noteSeparatePost?.();
},
});
apiMocks.sendGoogleChatMessage.mockResolvedValueOnce({
messageName: TYPING,
threadName: THREAD,
});

await processEvent({ account, core });

expect(apiMocks.deleteGoogleChatMessage).toHaveBeenCalledExactlyOnceWith({
account,
messageName: TYPING,
});
});

it("threads only the first visible answer in first mode", async () => {
const account = createAccount({ replyToMode: "first", typingIndicator: "none" });
const core = createCore({
Expand Down
35 changes: 33 additions & 2 deletions extensions/googlechat/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { resolveWebhookPath } from "openclaw/plugin-sdk/webhook-ingress";
import type { ResolvedGoogleChatAccount } from "./accounts.js";
import {
deleteGoogleChatMessage,
updateGoogleChatMessage,
downloadGoogleChatMedia,
GoogleChatApiError,
sendGoogleChatMessage,
Expand Down Expand Up @@ -387,6 +388,10 @@ async function processGoogleChatEvent(
onError: (error) => runtime.error?.(`Google Chat status update failed: ${String(error)}`),
})
: undefined;
// Progress folded into the activity message stays visible when the turn ends
// without a separately posted answer, e.g. after handing work to a subagent.
let foldedProgressText: string | undefined;
let answerPosted = false;
const unregisterProgressActivity =
activity && typingMessage
? registerGoogleChatProgressActivity({
Expand All @@ -407,7 +412,14 @@ async function processGoogleChatEvent(
}
hooks.assertDirectAdapterHandoff?.();
await hooks.onPlatformSendDispatch?.();
return await activity.updateText(chunk);
const updated = await activity.updateText(chunk);
if (updated) {
foldedProgressText = chunk;
}
return updated;
},
noteSeparatePost: () => {
answerPosted = true;
},
})
: undefined;
Expand All @@ -427,6 +439,18 @@ async function processGoogleChatEvent(
}
const placeholder = typingMessage;
typingMessage = undefined;
if (placeholder && foldedProgressText && !answerPosted) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark observed deliveries as separately posted answers

When a final source reply is confirmed through onObservedReplyDelivery—for example, a shared Gateway delivery—that callback sets only hasVisibleAnswer, not answerPosted. If progress was folded earlier, this condition remains true, so settlement restores the activity and returns instead of deleting it, leaving stale progress beside the confirmed answer. Set the separate-answer flag for observed delivery as well.

Useful? React with 👍 / 👎.

try {
await updateGoogleChatMessage({
account,
messageName: placeholder.name,
text: foldedProgressText,
});
return;
} catch (error) {
runtime.error?.(`Google Chat folded progress restore failed: ${String(error)}`);
}
}
if (placeholder) {
try {
await deleteGoogleChatMessage({ account, messageName: placeholder.name });
Expand Down Expand Up @@ -509,7 +533,13 @@ async function processGoogleChatEvent(
)[0];
if (text) {
try {
await activity.updateText(text);
const updated = await activity.updateText(text);
if (
updated &&
(payload.isCommentary === true || payload.isStatusNotice === true)
) {
foldedProgressText = text;
}
} catch (error) {
runtime.error?.(`Google Chat progress update failed: ${String(error)}`);
}
Expand Down Expand Up @@ -549,6 +579,7 @@ async function processGoogleChatEvent(
!isProgressReply(payload, info?.kind)
) {
hasVisibleAnswer = true;
answerPosted = true;
if (resolveReplyThreadName(payload)) {
hasThreadedReply = true;
}
Expand Down
2 changes: 2 additions & 0 deletions extensions/googlechat/src/progress-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type GoogleChatProgressActivity = {
threadName?: string;
/** Session that owns the turn, so concurrent turns never edit each other's activity. */
sessionKey: string;
/** Records a separate visible post in this placement, so the activity can be removed. */
noteSeparatePost?: () => void;
/** Returns false when the activity message was not edited. */
update: (
text: string,
Expand Down
Loading