GeezerVison is showing github.com — fix(opencode): show compaction progress with OpenCode 2.1+ by juliusmarminge · Pull Request #26206 · pingdotgg/t3code
Conversation
Problem
OpenCode 2.1+ no longer sends data.recent on session.compaction.started and session.compaction.ended. T3 bundles the 2.0.28 OpenCode protocol, which still requires it, so both live /api/event frames fail decoding and are silently skipped. The adapter never sees them, and an OpenCode thread never shows "Compacting context" or "Context compacted". Reproduced by driving real opencode serve 2.1.4 and 2.2.0 through T3's OpenCode2Client and running /compact (client.session.compact): both events appear on the wire, and T3 delivers neither. On 2.0.28 it delivers both.
Change
When a frame fails the normal decode, and it is a compaction start or end event with no recent key, OpenCode2Client decodes it again with recent: "". T3 never reads that field. Frames that decode today, including 2.0.x frames carrying recent, keep the original path. Any other failure still falls through to the existing undecodable handling. No dependency bump. Message-history decoding is untouched.
Scope and approval
Fixes #26193
Triaged via the automated issue flow.
Verification
vp test run src/server/v2/OpenCode2Client.test.ts in packages/provider-opencode:
- The new test
delivers compaction events from OpenCode 2.1 feeds the two frames captured from a real 2.1.4 server through OpenCode2Client.layer.
- On main it fails with
expected [] to deeply equal [ 'session.compaction.started', 'session.compaction.ended' ]. With this change, 2/2 pass.
vp run check:changed: format, lint, knip, typecheck (10 packages) and tests all pass.
- Runtime transcript: a scratch driver using
OpenCode2Client.layer + FetchHttpClient against real @opencode/cli servers. It creates a session, sends one prompt, then runs client.session.compact, while curl captures the raw SSE stream.
| OpenCode |
Wire (started / ended, recent present?) |
T3 delivered at main b88da91397 |
T3 delivered at 6aae4aa4f4 |
| 2.0.28 |
1 / 1, yes |
1 / 1 |
— (unchanged path) |
| 2.1.4 |
1 / 1, no |
0 / 0 |
1 / 1 |
| 2.2.0 |
1 / 1, no |
0 / 0 |
1 / 1 |
There is no visible surface beyond the existing compaction item, so this PR has no captures. Not checked: the adapter rendering of the compaction item in a running T3 thread. That adapter branch is unchanged and is reached once the event decodes.
Runtime transcript
# #26193 runtime transcript
Driver: driver.ts (T3's OpenCode2Client.layer + FetchHttpClient) against a real 'opencode serve' from @opencode/cli; create session, prompt claude-haiku-5-5, then client.session.compact. Raw /api/event SSE captured in parallel with curl. Synthetic scratch project; no real T3 data.
## OpenCode 2.1.4 @ main-b88da91397
wire: started=1 ended=1; frames carrying data.recent=0
T3 decoded: started=0 ended=0
started frame on wire:
"type":"session.compaction.started","location":{"directory":"/tmp/issue-lead-26193-r1/oc/proj"},"data":{"sessionID":"ses_e80415922ffetjml4RUW7tRPQL","reason":"manual","inputID":"msg_17fbf08b10019CxokkaEaAa
## OpenCode 2.2.0 @ main-b88da91397
wire: started=1 ended=1; frames carrying data.recent=0
T3 decoded: started=0 ended=0
started frame on wire:
"type":"session.compaction.started","location":{"directory":"/tmp/issue-lead-26193-r1/oc/proj2.2.0"},"data":{"sessionID":"ses_e803eadaeffejfXv1twitAWhI1","reason":"manual","inputID":"msg_17fc1b70b001k1g7bS
## OpenCode 2.0.28 @ main-b88da91397
wire: started=1 ended=1; frames carrying data.recent=2
T3 decoded: started=1 ended=1
started frame on wire:
"type":"session.compaction.started","location":{"directory":"/tmp/issue-lead-26193-r1/oc/proj2.0.28"},"data":{"sessionID":"ses_e803eadb0ffeOa2YNsXs5w08MP","reason":"manual","recent":"","inputID":"msg_17fc1
## OpenCode 2.1.4 @ fix-6aae4aa4f4
wire: started=1 ended=1; frames carrying data.recent=0
T3 decoded: started=1 ended=1
started frame on wire:
"type":"session.compaction.started","location":{"directory":"/tmp/issue-lead-26193-r1/oc/proj2.1.4"},"data":{"sessionID":"ses_e8039023effep7TFg7SOOYbckq","reason":"manual","inputID":"msg_17fc760f6001jb3s5c
## OpenCode 2.2.0 @ fix-6aae4aa4f4
wire: started=1 ended=1; frames carrying data.recent=0
T3 decoded: started=1 ended=1
started frame on wire:
"type":"session.compaction.started","location":{"directory":"/tmp/issue-lead-26193-r1/oc/proj2.2.0"},"data":{"sessionID":"ses_e8039022dffevNL5eo9BNOq02Q","reason":"manual","inputID":"msg_17fc75fa2001tM6S0o
## Decoder check of the 2.1.4 frames on main
session.compaction.started data keys: sessionID,reason,inputID | as sent: REJECTED SchemaError(Missing key at ["data"]["recent"] Expected a string matching template literal parts | with recent: ok
session.compaction.ended data keys: sessionID,reason,model,text,tokens,cost | as sent: REJECTED SchemaError(Missing key at ["data"]["recent"] Expected a string matching template literal parts | with recent: ok
Scratch driver (not committed)
// Scratch repro for #26193: drives a real OpenCode 2.x server through T3's OpenCode2Client
// and prints every event T3's decoder hands to the adapter. Run from packages/provider-opencode.
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Stream from "effect/Stream";
import * as FetchHttpClient from "effect/http/FetchHttpClient";
import { AbsolutePath, Location, Session } from "@opencode/client/effect";
import * as OpenCode2Client from "./src/server/v2/OpenCode2Client.ts";
const [baseUrl, password, directory] = process.argv.slice(2);
const program = Effect.gen(function* () {
const opencode = yield* OpenCode2Client.OpenCode2Client;
const { client, events } = yield* opencode.connect({ baseUrl, password });
const stream = yield* events;
const seen: string[] = [];
const fiber = yield* stream.pipe(
Stream.runForEach((event) =>
Effect.sync(() => {
if (event.type.startsWith("session.") || event.type.startsWith("unreadable.")) {
seen.push(event.type);
console.log("T3 decoded:", event.type);
}
}),
),
Effect.forkChild,
);
const created = yield* client.session.create({
location: Location.PublicRef.make({ directory: AbsolutePath.make(directory) }),
model: { providerID: "anthropic", id: "claude-haiku-5-5" } as never,
});
console.log("session", created.id);
const sessionID = Session.ID.make(created.id);
yield* client.session.prompt({ sessionID, text: "Reply with the single word: ready." } as never);
yield* Effect.sleep("25 seconds");
console.log("--- sending /compact");
yield* client.session.compact({ sessionID } as never);
yield* Effect.sleep("60 seconds");
yield* Fiber.interrupt(fiber);
console.log(
"compaction events T3 decoded:",
seen.filter((type) => type.includes("compaction")),
);
});
program.pipe(
Effect.provide(OpenCode2Client.layer),
Effect.provide(FetchHttpClient.layer),
Effect.runPromise,
).catch((error) => {
console.error(error);
process.exit(1);
});
Implemented and verified by Claude Opus 5.5 (lead, red test, fix, reviewer B) and GPT-6.1 Sol (reviewer A), in T3 Code through Claude Code and Codex.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…#26193)
These tests reproduce #26193: OpenCode 2.1+ omits data.recent on
session.compaction.started/ended, so the bundled protocol schema rejects
the frames and the events stream drops them.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
OpenCode 2.1 stopped sending data.recent on session.compaction.started
and session.compaction.ended. The bundled 2.0.28 protocol schema still
requires it, so both frames were rejected and silently dropped, and the
thread never showed compaction.
When an event fails to decode and is one of those two types without a
recent key, decode it again with recent filled as an empty string. T3
never reads recent. Frames that decode today take the same path as before.
Fixes #26193
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Approvability
Verdict: Approved at c49ffb4
Macroscope's review found this PR approvable — Restores compaction progress reporting for OpenCode 2.1+ by normalizing a missing legacy field before schema validation. Existing event handling remains intact, and the change does not initiate or alter compaction itself.
You can add or adjust custom eligibility rules. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Thread transfer impact
✅ Thread transfer remains within every enforced ceiling.
| Provider |
Metric |
Main baseline |
This PR |
Impact |
PR ceiling |
|
| Codex |
Total thread wire |
5.0 KiB |
5.0 KiB |
0 B (0.0%) |
6.8 KiB |
✅ |
| Codex |
Thread snapshot wire |
3.8 KiB |
3.8 KiB |
0 B (0.0%) |
4.9 KiB |
✅ |
| Codex |
Live turn WebSocket wire |
1.2 KiB |
1.2 KiB |
0 B (0.0%) |
2.0 KiB |
✅ |
| Codex |
Live turn WebSocket decoded |
21.5 KiB |
21.5 KiB |
0 B (0.0%) |
24.4 KiB |
✅ |
| Codex |
Live turn messages |
1 |
1 |
0 (0.0%) |
8 |
✅ |
| Claude |
Total thread wire |
5.0 KiB |
5.0 KiB |
0 B (0.0%) |
6.8 KiB |
✅ |
| Claude |
Thread snapshot wire |
3.8 KiB |
3.8 KiB |
0 B (0.0%) |
4.9 KiB |
✅ |
| Claude |
Live turn WebSocket wire |
1.2 KiB |
1.2 KiB |
0 B (0.0%) |
2.0 KiB |
✅ |
| Claude |
Live turn WebSocket decoded |
21.9 KiB |
21.9 KiB |
0 B (0.0%) |
24.4 KiB |
✅ |
| Claude |
Live turn messages |
1 |
1 |
0 (0.0%) |
8 |
✅ |
Baseline: b883156 · PR result: c49ffb4 · Source CI: failure
Scenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Oct 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
The OpenCode 2 client now accepts compaction-started and compaction-ended events that omit data.recent. A test verifies that the event stream emits both event types.
Changes: OpenCode compaction events
| Layer / File(s) |
Summary |
Compaction event fallback decoding packages/provider-opencode/src/server/v2/OpenCode2Client.ts |
When normal decoding fails, the client checks for compaction-started or compaction-ended events with object-valued data and no recent. It inserts an empty string and returns the event only if the existing schema accepts it. |
Event-stream handling and test packages/provider-opencode/src/server/v2/OpenCode2Client.ts, packages/provider-opencode/src/server/v2/OpenCode2Client.test.ts |
The event stream tries the fallback before marking an event undecodable. The test checks that both compaction event types are emitted in order. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
Possibly related PRs
- pingdotgg/t3code#22661: It normalizes compaction history responses that omit
recent; this PR handles live compaction event frames with the same schema incompatibility.
Suggested reviewers: maria-rcks
Merge Risk: Minimal · up to c49ff
-
The change addresses live compaction-event decoding without an identified merge-blocking issue. Normal checks remain appropriate.
Pre-merge checks: 3 · 1
-
Failed checks: 1 warning
| Check name |
Status |
Explanation |
Resolution |
| Out of Scope Changes check |
 |
The current head adds changes unrelated to #26193. OpenCode2Client.ts adds message-history response rewriting through fillCompactionRecents, plus native image-job discovery and remote image readin… |
Remove the unrelated message-history transformation and native image-job/image-reading implementation, with their tests, from this pull request. Submit that work under a separate linked objective if it is required. |
Passed checks: 3 passed
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title is concise, specific, and accurately describes the main change: restoring compaction progress for OpenCode 2.1 and later. |
| Description check |
 |
The description includes all required sections. It explains the problem, implementation, scope, linked issue, focused tests, broader checks, runtime verification, and the remaining unverified adapter-… |
| Linked Issues check |
 |
Active direct issue #26193 requires T3 to decode live OpenCode 2.1 compaction-start and compaction-end events. The reviewed PR retains the fallback that supplies recent: "" only when the normal even… |
Full details: Description check
-
Explanation
The description includes all required sections. It explains the problem, implementation, scope, linked issue, focused tests, broader checks, runtime verification, and the remaining unverified adapter-rendering check.
Full details: Linked Issues check
-
Explanation
Active direct issue #26193 requires T3 to decode live OpenCode 2.1 compaction-start and compaction-end events. The reviewed PR retains the fallback that supplies recent: "" only when the normal event decode fails for these event types. The added test covers both event types without data.recent. The existing adapter can process the decoded events. No excluded files affect this assessment.
Full details: Out of Scope Changes check
-
Explanation
The current head adds changes unrelated to #26193. OpenCode2Client.ts adds message-history response rewriting through fillCompactionRecents, plus native image-job discovery and remote image reading. The test file adds message-history normalization tests and image-job and image-reading tests. Issue #26193 concerns live /api/event compaction decoding and explicitly distinguishes message-history handling as separate work. These additions are not required to decode or deliver the live events.
Resolution
Remove the unrelated message-history transformation and native image-job/image-reading implementation, with their tests, from this pull request. Submit that work under a separate linked objective if it is required.
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt
Note This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
# Conflicts:
# packages/provider-opencode/src/server/v2/OpenCode2Client.test.ts
|
The automated pipeline stopped on this pull request and will not merge it:
someone else pushed to fix/issue-26193 (head is now b996e8f); the pipeline does not build on commits it did not review
It stays open for a person to finish or close.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The automated pipeline stopped on this pull request and will not merge it:
these checks fail on c49ffb4, also when run again: Check, Test Web, and the rework changed nothing:
No code change needed. The only real failure was Test Web: apps/web/src/components/RightPanelTabs.browser.test.tsx > 'a flick that scrolls the tab strip to its left edge keeps the thread, a swipe from the edge goes back'. Check failed only because it aggregates Test Web. The PR only touches packages/provider-opencode (OpenCode2Client.ts and its test), and the failing test is not even on the PR head. CI ran on a merge with main built just before main landed 42185a6 (#34191, 'right panel tab swipe test runs as macOS on any CI host'), which fixes that test's dependence on the platform on Linux runners. With current origin/main trial-merged locally (not committed), the test passes. A CI re-run will pick up the fix; the branch is left unchanged.
It stays open for a person to finish or close.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Generated by Claude Opus 5.5
RESPONDING ON BEHALF OF SHARAD
This catches a real break with OpenCode 2.1+, and the captured 2.1.4 frames show it clearly.
This PR's fallback decode on the event path and fillCompactionRecents (#22661) on the history path handle the same gap: the bundled @opencode/[email protected] requires recent on compactions, and OpenCode 2.1.0 removed it. Patching the schema and its declarations to make recent optional fixes both paths at the source, since @opencode/protocol and @opencode/client decode through it. T3 never reads recent, so neither workaround would be needed.
Would a schema patch be welcome here, given that #19213 dropped the earlier @opencode patches once 2.0.28 made them unnecessary? If so, the commit below could replace the OpenCode2Client.ts change and keep this PR's test as it is.
Checked on main at 6234afba12:
- Tests: with the patch, provider-opencode passes 290/290 and the server's OpenCode tests pass 225/225, including this PR's frames, fix(opencode): decode compaction history from OpenCode 2.1 #22661's six history shapes and the 2.0.18 compaction replay.
recent: 42 is still rejected. With the shim deleted and the schema unpatched, 6 tests fail.
- Size: 84 changed lines in three patch files: 4 in the runtime schema, 80 in generated d.ts (about 800 lines with diff context).
- History cost: on synthetic 2.1-style pages, deleting the shim cuts heap growth per 100-message
message.list page from 2.05 to 1.34 MiB, and mean decode time from 0.90 to 0.61 ms. T3 reads history in pages of 50–100 on backfill, snapshots, rollback and image recovery, not on every event, so I'd count this as a side benefit.
- Upstream: 2.0.29–2.0.32 still require
recent. Only 2.1+ drops it, which is a bigger upgrade.
I haven't run the patch against a real OpenCode server. It's checked against this PR's captured 2.1.4 frames, and the PR's runtime transcript shows the bug against real 2.1.4 and 2.2.0 servers.
Patch, benchmark and logs
Patch: 0001-fix-opencode-accept-compactions-without-recent.patch applies with git am on 6234afba12. It makes recent optional in @opencode/schema's session-event.js and session-message.js (2 lines each) and in the generated d.ts of all three packages (80 lines). It deletes fillCompactionRecents (56 lines), adds this PR's 2.1.4 frame test unchanged, and drops the history test's check on the recent value the shim filled in. The repo typechecks with skipLibCheck, so a separate probe compiles all 11 patched declaration files with it off and asserts that recent is optional in 10 of the types T3 reaches, including the event union and message.list's page. Those assertions fail on main.
Benchmark: the real OpenCode2Client message.list decodes a canned page of user, assistant (with tool calls) and idle messages, with one compaction per ~40 messages. Node 26.13.1, 3 alternating rounds per state. Times are means. MiB is the mean of each round's median heapUsed increase per decode, with GC forced before each sample and none observed during those windows. The machine was under load, so heap growth is the steadier figure. bench-table.md
| Page |
Messages |
main |
#26206 head |
patch |
control: shim deleted, schema unpatched |
2.1+ (no recent) |
100 |
0.90 ms (0.89–0.92), 2.05 MiB |
0.94 ms (0.86–1.07), 2.05 MiB |
0.61 ms (0.60–0.61), 1.34 MiB |
not run (rejects these pages) |
2.1+ (no recent) |
1,000 |
9.51 ms (9.36–9.67), 15.90 MiB |
9.37 ms (9.04–9.73), 15.89 MiB |
6.23 ms (6.08–6.47), 10.90 MiB |
not run (rejects these pages) |
2.0 (recent present) |
100 |
1.01 ms (0.99–1.03), 2.04 MiB |
1.02 ms (1.00–1.05), 2.04 MiB |
0.68 ms (0.66–0.71), 1.34 MiB |
0.60 ms (0.59–0.61), 1.34 MiB |
2.0 (recent present) |
1,000 |
9.53 ms (9.18–9.77), 15.87 MiB |
9.25 ms (8.73–9.71), 15.87 MiB |
6.13 ms (6.07–6.17), 10.90 MiB |
6.11 ms (5.93–6.39), 10.89 MiB |
4 states, 3 rounds each, heap samples with a GC: 0
Logs and scripts: proof-logs.txt has test summaries for every state, the red and control runs, the type probe, check:changed, the npm schema check, and the scripts that produced them.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
bugfix
Fix PR opened by an issue lead; enters the PR loop
pr:gate-failed
A land gate failed
size:S
10-29 changed lines (additions + deletions).
vouch:trusted
Author is trusted by repo permissions or the VOUCHED list.
Milestone
No milestone
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.
|