anomalyco / anomalyco/opencode
provider: stale composite reasoning item id (rs_A:rs_B) replayed after restart → invalid_request_error
@rekram1-node is already working on this.
Since Sep 10, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
After a service restart, the first reasoning turn of a resumed session fails on
a Responses-API provider with invalid_request_error: Referenced reasoning item 'rs_A:rs_B' was not found or has expired. Stored reasoning parts carry a
colon-composite itemId (responseRef:itemRef), which the backend accepts
while fresh but rejects once its server-side response state is gone. Every
subsequent fresh turn works; only the first post-restart resumed turn fails.
Environment
- opencode version: 0.0.0-beta-19271
- OS: Linux 6.17.0-1009-oracle (linux arm64)
- Terminal: Unavailable: headless service (systemd)
- Shell: /bin/bash
- Install/channel: beta
- Active plugins: oh-my-opencode-slim, conclave-v2 (local path),
magic-context-v2 (local path). Note: a temporary redacted wire-logging
plugin was attached during diagnosis and removed afterwards.
Reproduction
- Start a reasoning session against a Responses-style provider that keeps
server-side response state (observed via OpenCode Zen Go gateway). - Run several reasoning turns (succeeds; reasoning parts persist with
metadata.openai.itemIdshapedrs_<A>:rs_<B>). - Restart the opencode service.
- Resume the same session with one more reasoning turn.
- First post-restart turn fails with the error below; later turns recover.
Expected Behavior
Resume after restart either replays a reference the backend still resolves, or
falls back to self-contained reasoning content without failing the turn.
Actual Behavior
Error from provider (Console Go): Upstream request failed: [invalid_request_error] Referenced reasoning item 'rs_6aa28a10c05cf9f566f44022:rs_01a08aeb51217b92a5b853a0cb5b20ca' was not found or has expired.
Observed twice, both times as the first reasoning turn after a restart
(05:15→05:26 and 10:43→10:44 UTC); hundreds of same-format composite ids were
accepted intra-lifetime, so format alone is not the trigger — staleness across
restart/resume is.
Additional Context
- Stored part (redacted):
{"type":"reasoning","text":"", "metadata":{"openai":{"itemId":"rs_<A>:rs_<B>", "reasoningEncryptedContent":"<present, long blob>"}}}— i.e. empty text,
composite id, encrypted content present. - Session types affected: long-lived resumed sessions; fresh sessions unaffected.
- Not caused by user plugins: Magic Context v2 only appends a text system
block (source-verified, no reasoning handling); oh-my-opencode-slim contains
zero references toprevious_response_id/encrypted_content(source-verified). - Frequency: intermittent — only first post-restart resumed reasoning turn.
- Workaround: resend the message (next turn self-heals).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.