Skip to content

Commit 1ff40da

Browse files
committed
fix(agent): keep finality evidence private to runtimes
1 parent 01ca619 commit 1ff40da

8 files changed

Lines changed: 30 additions & 37 deletions

File tree

‎extensions/codex/src/app-server/dynamic-tools.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import {
3030
isMessagingToolSendAction,
3131
normalizeHeartbeatToolResponse,
3232
projectRuntimeToolInputSchema,
33-
readMessageToolSourceReplyFinal,
34-
resolveMessageToolSourceReplyFinal,
3533
resolveToolExecutionErrorKind,
3634
resolveToolResultFailureKind,
3735
runAgentHarnessAfterToolCallHook,
@@ -792,11 +790,7 @@ export function createCodexDynamicToolBridge(params: {
792790
params.hookContext?.sourceReplyDeliveryMode === "message_tool_only" &&
793791
toolName === "message" &&
794792
(toolConfirmedSourceReply || deliveredSourceReply || receiptConfirmedSourceReply);
795-
const sourceReplyFinal = confirmedSourceReply
796-
? (readMessageToolSourceReplyFinal(rawResult) ??
797-
readMessageToolSourceReplyFinal(result) ??
798-
resolveMessageToolSourceReplyFinal(executedArgs.final))
799-
: undefined;
793+
const sourceReplyFinal = confirmedSourceReply ? executedArgs.final !== false : undefined;
800794
collectToolTelemetry({
801795
toolName,
802796
args: executedArgs,

‎extensions/codex/src/app-server/run-attempt-finalize.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
embeddedAgentLog,
55
finalizeHarnessContextEngineTurn,
66
formatErrorMessage,
7-
hasCompletedSourceReplyDeliveryEvidence,
87
resolveContextEngineOwnerPluginId,
98
runAgentHarnessLlmOutputHook,
109
runHarnessContextEngineMaintenance,
@@ -47,6 +46,12 @@ import {
4746
refreshCodexUsageLimitPromptError,
4847
} from "./usage-limit-error.js";
4948

49+
function hasCompletedCodexSourceReplyDelivery(result: EmbeddedRunAttemptResult): boolean {
50+
return [result.messagingToolSentTargets, result.messagingToolSourceReplyPayloads].some(
51+
(entries) => entries?.some((entry) => entry.sourceReplyFinal === true),
52+
);
53+
}
54+
5055
export async function finalizeCodexAttempt(
5156
resources: CodexAttemptResources,
5257
turnRuntime: CodexAttemptTurnState,
@@ -285,7 +290,7 @@ export async function finalizeCodexAttempt(
285290
(completedTurnStatus === "completed" || recoveredTurnWatchTimeout || locallyCompletedTurn);
286291
// buildResult retains canonical source-delivery markers. Tool-only visible
287292
// output must clear an otherwise stale empty/reasoning-only classification.
288-
const completedSourceReply = turnSucceeded && hasCompletedSourceReplyDeliveryEvidence(result);
293+
const completedSourceReply = turnSucceeded && hasCompletedCodexSourceReplyDelivery(result);
289294
if (completedSourceReply) {
290295
// Harness classification only sees assistant/reasoning/plan projections.
291296
// A reply delivered entirely through the source message tool is visible

‎src/agents/embedded-agent-message-tool-source-reply.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ describe("message-tool source reply finality", () => {
358358
expect(
359359
readMessageToolSourceReplyFinal({ details: { payload: { sourceReplyFinal: true } } }),
360360
).toBe(true);
361-
expect(readMessageToolSourceReplyFinal({ details: { deliveryStatus: "sent" } })).toBeUndefined();
361+
expect(
362+
readMessageToolSourceReplyFinal({ details: { deliveryStatus: "sent" } }),
363+
).toBeUndefined();
362364
});
363365
});
364366

‎src/agents/embedded-agent-message-tool-source-reply.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ export function resolveMessageToolSourceReplyFinal(value: unknown): boolean {
4848
}
4949

5050
/** Read the producer-owned finality marker from a message-tool result envelope. */
51-
export function readMessageToolSourceReplyFinal(
52-
value: unknown,
53-
depth = 0,
54-
): boolean | undefined {
51+
export function readMessageToolSourceReplyFinal(value: unknown, depth = 0): boolean | undefined {
5552
if (!value || typeof value !== "object" || depth > 4) {
5653
return undefined;
5754
}

‎src/plugin-sdk/agent-harness-runtime.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ export { FAST_MODE_AUTO_PROGRESS_KIND } from "../auto-reply/reply-payload.js";
6565
export {
6666
isDeliveredMessageToolOnlySourceReplyResult,
6767
isDeliveredMessagingToolResult,
68-
readMessageToolSourceReplyFinal,
69-
resolveMessageToolSourceReplyFinal,
7068
} from "../agents/embedded-agent-message-tool-source-reply.js";
71-
export {
72-
hasCompletedSourceReplyDeliveryEvidence,
73-
} from "../agents/embedded-agent-runner/delivery-evidence.js";
7469
export { formatFastModeAutoProgressText, resolveFastModeForElapsed } from "../shared/fast-mode.js";
7570
export type { AgentMessage } from "../agents/runtime/index.js";
7671
export type { FastModeAutoProgressState } from "../shared/fast-mode.js";

‎test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/discord-group-codex-message-tool.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,16 @@ This is the deterministic model-bound layer stack OpenClaw can snapshot for the
225225
"roughTokens": 15373
226226
},
227227
"openClawDeveloperInstructions": {
228-
"chars": 3811,
229-
"roughTokens": 953
228+
"chars": 3686,
229+
"roughTokens": 922
230230
},
231231
"totalTextOnly": {
232-
"chars": 28194,
233-
"roughTokens": 7049
232+
"chars": 28069,
233+
"roughTokens": 7018
234234
},
235235
"totalWithDynamicToolsJson": {
236-
"chars": 89686,
237-
"roughTokens": 22422
236+
"chars": 89561,
237+
"roughTokens": 22391
238238
},
239239
"userInputText": {
240240
"chars": 1300,

‎test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/telegram-direct-codex-message-tool.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,16 @@ This is the deterministic model-bound layer stack OpenClaw can snapshot for the
225225
"roughTokens": 15296
226226
},
227227
"openClawDeveloperInstructions": {
228-
"chars": 2702,
229-
"roughTokens": 676
228+
"chars": 2577,
229+
"roughTokens": 645
230230
},
231231
"totalTextOnly": {
232-
"chars": 26714,
233-
"roughTokens": 6679
232+
"chars": 26589,
233+
"roughTokens": 6648
234234
},
235235
"totalWithDynamicToolsJson": {
236-
"chars": 87898,
237-
"roughTokens": 21975
236+
"chars": 87773,
237+
"roughTokens": 21944
238238
},
239239
"userInputText": {
240240
"chars": 929,

‎test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/telegram-heartbeat-codex-tool.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,16 @@ This is the deterministic model-bound layer stack OpenClaw can snapshot for the
226226
"roughTokens": 15679
227227
},
228228
"openClawDeveloperInstructions": {
229-
"chars": 2702,
230-
"roughTokens": 676
229+
"chars": 2577,
230+
"roughTokens": 645
231231
},
232232
"totalTextOnly": {
233-
"chars": 27130,
234-
"roughTokens": 6783
233+
"chars": 27005,
234+
"roughTokens": 6752
235235
},
236236
"totalWithDynamicToolsJson": {
237-
"chars": 89848,
238-
"roughTokens": 22462
237+
"chars": 89723,
238+
"roughTokens": 22431
239239
},
240240
"userInputText": {
241241
"chars": 1271,

0 commit comments

Comments
 (0)