model: /model never saves; config (or -m) is the default

The user's rule: what the config says is the default, -m overrides it for one
run, /model overrides it for the running process - and nothing is written to
the config or to the session. The session sidecar from the previous change made
/model persistent, which is exactly the harness behaviour this rejects.

- removed <session>.model writing and restoring; a reopened session starts on
  the config default or -m, not on the last /model choice.
- /new no longer copies the current model into the new session.
- Telegram's /model and probe buttons no longer write 90-model.conf; the
  switch lasts for the gateway process.
- existing .model sidecars were moved out of ~/.splinter; the stale 90-model
  drop-in was moved aside earlier.
- test_engine asserts that /model leaves no sidecar and that reopening uses
  test-model, not test-model-2; test_gateway asserts that no 90-model.conf is
  written.
- docs: "choice lasts for this run and is not saved".

Verified with the real config: default is junction/qwen3.6-35b-judged, -m
junction/qwen3.6-35b uses qwen3.6-35b for that run, /model switches to
claude-haiku for that run and the next start is judged again.

make check: all tests passed.
This commit is contained in:
lotherk committed 2026-11-18 12:38:29 +00:00
1 parent 6813fff1b5
commit d63da16c65
7 files changed
+52 -216

No files matched your search

+6 -5
View File
@@ -585,10 +585,10 @@ old one stays on disk, and the system prompt is put back.
`/model` lists the models the config names (the core endpoint, every delegate
with a model, every exit) as buttons and points the running transport at the
one you press. The choice is written to the session's sidecar
(`<session>.model`) and comes back when that session is opened again, so one
conversation can sit on a different model without changing what a new one
starts on. `/model <name>` keeps the endpoint and takes another model from it.
one you press. **The choice lasts for this run and is not saved**: the next
start uses the config's `default`, or `-m` when given. One conversation can sit
on a different model without touching what every later start begins with.
`/model <name>` keeps the endpoint and takes another model from it.
`/model probe` asks the configured endpoints `/v1/models` and lists what they
really serve.
@@ -723,7 +723,8 @@ conversation and puts it on screen. It continues that session id rather than
opening a fresh one beside it - the first version did the latter, which looked
like a resume and was none. The agent profile comes back too: the engine keeps
the session's profile in `<session>.agent`, so a session left in plan resumes
in plan; the model it was left on is in `<session>.model` and comes back too.
in plan. The model is not part of the session: `/model` did not save it, so a
resume starts on the config default (or `-m`).
## MCP
+4 -5
View File
@@ -512,11 +512,10 @@ and stand for `http://127.0.0.1:11434/v1` and
`https://opencode.ai/zen/go/v1` (the latter with
`OPENCODE_GO_API_KEY`).
`/model` offers the models the config names and switches the transport; the
choice is written to the session's sidecar (`<session>.model`) as a selector,
so reopening that session brings the model back without changing what a new
session starts on. The provider block supplies kind, endpoint and key variable;
the sidecar only names the choice. `/model probe` asks each endpoint
`/model` offers the models the config names and switches the transport for
**this run only**; nothing is written to the config or to the session, so the
next start is the config's `default` (or `-m`). The provider block supplies
kind, endpoint and key variable. `/model probe` asks each endpoint
`/v1/models` and lists what it really serves; the picker in the curses chat
also asks the endpoint the session is on and adds those models to its list.
`/model <name>` takes another model from the current endpoint. With a plugin
+2 -1
View File
@@ -83,7 +83,8 @@ Stream.
(`test_gateway.sh`, `test_ui.sh`); `/connect` auch im TUI
- **Modelle wechseln und Provider anlegen**: `/model` liest die konfigurierten
Modelle (Haupt-Endpoint, Delegates, Exits), haengt den Transport um, merkt
die Wahl in `<session>.model` und fragt per `/model probe` die Endpoints nach
die Wahl nur im laufenden Prozess (nichts wird gespeichert) und fragt per
`/model probe` die Endpoints nach
`/v1/models`; das TUI zeigt im Picker auch die Modelle des Endpoints, auf dem
die Sitzung gerade laeuft. `/connect` schreibt eine validierte
`delegate`-Zeile in den Drop-in neben der benutzten Konfiguration, prueft sie
+9 -120
View File
@@ -401,93 +401,18 @@ profile_save(struct sp_engine *e)
(void)chmod(path, 0600);
}
/* <session dir>/<id>.model: the model /model chose in this session */
static void
session_model_path(struct sp_engine *e, char *buf, size_t cap)
{
snprintf(buf, cap, "%s/%s.model", e->sess.dir, e->sess.id);
}
static int
session_model_save(struct sp_engine *e, const char *sel, char *err,
size_t errcap)
{
char path[800], tmp[820];
FILE *f;
if (e == NULL || sel == NULL || *sel == '\0')
return -1;
session_model_path(e, path, sizeof(path));
snprintf(tmp, sizeof(tmp), "%s.tmp", path);
f = fopen(tmp, "w");
if (f == NULL) {
if (err != NULL && errcap > 0)
snprintf(err, errcap, "%s", strerror(errno));
return -1;
}
(void)fchmod(fileno(f), 0600);
fprintf(f, "%s\n", sel);
if (fclose(f) != 0 || rename(tmp, path) != 0) {
if (err != NULL && errcap > 0)
snprintf(err, errcap, "%s", strerror(errno));
(void)unlink(tmp);
return -1;
}
return 0;
}
static int
session_model_read(struct sp_engine *e, char *buf, size_t cap)
{
char path[800], line[320];
FILE *f;
size_t n;
if (e == NULL || e->sess.dir[0] == '\0' || buf == NULL || cap == 0)
return -1;
session_model_path(e, path, sizeof(path));
f = fopen(path, "r");
if (f == NULL)
return -1;
if (fgets(line, sizeof(line), f) == NULL) {
fclose(f);
return -1;
}
fclose(f);
line[strcspn(line, "\r\n")] = '\0';
n = strlen(line);
if (n == 0 || n >= cap)
return -1;
memcpy(buf, line, n + 1);
return 0;
}
/* the selector that puts this engine back on the model it is on now */
static void
current_model_selector(struct sp_engine *e, char *buf, size_t cap)
{
const char *act = sp_usage_active();
if (act != NULL && *act != '\0')
snprintf(buf, cap, "%s/%s", sp_provider_label(act),
e->cur_model);
else
snprintf(buf, cap, "%s", e->cur_model);
}
/* the transcript note after a successful /model: saved in this session */
/*
* The transcript note after a successful /model. The choice lives only in
* this engine: nothing is written to the config and nothing to the session,
* so the next start is the config (or -m), not the last thing someone tried.
*/
static void
session_model_note(struct sp_engine *e, const char *sel, struct sp_buf *out,
const char *model, const char *provider)
{
char err[128];
err[0] = '\0';
if (session_model_save(e, sel, err, sizeof(err)) != 0)
sp_buf_printf(out, sp_t("model.save_failed"), model, provider,
err[0] != '\0' ? err : "?");
else
sp_buf_printf(out, sp_t("model.switched"), model, provider);
(void)e;
(void)sel;
sp_buf_printf(out, sp_t("model.switched"), model, provider);
}
static int
@@ -2040,13 +1965,6 @@ cmd_new(struct sp_engine *e, struct sp_buf *out)
(void)sp_log_open(e->sess.dir, e->sess.id);
sp_logf("session", "started: %s", e->sess.id);
profile_save(e);
{
char sel[320];
current_model_selector(e, sel, sizeof(sel));
if (sel[0] != '\0')
(void)session_model_save(e, sel, NULL, 0);
}
ev_push(e, SP_EV_CLEAR, 0, NULL, NULL);
sp_buf_printf(out, sp_t("session.new"), e->sess.id);
}
@@ -2813,7 +2731,7 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o,
{
struct sp_engine_opts local;
struct sp_engine *e;
char cwd[700], saved[320], saved_model[320];
char cwd[700];
int start = -1, code = -1;
if (out == NULL || o == NULL || o->conf == NULL || o->base == NULL)
@@ -2873,35 +2791,6 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o,
}
if (open_session(e, o, err, &code) != 0)
goto fail;
if (session_model_read(e, saved, sizeof(saved)) == 0) {
struct sp_choice ch;
memset(&ch, 0, sizeof(ch));
if (sp_provider_choose(e->conf, saved, &ch) == 0 &&
ch.d != NULL) {
local.endpoint = ch.d->endpoint;
snprintf(saved_model, sizeof(saved_model), "%s",
ch.model[0] != '\0' ? ch.model : ch.d->model);
local.model = saved_model;
local.kind = ch.d->kind;
local.key_env = ch.d->key_env;
sp_usage_set_active(ch.d->id);
} else if (strchr(saved, '/') == NULL) {
/* a model of the endpoint the run was configured with */
snprintf(saved_model, sizeof(saved_model), "%s", saved);
local.model = saved_model;
} else {
sp_logf("session", "saved model '%s' is gone; "
"using the default", saved);
saved[0] = '\0';
}
if (saved[0] != '\0') {
snprintf(e->cur_endpoint, sizeof(e->cur_endpoint), "%s",
local.endpoint != NULL ? local.endpoint : "");
snprintf(e->cur_model, sizeof(e->cur_model), "%.255s",
local.model != NULL ? local.model : "");
}
}
e->ag.sess = &e->sess;
sp_logf("session", "started: %s", e->sess.id);
if (load_plugins(e, o, err) != 0)
+19 -66
View File
@@ -1100,7 +1100,8 @@ tg_model_menu(const char *token, long chat_id, struct sp_config *conf,
for (i = 0; i < n && i < TG_MAX_MODELS; i++) {
if (sp_provider_at(conf, i, &p) != 0)
continue;
sp_buf_printf(&msg, "\n%s %s%s", p.id, p.model,
sp_buf_printf(&msg, "\n%s/%s%s",
sp_provider_label(p.id), p.model,
strcmp(p.id, tg_model_id) == 0 ? " *" : "");
if (p.key_env[0] != '\0' && getenv(p.key_env) == NULL)
sp_buf_printf(&msg, sp_t("model.no_key"), p.key_env);
@@ -1155,27 +1156,11 @@ tg_model_use(const char *token, long chat_id, struct sp_agent *ag,
}
snprintf(tg_model_id, sizeof(tg_model_id), "%s", p.id);
snprintf(tg_model_name, sizeof(tg_model_name), "%s", p.model);
{
struct sp_buf serr;
int saved;
sp_buf_init(&serr);
saved = sp_provider_save_choice(conf, &p, &serr);
if (sp_buf_init(&msg) == 0) {
if (saved == 0)
sp_buf_printf(&msg, sp_t("model.saved"),
p.model, p.id);
else if (saved < 0)
sp_buf_printf(&msg, sp_t("model.save_failed"),
p.model, p.id, serr.p != NULL ?
serr.p : "?");
else
sp_buf_printf(&msg, sp_t("model.switched"),
p.model, p.id);
(void)send_message(token, chat_id, msg.p, err);
sp_buf_free(&msg);
}
sp_buf_free(&serr);
if (sp_buf_init(&msg) == 0) {
sp_buf_printf(&msg, sp_t("model.switched"), p.model,
sp_provider_label(p.id));
(void)send_message(token, chat_id, msg.p, err);
sp_buf_free(&msg);
}
sp_buf_free(&perr);
}
@@ -1215,34 +1200,11 @@ tg_model_named(const char *token, long chat_id, struct sp_agent *ag,
return;
}
snprintf(tg_model_name, sizeof(tg_model_name), "%s", name);
{
struct sp_provider chosen;
struct sp_buf serr;
int saved;
memset(&chosen, 0, sizeof(chosen));
snprintf(chosen.id, sizeof(chosen.id), "%s", p.id);
snprintf(chosen.endpoint, sizeof(chosen.endpoint), "%s",
p.endpoint);
snprintf(chosen.model, sizeof(chosen.model), "%s", name);
snprintf(chosen.key_env, sizeof(chosen.key_env), "%s",
p.key_env);
sp_buf_init(&serr);
saved = sp_provider_save_choice(conf, &chosen, &serr);
if (sp_buf_init(&msg) == 0) {
if (saved == 0)
sp_buf_printf(&msg, sp_t("model.saved"), name,
p.id);
else if (saved < 0)
sp_buf_printf(&msg, sp_t("model.save_failed"),
name, p.id, serr.p != NULL ? serr.p : "?");
else
sp_buf_printf(&msg, sp_t("model.switched"), name,
p.id);
(void)send_message(token, chat_id, msg.p, err);
sp_buf_free(&msg);
}
sp_buf_free(&serr);
if (sp_buf_init(&msg) == 0) {
sp_buf_printf(&msg, sp_t("model.switched"), name,
sp_provider_label(p.id));
(void)send_message(token, chat_id, msg.p, err);
sp_buf_free(&msg);
}
sp_buf_free(&perr);
}
@@ -1307,7 +1269,7 @@ tg_model_pick_menu(const char *token, long chat_id, struct sp_config *conf,
perr.p != NULL ? perr.p : "?");
continue;
}
sp_buf_printf(&msg, "\n%s:", p.id);
sp_buf_printf(&msg, "\n%s:", sp_provider_label(p.id));
for (line = strtok(ids.p, "\n"); line != NULL;
line = strtok(NULL, "\n")) {
char label[64];
@@ -1324,8 +1286,8 @@ tg_model_pick_menu(const char *token, long chat_id, struct sp_config *conf,
tg_picks[0].key_env), "%s", p.key_env);
sp_buf_printf(&msg, " %s", line);
/* Telegram caps button text at 64 characters */
snprintf(label, sizeof(label), "%.20s: %.40s", p.id,
line);
snprintf(label, sizeof(label), "%.20s: %.40s",
sp_provider_label(p.id), line);
if (total > 0)
sp_buf_puts(&mark, ",");
sp_buf_puts(&mark, "[{\"text\":\"");
@@ -1353,9 +1315,9 @@ tg_model_pick_use(const char *token, long chat_id, struct sp_agent *ag,
struct sp_config *conf, size_t idx, struct sp_buf *err)
{
struct sp_provider p;
struct sp_buf msg, perr, serr;
int saved;
struct sp_buf msg, perr;
(void)conf;
if (idx >= tg_npicks || ag == NULL) {
(void)send_message(token, chat_id, sp_t("model.probe_stale"),
err);
@@ -1382,21 +1344,12 @@ tg_model_pick_use(const char *token, long chat_id, struct sp_agent *ag,
sp_buf_free(&perr);
snprintf(tg_model_id, sizeof(tg_model_id), "%s", p.id);
snprintf(tg_model_name, sizeof(tg_model_name), "%s", p.model);
sp_buf_init(&serr);
saved = sp_provider_save_choice(conf, &p, &serr);
if (sp_buf_init(&msg) == 0) {
if (saved == 0)
sp_buf_printf(&msg, sp_t("model.saved"), p.model, p.id);
else if (saved < 0)
sp_buf_printf(&msg, sp_t("model.save_failed"), p.model,
p.id, serr.p != NULL ? serr.p : "?");
else
sp_buf_printf(&msg, sp_t("model.switched"), p.model,
p.id);
sp_buf_printf(&msg, sp_t("model.switched"), p.model,
sp_provider_label(p.id));
(void)send_message(token, chat_id, msg.p, err);
sp_buf_free(&msg);
}
sp_buf_free(&serr);
}
/*
+7 -12
View File
@@ -286,25 +286,19 @@ main(void)
}
/*
* /model belongs to the session: the selector is written to the
* session's sidecar and comes back when the session is reopened.
* /model changes this run only. Nothing is written to the config or to
* a session sidecar, so a restart is the config (or -m), not the last
* model someone tried.
*/
kind = sp_engine_input(eng, "/model test-model-2", &out);
CHECK(kind == SP_INPUT_HANDLED);
CHECK(contains(out.p, "test-model-2"));
{
char mp[800], line[320];
FILE *mf;
char mp[800];
snprintf(mp, sizeof(mp), "%s/%s.model", path,
sp_engine_session_id(eng));
mf = fopen(mp, "r");
CHECK(mf != NULL);
if (mf != NULL) {
CHECK(fgets(line, sizeof(line), mf) != NULL);
CHECK(contains(line, "test-model-2"));
fclose(mf);
}
CHECK(access(mp, F_OK) != 0);
}
sp_buf_clear(&out);
@@ -360,7 +354,8 @@ main(void)
struct sp_engine_state st;
CHECK(sp_engine_state(eng2, &st) == 0);
CHECK(strcmp(st.model, "test-model-2") == 0);
/* the config wins: /model was not saved */
CHECK(strcmp(st.model, "test-model") == 0);
}
n2 = sp_engine_agents(eng2);
for (i = 0; i < n2; i++)
+5 -7
View File
@@ -177,7 +177,7 @@ check "a session file was opened" sh -c "ls '$D'/home/.splinter/sess-*.jsonl | t
run_text "/model" 'Provider far' 60 '^openai:'
check "the model menu lists the configured providers" \
grep -q '"callback_data":"model:far"' "$D/sent.log"
check "the model menu shows the models" grep -q 'far other' "$D/sent.log"
check "the model menu shows the models" grep -q 'far/other' "$D/sent.log"
check "the button switches the model" \
grep -q '^Modell: other (Provider far' "$D/sent.log"
# the next turn really uses the new endpoint (the test one is dead: port 9)
@@ -185,13 +185,11 @@ check "the next turn goes to the new endpoint" \
grep -q '^openai:' "$D/sent.log"
# /model probe asks the endpoint what it serves and switches to one of them
run_text "/model probe" 'gespeichert' 55
run_text "/model probe" 'Provider local' 55
check "the probe lists served models" grep -q '"callback_data":"mm:0"' "$D/sent.log"
check "a probed model is used" grep -q '^Modell: m (Provider main)' "$D/sent.log"
check "the choice is saved for the next start" \
test -f "$D/home/splinter.conf.d/90-model.conf"
check "the saved choice names the model" \
grep -q '^model = m$' "$D/home/splinter.conf.d/90-model.conf"
check "a probed model is used" grep -q '^Modell: m (Provider local' "$D/sent.log"
check "the choice is not saved" \
test ! -f "$D/home/splinter.conf.d/90-model.conf"
# /connect writes a provider to the config drop-in
run_text "/connect" 'Provider testprov gespeichert' 70