Skip to content

Commit e421225

Browse files
committed
feat(car): adopt car-runtime 0.46.0 and drop the prompt-smuggling hack
CarHost auto-updates via Sparkle and had already moved to 0.46.0, leaving opencode's pinned 0.44.0 client older than the daemon it talks to — the reverse of the skew the version rule exists to prevent. car-runtime is now excluded from bunfig's minimumReleaseAge so the client can track a daemon that updates itself; the tradeoff is accepted deliberately for this one package, which we publish. Correlate delegated calls with GenerateRequest.client_ref (car-releases#78). The UUID was previously smuggled through `prompt`, the only field surviving the serde round-trip, which held only because delegated models ignore it. `prompt` is still a required field, so it stays as an empty placeholder — the integration suite caught that when it was dropped entirely. Verified against a real 0.46.0 daemon rather than by inspection: - client_ref is echoed verbatim into inference.runner.invoke, with prompt set to a throwaway value to prove it is no longer load-bearing (anomalyco#78) - completing with no preceding event yields exactly one invoke and preserves RunnerResult.text; previously two invokes and an empty result (anomalyco#76) - concurrent delegated calls no longer cross-talk (anomalyco#77) - car-releases#75 is improved but open: 5066/5108/5289ms on 0.44.0 became 1879/4181/4251ms on 0.46.0 — a constant became variable seconds, so CAR stays off by default Not adopting per-project memory namespaces yet, despite 0.46.0 adding them. Namespace memory is never written to disk: it is lost on daemon restart, and memory.persist silently writes zero records while a namespace is bound (car-releases#82). Since CarHost restarts on every update, binding one today would trade the cross-project leakage of anomalyco#79 for silent data loss. Staying on the shared graph, with the tradeoff documented, until that closes. CAR integration suite: 11 pass against a live 0.46.0 daemon, and it now runs in half the wall time. CAR off: 3231 pass, 1 fail — a load flake that passes 21/21 in isolation.
1 parent 42e1a88 commit e421225

6 files changed

Lines changed: 29 additions & 25 deletions

File tree

‎CAR.md‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Enable it with:
1212
OPENCODE_ENABLE_CAR=true opencode
1313
```
1414

15-
Off by default is not timidity. Two concrete problems make CAR-on unsuitable as a default today, both on the CAR side and both filed:
15+
Off by default is not timidity. Delegated model calls still cost seconds before CAR dispatches them to the host runner — measured 1.9–4.3 s on 0.46.0, improved from a constant ~5 s on 0.44.0 but not gone ([car-releases#75](https://github.com/Parslee-ai/car-releases/issues/75)). That is the remaining blocker to making CAR-on the default.
1616

17-
- Every delegated model call costs a constant **~5 s** before CAR dispatches it to the host runner ([car-releases#75](https://github.com/Parslee-ai/car-releases/issues/75)).
18-
- A daemon holds **one** inference-runner slot, last registrant wins, so two opencode processes against one daemon steal each other's calls ([car-releases#77](https://github.com/Parslee-ai/car-releases/issues/77)).
17+
Fixed in 0.46.0, so no longer a concern: concurrent opencode processes stealing each other's delegated calls ([#77](https://github.com/Parslee-ai/car-releases/issues/77)), and completing without an event causing a duplicate invoke ([#76](https://github.com/Parslee-ai/car-releases/issues/76)).
1918

2019
## What CAR does and does not replace
2120

@@ -70,9 +69,11 @@ Check with `opencode debug car`; if `delegatedModelRegistered` is `false`, resta
7069

7170
Memory paths are sandboxed to `~/.car/memory` by the daemon. Absolute paths outside it are rejected, and relative names resolve under the base — which is why opencode passes a bare filename rather than a path of its own.
7271

73-
> **CAR memory is shared across every project on the machine.** CAR keeps one global memory graph: `loadMemory` merges into it and `persistMemory` writes the entire graph to whatever filename it is given ([car-releases#79](https://github.com/Parslee-ai/car-releases/issues/79)). opencode therefore uses a single `opencode.json` rather than one file per project — per-project filenames never isolated anything, they just wrote one copy of the same union per project while implying a separation that did not exist.
72+
> **CAR memory is shared across every project on the machine.** CAR keeps one global memory graph unless a connection binds a namespace, and `persistMemory` writes that whole graph to whatever filename it is given. opencode therefore uses a single `opencode.json` rather than one file per project — per-project filenames never isolated anything, they just wrote one copy of the same union per project.
7473
>
75-
> Facts learned in one codebase can surface in another's context. If you work across codebases where that matters, leave CAR disabled until #79 gains a memory namespace.
74+
> 0.46.0 added per-project isolation via `CAR_MEMORY_NAMESPACE`, but opencode does not use it yet, for two reasons. Namespace memory is never written to disk, so it is lost on every daemon restart and `persistMemory` silently writes nothing while a namespace is bound ([car-releases#82](https://github.com/Parslee-ai/car-releases/issues/82)) — adopting it today would trade a privacy problem for data loss, and CarHost restarts on every update. And the variable can only be set before the process starts, since bun does not propagate runtime `process.env` writes to native code ([car-releases#81](https://github.com/Parslee-ai/car-releases/issues/81)).
75+
>
76+
> Until #82 closes, facts learned in one codebase can surface in another's context. If you work across codebases where that matters, leave CAR disabled.
7677
7778
## Delegated inference
7879

@@ -92,9 +93,9 @@ Only three event shapes are accepted; anything else returns `unrecognised runner
9293
{ "type": "usage", "input_tokens": 0, "output_tokens": 0 }
9394
```
9495

95-
The host correlates an invoke back to its own pending call by smuggling a UUID through `GenerateRequest.prompt`, because nothing else the host supplies survives the serde round-trip and there is no correlation field. This works only because delegated models ignore `prompt` for prompt construction ([car-releases#78](https://github.com/Parslee-ai/car-releases/issues/78) asks for a real one).
96+
The host correlates an invoke back to its own pending call with `GenerateRequest.client_ref`, an opaque token the daemon echoes into the invoke payload (0.46.0, [car-releases#78](https://github.com/Parslee-ai/car-releases/issues/78)). Before that field existed, hosts had to smuggle a UUID through `prompt` — the only field surviving the serde round-trip — which worked only because delegated models ignore it.
9697

97-
Completing without emitting at least one event causes the daemon to invoke the runner a second time and doubles latency ([car-releases#76](https://github.com/Parslee-ai/car-releases/issues/76)).
98+
`inference.runner.complete` is terminal on its own; a runner with nothing to stream may complete without emitting any event.
9899

99100
## Diagnostics
100101

@@ -148,5 +149,5 @@ This is what opencode cannot do alone: its "always" answers live in per-project
148149

149150
## Open decisions
150151

151-
- **Memory model.** Per-project files do not isolate ([#79](https://github.com/Parslee-ai/car-releases/issues/79)). Accept shared memory, isolate another way, or wait for a namespace parameter.
152+
- **Memory model.** Namespaces exist as of 0.46.0 but are not durable ([#82](https://github.com/Parslee-ai/car-releases/issues/82)); adopt them once they persist across daemon restarts.
152153
- **Recall.** `queryFacts` is exposed but nothing routes recalled facts into the prompt beyond the single `buildContext` block.

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ This fork can run opencode's agent engine on top of [CAR](https://github.com/Par
105105

106106
**Known limitations, all filed upstream against CAR:**
107107

108-
- Delegated inference costs a constant ~5s per model call before CAR dispatches it ([#75](https://github.com/Parslee-ai/car-releases/issues/75)) — the main reason CAR is not the default.
109-
- A daemon holds one inference-runner slot, so two opencode processes against one daemon steal each other's calls ([#77](https://github.com/Parslee-ai/car-releases/issues/77)).
110-
- CAR keeps one global memory graph, so memory is shared across every project on the machine — facts from one codebase can surface in another's context ([#79](https://github.com/Parslee-ai/car-releases/issues/79)).
108+
- Delegated inference costs seconds per model call before CAR dispatches it — 1.9–4.3s on 0.46.0, down from a constant ~5s ([#75](https://github.com/Parslee-ai/car-releases/issues/75)). This is the main reason CAR is not the default.
109+
- Memory is shared across every project on the machine, so facts from one codebase can surface in another's context. 0.46.0 added per-project namespaces, but they are not yet durable across daemon restarts ([#82](https://github.com/Parslee-ai/car-releases/issues/82)), so opencode has not adopted them.
111110

112111
- **Durable approvals** — CAR classifies each action's risk tier from the command's content and records your permission answers to an auditable ledger, so an approval given once is honoured on later evaluations. opencode's own ruleset stays authoritative: CAR can skip a prompt you've already answered, never allow something opencode denies.
113112

‎bun.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bunfig.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
exact = true
33
# Only install newly resolved package versions published at least 3 days ago.
44
minimumReleaseAge = 259200
5-
minimumReleaseAgeExcludes = ["@ai-sdk/amazon-bedrock", "@ai-sdk/anthropic", "@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-arm64-musl", "@opentui/core-linux-x64", "@opentui/core-linux-x64-musl", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "opentui-spinner", "gitlab-ai-provider", "opencode-gitlab-auth", "@ff-labs/fff-node", "@ff-labs/fff-bun", "@ff-labs/fff-bin-darwin-arm64", "@ff-labs/fff-bin-darwin-x64", "@ff-labs/fff-bin-linux-arm64-gnu", "@ff-labs/fff-bin-linux-arm64-musl", "@ff-labs/fff-bin-linux-x64-gnu", "@ff-labs/fff-bin-linux-x64-musl", "@ff-labs/fff-bin-win32-arm64", "@ff-labs/fff-bin-win32-x64", "@pierre/diffs", "@pierre/theming", "app-builder-lib", "dmg-builder", "electron-builder", "electron-publish"]
5+
minimumReleaseAgeExcludes = ["car-runtime", "@ai-sdk/amazon-bedrock", "@ai-sdk/anthropic", "@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-arm64-musl", "@opentui/core-linux-x64", "@opentui/core-linux-x64-musl", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "opentui-spinner", "gitlab-ai-provider", "opencode-gitlab-auth", "@ff-labs/fff-node", "@ff-labs/fff-bun", "@ff-labs/fff-bin-darwin-arm64", "@ff-labs/fff-bin-darwin-x64", "@ff-labs/fff-bin-linux-arm64-gnu", "@ff-labs/fff-bin-linux-arm64-musl", "@ff-labs/fff-bin-linux-x64-gnu", "@ff-labs/fff-bin-linux-x64-musl", "@ff-labs/fff-bin-win32-arm64", "@ff-labs/fff-bin-win32-x64", "@pierre/diffs", "@pierre/theming", "app-builder-lib", "dmg-builder", "electron-builder", "electron-publish"]
66

77
[test]
88
root = "./do-not-run-tests-from-root"

‎packages/opencode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"ai": "catalog:",
115115
"ai-gateway-provider": "3.1.2",
116116
"bonjour-service": "1.3.0",
117-
"car-runtime": "0.44.0",
117+
"car-runtime": "0.46.0",
118118
"chokidar": "4.0.3",
119119
"cross-spawn": "catalog:",
120120
"decimal.js": "10.5.0",

‎packages/opencode/src/car/inference-bridge.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ interface BridgeContext {
4444
aborted?: boolean
4545
}
4646

47-
// `GenerateRequest` is a typed Rust struct, so unknown fields are dropped on the
48-
// serde round-trip and we cannot attach our own correlation id to the request.
49-
// We smuggle it through `prompt`, which delegated models ignore for prompt
50-
// construction (the runner builds the real prompt from `ctx.params`). The
51-
// daemon's own `call_id` is what we quote back when emitting events.
47+
// Correlated by `client_ref`, an opaque token the daemon echoes back into
48+
// `inference.runner.invoke` (car-releases#78, car-runtime 0.46.0). Before that
49+
// existed the only field surviving the serde round-trip was `prompt`, so hosts
50+
// smuggled a UUID through it — which held only because delegated models ignore
51+
// `prompt` for prompt construction. The daemon's own `call_id` is what we quote
52+
// back when emitting events.
5253
const bridge = new Map<string, BridgeContext>()
5354

5455
class AsyncQueue<T> {
@@ -170,17 +171,17 @@ class RunnerConnection {
170171
}
171172

172173
if (msg.method === "inference.runner.invoke") {
173-
const params = msg.params as { call_id?: string; request?: { prompt?: string } }
174+
const params = msg.params as { call_id?: string; request?: { client_ref?: string } }
174175
void this.onInvoke(params)
175176
}
176177
}
177178

178-
private async onInvoke(params: { call_id?: string; request?: { prompt?: string } }): Promise<void> {
179+
private async onInvoke(params: { call_id?: string; request?: { client_ref?: string } }): Promise<void> {
179180
const callId = params.call_id
180-
const correlationID = params.request?.prompt
181+
const correlationID = params.request?.client_ref
181182
if (!callId) return
182183
if (!correlationID) {
183-
this.emit("inference.runner.fail", { call_id: callId, error: "missing correlation id in request.prompt" })
184+
this.emit("inference.runner.fail", { call_id: callId, error: "missing client_ref on the delegated request" })
184185
return
185186
}
186187
const ctx = bridge.get(correlationID)
@@ -355,7 +356,10 @@ export function runInference(rt: CarRuntime, params: StreamTextParams): Inferenc
355356
{ once: true },
356357
)
357358

358-
const requestJson = JSON.stringify({ model: DELEGATED_MODEL_ID, prompt: callId })
359+
// `prompt` is still required by GenerateRequest even though a delegated model
360+
// ignores it — the host builds the real request from `ctx.params`. Correlation
361+
// rides on `client_ref` now, so this is genuinely just a placeholder.
362+
const requestJson = JSON.stringify({ model: DELEGATED_MODEL_ID, prompt: "", client_ref: callId })
359363

360364
// Registration must land before the delegated call, or the daemon rejects it
361365
// with "no WebSocket inference runner registered".

0 commit comments

Comments
 (0)