test(native-chat): pin the replay flag and say why an echo went unmarked

`resolveClaudeReplayWaiter` now settles a send only on the `isReplay` marker,
so `--replay-user-messages` is load-bearing - but no test asserted it was in
CLAUDE_STRUCTURED_BASE_ARGS, and both fake connections synthesize the marker
themselves, so dropping the flag would have left the suite fully green while
every real send blocked its whole ack budget and landed "delivery unconfirmed".

Pin the flag, and warn once when a top-level user frame arrives without the
marker while a send is waiting. A CLI that echoes unmarked is otherwise
indistinguishable at runtime from a turn with no tool boundary inside the
budget: both just report delivery unconfirmed.

Found by the review loop on #15657.
This commit is contained in:
Brennan Benson
2026-08-20 18:38:05 -07:00
parent 0f76371cbd
commit 69d024147b
2 changed files with 29 additions and 0 deletions
@@ -78,11 +78,36 @@ function isClaudeUserMessageReplay(message: Record<string, unknown>): boolean {
return message.type === 'user' && message.parent_tool_use_id === null && message.isReplay === true
}
let warnedAboutMissingReplayMarker = false
/** A CLI that echoes without the marker cannot be told apart at runtime from a
* turn that simply had no boundary inside the ack budget: both just report
* "delivery unconfirmed". Say it once so the cause is diagnosable. */
function warnIfEchoLacksReplayMarker(message: Record<string, unknown>): void {
if (
warnedAboutMissingReplayMarker ||
message.type !== 'user' ||
message.parent_tool_use_id !== null ||
message.isReplay !== undefined ||
message.tool_use_result !== undefined
) {
return
}
warnedAboutMissingReplayMarker = true
console.warn(
'[claude-structured] user frame arrived without isReplay while a send was waiting; ' +
'sends will report delivery unconfirmed until the CLI stamps the marker'
)
}
export function resolveClaudeReplayWaiter(
session: ClaudeSession,
message: Record<string, unknown>
): void {
const isUserReplay = isClaudeUserMessageReplay(message)
if (!isUserReplay && session.dispatchWaiters.length > 0) {
warnIfEchoLacksReplayMarker(message)
}
const isCompletedCommand = message.type === 'result'
if (
(!isUserReplay && !isCompletedCommand) ||
@@ -60,6 +60,10 @@ describe('claude structured launch resolution', () => {
expect(first.args).toContain('--setting-sources')
expect(first.args).toContain(CLAUDE_DEFAULT_SETTING_SOURCES.join(','))
expect(CLAUDE_STRUCTURED_BASE_ARGS).toContain('--verbose')
// Load-bearing: `resolveClaudeReplayWaiter` settles a send only on the
// `isReplay` marker this flag asks for. Drop it and every send blocks its
// whole ack budget and lands "delivery unconfirmed".
expect(CLAUDE_STRUCTURED_BASE_ARGS).toContain('--replay-user-messages')
})
it('resumes the session and leaf at the durable chain head', async () => {