Skip to content

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

fix(server): hold a blocking ticket's by principal to the chart (#851)

lmliheng2a1d6c8578a4
diff --git a/changelog/unreleased/2026-10-11-block-by-principal-check.md b/changelog/unreleased/2026-10-11-block-by-principal-check.md
new file mode 100644
index 00000000..4fb79b96
--- /dev/null
+++ b/changelog/unreleased/2026-10-11-block-by-principal-check.md
@@ -0,0 +1,11 @@
+# Blocking a ticket checks the `by` principal against the chart
+
+- **Date:** 2026-10-11
+- **Type:** fix
+- **Scope:** `server`
+
+[中文版](2026-10-11-block-by-principal-check.zh.md)
+
+Ported from upstream PenguinHarness (#851, commit `4ea0d5f9`).
+
+Blocking a ticket — the `block` route, `penguin org ticket block --by`, and the employee tool — now holds a `by` of the form `agent:<id>` or `user:<id>` to the rule every other principal an organization accepts already follows: the agent must be an employee on the chart and the user a member of the Project, otherwise the write is refused with `400 invalid_principal`. Before, any shape-valid id landed in `blocked_by` and rendered as "(by …)" in the digest and on the board. The ticket-id form keeps its existence check, omitting `by` still clears `blockedBy`, and stored values are not rewritten.
diff --git a/changelog/unreleased/2026-10-11-block-by-principal-check.zh.md b/changelog/unreleased/2026-10-11-block-by-principal-check.zh.md
new file mode 100644
index 00000000..d9f301c4
--- /dev/null
+++ b/changelog/unreleased/2026-10-11-block-by-principal-check.zh.md
@@ -0,0 +1,11 @@
+# 阻塞工单时按组织架构校验 `by` 主体
+
+- **Date:** 2026-10-11
+- **Type:** fix
+- **Scope:** `server`
+
+[English](2026-10-11-block-by-principal-check.md)
+
+移植自上游 PenguinHarness(#851,提交 `4ea0d5f9`)。
+
+阻塞工单——`block` 接口、`penguin org ticket block --by` 与员工工具——现在对 `agent:<id>` / `user:<id>` 形式的 `by` 施加组织接受的其他主体早已遵循的规则:agent 必须是架构图上的员工,user 必须是 Project 成员,否则以 `400 invalid_principal` 拒绝写入。此前任何形状合法的 id 都会写进 `blocked_by`,并在摘要与看板上显示为「(by …)」。工单 id 形式仍只做存在性检查;省略 `by` 仍清除 `blockedBy`;已存储的值不会被改写。
diff --git a/packages/server/src/runtime/organization/service.ts b/packages/server/src/runtime/organization/service.ts
index 2a5601a2..8414da19 100644
--- a/packages/server/src/runtime/organization/service.ts
+++ b/packages/server/src/runtime/organization/service.ts
@@ -1716,6 +1716,13 @@ export class OrganizationService {
if (isTicket && (await this.deps.store.findTicket(org.dir, by)) === null) {
throw badRequest(`Blocking ticket does not exist: ${by}`);
}
+ if (p?.kind === "agent" || p?.kind === "user") {
+ // A named principal is held to the same chart as a channel member: an
+ // agent:<id> that names no employee, or a user:<id> outside the Project,
+ // would still render as "(by …)" in the digest and on the board — an
+ // attribution nobody can answer for.
+ this.requireChannelPrincipal(org, by);
+ }
}
const d = t.doc;
d.blocked = reason.trim();
diff --git a/packages/server/test/organization-runtime.test.ts b/packages/server/test/organization-runtime.test.ts
index 66ae6485..71bf7cca 100644
--- a/packages/server/test/organization-runtime.test.ts
+++ b/packages/server/test/organization-runtime.test.ts
@@ -2017,6 +2017,42 @@ describe("organization runtime", () => {
).toBeUndefined();
});
+ it("holds a blocking ticket's by principal to the chart: a shape-valid id that names nobody is refused", async () => {
+ const t = await service.createTicket(P, ORG, { title: "Launch" }, { userId: "alice" });
+ // A principal that names no employee, or a person outside the Project, is refused
+ // instead of landing on the digest and the board as an unanswerable "(by …)".
+ await expect(
+ service.blockTicket(P, ORG, t.ticketId, "waiting", "agent:acme_ghost", {
+ userId: "alice",
+ }),
+ ).rejects.toMatchObject({ status: 400, code: "invalid_principal" });
+ await expect(
+ service.blockTicket(P, ORG, t.ticketId, "waiting", "user:stranger", { userId: "alice" }),
+ ).rejects.toMatchObject({ status: 400, code: "invalid_principal" });
+ // Real employees and Project members keep working, and a blocking ticket id needs
+ // no principal check at all.
+ await service.blockTicket(P, ORG, t.ticketId, "waiting on review", `agent:${CEO}`, {
+ userId: "alice",
+ });
+ expect((await service.ticket(P, ORG, t.ticketId)).blockedBy).toBe(`agent:${CEO}`);
+ await service.unblockTicket(P, ORG, t.ticketId, { userId: "alice" });
+ await service.blockTicket(P, ORG, t.ticketId, "waiting on review", "user:alice", {
+ userId: "alice",
+ });
+ expect((await service.ticket(P, ORG, t.ticketId)).blockedBy).toBe("user:alice");
+ const blocker = await service.createTicket(
+ P,
+ ORG,
+ { title: "The blocker" },
+ { userId: "alice" },
+ );
+ await service.unblockTicket(P, ORG, t.ticketId, { userId: "alice" });
+ await service.blockTicket(P, ORG, t.ticketId, "waiting for it", blocker.ticketId, {
+ userId: "alice",
+ });
+ expect((await service.ticket(P, ORG, t.ticketId)).blockedBy).toBe(blocker.ticketId);
+ });
+
it("reports a `# Ticket:` file as an invalid file: listed nowhere, refused on write, never rewritten", async () => {
const valid = await service.createTicket(
P,