Skip to content

session: failed turns replay already-executed side-effectful tool calls (duplicate external writes per retry) #53184

Description

@satwareAG-ironMike

Description

The bug: when a turn fails at the persistence layer (e.g. the session_message insert failure from #53146), opencode drains/retries the turn and re-executes its pending tool calls. A side-effectful call from the failed turn (in our case a bash tea issue create against a forge API) runs once per retry. The agent never receives any result between retries, so no agent-side protocol (search-before-create, verification) can intervene - the replay happens below the reasoning layer.

Blast radius (one incident, one host, one day): 35 duplicate forge issues from a single session, in two bursts at transport-retry cadence (~40-70 s apart), each burst bracketed by Failed to drain Session ERRORs in the server log.

Evidence (happy to share sanitized logs):

Trigger relationship to #53146: #53146 (independent per-process seq counters on a shared db) is one way to fail the turn; the replay is a distinct defect in the retry path. Fixing #53146 removes a common trigger but any other persistence failure would replay side effects again.

Expected behavior: a retried turn must not re-execute tool calls whose execution already started or completed (record intent before dispatch, or mark side-effectful calls as non-replayable and fail the turn explicitly). Failures should surface to the agent as a turn error it can observe, not be silently replayed.

Environment: opencode 2.0.22 (also observed on 1.18.34 fleet-side), Linux workstation, serve --service + TUI topology as in #53146.

Cross-ref: satware.ai/harness#1166 (RCA), satware.ai/harness#1168 (downstream duplication RCA + cleanup), #53146 (seq collision trigger).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions