Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
366f0a9
test(opencode): prove Windows owner-death cleanup with real processes…
arena-agent Oct 31, 2026
34d8f92
test(opencode): give the stall test's post-bound phases fresh deadlines
arena-agent Oct 31, 2026
2edb1d9
test(opencode): make the stall test verify cleanup even when its firs…
arena-agent Oct 31, 2026
6c4e760
test(opencode): return the stall test to the accepted budget envelope…
arena-agent Oct 31, 2026
9bbe7bd
test(opencode): MUTATION CONTROL - disable the job binding (reverted …
arena-agent Oct 31, 2026
bd64297
Revert "test(opencode): MUTATION CONTROL - disable the job binding (r…
agenteinstinct1-max Oct 31, 2026
05fe976
test(opencode): give the happy path fresh per-phase deadlines too
arena-agent Oct 31, 2026
44e0637
feat(opencode): recover the turn after the repetition guard trips
agenteinstinct1-max Oct 31, 2026
65efb5b
Merge origin/dev-vibecoded into arena/bd152f4e-silvercode (sync head)
agenteinstinct1-max Oct 31, 2026
85ab78e
Merge PR #747 head (65efb5b) into the repair branch (sync head)
agenteinstinct1-max Oct 31, 2026
d53ccb4
fix(opencode): make repetition recovery run-wide, visible and typed (…
agenteinstinct1-max Oct 31, 2026
bb30e16
chore: integrate accepted tip 4a08a04
agenteinstinct1-max Nov 1, 2026
17d558c
fix(opencode): integrate repetition recovery from exact PR 757 head
agenteinstinct1-max Nov 1, 2026
ededd37
test(opencode): prove queued input survives terminal repetition recovery
agenteinstinct1-max Nov 1, 2026
5293dd1
fix(opencode): let a queued prompt settle on its own guard-recovery a…
arena-agent Nov 1, 2026
503b5c7
chore(opencode): merge current integration base
agenteinstinct1-max Nov 1, 2026
cdbc4c8
fix(opencode): fail closed on repeated recovery results
agenteinstinct1-max Nov 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/opencode/src/session/llm/repetition-guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LLMEvent } from "@opencode-ai/llm"
import { isRecord } from "@/util/record"
import { Effect, Stream } from "effect"

// SessionRetry.retryable excludes messages with this prefix, so a tripped
Expand Down Expand Up @@ -58,6 +59,19 @@ export class RepetitionDetectedError extends Error {
}
}

// Stable identity for a tripped guard on the persisted assistant message.
// MessageV2.fromError records this marker in UnknownError.data.ref; the error
// keeps its name and message text, so every existing renderer and the retry
// exclusion see exactly what they saw before. Recovery reads the marker instead
// of matching REPETITION_MESSAGE, because a provider HTTP error can quote the
// guard text while being a different failure entirely (issue #738).
export const ERROR_REF = "repetition-guard"

/** True when a persisted `Assistant["error"]` is the harness's own guard abort. */
export function isStoredError(error: unknown): boolean {
return isRecord(error) && error.name === "UnknownError" && isRecord(error.data) && error.data.ref === ERROR_REF
}

type GuardOptions = {
readonly thresholds: Thresholds
}
Expand Down
32 changes: 26 additions & 6 deletions packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SessionID, MessageID } from "./schema"
import { RepetitionGuard } from "./llm/repetition-guard"
import { SessionV1 } from "@opencode-ai/core/v1/session"
import { ProviderV2 } from "@opencode-ai/core/provider"
import {
Expand Down Expand Up @@ -68,10 +69,9 @@ type Cursor = typeof Cursor.Type

const decodeCursor = Schema.decodeUnknownSync(Cursor)

export class InvalidCursorError extends Schema.TaggedErrorClass<InvalidCursorError>()(
"MessageV2.InvalidCursorError",
{ message: Schema.String },
) {
export class InvalidCursorError extends Schema.TaggedErrorClass<InvalidCursorError>()("MessageV2.InvalidCursorError", {
message: Schema.String,
}) {
static isInstance(input: unknown): input is InvalidCursorError {
return input instanceof InvalidCursorError
}
Expand Down Expand Up @@ -263,8 +263,18 @@ export const toModelMessagesEffect = Effect.fnUntraced(function* (
if (
msg.info.error &&
!(
AbortedError.isInstance(msg.info.error) &&
msg.parts.some((part) => part.type !== "step-start" && part.type !== "reasoning")
(AbortedError.isInstance(msg.info.error) &&
msg.parts.some((part) => part.type !== "step-start" && part.type !== "reasoning")) ||
// Issue #738: a guard abort is a deliberate cutoff of a generation,
// not evidence that its work should disappear. The parts persisted
// before the abort (streamed text and any tool call that already
// completed) stay visible to the recovery request, so the model can
// build on what happened instead of re-issuing a finished call.
// Replaying this transcript state never re-executes a tool: completed
// calls are presented with their recorded output, and calls still
// pending/running keep their existing "[Tool execution was
// interrupted]" rendering below.
RepetitionGuard.isStoredError(msg.info.error)
)
) {
continue
Expand Down Expand Up @@ -732,6 +742,16 @@ export function fromError(
},
{ cause: e },
).toObject()
// Issue #738: a tripped repetition guard is the harness's own abort, so it
// is recorded with a stable identity instead of being inferred later from
// its message text. The UnknownError name and message stay byte-identical
// (renderers and SessionRetry.retryable read them); data.ref is the typed
// marker recovery checks, and a provider HTTP error can never carry it.
case e instanceof RepetitionGuard.RepetitionDetectedError:
return new NamedError.Unknown(
{ message: errorMessage(e), ref: RepetitionGuard.ERROR_REF },
{ cause: e },
).toObject()
// Named session errors thrown upstream (e.g. from a provider-error stream
// event, #409) keep their classification instead of degrading to Unknown.
case ContextOverflowError.isInstance(e):
Expand Down
Loading
Loading