usage: an OpenCode session's row shows the effort and the model it asked for (#680, Sun1090: 数据不完整,推理强度是有的)
OpenCode rows read from its own data (opencode.db or storage/) had 请求模型 and 推理强度 as —. OpenCode keeps both on each reply (packages/schema/src/v1/session.ts, AssistantMessage): variant, the effort picked in its model menu for the prompt (high, max, low, xhigh, none, thinking … as the provider's variants name them; prompt.ts copies lastUser.model.variant onto every reply), and modelID, the model the reply was sent to. OpenCode 2 (session_message) keeps the variant in model.variant (Model.Ref). It records no model the response named, so modelID is what was asked for, as a Codex rollout's model is.
Now a call's Effort is the reply's variant ("default" or none is no effort picked); a compaction in OpenCode 2 takes the effort last replied with, as it takes the model. In the ledger an OpenCode call is told as a Codex one: requested = its model, served left empty rather than claimed. The call cache moves to calls-v5 so calls read before carry the effort.
TestOpenCodeCallsJSON/DB/V2 (fixtures with variant high, default, xhigh and none) and TestOpenCodeSessionCallIsWhatItAskedFor fail on the old code and pass. go vet ./internal/..., builds (nogui, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried against a real OpenCode database with variants (this machine's OpenCode data predates them).
This commit is contained in:
@@ -21,7 +21,8 @@ import (
|
||||
// v3 persists Codex cumulative counters explicitly; v2 shards can contain
|
||||
// inflated deltas after a reload, so rebuild their derived rows from source.
|
||||
// v4: a Codex call's input no longer holds what it wrote to the cache (#589).
|
||||
const callCacheVersion = "calls-v4"
|
||||
// v5: an OpenCode call keeps the effort its prompt asked for (#680).
|
||||
const callCacheVersion = "calls-v5"
|
||||
const maxKeptCalls = 131072
|
||||
const maxKeptFiles = 64
|
||||
|
||||
|
||||
@@ -218,6 +218,11 @@ func ocCall(st *callFile, m ocMessage, dir string) (Call, bool) {
|
||||
if m.Path != nil && m.Path.Cwd != "" {
|
||||
c.Cwd = st.str(m.Path.Cwd)
|
||||
}
|
||||
// the effort picked for the prompt in OpenCode's model menu, which each
|
||||
// of its replies carries; "default" is none picked (#680)
|
||||
if m.Variant != "" && m.Variant != "default" {
|
||||
c.Effort = st.str(m.Variant)
|
||||
}
|
||||
if !done.IsZero() && !created.IsZero() && done.After(created) {
|
||||
c.Millis = done.Sub(created).Milliseconds()
|
||||
}
|
||||
|
||||
@@ -38,9 +38,13 @@ func checkOCCalls(t *testing.T, cs map[string]Call) {
|
||||
!a.Time.Equal(at("2026-09-26T10:00:30Z")) {
|
||||
t.Fatalf("astra: %+v", a)
|
||||
}
|
||||
// the effort picked in OpenCode's model menu, its reply's variant (#680)
|
||||
if a.Effort != "high" {
|
||||
t.Fatalf("astra's effort %q, want high", a.Effort)
|
||||
}
|
||||
o, ok := cs["msg_0004"]
|
||||
if !ok || o.Model != "claude-opus-5-5" || o.Upstream != "anthropic" || o.Session != ocMain ||
|
||||
o.Tokens != (Tokens{40, 60, 700, 300}) || o.Millis != 30000 {
|
||||
o.Tokens != (Tokens{40, 60, 700, 300}) || o.Millis != 30000 || o.Effort != "" {
|
||||
t.Fatalf("the subagent's opus: %+v", o)
|
||||
}
|
||||
if len(cs) != 2 {
|
||||
@@ -81,11 +85,12 @@ func TestOpenCodeCallsDB(t *testing.T) {
|
||||
|
||||
// a failed reply is a failed call; one only stopped is none
|
||||
ocInsert(t, db, ocChild, "msg_0005", 1790416990000, 1790417000000,
|
||||
`{"id":"msg_0005","role":"assistant","modelID":"claude-opus-5-5","providerID":"anthropic","tokens":{"input":0,"output":0,"reasoning":0,"cache":{"read":0,"write":0}},"error":{"name":"APIError","data":{"message":"Overloaded","statusCode":529}},"time":{"created":1790416990000,"completed":1790417000000}}`)
|
||||
`{"id":"msg_0005","role":"assistant","modelID":"claude-opus-5-5","providerID":"anthropic","variant":"default","tokens":{"input":0,"output":0,"reasoning":0,"cache":{"read":0,"write":0}},"error":{"name":"APIError","data":{"message":"Overloaded","statusCode":529}},"time":{"created":1790416990000,"completed":1790417000000}}`)
|
||||
ocInsert(t, db, ocChild, "msg_0006", 1790417010000, 1790417020000,
|
||||
`{"id":"msg_0006","role":"assistant","modelID":"claude-opus-5-5","providerID":"anthropic","tokens":{"input":0,"output":0,"reasoning":0,"cache":{"read":0,"write":0}},"error":{"name":"MessageAbortedError","data":{"message":"aborted"}},"time":{"created":1790417010000}}`)
|
||||
cs := ocCalls(t)
|
||||
if e := cs["msg_0005"]; e.Error != "APIError" || e.ErrorText != "Overloaded" || e.Session != ocMain {
|
||||
// "default" is no effort picked
|
||||
if e := cs["msg_0005"]; e.Error != "APIError" || e.ErrorText != "Overloaded" || e.Session != ocMain || e.Effort != "" {
|
||||
t.Fatalf("a failed reply: %+v", e)
|
||||
}
|
||||
if _, ok := cs["msg_0006"]; ok {
|
||||
@@ -105,7 +110,7 @@ func TestOpenCodeCallsV2(t *testing.T) {
|
||||
}
|
||||
// and one after OpenCode's own reply is OpenCode's
|
||||
if _, err := db.Exec(`INSERT INTO session_message VALUES ('msg_0007', ?, 'assistant', 10, 1790417020000, 1790417030000, ?), ('msg_0008', ?, 'compaction', 11, 1790417040000, 1790417050000, ?)`,
|
||||
ocMain, `{"model":{"id":"big-pickle","providerID":"opencode"},"content":[],"cost":0,"tokens":{"input":7,"output":3,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1790417020000,"completed":1790417030000}}`,
|
||||
ocMain, `{"model":{"id":"big-pickle","providerID":"opencode","variant":"xhigh"},"content":[],"cost":0,"tokens":{"input":7,"output":3,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1790417020000,"completed":1790417030000}}`,
|
||||
ocMain, `{"status":"completed","reason":"auto","cost":0,"tokens":{"input":11,"output":2,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1790417040000}}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -113,10 +118,11 @@ func TestOpenCodeCallsV2(t *testing.T) {
|
||||
if _, ok := cs["msg_0005"]; ok {
|
||||
t.Fatalf("a compaction through magpie counted: %+v", cs["msg_0005"])
|
||||
}
|
||||
if c := cs["msg_0007"]; c.Model != "big-pickle" || c.Upstream != "opencode" || c.Tokens != (Tokens{7, 3, 0, 0}) {
|
||||
if c := cs["msg_0007"]; c.Model != "big-pickle" || c.Upstream != "opencode" || c.Tokens != (Tokens{7, 3, 0, 0}) || c.Effort != "xhigh" {
|
||||
t.Fatalf("an OpenCode Zen reply: %+v", c)
|
||||
}
|
||||
if c := cs["msg_0008"]; c.Model != "big-pickle" || c.Upstream != "opencode" || c.Tokens != (Tokens{11, 2, 0, 0}) {
|
||||
// a compaction is made with the model and effort last replied with
|
||||
if c := cs["msg_0008"]; c.Model != "big-pickle" || c.Upstream != "opencode" || c.Tokens != (Tokens{11, 2, 0, 0}) || c.Effort != "xhigh" {
|
||||
t.Fatalf("its compaction: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ type ocMessage struct {
|
||||
ModelID string `json:"modelID"`
|
||||
// the provider the reply came from: magpie's gateway is "magpie"
|
||||
ProviderID string `json:"providerID,omitempty"`
|
||||
// a reply's variant: the reasoning effort picked in OpenCode's model
|
||||
// menu for its prompt (high, max, low …; "default" or none when none
|
||||
// was). OpenCode 2 keeps it in model.variant (#680)
|
||||
Variant string `json:"variant,omitempty"`
|
||||
// what ended the reply, when something did: {name, data {message}}, or
|
||||
// in OpenCode 2 {type, message}
|
||||
Error json.RawMessage `json:"error,omitempty"`
|
||||
@@ -316,7 +320,7 @@ func (s ocV2DB) messages(sid string) [][]byte {
|
||||
}
|
||||
defer rows.Close()
|
||||
var out [][]byte
|
||||
last, lastProvider := "", ""
|
||||
last, lastProvider, lastVariant := "", "", ""
|
||||
for rows.Next() {
|
||||
var id, typ string
|
||||
var b []byte
|
||||
@@ -328,20 +332,21 @@ func (s ocV2DB) messages(sid string) [][]byte {
|
||||
Model *struct {
|
||||
ID string `json:"id"`
|
||||
ProviderID string `json:"providerID"`
|
||||
Variant string `json:"variant"`
|
||||
} `json:"model"`
|
||||
}
|
||||
if json.Unmarshal(b, &m) != nil || json.Unmarshal(b, &v) != nil {
|
||||
continue
|
||||
}
|
||||
m.ID, m.Role, m.ModelID, m.ProviderID = id, "assistant", last, lastProvider
|
||||
m.ID, m.Role, m.ModelID, m.ProviderID, m.Variant = id, "assistant", last, lastProvider, lastVariant
|
||||
if v.Model != nil && v.Model.ID != "" {
|
||||
m.ModelID, m.ProviderID = v.Model.ID, v.Model.ProviderID
|
||||
m.ModelID, m.ProviderID, m.Variant = v.Model.ID, v.Model.ProviderID, v.Model.Variant
|
||||
}
|
||||
switch typ {
|
||||
case "user":
|
||||
m.Role, m.ModelID, m.ProviderID, m.Tokens = "user", "", "", nil
|
||||
m.Role, m.ModelID, m.ProviderID, m.Variant, m.Tokens = "user", "", "", "", nil
|
||||
case "assistant":
|
||||
last, lastProvider = m.ModelID, m.ProviderID
|
||||
last, lastProvider, lastVariant = m.ModelID, m.ProviderID, m.Variant
|
||||
}
|
||||
if o, err := json.Marshal(m); err == nil {
|
||||
out = append(out, o)
|
||||
|
||||
@@ -314,7 +314,7 @@ func ocMakeV2(t *testing.T, path string) *sql.DB {
|
||||
for i, m := range []struct{ sid, id, typ, data string }{
|
||||
{ocMain, "msg_0001", "user", `{"text":"Why does the login test\nflake?","time":{"created":1790416805000}}`},
|
||||
{ocMain, "msg_0001s", "synthetic", `{"text":"Called the Read tool with the following input","time":{"created":1790416805000}}`},
|
||||
{ocMain, "msg_0002", "assistant", `{"agent":"build","model":{"id":"gpt-6-astra","providerID":"openai","variant":"default"},"content":[{"type":"reasoning","text":"…"},{"type":"text","text":"Let me look."}],"cost":0.01,"tokens":{"input":1000,"output":100,"reasoning":20,"cache":{"read":5000,"write":0}},"time":{"created":1790416806000,"completed":1790416830000}}`},
|
||||
{ocMain, "msg_0002", "assistant", `{"agent":"build","model":{"id":"gpt-6-astra","providerID":"openai","variant":"high"},"content":[{"type":"reasoning","text":"…"},{"type":"text","text":"Let me look."}],"cost":0.01,"tokens":{"input":1000,"output":100,"reasoning":20,"cache":{"read":5000,"write":0}},"time":{"created":1790416806000,"completed":1790416830000}}`},
|
||||
{ocMain, "msg_0003", "assistant", `{"agent":"build","model":{"id":"codex/gpt-6-luna","providerID":"magpie","variant":"default"},"content":[{"type":"text","text":"It races the clock."}],"cost":0,"tokens":{"input":300,"output":50,"reasoning":10,"cache":{"read":2000,"write":0}},"time":{"created":1790416890000,"completed":1790416980000}}`},
|
||||
{ocMain, "msg_0003i", "idle", `{"outcome":"succeeded","time":{"created":1790416980000}}`},
|
||||
{ocChild, "msg_0004", "assistant", `{"agent":"general","model":{"id":"claude-opus-5-5","providerID":"anthropic"},"content":[],"cost":0,"tokens":{"input":40,"output":60,"reasoning":0,"cache":{"read":700,"write":300}},"time":{"created":1790416860000,"completed":1790416890000}}`},
|
||||
|
||||
Vendored
+2
-1
@@ -8,6 +8,7 @@
|
||||
"agent": "build",
|
||||
"model": {
|
||||
"providerID": "openai",
|
||||
"modelID": "gpt-6-astra"
|
||||
"modelID": "gpt-6-astra",
|
||||
"variant": "high"
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -25,5 +25,6 @@
|
||||
"created": 1790416806000,
|
||||
"completed": 1790416830000
|
||||
},
|
||||
"variant": "high",
|
||||
"finish": "tool-calls"
|
||||
}
|
||||
|
||||
@@ -224,13 +224,14 @@ const UnknownProvider = "session-unknown"
|
||||
// unknown, and what the file doesn't say is left out. Nothing
|
||||
// stood between the agent and the vendor, so what was sent is what the agent
|
||||
// asked for. Claude Code's file names the model it asked for (as it runs) and
|
||||
// the one the API answered with, which is the served model; Codex's names the
|
||||
// one it asked for.
|
||||
// the one the API answered with, which is the served model; Codex's and
|
||||
// OpenCode's name only the one they asked for (OpenCode's reply keeps the
|
||||
// model it was sent to, never the one the response named) (#680).
|
||||
func logRecord(c sessions.Call) Record {
|
||||
r := Record{Time: c.Time, Agent: c.Agent, Provider: UnknownProvider, Model: c.Model, Served: c.Model, Requested: c.Requested,
|
||||
Input: c.Input, Output: c.Output, CacheRead: c.CacheRead, CacheWrite: c.CacheWrite, Reasoning: c.Reasoning, Effort: c.Effort,
|
||||
Millis: c.Millis, TTFT: c.TTFT, Session: c.Session, RequestID: c.RequestID, Error: c.ErrorText, ErrType: c.Error}
|
||||
if c.Agent == "codex" {
|
||||
if c.Agent == "codex" || c.Agent == "opencode" {
|
||||
r.Requested, r.Served = c.Model, ""
|
||||
}
|
||||
if r.Requested != "" {
|
||||
|
||||
@@ -270,3 +270,24 @@ func TestLedgerKeepsLocalAccountsSeparateFromGatewayProviders(t *testing.T) {
|
||||
t.Fatalf("local identity was lost or guessed: %+v", rows)
|
||||
}
|
||||
}
|
||||
|
||||
// An OpenCode reply names only the model it was sent to, and the effort
|
||||
// picked for its prompt (#680): the row's requested model and effort, not a
|
||||
// served model the file never saw.
|
||||
func TestOpenCodeSessionCallIsWhatItAskedFor(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
||||
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
||||
logs := []sessions.Call{{Time: time.Now(), Agent: "opencode", Model: "space-bunny-free", Upstream: "opencode", Effort: "high",
|
||||
Tokens: sessions.Tokens{Input: 10, Output: 2}}}
|
||||
rows, _, _, _ := ledgerWith(time.Time{}, Filter{}, nil, logs)
|
||||
if len(rows) != 1 {
|
||||
t.Fatalf("rows %+v", rows)
|
||||
}
|
||||
if r := rows[0]; r.Requested != "space-bunny-free" || r.Model != "space-bunny-free" || r.Served != "" || r.Effort != "high" {
|
||||
t.Fatalf("an OpenCode call: requested %q model %q served %q effort %q", r.Requested, r.Model, r.Served, r.Effort)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user