fix: address P2 review comments on compaction notices

P2-1 (agent-runner.ts): Restrict direct completion notice to
block-streaming runs. The condition now checks blockStreamingEnabled
in addition to opts?.onBlockReply, preventing duplicate completion
notices in non-streaming sessions where verboseNotices already handles
the compaction-complete text.

P2-2 (agent-runner-execution.ts): Emit compaction start notice when
streaming is off. blockReplyHandler is a no-op for non-streaming runs,
so add a direct fallback path: when blockStreamingEnabled is false and
opts.onBlockReply is present, send the start notice directly with
applyReplyToMode threading applied.
This commit is contained in:
zidongdesign 2026-03-08 12:39:14 +08:00 committed by Josh Lehman
parent 197ef0a1f5
commit bcc2d2188e
No known key found for this signature in database
GPG Key ID: D141B425AC7F876B
2 changed files with 16 additions and 2 deletions

View File

@ -418,10 +418,24 @@ export async function runAgentTurnWithFallback(params: {
if (phase === "start") {
if (params.opts?.onCompactionStart) {
await params.opts.onCompactionStart();
} else {
} else if (params.blockStreamingEnabled) {
// Route through the shared block reply handler so
// reply-to threading matches other in-run notices.
await blockReplyHandler?.({ text: "🧹 Compacting context..." });
} else if (params.opts?.onBlockReply) {
// blockReplyHandler is a no-op when streaming is disabled.
// Fall back to direct delivery so non-streaming runs also
// receive the compaction start notice.
const currentMessageId =
params.sessionCtx.MessageSidFull ?? params.sessionCtx.MessageSid;
const noticePayload = params.applyReplyToMode({
text: "🧹 Compacting context...",
replyToId: currentMessageId,
replyToCurrent: true,
});
await params.opts.onBlockReply(noticePayload);
} else {
await params.opts?.onBlockReply?.({ text: "🧹 Compacting context..." });
}
}
const completed = evt.data?.completed === true;

View File

@ -423,7 +423,7 @@ export async function runReplyAgent(params: {
// stopped, so the enqueue does not set didStream() = true and cause
// buildReplyPayloads to discard the real assistant reply. We still apply a
// timeout so the notice cannot stall the run indefinitely.
if (autoCompactionCompleted && opts?.onBlockReply) {
if (autoCompactionCompleted && blockStreamingEnabled && opts?.onBlockReply) {
const verboseEnabled = resolvedVerboseLevel !== "off";
const completionText = verboseEnabled
? `🧹 Auto-compaction complete.`