A local-first multi-agent app development platform, built on PenguinHarness
fix(server,skills): an organization's tool call is denied, never left waiting for a person (#785)
Yaowei Zheng5c95233f8bc8
diff --git a/changelog/unreleased/2026-09-17-org-approval-deny.md b/changelog/unreleased/2026-09-17-org-approval-deny.mdnew file mode 100644index 00000000..49277461--- /dev/null+++ b/changelog/unreleased/2026-09-17-org-approval-deny.md@@ -0,0 +1,37 @@+# An organization's tool call is denied rather than left waiting for a person++- **Date:** 2026-09-17+- **Type:** fix+- **Scope:** `server`, `skills`+- **PR:** [#785](https://github.com/Prism-Shadow/penguin-harness/pull/785)++[中文版](2026-09-17-org-approval-deny.zh.md)++In company mode, a tool call that the organization's approval mode hands to a person is now+denied the moment it is made, instead of suspending the run until somebody answers. Desk,+ticket and the sub-sessions they spawn have nobody watching them, so under `read-only` a+read-write call used to park a work run for good. The employee protocol reads the denial as+the cue to ask the board.++## Details++- The approval callback the server hands to `Session.run` (`makeApprove`, built per Session+ in `SessionManager.entryApprove`) takes an `unattended` reading, re-read per decision like+ the approval mode itself. It is the session row's durable `client = "org"` stamp — every+ session the organization runtime opens, and the sub-sessions that inherit it. When it is+ set, the one route that would wait for a person answers `deny` at once and pushes no+ `approval_request`; the automatic answers (`allow-all`, `deny-all`, `read-only`'s read+ tools) and the command policy's veto are untouched. Development mode's sessions under the+ same approval mode keep suspending for their user.+- The model reads the denial as the existing fixed `aborted` tool output,+ `Tool call denied by user.`; no message type, field or decision value was added.+- `company-employee` (plugin `agent-company` `2026.09.17.2`) says so in "What you may not+ decide alone" and in its unattended caution: a refusal in a desk or ticket session means+ nobody was asked, so it is the cue to ask the board — a channel message to the creator,+ `penguin org ticket block --by user:<id>`, and the end of the run — and never something to+ retry. It also names what a `read-only` organization refuses along the way: the+ `penguin org` commands themselves, which run through a read-write tool.+- Comments in the organization runtime that still named the pre-frontmatter ticket headers+ (`Parent`, `Blocked`, "the header") were rewritten to the frontmatter fields, in+ `company-finance` too, and `OrgStore.listTickets` now describes the files it actually+ lists — it never filtered names by the ticket-id pattern.diff --git a/changelog/unreleased/2026-09-17-org-approval-deny.zh.md b/changelog/unreleased/2026-09-17-org-approval-deny.zh.mdnew file mode 100644index 00000000..f39f7902--- /dev/null+++ b/changelog/unreleased/2026-09-17-org-approval-deny.zh.md@@ -0,0 +1,17 @@+# 组织的工具调用当场被拒,不再挂着等人++- **Date:** 2026-09-17+- **Type:** fix+- **Scope:** `server`, `skills`+- **PR:** [#785](https://github.com/Prism-Shadow/penguin-harness/pull/785)++[English](2026-09-17-org-approval-deny.md)++公司模式下,审批模式判给人的工具调用现在在发起的那一刻即被拒绝,不再挂起整个运行等人答复。工位会话、工单会话以及它们派生的子会话都没有人在看,`read-only` 下一次读写调用足以让一轮工作永远停在那里。员工协议把这条拒绝当作向董事会请示的信号。++## 细节++- 服务端交给 `Session.run` 的审批回调(`makeApprove`,由 `SessionManager.entryApprove` 按 Session 构造)新增 `unattended` 读取,与审批模式一样逐次决策重读。它取会话行上持久的 `client = "org"` 标记——组织运行时开出的每个会话,以及继承该标记的子会话。标记成立时,唯一会等人的那条路径当场答 `deny`,也不再推 `approval_request`;自动判定(`allow-all`、`deny-all`、`read-only` 的只读工具)与命令策略的否决一律不变。开发模式的会话在同样的审批模式下照旧挂起等用户。+- 模型读到的仍是既有的固定 `aborted` 工具结果 `Tool call denied by user.`;没有新增消息类型、字段或决策值。+- `company-employee`(插件 `agent-company` `2026.09.17.2`)在「What you may not decide alone」与无人值守那条提醒里写明:工位会话或工单会话里的一次拒绝意味着根本没人被问到,因而是向董事会请示的信号——在频道里 @ 创建者、`penguin org ticket block --by user:<id>`、结束本轮——而不是换个写法重试。同时点明 `read-only` 组织顺带拒掉的东西:`penguin org` 命令本身走的就是读写工具。+- 组织运行时里仍以旧工单标题命名的注释(`Parent`、`Blocked`、「the header」)改写为 frontmatter 字段,`company-finance` 同此;`OrgStore.listTickets` 的说明改为它实际列出的文件——它从未按工单 id 的格式过滤文件名。diff --git a/packages/server/src/organization/store.ts b/packages/server/src/organization/store.tsindex 2fed0f1d..07e3563d 100644--- a/packages/server/src/organization/store.ts+++ b/packages/server/src/organization/store.ts@@ -332,8 +332,11 @@ export class OrgStore {// ---- tickets ----/**- * Every ticket file across months and columns. A file whose name is not a ticket id, or- * that sits in a directory that is not a column, is skipped — it is not a ticket.+ * Every `.md` file under a `<yyyy-mm>/<column>/` directory, its name minus the extension+ * taken as the ticket id. Anything outside that shape — another month directory, a+ * directory that is not one of the columns, a file that is not Markdown — is skipped.+ * The id itself is NOT matched against `TICKET_ID_PATTERN` here: a file named by hand is+ * still a ticket the board has to show, and what it is called is the caller's to judge.*/async listTickets(dir: string): Promise<TicketFile[]> {const out: TicketFile[] = [];@@ -400,7 +403,7 @@ export class OrgStore {await writeText(ticketPath(dir, ticketId, column), serializeTicket(doc));}- /** Rewrites the file in its new column and removes the old one (the header was updated by the caller). */+ /** Rewrites the file in its new column and removes the old one (the frontmatter was updated by the caller). */async moveTicket(dir: string,ticketId: string,diff --git a/packages/server/src/runtime/approvals.ts b/packages/server/src/runtime/approvals.tsindex 49ca5a2f..ce6c24bf 100644--- a/packages/server/src/runtime/approvals.ts+++ b/packages/server/src/runtime/approvals.ts@@ -10,6 +10,9 @@* `POST /approvals/:toolCallId`; no timeout — pending approvals are resolved to deny* when the Task is interrupted (then proceeds through the abort flow).*+ * An unattended Session takes that one route differently: there is no frontend to ask, so+ * the call is denied on the spot instead of suspending forever (see `unattended` below).+ ** Every approval decision re-reads the current approval_mode (`getMode` reads the DB),* so mode changes take effect immediately.* Docs: /docs/tools § "Approval".@@ -93,7 +96,8 @@ export class ApprovalRegistry {/*** Build the approve callback: re-reads the approval mode on every call; when routed to* manual approval, registers a pending entry and suspends after pushing an- * `approval_request` server event via `publishRequest`.+ * `approval_request` server event via `publishRequest` — unless the Session is unattended,+ * in which case that one route answers deny immediately.*/export function makeApprove(args: {getMode: () => ApprovalMode;@@ -101,9 +105,20 @@ export function makeApprove(args: {toolPermission: (name: string) => "r" | "rw" | undefined;registry: ApprovalRegistry;publishRequest: (pending: PendingApproval) => void;+ /**+ * Whether nobody is watching this Session — an organization's desk, ticket and spawned+ * sessions, the only unattended ones the server drives. Re-read per decision like the+ * mode. It changes exactly one route: a call the mode would hand to a person is denied at+ * once instead of parking for an answer that is never coming, and no `approval_request`+ * is pushed. The automatic answers (allow-all, deny-all, read-only's read tools) and the+ * command policy's veto are untouched — they never asked anyone in the first place.+ * Absent (development mode) keeps the suspending behaviour.+ */+ unattended?: () => boolean;}): ApproveFn {- const { getMode, toolPermission, registry, publishRequest } = args;+ const { getMode, toolPermission, registry, publishRequest, unattended } = args;const manual = (toolCall: OmniMessage<ToolCallPayload>): Promise<ApprovalDecision> => {+ if (unattended?.() === true) return Promise.resolve<ApprovalDecision>("deny");const promise = registry.wait(toolCall);publishRequest({toolCall,diff --git a/packages/server/src/runtime/organization/budget.ts b/packages/server/src/runtime/organization/budget.tsindex 120f6f5e..58f3dd1f 100644--- a/packages/server/src/runtime/organization/budget.ts+++ b/packages/server/src/runtime/organization/budget.ts@@ -22,7 +22,7 @@ export interface OrgSpend {cumulative: Map<string, number>;/** A ticket's share of its contributing sessions (a session on n tickets counts 1/n). */ticket: Map<string, number>;- /** A ticket's share plus its descendants' along `Parent`. */+ /** A ticket's share plus its descendants' along `parent`. */ticketRolledUp: Map<string, number>;/** Some usage ran on an unpriced model. */unpriced: boolean;diff --git a/packages/server/src/runtime/organization/service.ts b/packages/server/src/runtime/organization/service.tsindex 0d7d5e5a..c13d6dd8 100644--- a/packages/server/src/runtime/organization/service.ts+++ b/packages/server/src/runtime/organization/service.ts@@ -444,7 +444,7 @@ export class OrganizationService {** - `mentions`: the all-hands messages of the window `recentMessages` reads (the* organization's current day) that name the caller or `all`, newest first.- * - `blockedTickets`: every ticket carrying a `Blocked` reason, whoever it waits on —+ * - `blockedTickets`: every ticket carrying a `blocked` reason, whoever it waits on —* uncapped, because a blocked ticket is work nobody is doing.* - `doneTickets`: tickets in `done` that closed in the current budget period, `closedAt`* taken from the last `moved`-to-`done` history entry. A ticket whose file was moved by@@ -1189,7 +1189,7 @@ export class OrganizationService {// Tickets// ---------------------------------------------------------------------------- /** `known` is every ticket id in the same listing: a `Parent` naming none is flagged invalid. */+ /** `known` is every ticket id in the same listing: a `parent` naming none is flagged invalid. */private ticketItem(t: LoadedTicket, spend: OrgSpend, known: ReadonlySet<string>): OrgTicketItem {const d = t.doc;const running = d.sessions.some((s) => this.deps.runner.statusOf(s) !== "idle");diff --git a/packages/server/src/runtime/session-manager.ts b/packages/server/src/runtime/session-manager.tsindex 4d041b60..bae40f59 100644--- a/packages/server/src/runtime/session-manager.ts+++ b/packages/server/src/runtime/session-manager.ts@@ -22,7 +22,9 @@* event;* - Approval registration and interrupt convergence: each approval decision re-reads* approval_mode from the DB (takes effect immediately); an interrupt first- * converges pending approvals to deny, then aborts.+ * converges pending approvals to deny, then aborts. An organization's sessions have+ * nobody to ask, so a call their mode would hand to a person is denied at once+ * (see entryApprove).** The underlying implementation of get-or-resume-or-heal is injected via* `SessionLoader`: production uses the core SDK (createCoreSessionLoader), tests inject@@ -863,6 +865,14 @@ export class SessionManager {* The entry-lifetime approval callback: the registry, the per-decision approval-mode* re-read, and the SSE escalation are all entry-scoped, so one instance serves every run* of the entry and the children's session-lifetime fallback sink alike.+ *+ * This is also where the one cross-cutting approval override lives — wrapping the callback+ * handed to `Session.run` rather than teaching the engine anything: an organization's+ * sessions run with nobody watching, so a call their approval mode would hand to a person+ * is denied here instead of waiting for an answer that is never coming (see `unattended`+ * in approvals.ts). The marker is the row's durable `client = "org"` stamp — desk, ticket+ * and the sub-sessions that inherit it — read per decision, so a row the reconcile pass+ * stamps later is covered from its next decision on.*/private entryApprove(entry: RuntimeEntry): ApproveFn {return makeApprove({@@ -870,6 +880,7 @@ export class SessionManager {getMode: () => this.deps.sessions.findById(entry.sessionId)?.approvalMode ?? "always-ask",toolPermission: (name) => entry.session.toolPermission(name),registry: entry.approvals,+ unattended: () => this.deps.sessions.findById(entry.sessionId)?.client === "org",publishRequest: (pending) =>this.publishEvent(entry, {type: "approval_request",diff --git a/packages/server/test/organization-runtime.test.ts b/packages/server/test/organization-runtime.test.tsindex 2aa60141..4bad1f9d 100644--- a/packages/server/test/organization-runtime.test.ts+++ b/packages/server/test/organization-runtime.test.ts@@ -887,6 +887,30 @@ describe("organization runtime", () => {expect(sessions.findById(ceoDesk)?.client).toBe("org");expect(sessions.findById(work)?.client).toBe("org");});++ it("opens desk and ticket sessions under the organization's approval mode", async () => {+ await createOrg();+ await service.patch(P, ORG, { approvalMode: "read-only" }, "alice");+ // A desk opened after the change carries the mode; the row is what the session+ // runtime reads per decision (with `client: "org"`, a call that mode would hand to a+ // person is denied at once — see session-manager.test.ts).+ const desk = (await service.desk(P, ORG, CEO, { renew: true })).sessionId;+ expect(sessions.findById(desk)?.approvalMode).toBe("read-only");+ const t = await service.createTicket(+ P,+ ORG,+ { title: "Ship it", owner: `agent:${CEO}` },+ { userId: "alice" },+ );+ const { sessionId: work } = await service.startTicket(+ P,+ ORG,+ t.ticketId,+ {},+ { userId: "alice" },+ );+ expect(sessions.findById(work)?.approvalMode).toBe("read-only");+ });});describe("who starts a ticket session", () => {diff --git a/packages/server/test/session-manager.test.ts b/packages/server/test/session-manager.test.tsindex 13dc5da0..606be9c0 100644--- a/packages/server/test/session-manager.test.ts+++ b/packages/server/test/session-manager.test.ts@@ -2,6 +2,7 @@* Unit tests for the Session runtime (a fake Session / Loader is injected; no* real LLM requests are made): driving and state transitions, 409 mutual* exclusion, the four approval modes and taking effect immediately on change,+ * an organization's session denying rather than waiting for a person who is not there,* abort collapsing to deny, self-healing id swaps, vault invalidation re-resuming* stale runtimes, and LLM / tool errors in the message stream being persisted* (core doesn't throw, so try/catch can't catch them).@@ -875,6 +876,58 @@ describe("session-manager", () => {);});+ it("an organization's session denies a call its mode would hand to a person, at once", async () => {+ // A desk or ticket session as the organization runtime opens it: the organization's+ // approval mode on the row, stamped `client: "org"`. Nobody is watching it.+ sessions.insert({+ ...ROW,+ sessionId: "session-org",+ approvalMode: "read-only",+ client: "org",+ });+ const manager = makeManager(loaderOf(approvalFakeSession("session-org")));+ const events = capture("session-org");+ await manager.startTask("session-org", [userText("go")]);+ // No decision is ever submitted here: the run settles on its own and ends normally.+ await waitFor(() => manager.statusOf("session-org") === "idle");+ expect(manager.pendingApprovalCount("session-org")).toBe(0);+ expect(serverEvents(events).filter((e) => e.type === "approval_request")).toEqual([]);+ expect(recorded.some((m) => (m.payload as { text?: string }).text === "decision=deny")).toBe(+ true,+ );++ // Only that one route changed: a read-only tool is still auto-approved there.+ recorded = [];+ const manager2 = makeManager(loaderOf(approvalFakeSession("session-org", "read_tool")));+ await manager2.startTask("session-org", [userText("go")]);+ await waitFor(() => manager2.statusOf("session-org") === "idle");+ expect(recorded.some((m) => (m.payload as { text?: string }).text === "decision=allow")).toBe(+ true,+ );+ });++ it("a development session under the same mode still waits for the person", async () => {+ // Same approval mode, same tool — the row carries no organization stamp.+ sessions.updateApprovalMode("session-1", "read-only");+ const manager = makeManager(loaderOf(approvalFakeSession("session-1")));+ const events = capture("session-1");+ await manager.startTask("session-1", [userText("go")]);+ await waitFor(() => manager.pendingApprovalCount("session-1") === 1);+ expect(serverEvents(events).filter((e) => e.type === "approval_request")).toHaveLength(1);+ // Still parked on the question: no decision was made for it.+ expect(manager.statusOf("session-1")).toBe("running");+ expect(+ recorded.some((m) => (m.payload as { type?: string }).type === "approval_decision"),+ ).toBe(false);++ // Answer it, so the run finishes rather than hanging.+ expect(manager.decideApproval("session-1", "tc-1", "deny")).toBe(true);+ await waitFor(() => manager.statusOf("session-1") === "idle");+ expect(recorded.some((m) => (m.payload as { text?: string }).text === "decision=deny")).toBe(+ true,+ );+ });+it("a sub-session registered under an organization's Session inherits its org stamp; one under an ordinary Session stays unmarked", async () => {// A desk session: the organization runtime stamped it at creation.sessions.insert({ ...ROW, sessionId: "session-org", client: "org" });diff --git a/plugins/agent-company/plugin.json b/plugins/agent-company/plugin.jsonindex c6de3cda..2b3e5494 100644--- a/plugins/agent-company/plugin.json+++ b/plugins/agent-company/plugin.json@@ -3,7 +3,7 @@"description_zh": "把 Project 里的 Agent 组织成一家公司:先与用户一问一答地创建组织,再是每个工位会话与工单会话都遵循的员工协议(触发块、工单看板、频道礼仪、预算、重负载或不可逆的事先向董事会请示),以及 CEO、人事与财务的操作手册——使命拆解为工单、招募与日程、预算与成本巡检——还有科研协议(在董事会批准的资源额度内跑 autoresearch 式实验循环、作者与审稿人对抗评审),以及让数字分身在真人之间传话的镜像协议。","short_description": "Company setup plus the employee, CEO, HR, finance, research and mirror playbooks.","short_description_zh": "创建组织,以及员工、CEO、人事、财务、科研、镜像公司的操作手册。",- "version": "2026.09.17.1",+ "version": "2026.09.17.2","category": "agent-company","preinstall": false}diff --git a/plugins/agent-company/skills/company-employee/SKILL.md b/plugins/agent-company/skills/company-employee/SKILL.mdindex 90519620..f21eabfd 100644--- a/plugins/agent-company/skills/company-employee/SKILL.md+++ b/plugins/agent-company/skills/company-employee/SKILL.md@@ -139,7 +139,7 @@ penguin org ticket unblock <ticket_id> # after you verified the blocker is## What you may not decide alone-Your sessions run unattended under the organization's approval mode, so the line between "do it" and "ask" is yours to hold. Four rules, by what the action touches:+Your sessions run unattended under the organization's approval mode, so the line between "do it" and "ask" is yours to hold. Nothing ever waits for a person there: a call the mode would put to one is refused the moment you make it, and the result reads `Tool call denied by user.` although nobody saw it. Read a refusal as "this one needs the board", never as the board's answer — and never as something to retry with a different wording. Four rules, by what the action touches:**Ask the board first and wait** — anything that touches the machine this organization runs on, spends money or reaches outside the organization:@@ -233,6 +233,6 @@ penguin org finance [--period <YYYY-MM>] [--json] # spend (cumulat- **Facts are the server's.** `desks.toml`, a ticket's `sessions` and `history` fields and the channels' message files are written by the server; for everything else you would edit by hand, the CLI is the writer.- **A moved file must carry its status.** `penguin org ticket move` changes the column directory and the frontmatter's `status` together; a hand move that changes one and not the other marks the ticket invalid on the board until it is fixed. Ticket ids are `<yyyy-mm-dd>-<slug>`, the slug lowercase English words joined by hyphens, and stay in their creation month's directory; moving columns never changes the month.-- **Unattended means unattended.** Desk and ticket sessions run under the organization's approval mode with nobody watching; do not plan on a human approving a step mid-run — block the ticket and say what you need.+- **Unattended means unattended.** Desk and ticket sessions run under the organization's approval mode with nobody watching, so a call that mode would hand to a person is denied on the spot rather than held for one; never plan on a human approving a step mid-run — ask the board for it, block the ticket and end the run. Under a mode that keeps read-write tools for a person (`read-only`), that includes the `penguin org` commands themselves: when even a progress line is refused, end the run saying what you needed and which mode refused it, and wait for the board — do not retry it.- **Your own scheduled tasks are not calendar events.** `penguin schedule …` writes `agent_state/schedule/` and fires regardless of the organization; schedule organization work with `penguin org calendar …`, which respects the organization's status and budgets.- **Never mention yourself and never schedule at your own session to "check back".** Every automated conversation must terminate; the calendar is the only recurring driver.diff --git a/plugins/agent-company/skills/company-finance/SKILL.md b/plugins/agent-company/skills/company-finance/SKILL.mdindex 29c7ac92..69b0aec4 100644--- a/plugins/agent-company/skills/company-finance/SKILL.md+++ b/plugins/agent-company/skills/company-finance/SKILL.md@@ -15,7 +15,7 @@ If the message only names this skill without a concrete request, ask what financ- `budget` is a field of each employee's entry in `org_chart.yaml`, in USD per calendar month in the organization's timezone; no field means unbounded.- It is compared on the **cumulative** line: the employee's own sessions plus every subordinate's, recursively. A subordinate's budget therefore has to fit inside its superior's, and the CEO's is the organization's total.-- Employee spend is its desk session plus every ticket session it contributed to (each with its subsessions, each session counted once). Ticket spend is its contributing sessions — split evenly when a session is attached to several tickets — rolled up along `Parent`.+- Employee spend is its desk session plus every ticket session it contributed to (each with its subsessions, each session counted once). Ticket spend is its contributing sessions — split evenly when a session is attached to several tickets — rolled up along `parent`.- At `budget_warn_ratio` (default 0.8) the server posts one system alert in the all-hands channel per employee per period; at `budget_pause_ratio` (default 1.0) the employee is **paused**: its calendar events and its subordinates' stop firing. Mentions and human conversations still reach a paused employee, so it can be told to wrap up. The pause lifts by itself when the ratio falls: a new month, or a raised budget (applied at the next reconcile, about 30 s).- Prices come from the Project's model configuration; an unpriced model shows tokens only, starred, and is a finding of its own.