Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat: 模型没额度了,也能在这次对话里换掉它

lmliheng9eeb78d6d0f4
diff --git a/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.md b/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.md
new file mode 100644
index 00000000..3a68f69f
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.md
@@ -0,0 +1,51 @@
+# A model with no quota left can still be left inside the conversation
+
+- **Date:** 2026-10-29
+- **Type:** feature
+- **Scope:** `core`, `server`, `web`
+- **Breaking:** no
+
+[中文](2026-10-29-model-switch-drops-dead-context.zh.md)
+
+Switching the model inside a conversation starts by having the **current** model compact the context into a
+summary — and that summarize request goes to that same model. So once a model is entirely unusable (quota
+exhausted, credential rejected, endpoint down), the conversation is stuck on it: the first step of leaving it
+cannot be sent.
+
+The switch dialog now carries a box that is off by default: **switch even if it cannot be compacted**. With it
+ticked, a compaction that really cannot run means the context is dropped whole instead, nothing further is
+sent, and the conversation moves to the target model. The failed summarize's event pair is followed by a
+`discard` pair, so what happened is visible in the transcript. The box says what it costs: the summary is gone —
+the transcript stays, but the new model does not inherit that working memory.
+
+A caller can ask for the same thing directly: `POST /api/sessions/:id/switch-model` with
+`onCompactionFailure: "discard"`. Leaving it out is the old behaviour (the switch fails and stays put). An
+abort is not a compaction failure and never drops a context.
+
+## Details
+
+- `packages/core/src/engine/context-engine.ts`: `SwitchFailurePolicy = "stay" | "discard"`, and
+ `switchContext(signal?, opts?)` — when a summarize does not complete and the caller asked for `"discard"`, a
+ `discard` event pair follows (`discardContext("manual")`, which sends nothing) and the switch completes. Only
+ `fatal` / `retryable` failures degrade; `aborted` and a switch that never got to start a compaction are left
+ as they were. What rides to the new context is still text alone, matching the switch's existing rule.
+- `packages/core/src/session.ts`: `ModelSwitchOptions.onCompactionFailure` is passed through, and the type joins
+ core's export list.
+- `packages/server/src/runtime/session-manager.ts`: `startSwitch` takes a third argument and passes it on.
+ `POST /:sessionId/switch-model` validates the field with `optionalEnum` (anything outside the pair is a 400),
+ and `SessionSwitchModelRequest` (`packages/server/src/api/types.ts`) carries it.
+- `packages/web/src/features/chat/chat-page.tsx`: the box is offered only on the shape that really compacts (the
+ other two run no compaction), off by default, and only a ticked box puts `onCompactionFailure` in the request
+ body.
+- Copy: one key and its hint in `strings.ts` / `strings-en.ts` (`modelSwitchInSessionDiscardFails`).
+- Tests: two in `packages/core/test/model-switch.test.ts` (a failure that degrades rotates onto the target with
+ no summary in its file; an abort does not degrade), one in
+ `packages/core/test/prompt-cache-invariants.test.ts` (the retry-exhausted kind of failure degrades too, and the
+ dead model receives nothing more), two in `packages/server/test/session-switch-model.test.ts` (the field reaches
+ core as sent; an invalid value is a 400).
+- Docs: the in-session model switch section of `packages/docs/content/sessions-and-traces.{zh,en}.md`.
+
+## Compatibility
+
+- Omitting the field is the old behaviour: a failed compaction keeps the model. Nothing about the on-disk or
+ Trace record shapes changes (only the already-existing `discard` pair appears), and AMSP is untouched.
diff --git a/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.zh.md b/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.zh.md
new file mode 100644
index 00000000..9338b0fa
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-model-switch-drops-dead-context.zh.md
@@ -0,0 +1,46 @@
+# 模型没额度了,也能在这次对话里换到别的模型
+
+- **日期:** 2026-10-29
+- **类型:** feature
+- **范围:** `core`、`server`、`web`
+- **破坏性:** 无
+
+[English](2026-10-29-model-switch-drops-dead-context.md)
+
+在会话里换模型,第一步是让**当前**这个模型把上下文压成一段摘要 —— 而这次摘要请求也要发到那个模型上。
+所以模型一旦整个不可用(额度用尽、凭据失效、接口不通),这个会话就卡死在它上面:换模型的第一步自己就
+发不出去。
+
+现在切换确认框里多了一个默认不勾的选项:**压缩失败就直接切换(放弃摘要)**。勾上以后,压缩真的压不动
+时,上下文被整段丢弃(不再发任何请求),对话照常切到目标模型;事件流里失败的压缩之后紧跟一对 `discard`
+事件,所以发生过什么,对话里看得见。代价就写在选项下面:摘要没了 —— 对话正文仍在,但新模型接不到这段
+工作记忆。
+
+调用方也可以直接走接口:`POST /api/sessions/:id/switch-model` 带 `onCompactionFailure: "discard"`。不传
+就是老行为(切换失败,留在原模型)。被用户中断(`aborted`)不算压缩失败,任何时候都不会因此丢上下文。
+
+## 细节
+
+- `packages/core/src/engine/context-engine.ts`:新增 `SwitchFailurePolicy = "stay" | "discard"`;
+ `switchContext(signal?, opts?)` 在 summarize 未能完成且调用方要求 `"discard"` 时,跟上一对
+ `discard` 事件(`discardContext("manual")`,不发请求)并照常完成切换 —— 只在 `fatal` / `retryable`
+ 两种失败上降级,`aborted` 与「压根没能开始压缩」都保持原样。带到新上下文的仍只取文本,与既有的切换
+ 规则一致。
+- `packages/core/src/session.ts`:`ModelSwitchOptions.onCompactionFailure` 透传给引擎;`core` 的
+ 导出表加上这个类型。
+- `packages/server/src/runtime/session-manager.ts`:`startSwitch` 接第三个参数并透传;路由:
+ `POST /:sessionId/switch-model` 用 `optionalEnum` 校验,只认这两个值,其余 400;
+ `SessionSwitchModelRequest`(`packages/server/src/api/types.ts`)加上这个可选字段。
+- `packages/web/src/features/chat/chat-page.tsx`:确认框只在「会跑压缩」的那种形状上给出这个复选框
+ (另外两种形状不压缩,勾了也没意义),默认不勾,勾上才把 `onCompactionFailure` 放进请求体。
+- 文案:`strings.ts` / `strings-en.ts` 各加两条(`modelSwitchInSessionDiscardFails` 与其说明)。
+- 测试:`packages/core/test/model-switch.test.ts` 两条(失败降级后轮换到目标、目标的新文件里没有摘要;
+ 被中断时不降级),`packages/core/test/prompt-cache-invariants.test.ts` 一条(重试预算耗尽那种失败
+ 同样降级,死掉的模型此后再也收不到请求),`packages/server/test/session-switch-model.test.ts` 两条
+ (字段按原样透传到 core;非法取值 400)。
+- 文档:`packages/docs/content/sessions-and-traces.{zh,en}.md` 的「会话内切换模型」一节。
+
+## 兼容
+
+- 不传新字段就是老行为:压缩失败仍留在原模型。磁盘格式与 Trace 记录格式没变(新出现的只是既有
+ `discard` 事件对),AMSP 协议未动。
diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.md
index eb25355d..d4c604dc 100644
--- a/docs/FORK-PROGRESS.md
+++ b/docs/FORK-PROGRESS.md
@@ -18867,3 +18867,56 @@ cli **38 / 561** · web **271 / 3339 通过 / 2 跳过** · ui-gallery **20 / 14
豆包式画板的**二期界面**(`packages/ui/src/components/overlays/lightbox/lightbox.tsx` 的胶囊工具条 + 同批缩略图 +
真实像素角标)—— 已经在第一百五十八轮末尾点名;待办里那几条卡点(2.2c / 3.5 / 3.6 / 4.1–4.3 / 5.6 / 5.10)照旧
等人拍板或等 key,不动。
+
+## 第一百六十轮:模型没额度也能在这次会话里换掉它(2026-10-29,用户拍板 A 方案)
+
+### 开工自检
+
+`/root/adelie-fork` 的 `main` 在 `569eb3ef`(第一百五十九轮),`origin/main` 与它同号。`git status --short`
+**不干净**:树里带着**别处留下的**未提交改动 —— 豆包式画板那一轮(`packages/ui/.../lightbox/lightbox.tsx`、
+新增 `image-board.ts`、`packages/ui/src/strings.ts`、两个 ui 测试、`packages/web/src/features/chat/chat-input.tsx`、
+`packages/web/src/lib/{strings,strings-en,ui-strings}.ts`、两份 `changelog/unreleased/2026-10-29-image-board-bar{,.zh}.md`),
+最后写入 23:08,此后五十多分钟没有动静。
+
+因此本轮**只提交自己的文件**;落在别人文件里的自己的改动,用 `git diff` 拆出各自 hunk 后
+`git apply --cached` 单独入暂存区。那批在途改动原样留在工作树里,一个字节都没动。
+
+### 这一轮做了什么
+
+用户拍板的 **A 方案**:会话内换模型时,如果那段压缩压不动,允许**放弃摘要直接切换**。
+
+动机是这条链条:切换模型的第一步是让**当前**模型把上下文压成摘要,而这次摘要请求也发到当前模型上。
+于是模型整个不可用(额度用尽、凭据失效)时,会话卡死在它上面 —— 换模型的第一步自己就发不出去,而会话内
+换模型是唯一能改变当前模型的手段。`packages/core/test/model-switch.test.ts` 里那条
+「a compaction that fails keeps the old model」正是这个死结的既有写照。
+
+### 它怎么落地
+
+- core:`SwitchFailurePolicy = "stay" | "discard"`;`switchContext(signal?, opts?)` 在 summarize 未能完成、
+ 且调用方要求 `discard` 时,紧随其后地走 `discardContext("manual")` —— 那条路不发任何请求,所以它在死掉的
+ 模型上也能走通 —— 然后照常轮换、返回 `completed`。只在 `fatal` / `retryable` 两种失败上降级;`aborted`
+ 是用户自己停的,永远不降级。带到新上下文的仍只取文本,与既有切换规则一致。
+- server:`startSwitch` 第三个参数透传;路由用 `optionalEnum` 只认这两个值,其余 400;DTO 加可选字段。
+- web:确认框只在「会跑压缩」的那种形状上给一个**默认不勾**的复选框,勾上才把字段放进请求体。丢上下文是
+ 用户的选择,不做成静默行为。
+
+### 验证
+
+- core:`model-switch.test.ts` 30 条、`prompt-cache-invariants.test.ts` 9 条全绿;**core 全量 70 文件 /
+ 1452 通过 / 6 跳过**(比上一轮多 3 条,都是本轮新增)。
+- server:`session-switch-model.test.ts` 21 条全绿;**server 全量 206 文件 / 3013 通过 / 15 跳过**(多 2 条)。
+- web:**全量 271 文件 / 3339 通过 / 2 跳过**。
+- `pnpm --filter @adelie/core build` 成功(server/web 从 `dist` 解析类型);`core` / `server` / `web` 三包
+ `typecheck` **EXIT=0**(`gen:ifaces` 报 `src/ifaces.json unchanged`)。
+- 改动文件 `prettier --check` 干净(`model-switch.test.ts` 用 `--write` 修过一次格式,改动只落在本轮新增的段落上)、
+ `oxlint` 0 警告 0 错误。
+
+### 没做 / 留着的
+
+- 真浏览器里点一遍这个复选框(切到别的模型、看失败压缩后是否出现 `discard` 事件对)还没做。
+- B 方案(给压缩配一个备案模型,把 Trace 回放成历史灌进另一个模型)没做:`setHistory` 这条路是通的,代价
+ 与收益在那一轮的对话里列过,等用户另外拍板。
+
+### 下一轮
+
+豆包式画板二期那条在途改动(如果还没被它自己的提交收走)先让它落,再谈别的。
diff --git a/packages/core/src/engine/context-engine.ts b/packages/core/src/engine/context-engine.ts
index 32b792dc..b3e1a722 100644
--- a/packages/core/src/engine/context-engine.ts
+++ b/packages/core/src/engine/context-engine.ts
@@ -141,6 +141,22 @@ export interface OpenContextOptions {
emit: (msg: OmniMessage) => void;
}
+/**
+ * What a model switch does when the summarize compaction that closes its old context cannot
+ * complete (see {@link ContextEngine.switchContext}).
+ *
+ * - `"stay"` (default) — the switch fails and the Session keeps the model it is on. A context is
+ * dropped on purpose or not at all, never as a side effect of a failed request.
+ * - `"discard"` — the context is dropped **without sending anything** and the switch completes on
+ * the target. This is the way out of a model that cannot answer at all: the summarize request is
+ * one of that model's own requests, so a model that is out of quota or whose credential was
+ * rejected cannot summarize itself, and the user would otherwise be unable to leave it inside
+ * the Session (a model switch is the only way to change it in place). What it costs is the
+ * summary: the conversation's working memory is gone (the Transcript, the Trace files and the
+ * Session itself stay), and the next context opens with the carried text alone.
+ */
+export type SwitchFailurePolicy = "stay" | "discard";
+
/** Result of one compaction run: a StopReason terminal state (completed / aborted / retryable — abandoned, made up at the next trigger / fatal — needs a config change first); carries the summary message when summarize succeeds. */
interface CompactionResult {
status: StopReason;
@@ -1125,7 +1141,7 @@ export class ContextEngine {
* the summary is what the next model continues from. It is an ordinary compaction request
* on the running LLM object — the same model, prompt, toolset and parameters, one appended
* user turn — so it extends the prefix the provider has cached. Short of `completed`, the
- * context stays as it was.
+ * context stays as it was — unless `opts.onCompactionFailure` says otherwise (see below).
* - A context with none has nothing to summarize and is simply replaced: no request and no
* event pair. Its pending text rides on in memory. Nothing is written until the next
* context is open, so an opener that throws leaves the Trace as it was.
@@ -1134,11 +1150,37 @@ export class ContextEngine {
* its `session_meta` is the durable record of the switch — a resume reads the model from
* the latest file — and the summary the context opens with follows it. That meta is yielded
* last. Returns the terminal status.
+ *
+ * `opts.onCompactionFailure` decides what a summarize that cannot complete means: `"stay"`
+ * (the default, and what a caller that passes nothing gets) leaves the Session on its model,
+ * while `"discard"` drops the context and switches anyway — the paired `discard` events say so
+ * on the stream and in the Trace, right after the `fatal`/`retryable` end of the failed
+ * summarize. Only a **failure** degrades: `aborted` is the user stopping the switch, and a
+ * switch that could not start a compaction at all is not a compaction failure either.
*/
- async *switchContext(signal?: AbortSignal): AsyncGenerator<OmniMessage, StopReason> {
+ async *switchContext(
+ signal?: AbortSignal,
+ opts?: { onCompactionFailure?: SwitchFailurePolicy },
+ ): AsyncGenerator<OmniMessage, StopReason> {
if (this.sessionTurns > 0) {
const status = yield* this.compact({ signal, mode: "summarize" });
- if (status !== "completed") return status ?? "fatal";
+ const degraded =
+ status !== "completed" &&
+ opts?.onCompactionFailure === "discard" &&
+ (status === "fatal" || status === "retryable");
+ if (degraded) {
+ // The failed summarize already wrote its Prompt and its event pair to the old Trace, so
+ // what is being given up stays visible; the drop itself sends nothing (the discard path
+ // needs no model), which is exactly what makes an unusable model leavable. The carry
+ // rule is the switch's own: text alone, since tool outputs pair with tool calls only the
+ // context left behind holds and images stay behind with them.
+ this.pendingCarryOver = this.pendingCarryOver.filter(
+ (m) => (m.payload as { type?: string }).type === "text",
+ );
+ yield* this.discardContext("manual");
+ } else if (status !== "completed") {
+ return status ?? "fatal";
+ }
} else {
yield* this.startNewContext();
// A switch carries text alone: tool outputs pair with tool calls only the context left
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 19494b30..9686e5ed 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -46,6 +46,7 @@ export type {
OpenContextOptions,
OpenedContext,
RunOptions,
+ SwitchFailurePolicy,
TraceSink,
} from "./engine/context-engine.js";
export { ModelSwitchRefusedError, Session } from "./session.js";
diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts
index 860d32a0..774f113d 100644
--- a/packages/core/src/session.ts
+++ b/packages/core/src/session.ts
@@ -67,6 +67,7 @@ import type {
OpenContextOptions,
OpenedContext,
RunOptions,
+ SwitchFailurePolicy,
TraceSink,
} from "./engine/context-engine.js";
@@ -233,11 +234,20 @@ export interface ModelSwitchSupport {
reassembleInitialContext(ref: ModelRef): Promise<Omit<SessionOpenedContext, "llm">>;
}
-/** `Session.switchModel` options: the target's paired reference, and the abort signal for the compaction request. */
+/** `Session.switchModel` options: the target's paired reference, the abort signal for the compaction request, and what a summarize that cannot complete means. */
export interface ModelSwitchOptions {
provider: string;
modelId: string;
signal?: AbortSignal;
+ /**
+ * What to do when the summarize compaction that closes the running context cannot complete:
+ * `"stay"` (default) keeps today's rule — the switch fails and the Session stays on the model
+ * it is on, leaving the context untouched — while `"discard"` drops the context without sending
+ * anything and completes the switch on the target (see `ContextEngine.switchContext`). The
+ * second one is the only way out of a model that cannot answer at all — an exhausted quota, a
+ * rejected credential — since the summarize request would be that same model's.
+ */
+ onCompactionFailure?: SwitchFailurePolicy;
}
/**
@@ -943,7 +953,10 @@ export class Session {
*
* Returns the terminal status: `completed` — the Session is on the target, and children
* spawned from here inherit it; anything else — the switch was stopped or its compaction
- * failed (the events say how) and the Session stays on the model it was on.
+ * failed (the events say how) and the Session stays on the model it was on. That last part is
+ * what `opts.onCompactionFailure: "discard"` changes for a failed compaction: the context is
+ * dropped and the switch completes, which is how a Session leaves a model whose requests all
+ * fail (see `ModelSwitchOptions`).
*/
async *switchModel(opts: ModelSwitchOptions): AsyncGenerator<OmniMessage, StopReason> {
const target: ModelRef = { provider: opts.provider, model_id: opts.modelId };
@@ -976,7 +989,12 @@ export class Session {
if (!(yield* this.ensureEngine(opts.signal))) return "aborted";
this.switchTarget = target;
try {
- const status = yield* this.engine!.switchContext(opts.signal);
+ const status = yield* this.engine!.switchContext(
+ opts.signal,
+ opts.onCompactionFailure === undefined
+ ? undefined
+ : { onCompactionFailure: opts.onCompactionFailure },
+ );
// Input an aborted bootstrap left with the Session rides on like the engine's pending
// input: its text alone, in memory (the original stays where the abort wrote it).
if (status === "completed") {
diff --git a/packages/core/test/model-switch.test.ts b/packages/core/test/model-switch.test.ts
index ea203f48..8f23ce16 100644
--- a/packages/core/test/model-switch.test.ts
+++ b/packages/core/test/model-switch.test.ts
@@ -14,10 +14,11 @@
* compaction; none — a context a compaction just closed, or an open one that has not answered
* yet: simply replaced, with no event pair), switching twice before typing, the never-run
* Session, the same-model and refused-target no-ops, the failure paths that keep the old
- * model, and — for every switch path — the file the switch opened and what `resumeTrace`
- * recovers from it. The real Agent's composition (Project config, credentials, spawn
- * inheritance) is in agent.test.ts; `agent.resumeSession` on a switched Session's Trace is in
- * resume.test.ts.
+ * model — plus the one that does not when asked to drop the context instead
+ * (`onCompactionFailure: "discard"`) — and, for every switch path, the file the switch opened
+ * and what `resumeTrace` recovers from it. The real Agent's composition (Project config,
+ * credentials, spawn inheritance) is in agent.test.ts; `agent.resumeSession` on a switched
+ * Session's Trace is in resume.test.ts.
*/
import { mkdtemp, readdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
@@ -47,7 +48,7 @@ import type {
LLMInterface,
LLMOutcome,
} from "../src/interfaces/index.js";
-import type { CompactionSettings } from "../src/engine/context-engine.js";
+import type { CompactionSettings, SwitchFailurePolicy } from "../src/engine/context-engine.js";
import { ModelSwitchRefusedError, Session } from "../src/session.js";
import type {
ModelSwitchSupport,
@@ -300,11 +301,17 @@ function harness(
return { opens, validated, reassembled, written, trace, session, files };
}
-const switchTo = (session: Session, model: ModelRef, signal?: AbortSignal) =>
+const switchTo = (
+ session: Session,
+ model: ModelRef,
+ signal?: AbortSignal,
+ onCompactionFailure?: SwitchFailurePolicy,
+) =>
session.switchModel({
provider: model.provider,
modelId: model.model_id,
...(signal ? { signal } : {}),
+ ...(onCompactionFailure ? { onCompactionFailure } : {}),
});
// ---------------------------------------------------------------------------
@@ -1033,6 +1040,83 @@ describe("in-session model switch", () => {
expect(h.trace.currentPath()).toBe(oldPath);
});
+ it("a summarize that cannot complete still switches when told to drop the context: the discard pair follows the failed one, and the target opens empty", async () => {
+ const llmA = new ScriptedLLM(
+ [
+ { messages: [assistantText("answer one"), usage(50, 50)] },
+ { messages: [], outcome: { status: "fatal", errorCode: "auth", errorMessage: "nope" } },
+ ],
+ "A",
+ );
+ const llmB = new ScriptedLLM([{ messages: [assistantText("answer two"), usage(20, 70)] }], "B");
+ const h = harness(traces, { llmA, llms: { [MODEL_B.model_id]: [llmB] } });
+ sessions.push(h.session);
+ await collect(h.session.run([userText("task one")], { approve: allowAll }));
+
+ const { all, result } = await collectWithReturn(
+ switchTo(h.session, MODEL_B, undefined, "discard"),
+ );
+
+ // The model that cannot summarize itself is left behind. Two pairs on the stream: the
+ // summarize that failed, then the drop that took its place. Nothing was sent for the drop —
+ // the discard path needs no model at all, which is the whole point — so the old model saw
+ // its turn and its one failed compaction request, and nothing more.
+ expect(result).toBe("completed");
+ expect(
+ compactionEvents(all).map((e) => [e.type, e.mode, (e as CompactionEndPayload).status]),
+ ).toEqual([
+ ["compaction_begin", "summarize", undefined],
+ ["compaction_end", "summarize", "fatal"],
+ ["compaction_begin", "discard", undefined],
+ ["compaction_end", "discard", "completed"],
+ ]);
+ expect(llmA.calls).toHaveLength(2);
+ expectEndsWithMetaOn(all, MODEL_B);
+ expect(h.opens).toEqual([MODEL_B]);
+ expect(h.session.modelId).toBe(MODEL_B.model_id);
+ expect(h.session.compactability()).toBe("just_compacted");
+
+ // The switch opened the target's file at once, and nothing of the dropped context is in it:
+ // the summary was never written (the drop replaces it), so a resume reads an empty context.
+ expect(await h.files()).toEqual([`${SESSION_ID}_001.jsonl`, `${SESSION_ID}_002.jsonl`]);
+ const opened = await readTrace(h.trace.currentPath());
+ expect(payloadTypes(opened)).toEqual(["session_meta", "tool_list_ready"]);
+ expect(modelOf(opened[0]!)).toEqual(MODEL_B);
+ const resumed = resumeTrace(opened);
+ expect(resumed.contextClosed).toBe(false);
+ expect(resumed.carryOver).toEqual([]);
+
+ await collect(h.session.run([userText("task two")], { approve: allowAll }));
+ expect(llmB.calls[0]!.map(textOf)).toEqual(["task two"]);
+ });
+
+ it("an aborted summarize is the user stopping the switch, not a failure to degrade: the Session keeps its model", async () => {
+ const llmA = new ScriptedLLM(
+ [
+ { messages: [assistantText("answer one"), usage(50, 50)] },
+ { messages: [], outcome: { status: "aborted" } },
+ ],
+ "A",
+ );
+ const llmB = new ScriptedLLM([], "B");
+ const h = harness(traces, { llmA, llms: { [MODEL_B.model_id]: [llmB] } });
+ sessions.push(h.session);
+ const oldPath = h.trace.currentPath();
+ await collect(h.session.run([userText("task one")], { approve: allowAll }));
+
+ const { all, result } = await collectWithReturn(
+ switchTo(h.session, MODEL_B, undefined, "discard"),
+ );
+
+ expect(result).toBe("aborted");
+ expect(compactionEvents(all).map((e) => e.mode)).toEqual(["summarize", "summarize"]);
+ expect(hasMeta(all)).toBe(false);
+ expect(h.opens).toEqual([]);
+ expect(h.session.modelId).toBe(MODEL_A.model_id);
+ expect(await h.files()).toEqual([`${SESSION_ID}_001.jsonl`]);
+ expect(h.trace.currentPath()).toBe(oldPath);
+ });
+
it("an aborted compaction request keeps the old model too, and the compaction after it opens on that model", async () => {
const llmA = new ScriptedLLM(
[
diff --git a/packages/core/test/prompt-cache-invariants.test.ts b/packages/core/test/prompt-cache-invariants.test.ts
index d2e7744d..4e57b712 100644
--- a/packages/core/test/prompt-cache-invariants.test.ts
+++ b/packages/core/test/prompt-cache-invariants.test.ts
@@ -379,4 +379,48 @@ describe("prompt-cache invariants of request assembly", () => {
expect(last.role).toBe("user");
expect(last.content.at(-1)!.text).toBe("task two");
});
+
+ it("a switch whose compaction is out of retries drops the context when asked to, so the dead model's line ends there", async () => {
+ const target = "claude-opus-4-7";
+ const first = recordingModel(modelConfig(), [
+ { text: "First answer.", promptTokens: 20 },
+ // A provider that keeps dropping the compaction request — an exhausted quota reads the
+ // same way. The budget is zero, so the one attempt exhausts it and the compaction ends
+ // `retryable` instead of retrying.
+ { text: "[summary]half a summ", promptTokens: 30, outcome: "retryable-after-text" },
+ ]);
+ const second = recordingModel(modelConfig({ modelId: target }), [
+ { text: "Starting over on the new model." },
+ ]);
+ const engine = new ContextEngine({
+ llm: first.model,
+ environment: fakeEnvironment,
+ compaction: compactionSettings(),
+ compactionMaxReconnects: 0,
+ openNextContext: () => ({ llm: second.model }),
+ });
+
+ await collect(engine.run([userText("task one")], { approve: allowAll }));
+
+ const events: string[] = [];
+ for await (const msg of engine.switchContext(undefined, { onCompactionFailure: "discard" })) {
+ const payload = msg.payload as { type?: string; mode?: string; status?: string };
+ if (payload.type === "compaction_end") events.push(`${payload.mode}:${payload.status}`);
+ }
+ expect(events).toEqual(["summarize:retryable", "discard:completed"]);
+
+ await collect(engine.run([userText("task two")], { approve: allowAll }));
+
+ // The dead model saw its turn and the one compaction request that failed, and nothing more:
+ // the drop sends nothing, which is what makes a model with no quota leavable.
+ expect(first.requests).toHaveLength(2);
+ expect(second.requests).toHaveLength(1);
+ expect(second.requests[0]!.wireConfig.model).toBe(target);
+ // No summary was written (there is none), so the target's first request is the new line the
+ // switch opened, carrying the new turn alone.
+ const opening = wireMessage(second.requests[0]!, 0);
+ expect(opening.role).toBe("user");
+ expect(blockTypes(opening)).toEqual(["text"]);
+ expect(opening.content[0]!.text).toBe("task two");
+ });
});
diff --git a/packages/docs/content/sessions-and-traces.en.md b/packages/docs/content/sessions-and-traces.en.md
index 62224b82..779d8ab5 100644
--- a/packages/docs/content/sessions-and-traces.en.md
+++ b/packages/docs/content/sessions-and-traces.en.md
@@ -141,7 +141,7 @@ The model picker in an active conversation's toolbar switches the model inside t
The compaction is an ordinary `manual` one: nothing on the `compaction_begin` / `compaction_end` pair names a model. A context with no completed turn has nothing to summarize, so the switch sends no request and records no pair. One that was just compacted hands its held summary to the new file. One whose first request failed or was stopped is left as it is: the summary it opened with, if any, is written again at the head of the new file, and of its other pending input only the text rides on, in memory. A switch carries no image to the new context.
-The Session keeps its model when the compaction fails or is aborted. The target must be in the Project configuration and constructible (credentials in place), or the switch is refused before any request. A Session that never ran has no context to compact: it switches directly and writes nothing.
+The Session keeps its model when the compaction fails or is aborted by default. A **failed** compaction can instead give up the context: the caller asks for `onCompactionFailure: "discard"` (the Web App offers it as a box that is off by default in the switch dialog), and the failed summarize's event pair is followed by a `discard` pair — the context is dropped whole, nothing further is sent, and the switch completes. This is the only way out of a model that is itself unusable: the summarize request would go to that same model, which cannot compact itself. What it costs is the summary: the conversation's text stays in the transcript and the Trace files, but the new model does not inherit its working memory. An abort is not a compaction failure and never drops a context. The target must be in the Project configuration and constructible (credentials in place), or the switch is refused before any request. A Session that never ran has no context to compact: it switches directly and writes nothing.
Resume reads the model from the latest file, so a Session restarted right after a switch runs on the new model with the summary pending. The summary is still known as the one that file opened with: another switch before the first turn completes writes it on to the next file, restart or not. A switch that dies before its new file exists is lost, the summary is not: the Session resumes on the model it was on, with the summary pending.
diff --git a/packages/docs/content/sessions-and-traces.zh.md b/packages/docs/content/sessions-and-traces.zh.md
index a6695c31..a32660ba 100644
--- a/packages/docs/content/sessions-and-traces.zh.md
+++ b/packages/docs/content/sessions-and-traces.zh.md
@@ -141,7 +141,7 @@ summarize 模式下,恢复后会重建 `[context_summary]`,并把它加在
这次压缩是普通的 `manual` 压缩:`compaction_begin` / `compaction_end` 事件对上没有任何字段记录模型。没有完成任何一轮的上下文没有内容可总结,切换既不发请求,也不记录事件对。刚压缩过的上下文把手中的摘要直接写在新文件开头。首个请求失败或被停止的上下文保持原样:它开启时所带的摘要(如有)会再写一次到新文件开头,其余待发的输入只带文本,且只在内存中带过去。切换不会把图片带进新上下文。
-压缩失败或被中断时,Session 保持原模型。目标必须在 Project 配置中且能构造出来(凭据齐全),否则切换在发出任何请求之前就被拒绝。从未运行过的 Session 没有上下文可压缩:直接切换,不写入任何内容。
+压缩失败或被中断时,Session 默认保持原模型。压缩**失败**时可以改为丢弃上下文:调用方传 `onCompactionFailure: "discard"`(Web App 在切换确认框里给一个默认不勾的选项),失败的 summarize 事件对之后紧跟一对 `discard` 事件,上下文整段丢弃、不再发送任何请求,切换照常完成。这是模型本身已经不可用时的唯一出路——摘要请求也得靠这个模型发出,它压不动自己;代价是摘要丢失,对话正文仍在对话记录与 Trace 文件里,新模型接不到这段工作记忆。被中断(`aborted`)不算压缩失败,任何情况下都不会因此丢弃上下文。目标必须在 Project 配置中且能构造出来(凭据齐全),否则切换在发出任何请求之前就被拒绝。从未运行过的 Session 没有上下文可压缩:直接切换,不写入任何内容。
恢复从最新文件读取模型,所以切换后立刻重启的 Session 仍运行在新模型上,摘要待发。这条摘要仍被认作该文件开头的摘要:在完成第一轮之前再次切换,无论其间是否重启,它都会写到下一个文件的开头。切换在新文件建立之前中断时,丢失的只是这次切换,摘要不丢:Session 恢复在原模型上,摘要待发。
diff --git a/packages/server/src/api/types.ts b/packages/server/src/api/types.ts
index 51dc295e..3f967d1b 100644
--- a/packages/server/src/api/types.ts
+++ b/packages/server/src/api/types.ts
@@ -2645,6 +2645,16 @@ export interface SessionSwitchModelRequest {
provider: string;
/** Upstream model_id of the target model. */
modelId: string;
+ /**
+ * What to do when the summarize compaction that closes the running context cannot complete
+ * (`POST …/switch-model`, body). `"stay"` (the default when the field is absent) fails the
+ * switch and leaves the Session on the model it is on; `"discard"` drops the context without
+ * sending anything and completes the switch on the target — the way out of a model whose every
+ * request fails (an exhausted quota, a rejected credential), since the summarize request would
+ * be that same model's. The cost is the conversation's working memory: the summary is what the
+ * new context would have opened with.
+ */
+ onCompactionFailure?: "stay" | "discard";
}
export interface TaskCreateResponse {
diff --git a/packages/server/src/http/routes/sessions.ts b/packages/server/src/http/routes/sessions.ts
index e4d418c0..d5d87f56 100644
--- a/packages/server/src/http/routes/sessions.ts
+++ b/packages/server/src/http/routes/sessions.ts
@@ -21,7 +21,7 @@ import {
userText,
videoUrlMessage,
} from "@adelie/core";
-import type { OmniMessage } from "@adelie/core";
+import type { OmniMessage, SwitchFailurePolicy } from "@adelie/core";
import type {
ApprovalMode,
FilesStatResponse,
@@ -205,6 +205,14 @@ export const APPROVAL_MODES: readonly ApprovalMode[] = [
"always-ask",
];
+/**
+ * What a model switch may do when the summarize compaction that closes the context cannot
+ * complete — core's `SwitchFailurePolicy`, spelled out for the route's validation: `"stay"`
+ * leaves the Session on its model, `"discard"` drops the context without sending anything and
+ * completes the switch, which is the only way out of a model whose every request fails.
+ */
+export const SWITCH_FAILURE_POLICIES: readonly SwitchFailurePolicy[] = ["stay", "discard"];
+
/** Unit-count bounds for windowed history reads (`tailLimit` / `limit`), and the `before` page's default. */
const MESSAGES_PAGE_LIMIT_MAX = 1000;
const MESSAGES_PAGE_LIMIT_DEFAULT = 200;
@@ -1783,6 +1791,11 @@ export function sessionsRoutes(deps: SessionsRouteDeps): Hono<AppEnv> {
// pair, nothing inferred — one half alone is a 400 like everywhere else a model is named.
// 202 when the switch streams as a compaction; 200 with the fresh DTO when a Session that
// never ran switched inside the call (the manager tells the two apart).
+ //
+ // `onCompactionFailure: "discard"` is the caller's answer to a model that cannot summarize
+ // itself (quota exhausted, credential rejected): the context is dropped instead of the switch
+ // failing, so the Session can leave a model every one of whose requests fails. Absent means
+ // core's default, "stay" (see the manager's startSwitch).
app.post("/:sessionId/switch-model", async (c) => {
const row = resolveSession(c);
const body = await readJson(c);
@@ -1790,7 +1803,17 @@ export function sessionsRoutes(deps: SessionsRouteDeps): Hono<AppEnv> {
provider: requireString(body, "provider", { minLen: 1 }),
modelId: requireString(body, "modelId", { minLen: 1 }),
};
- const outcome = await deps.manager.startSwitch(row.sessionId, ref);
+ const onCompactionFailure = optionalEnum(
+ body,
+ "onCompactionFailure",
+ SWITCH_FAILURE_POLICIES,
+ "onCompactionFailure",
+ );
+ const outcome = await deps.manager.startSwitch(
+ row.sessionId,
+ ref,
+ onCompactionFailure === undefined ? undefined : { onCompactionFailure },
+ );
if (!outcome.switched) {
return c.json({ sessionId: outcome.sessionId } satisfies TaskCreateResponse, 202);
}
diff --git a/packages/server/src/runtime/session-manager.ts b/packages/server/src/runtime/session-manager.ts
index f4f3c607..f3716114 100644
--- a/packages/server/src/runtime/session-manager.ts
+++ b/packages/server/src/runtime/session-manager.ts
@@ -63,6 +63,7 @@ import type {
StopReason,
SubagentMessageOptions,
SubagentMessageOutcome,
+ SwitchFailurePolicy,
TextPayload,
ThinkingLevelName,
ToolDetachResult,
@@ -1424,10 +1425,16 @@ export class SessionManager {
* leaves them where they were. Usage: a drive bills to the model it started on, so the
* switch's compaction request goes to the model that served it and the next run to the new
* one.
+ *
+ * `opts.onCompactionFailure` is passed straight to core (`"discard"` drops the context and
+ * switches anyway): it is the route's answer to a model whose requests all fail, where the
+ * closing summarize could never succeed. Nothing here reads it — the events the drive streams
+ * say which of the two happened.
*/
async startSwitch(
sessionId: string,
ref: ModelRefDto,
+ opts?: { onCompactionFailure?: SwitchFailurePolicy },
): Promise<{ sessionId: string; switched: boolean }> {
return this.withLock(sessionId, async () => {
this.assertOpen();
@@ -1450,7 +1457,13 @@ export class SessionManager {
);
}
const ac = new AbortController();
- const gen = entry.session.switchModel({ ...ref, signal: ac.signal });
+ const gen = entry.session.switchModel({
+ ...ref,
+ signal: ac.signal,
+ ...(opts?.onCompactionFailure !== undefined
+ ? { onCompactionFailure: opts.onCompactionFailure }
+ : {}),
+ });
const head = gen.next();
const settled = (): void => {
entry.abort = null;
diff --git a/packages/server/test/session-switch-model.test.ts b/packages/server/test/session-switch-model.test.ts
index e7387cff..c050e83a 100644
--- a/packages/server/test/session-switch-model.test.ts
+++ b/packages/server/test/session-switch-model.test.ts
@@ -10,7 +10,9 @@
* (so `GET /` and the compaction threshold follow it, and a client re-reading the Session on the
* new context's `session_meta` already finds it), stay put when the compaction fails or is aborted,
* and usage is attributed to the model that served each request — the switch's own compaction
- * request to the previous model, the next Task to the new one.
+ * request to the previous model, the next Task to the new one. The one body field beyond the pair,
+ * `onCompactionFailure`, is the caller's escape hatch for a model that cannot summarize itself; it
+ * is passed straight through to core, and anything outside its pair is a 400.
*/
import fs from "node:fs";
import path from "node:path";
@@ -75,6 +77,8 @@ interface SwitchFake extends RuntimeSession {
modelId: string;
/** The signals `switchModel` was handed, so a test can see the abort reach it. */
signals: AbortSignal[];
+ /** What the route passed down, normalised (the signal left out): the body's own fields. */
+ switchOpts: { provider: string; modelId: string; onCompactionFailure?: string }[];
/** Whether a `switchModel` call has run to its end. */
ended: boolean;
}
@@ -99,6 +103,7 @@ function switchFake(model: ModelRefDto, behaviour: SwitchBehaviour): SwitchFake
provider: model.provider,
modelId: model.modelId,
signals: [],
+ switchOpts: [],
ended: false,
toolPermission: () => "rw",
generateTitle: async () => ({ title: null, usage: null }),
@@ -114,6 +119,13 @@ function switchFake(model: ModelRefDto, behaviour: SwitchBehaviour): SwitchFake
async *compact(): AsyncGenerator<OmniMessage> {},
async *switchModel(opts): AsyncGenerator<OmniMessage, StopReason> {
fake.signals.push(opts.signal);
+ fake.switchOpts.push({
+ provider: opts.provider,
+ modelId: opts.modelId,
+ ...(opts.onCompactionFailure !== undefined
+ ? { onCompactionFailure: opts.onCompactionFailure }
+ : {}),
+ });
if (behaviour.kind === "throw") throw behaviour.error;
if (behaviour.kind === "inline") {
fake.provider = opts.provider;
@@ -279,6 +291,30 @@ describe("POST /switch-model", () => {
expect(row().modelId).toBe(A.modelId);
});
+ it("onCompactionFailure: the field reaches core as asked, and a value outside the pair is a 400", async () => {
+ const fake = switchFake(A, { kind: "stream", status: "completed" });
+ adopt(fake);
+ const bad = await api.post(url, { ...B, onCompactionFailure: "drop" });
+ expect(bad.status).toBe(400);
+ expect(await errorCode(bad)).toBe("bad_request");
+ expect(fake.switchOpts).toEqual([]); // refused before core was asked
+
+ expect((await api.post(url, { ...B, onCompactionFailure: "discard" })).status).toBe(202);
+ await waitFor(() => t.deps.manager.statusOf(SID) === "idle");
+ expect(fake.switchOpts).toEqual([
+ { provider: B.provider, modelId: B.modelId, onCompactionFailure: "discard" },
+ ]);
+ expect(row()).toMatchObject(B);
+ });
+
+ it("onCompactionFailure is absent unless the caller sends it: the body's own fields are what core sees", async () => {
+ const fake = switchFake(A, { kind: "stream", status: "completed" });
+ adopt(fake);
+ expect((await api.post(url, B)).status).toBe(202);
+ await waitFor(() => t.deps.manager.statusOf(SID) === "idle");
+ expect(fake.switchOpts).toEqual([{ provider: B.provider, modelId: B.modelId }]);
+ });
+
it("409 same_model: the target is the model the Session already runs on", async () => {
const fake = switchFake(A, { kind: "inline" });
adopt(fake);
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index f2d6a0cf..7bc803e1 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -33,6 +33,7 @@ import type {
import {
ActivityIcon,
Button,
+ Checkbox,
ConfirmModal,
CopyButton,
Dot,
@@ -368,10 +369,13 @@ export function ChatPage() {
// A pick in the session toolbar's model picker, waiting on its confirm dialog (null = no
// dialog). `shape` is what the switch will do to the context — compact it first, switch an
// empty conversation at once, or continue from a summary already held — so the dialog and
- // the toast promise only that. See onPickSessionModel / confirmModelSwitch.
+ // the toast promise only that. `discardIfCompactionFails` is the opt-in escape hatch of the
+ // compacting shape: the model being left is the one that has to write the summary, so a model
+ // whose every request fails could never be left (see confirmModelSwitch).
const [modelSwitchAsk, setModelSwitchAsk] = useState<{
to: ModelRefDto;
shape: SwitchContextShape;
+ discardIfCompactionFails: boolean;
} | null>(null);
// The dialog stays open (its buttons busy) until the switch request answers, so a double
// click cannot post the switch twice.
@@ -1834,7 +1838,7 @@ export function ChatPage() {
// Read at pick time: the model's items mutate in place. The live tail decides, behind
// whatever window was backfilled above it.
const shape = switchContextShape([...stream.prefixItems, ...stream.model.items]);
- setModelSwitchAsk({ to: ref, shape });
+ setModelSwitchAsk({ to: ref, shape, discardIfCompactionFails: false });
},
[selected, stream.taskState, stream.prefixItems, stream.model],
);
@@ -1856,6 +1860,11 @@ export function ChatPage() {
const res = await api.switchSessionModel(selected.sessionId, {
provider: ask.to.provider,
modelId: ask.to.modelId,
+ // Only the compacting shape can fail at it: the other two run no compaction, so the box
+ // is not offered there and the field stays out of the request.
+ ...(ask.shape === "compact" && ask.discardIfCompactionFails
+ ? { onCompactionFailure: "discard" as const }
+ : {}),
});
if ("session" in res) {
applySessionRow(res.session);
@@ -2795,10 +2804,12 @@ export function ChatPage() {
)}
</ConfirmModal>
- {/* In-conversation model switch confirmation (the session toolbar's model picker), two
- choices only: compact and switch, or cancel. There is no "switch anyway" — a switch
- always compacts on the current model first, and a failed compaction keeps it. The two
- shapes with nothing to compact read "switch" instead: an empty transcript (the switch
+ {/* In-conversation model switch confirmation (the session toolbar's model picker). The
+ compacting shape offers one extra choice, off by default: drop the context when that
+ compaction cannot complete, which is what lets the conversation leave a model whose
+ every request fails (see the Checkbox below). Without it a switch always compacts on the
+ current model first, and a failed compaction keeps it. The two shapes with nothing to
+ compact read "switch" instead: an empty transcript (the switch
is immediate) and a transcript ending in a completed compaction or a model switch (no
compaction runs; the conversation continues from what is already held). The session
can start running while the dialog is up (a queued follow-up, a schedule): the confirm
@@ -2837,6 +2848,22 @@ export function ChatPage() {
{S.chat.thinkingSwitchBusyHint}
</p>
)}
+ {/* The escape hatch, only where a compaction really runs (the two other shapes run
+ none). Off by default: dropping the context is the user's call, never a surprise. */}
+ {modelSwitchAsk?.shape === "compact" && (
+ <div className="mt-3">
+ <Checkbox
+ checked={modelSwitchAsk.discardIfCompactionFails}
+ onChange={(next) =>
+ setModelSwitchAsk((prev) =>
+ prev === null ? prev : { ...prev, discardIfCompactionFails: next },
+ )
+ }
+ label={S.chat.modelSwitchInSessionDiscardFails}
+ hint={S.chat.modelSwitchInSessionDiscardFailsHint}
+ />
+ </div>
+ )}
</ConfirmModal>
</div>
);
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index e0c8ee47..1135d90f 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3067,6 +3067,9 @@ export const en: Strings = {
modelSwitchInSessionDirectConfirm: "Switch",
modelSwitchInSessionBody: (from: string, to: string): string =>
`The context is compacted on the current model "${from}" first, and this conversation then continues on "${to}". If the compaction fails, it stays on "${from}".`,
+ modelSwitchInSessionDiscardFails: "Switch even if it cannot be compacted",
+ modelSwitchInSessionDiscardFailsHint:
+ "If the current model cannot compact this conversation (quota exhausted, credential rejected), switch to the model above anyway. The cost is the summary: the transcript stays, but the new model does not inherit the conversation's working memory.",
modelSwitchInSessionDirectBody: (to: string): string =>
`This conversation has no context yet, so it switches to "${to}" right away.`,
modelSwitchInSessionCompactedBody: (to: string): string =>
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 4869a74c..96292e1e 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3086,13 +3086,21 @@ export const zh = {
thinkingSwitchApplied: (to: string): string => `上下文已压缩,思考等级已切换为「${to}」。`,
/** Compaction ended without completing — the switch still applies, so say both. */
thinkingSwitchCompactFailed: "压缩未成功完成,思考等级已照常切换。",
- /** In-conversation model switch (the session toolbar's model picker). Title is the confirm dialog's accessible name only. Unlike the thinking level there is no "switch anyway": a switch always compacts on the current model first, and a failed compaction keeps it. */
+ /** In-conversation model switch (the session toolbar's model picker). Title is the confirm dialog's accessible name only. Unlike the thinking level there is no separate "switch anyway" button: a switch always compacts on the current model first, and a failed compaction keeps it — the opt-in box below is the one exception, and only where a compaction really runs. */
modelSwitchInSessionTitle: "切换模型",
modelSwitchInSessionConfirm: "压缩并切换",
/** Confirm label when the transcript is empty: nothing to compact, so it only switches. */
modelSwitchInSessionDirectConfirm: "切换",
modelSwitchInSessionBody: (from: string, to: string): string =>
`将先用当前模型「${from}」压缩上下文,成功后以「${to}」继续本对话;压缩失败则保持「${from}」。`,
+ /**
+ * The escape hatch, offered only where a compaction really runs: the model to leave is the
+ * one that has to summarize, so a model whose every request fails (no quota left, a rejected
+ * credential) can never summarize itself and the switch would fail forever.
+ */
+ modelSwitchInSessionDiscardFails: "压缩失败就直接切换(放弃摘要)",
+ modelSwitchInSessionDiscardFailsHint:
+ "当前模型若压不动这段对话(额度用尽、凭据失效),仍然切到上面的模型。代价是摘要丢失:对话正文还在,但新模型接不到它的工作记忆。",
/** Body when the transcript is empty: there is no context to compact, so the switch is immediate. */
modelSwitchInSessionDirectBody: (to: string): string =>
`当前上下文没有内容,将直接切换到「${to}」。`,