Repository navigation
Conversation
Greptile SummaryThis PR adds a one-shot suppression mechanism to prevent duplicate user-message persistence when the embedded runner retries with a fallback model after the current turn has already been written to the session transcript. The approach is sound: a callback fires on actual persistence, a run-scoped flag records that, and subsequent fallback attempts receive Confidence Score: 5/5Safe to merge; no correctness issues found. The suppression mechanism is correctly scoped to the current turn and properly resets across outer retry iterations. All findings are P2 (style/type consistency). The core logic — tracking persistence via callback, suppressing only on fallback retries after the flag flips, resetting per outer loop iteration — is sound and well-tested. No files require special attention.
|
| */ | ||
| allowTransientCooldownProbe?: boolean; | ||
| suppressNextUserMessagePersistence?: boolean; | ||
| onUserMessagePersisted?: () => void; |
There was a problem hiding this comment.
onUserMessagePersisted signature is narrower than the guard's
RunEmbeddedPiAgentParams declares onUserMessagePersisted?: () => void, but installSessionToolResultGuard calls it as opts?.onUserMessagePersisted?.(finalMessage), passing the persisted user message as an argument. TypeScript's callback assignability makes this compile without error, but the narrower signature in params.ts (and the matching declaration in attempt-execution.ts) hides that the callback receives the user message. Any future caller who wants to inspect the persisted message from this hook would have to discover the richer guard-level signature independently.
Consider aligning the declaration here with the guard's full signature, or add a comment noting that the underlying guard does supply the message argument.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/params.ts
Line: 133
Comment:
**`onUserMessagePersisted` signature is narrower than the guard's**
`RunEmbeddedPiAgentParams` declares `onUserMessagePersisted?: () => void`, but `installSessionToolResultGuard` calls it as `opts?.onUserMessagePersisted?.(finalMessage)`, passing the persisted user message as an argument. TypeScript's callback assignability makes this compile without error, but the narrower signature in `params.ts` (and the matching declaration in `attempt-execution.ts`) hides that the callback receives the user message. Any future caller who wants to inspect the persisted message from this hook would have to discover the richer guard-level signature independently.
Consider aligning the declaration here with the guard's full signature, or add a comment noting that the underlying guard does supply the message argument.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Addressed in 5b523195c7.
I aligned the callback signature across run/params.ts, attempt-execution.ts, and the embedded attempt wiring so onUserMessagePersisted now explicitly receives the persisted user message instead of hiding that richer contract behind a () => void type.
|
Status note from our side: this is the clean v2 PR to review for the duplicate-persistence-on-fallback fix.
If maintainers still want this behavior fixed upstream, this is the minimal agents-only diff we would point at rather than the older PR. |
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. Source inspection on current main shows Next step before merge Security Review detailsBest possible solution: Land this PR or an equivalent agents-only fix after exact-head CI, keeping suppression tied to actual current-turn append success. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection on current main shows Is this the best way to solve the issue? Yes. The callback-based one-shot guard is the narrowest maintainable solution because it suppresses only duplicate retry transcript writes after a real append while preserving the retry prompt sent to the model. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 89ac1261800d. |
831a96b to
a90c197
Compare
a90c197 to
a5fea22
Compare
|
Merged via squash.
Thanks @dashhuang! |
…penclaw#63696) * fix(agents): suppress duplicate user persistence on fallback retries * refactor(agents): align persisted-user callback types * docs: note fallback transcript dedupe * refactor(agents): remove fallback persistence casts --------- Co-authored-by: Altay <[email protected]>
…penclaw#63696) * fix(agents): suppress duplicate user persistence on fallback retries * refactor(agents): align persisted-user callback types * docs: note fallback transcript dedupe * refactor(agents): remove fallback persistence casts --------- Co-authored-by: Altay <[email protected]>
…penclaw#63696) * fix(agents): suppress duplicate user persistence on fallback retries * refactor(agents): align persisted-user callback types * docs: note fallback transcript dedupe * refactor(agents): remove fallback persistence casts --------- Co-authored-by: Altay <[email protected]>
…penclaw#63696) * fix(agents): suppress duplicate user persistence on fallback retries * refactor(agents): align persisted-user callback types * docs: note fallback transcript dedupe * refactor(agents): remove fallback persistence casts --------- Co-authored-by: Altay <[email protected]>
Summary
Why
#58301 preserves the original message body on fallback retries, which is the right fix for prompt continuity. But once the original body is preserved, fallback retries can still append that same user turn again if the current turn already flushed before the retry.
This patch narrows the suppression decision to the current turn only:
That keeps retry context intact without duplicating the transcript.
What changed
src/agents/session-tool-result-guard.tsonUserMessagePersistedcallback that fires only after a user message is successfully writtensrc/agents/session-tool-result-guard-wrapper.tsguardSessionManager(...)src/agents/pi-embedded-runner/run/params.tssrc/agents/pi-embedded-runner/run.tssrc/agents/pi-embedded-runner/run/attempt.tssrc/agents/command/attempt-execution.tsonUserMessagePersistedandsuppressPromptPersistenceOnRetryintorunEmbeddedPiAgent(...)src/agents/agent-command.tscurrentTurnUserMessagePersistedflag and suppress duplicate persistence only on fallback retries after that flag flips truesrc/agents/session-tool-result-guard.test.tssrc/agents/agent-command.live-model-switch.test.tsScope
Related
Validation
Ran locally on a fresh
mainclone:corepack pnpm exec vitest run --config vitest.config.ts src/agents/session-tool-result-guard.test.ts src/agents/agent-command.live-model-switch.test.ts src/agents/pi-embedded-runner.guard.test.ts src/agents/command/attempt-execution.test.ts4 files passed, 52 tests passedcorepack pnpm exec vitest run --config vitest.e2e.config.ts src/agents/model-fallback.run-embedded.e2e.test.ts1 file passed, 13 tests passedAlso checked:
git diff --checkNotes
corepack pnpm buildcurrently fails on freshmainbefore this diff is applied due an unrelated baseline resolver error:Could not resolve 'acpx/runtime' in extensions/acpx/src/runtime.tsI did not change any
acpxfiles in this PR.