Repository navigation
fix(session): bound repetition-guard recovery to its own caller (Refs #738) - #777
Closed
agenteinstinct1-max wants to merge 1 commit into
Closed
agenteinstinct1-max wants to merge 1 commit into
agenteinstinct1-max wants to merge 1 commit into
Conversation
…738) A repetition-guard abort was handled by a single "is this the newest user message" check, so a recovery instruction could be consumed by, or dangle behind, a prompt queued while it ran, and a silent injection could suppress the one recovery the aborted prompt was owed. This replay applies the #738 work on top of the current accepted tip instead of the stale tree PR #769 was based on: - repetition-guard: persist a stable `data.ref` marker on the guard abort so recovery reads identity, not message text (an HTTP 400 that quotes the guard text is a different failure). - message-v2: keep the parts a guard abort already persisted, so a completed tool call stays visible to the recovery request and is not re-executed. - subagent-result: declare a recovery's prompt lineage in its synthetic part metadata and treat exactly that continuation as a continuation. - prompt: choose the generation target from the transcript plus the live set of waiting callers, scope the recovery budget per prompt lineage, settle each caller on its own answer, and preserve a persisted no-reply intent. - schema: store `PromptInput.noReply` on the user message, because part shape cannot distinguish a silent injection from a caller that submitted synthetic parts. Recovery wording now states that earlier copies of the repeated fragment stay in the transcript and only the output past the cutoff is missing. Refs #738 Co-authored-by: arena-agent <[email protected]>
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Refs #738 (not
Closes: the report describes a symptom we can now bound and prove, but the underlying prompt/run architecture keeps the door open for adjacent ordering bugs; #738 lists four acceptance points and all four have dedicated tests here).This PR replaces the superseded draft #769. It is a clean replay of the six-file #738 change on top of the current accepted tip, not a rebase or a revert of anything accepted.
Type of change
What does this PR do?
A repetition-guard abort cuts a generation off mid-stream. #738 asks that the aborted prompt get exactly one bounded continuation, that the continuation stay with that prompt even when another prompt is queued/created/persisted while it runs, that a silent injection never suppress or steal it, and that nothing be re-executed or re-requested.
Base and head
dev-vibecoded@a241c84e3b57c958977fd31d51cc3a30e84d341f(the current accepted tip, selector fix(tui): simplify agent effort selector copy (Supersedes #762, Refs #716) #771)arena/47d94bed-silvercode@bb5dc0bfb6b298b2b1056505d67f2d3092a51edfcdbc4c842e7c9520b077e6785883e1e1a3712b03(fix(opencode): keep repetition recovery results with their callers (Refs #738) #769), which was based on503b5c7and therefore carried a stale reverse-fix(tui): simplify agent effort selector copy (Supersedes #762, Refs #716) #771 delta. That tree is not part of this PR.Files (7)
packages/opencode/src/session/llm/repetition-guard.ts— persists a stabledata.refmarker on the guard abort. Recovery now identifies its own abort by typed identity, not by message text, so an HTTP 400 that happens to quote the guard text is a different failure (test included).packages/opencode/src/session/message-v2.ts— records that marker, and keeps the parts a guard abort had already persisted. Because of this a completed tool call stays visible to the continuation request, so the model builds on it instead of issuing it again (test asserts one call, recorded output, no second execution). A provider HTTP error cannot carry the marker, so nothing else changes classification.packages/opencode/src/session/subagent-result.ts— the recovery message declares{ promptID, attempt }in its synthetic text-part metadata, and only that exact continuation counts as a continuation of its declared prompt. A synthetic-only user message that is anything else (shell marker, task summary, bridge text) is still a boundary, and a recovery whose declared prompt is not its immediate predecessor is treated as a boundary instead of borrowing neighbour lineage.packages/opencode/src/session/prompt.ts— the behavioural core:generationTargetchooses the message a generation belongs to from the transcript and the live set of callers currently waiting: (1) an unanswered recovery continuation the runner already injected, (2) the newest prompt whose caller is still waiting and unanswered, (3) a message persisted after the latest assistant, (4) the owner of the turn that produced the latest assistant, (5) newest replyable / newest message.cancel, a released queued prompt stays persisted and unanswered forever. A caller registers in a per-session refcount while it is inside the run.REPETITION_RECOVERY_MAX = 1), so a second trip surfaces the error instead of looping, and a spent lineage is never regenerated.expectsReplyrespects the persisted no-reply intent, so a silent marker cannot suppress the recovery the aborted prompt is owed.packages/schema/src/v1/session.ts— seventh file, added deliberately:User.noReplyis the persisted form ofPromptInput.noReply. Previously the intent existed only in memory, so a later run could not tell a silent injection from a caller that legitimately submitted synthetic parts. Part shape cannot stand in for it, which is exactly the gap that let a silent marker suppress the P1 recovery. Optional field, no migration needed.packages/opencode/test/session/prompt.test.ts— the eight opencode: recover the task after the repetition guard trips instead of abandoning the turn #738 guard tests (Q1/Q2/Q3, HTTP-400-quote, adversarial cases) plus the controlled-runtime coverage described below; each test has its own prompt/call/parent/idle/text assertions.packages/opencode/test/session/subagent-result.test.ts— lineage helper unit tests, including the "another synthetic message is still a boundary" and "marker readable only from a synthetic text part" directions.Behaviour covered by new/rewritten tests (all against the real prompt runtime with a scripted provider, not a stub of the logic):
[P1, A1 trip, r1, P2]: the later P2 does not steal the generation, and r1 does not dangle on a P1 guard error.UnknownError/parts: []with no generation.No budget, timeout or assertion was relaxed; no test was retried into green.
How did you verify your code works?
Bun 1.3.14,
packages/opencode, this sandbox (2 vCPU / 4 GB).bun test --timeout 30000 test/session/prompt.test.ts→ 151 pass / 1 skip / 0 fail, 888expect()calls, 258.9 s (skip is the pre-existing "v2 projector disabled" case).-t "repetition-guard"→ 12 pass / 0 fail.bun test --timeout 30000 test/session/subagent-result.test.ts test/session/llm/repetition-guard.test.ts test/session/llm-repair.test.ts→ 63 pass / 0 fail.bun test --timeout 30000 test/permission test/permission-task.test.ts→ 126 pass / 0 fail (test(opencode): preload config before permission waits (Refs #489, #732) #751 surface, untouched by this PR, re-run as a cross-check).bun test --timeout 30000 test/session(36 files) → 878 pass / 8 skip / 1 todo / 1 fail; the failure is the pre-existing timing testmodel switch during long backoff cancels retry promptly (not after full delay)at 2953 ms under full-directory load. Re-run standalone,test/session/model-switch-retry.test.ts→ 5 pass / 0 fail (same test 1197 ms). See unresolved below — I am not claiming this is fixed.NODE_OPTIONS=--max-old-space-size=3072 bun run typecheck→ clean. The plain script OOMs in this 4 GB sandbox (FATAL ERROR: Ineffective mark-compacts, ~1.9 GB heap) becausetscover the whole package needs more than the default ceiling; this is sandbox memory, not a code error, and no type errors are reported.prompt.ts/prompt.test.tswere not prettier-clean, so a small number of whitespace-only lines appear in the diff;git diff --ignore-all-spaceshows the semantic change only.Positive mutants (each one re-broken on the green tree, then restored)
message-v2.ts: replacing theRepetitionGuard.isStoredError(...)clause withfalsefails 2 guard tests — the recovery injection and the "completed tool call stays visible".prompt.tsexpectsReply: droppingnoReply !== truefails "a silent no-reply marker does not suppress the one recovery".prompt.tstarget rule 2: droppingwaiting.has(...)fails "queued prompts are released by cancel and the next prompt runs once".Scope
git diff --stat a241c84..HEADis exactly the 7 files above (2,024 insertions, 229 deletions), of which ~1,780 are tests.llm.ts,llm-repair.test.ts, thellm-server.tstoolRawhelpers, the #751 permission tests, the #735 activity code/tests and both CLI retry fixtures are byte-identical toa241c84— no file outside the list is touched.Unresolved / not claimed
<1500 msmodel-switch timing test fails only under full-directory load in this sandbox (2953 ms) and passes standalone (1197 ms). This was already unexplained in the previous attempt; it is not addressed here and not caused by the guard changes (no retry/backoff file is touched).state-840/kv.jsonreadiness race and a one-off mime-prep failure. Neither is reproduced or explained here.<1mss-liver case was never hit live, so this PR does not claim it as verified.Screenshots / recordings
Not a UI change.
Checklist