Skip to content

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

fix(web): switching the model on a desk moves the desk (#807)

Myriad-Dreamin8a838a923a11
diff --git a/changelog/unreleased/2026-09-20-desk-model-switch.md b/changelog/unreleased/2026-09-20-desk-model-switch.md
new file mode 100644
index 00000000..c8a98f46
--- /dev/null
+++ b/changelog/unreleased/2026-09-20-desk-model-switch.md
@@ -0,0 +1,12 @@
+# Company mode: switching the model on a desk moves the desk
+
+- **Date:** 2026-09-20
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#807](https://github.com/Prism-Shadow/penguin-harness/pull/807)
+
+[中文版](2026-09-20-desk-model-switch.zh.md)
+
+`/model` in a desk conversation forked it like any other conversation: a new ordinary Session of the employee's Agent on the picked model, which the window then moved to. The employee's model in the chart and the desk recorded in `desks.toml` stayed as they were — so the organization kept sending its calendar rounds and @mentions to the old Session on the old model, the sidebar's desk still opened that one, and the Session the person was now talking in was listed by no page of the organization.
+
+On the employee's current desk the switch is now the employee's: the picked model is written to its chart entry (what every later desk and ticket Session of that employee is opened on), the desk is renewed onto it, and the carried-over first input goes to the new desk. The chart and the desk list are reloaded, so the sidebar follows. A ticket's work Session, or a desk that has already been replaced, still forks as before.
diff --git a/changelog/unreleased/2026-09-20-desk-model-switch.zh.md b/changelog/unreleased/2026-09-20-desk-model-switch.zh.md
new file mode 100644
index 00000000..bae373af
--- /dev/null
+++ b/changelog/unreleased/2026-09-20-desk-model-switch.zh.md
@@ -0,0 +1,12 @@
+# 公司模式:在工位里切换 Model,工位随之更换
+
+- **Date:** 2026-09-20
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#807](https://github.com/Prism-Shadow/penguin-harness/pull/807)
+
+[English](2026-09-20-desk-model-switch.md)
+
+在工位对话里使用 `/model`,原先与普通对话一样是分叉:为该员工的 Agent 在所选 Model 上另开一个普通 Session,窗口随即跳过去。员工条目里的 Model 与 `desks.toml` 里记的工位都没变——组织的日程与 @ 仍发往旧会话、用的还是旧 Model,侧栏的工位打开的也还是旧会话,而人正在说话的那个会话不被组织的任何页面列出。
+
+现在,在员工当前的工位里切换 Model 是员工的事:所选 Model 写入它的员工条目(此后该员工的工位与工单会话都用它),工位更换到新 Model 上,携带来源信息的首条输入发往新工位;员工树与工位列表随即刷新,侧栏跟着走。工单的工作会话、以及已经被替换的旧工位,仍按原来的方式分叉。
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index e22d18bc..54fd7aee 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -33,6 +33,8 @@ import type {
TaskInputPart,
} from "@prismshadow/penguin-server/api";
import * as api from "../../api/endpoints";
+import { switchDeskModel } from "../company/desk-model";
+import { useCompany } from "../../state/company";
import { ApiError } from "../../api/client";
import { S } from "../../lib/strings";
import { useWorkflowTabs, WorkflowFrame, WorkflowTabStrip } from "../workflows/workflow-tabs";
@@ -308,6 +310,7 @@ export function ChatPage() {
const location = useLocation();
const params = useParams<{ sessionId?: string }>();
const { user } = useAuth();
+ const company = useCompany();
const { currency } = useTheme();
const { currentProject, currentAgent, setCurrentAgentId, reloadAgents, agents } = useProject();
const projectId = currentProject?.projectId ?? null;
@@ -1262,6 +1265,38 @@ export function ChatPage() {
prevModelId: selected.modelId,
}),
};
+ // A desk is not forked: the switch is the EMPLOYEE's. Its model goes into the chart and
+ // its desk is renewed onto it (features/company/desk-model.ts), so the organization —
+ // its sidebar, its calendar rounds, its @mentions — follows to the Session the person
+ // is now talking in, instead of staying on the old one while a stray one is opened.
+ if (selected.orgId !== undefined) {
+ try {
+ const deskId = await switchDeskModel(
+ api,
+ {
+ projectId,
+ orgId: selected.orgId,
+ agentId: selected.agentId,
+ sessionId: selected.sessionId,
+ },
+ ref,
+ );
+ if (deskId !== null) {
+ const res = await api.postTask(deskId, { input: [origin, ...input] });
+ discardSessionDraft();
+ void company.reloadOrgChart();
+ void company.reloadOrgSessions();
+ navigate(`/chat/${res.sessionId}`);
+ return true;
+ }
+ } catch (e) {
+ // The model may be written and the desk renewed by now; the lists say which.
+ void company.reloadOrgChart();
+ void company.reloadOrgSessions();
+ toastError(apiErrorText(e, { modelId: ref.modelId }));
+ return false;
+ }
+ }
let createdId: string | null = null;
try {
const created = await api.createSession(
@@ -1293,7 +1328,7 @@ export function ChatPage() {
return false;
}
},
- [projectId, selected, addSession, discardSessionDraft, navigate],
+ [projectId, selected, addSession, discardSessionDraft, navigate, company],
);
// /agent handoff: doesn't use the current Session — creates a new chat for the picked agent
diff --git a/packages/web/src/features/company/desk-model.ts b/packages/web/src/features/company/desk-model.ts
new file mode 100644
index 00000000..12461087
--- /dev/null
+++ b/packages/web/src/features/company/desk-model.ts
@@ -0,0 +1,42 @@
+/**
+ * Switching the model of a DESK.
+ *
+ * `/model` in an ordinary conversation forks it: a new Session of the same Agent on the picked
+ * model, and the old one stays where it was. A desk is not a conversation that can be forked —
+ * it is the employee's standing Session, the one its calendar rounds and @mentions are sent
+ * to, recorded in `desks.toml`. Forking it left the organization on the old Session and the old
+ * model while the person talked to a stray one that no page of the organization lists.
+ *
+ * So on a desk the switch is the employee's: its model is written to the chart (what every
+ * later desk and ticket Session of that employee is opened on), and the desk is renewed — a
+ * new desk Session on that model, recorded as the desk, the previous one kept in its history.
+ */
+import type { ModelRefDto, OrgDeskResponse } from "@prismshadow/penguin-server/api";
+
+/** The three calls this needs, so a test can stand in for the API. */
+export interface DeskModelApi {
+ getOrgDesk(projectId: string, orgId: string, agentId: string): Promise<OrgDeskResponse>;
+ patchOrgEmployee(
+ projectId: string,
+ orgId: string,
+ agentId: string,
+ body: { model: ModelRefDto },
+ ): Promise<unknown>;
+ renewOrgDesk(projectId: string, orgId: string, agentId: string): Promise<OrgDeskResponse>;
+}
+
+/**
+ * Switches the employee's model and renews its desk; resolves to the NEW desk Session's id.
+ * Null when `sessionId` is not that employee's current desk — a ticket's work Session, or a
+ * desk already replaced — and the caller forks as it would anywhere else.
+ */
+export async function switchDeskModel(
+ api: DeskModelApi,
+ at: { projectId: string; orgId: string; agentId: string; sessionId: string },
+ ref: ModelRefDto,
+): Promise<string | null> {
+ const desk = await api.getOrgDesk(at.projectId, at.orgId, at.agentId).catch(() => null);
+ if (desk === null || desk.sessionId !== at.sessionId) return null;
+ await api.patchOrgEmployee(at.projectId, at.orgId, at.agentId, { model: ref });
+ return (await api.renewOrgDesk(at.projectId, at.orgId, at.agentId)).sessionId;
+}
diff --git a/packages/web/test/desk-model.test.ts b/packages/web/test/desk-model.test.ts
new file mode 100644
index 00000000..2c4cb734
--- /dev/null
+++ b/packages/web/test/desk-model.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from "vitest";
+import type { OrgDeskResponse } from "@prismshadow/penguin-server/api";
+import { switchDeskModel } from "../src/features/company/desk-model";
+import type { DeskModelApi } from "../src/features/company/desk-model";
+
+const desk = (sessionId: string): OrgDeskResponse => ({
+ agentId: "acme_ceo",
+ sessionId,
+ workspace: "/w",
+ openedAt: "2026-09-20T00:00:00Z",
+ created: false,
+});
+
+function fakeApi(current: string) {
+ const calls: string[] = [];
+ const api: DeskModelApi = {
+ getOrgDesk: async () => (calls.push("get"), desk(current)),
+ patchOrgEmployee: async (_p, _o, agentId, body) =>
+ void calls.push(`patch ${agentId} ${body.model.provider}/${body.model.modelId}`),
+ renewOrgDesk: async () => (calls.push("renew"), desk("desk-2")),
+ };
+ return { api, calls };
+}
+
+const AT = { projectId: "p", orgId: "acme", agentId: "acme_ceo" };
+const REF = { provider: "openai", modelId: "gpt-x" };
+
+describe("switching the model of a desk", () => {
+ it("writes the employee's model, THEN renews the desk, and answers the new desk", async () => {
+ // The order is the point: the renewed desk is opened on whatever the chart says.
+ const { api, calls } = fakeApi("desk-1");
+ expect(await switchDeskModel(api, { ...AT, sessionId: "desk-1" }, REF)).toBe("desk-2");
+ expect(calls).toEqual(["get", "patch acme_ceo openai/gpt-x", "renew"]);
+ });
+
+ it("leaves anything that is not the employee's current desk to an ordinary fork", async () => {
+ const { api, calls } = fakeApi("desk-1");
+ expect(await switchDeskModel(api, { ...AT, sessionId: "a-ticket-session" }, REF)).toBeNull();
+ expect(calls).toEqual(["get"]);
+ });
+
+ it("does not renew a desk whose model could not be written", async () => {
+ const { api, calls } = fakeApi("desk-1");
+ api.patchOrgEmployee = async () => {
+ throw new Error("Model is not in the Project config");
+ };
+ await expect(switchDeskModel(api, { ...AT, sessionId: "desk-1" }, REF)).rejects.toThrow(
+ "Model is not in the Project config",
+ );
+ expect(calls).toEqual(["get"]);
+ });
+});