Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Refuse a tenant package that repeats itself instead of failing at boot (#686)
Omkar Chebale53eac39fc5f4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex af774e5b..7decbee8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,17 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A tenant package that repeats itself is refused by name, instead of failing at boot++Validation now refuses each of these, with a sentence naming the file and the repeated id:+- A skill named twice by one agent, or an agent listed twice in one channel's `permitted_agents`.+ Before, the server stopped at boot with a raw SQL error.+- An agent id repeated within `agents.yaml`, a channel id within `channels.yaml`, or a skill slug+ within `skills.yaml`. Before, the last entry silently won, though two files declaring the same+ agent were already refused.+- A remote agent left blank in `agents.yaml` but declared with an endpoint under `agents/` was+ dropped from every channel that named it. It is now treated as declared.+### `start.sh` and `stop.sh` see their own processes on WindowsIn Git Bash on Windows, which has no `lsof`, `pgrep` or `pkill`, every process and port lookup indiff --git a/server/src/tenant-package.ts b/server/src/tenant-package.tsindex f4077371..46ee6423 100644--- a/server/src/tenant-package.ts+++ b/server/src/tenant-package.ts@@ -469,7 +469,15 @@ function collectAgents("agents.yaml",omittedAgentIds,);- const declaredIn = new Map(agents.map((agent) => [agent.id, "agents.yaml"]));+ // The same refusal within `agents.yaml` as across files. Sync upserts one row per entry, so a+ // repeated id there was not refused but silently became whichever entry came last.+ const declaredIn = new Map<string, string>();+ for (const agent of agents) {+ if (declaredIn.has(agent.id)) {+ throw new Error(`agent "${agent.id}" is declared twice in agents.yaml`);+ }+ declaredIn.set(agent.id, "agents.yaml");+ }for (const file of agentFiles) {const source = `agents/${file.filename}`;const document = yaml(file.contents, source);@@ -515,10 +523,24 @@ export function validateTenantPackage(files: PackageFiles): TenantPackage {omittedAgentIds,);const agentIds = new Set(agents.map((agent) => agent.id));+ /*+ * An id left blank in one place and declared properly in another is declared, not omitted.+ * Otherwise it was seeded and then filtered out of every channel that names it, and disabled and+ * re-enabled on each sync. A real declaration wins whichever file it is in, so the answer does not+ * depend on the order a directory is read in.+ */+ for (const id of agentIds) omittedAgentIds.delete(id);const packageSkills = parseTenantSkills(skillsYaml.skills);const skillSlugs = new Set(packageSkills.map((skill) => skill.slug));for (const agent of agents) {+ // Sync writes one grant row per entry in a single INSERT ... ON CONFLICT, which Postgres refuses+ // when two of its rows collide, so a repeated slug stopped the server at boot with a SQL error.+ const named = new Set<string>();for (const slug of agent.skills) {+ if (named.has(slug)) {+ throw new Error(`agent "${agent.id}" names skill "${slug}" twice`);+ }+ named.add(slug);/** Checked against this package's own skills and nothing else, and refused rather than dropped.*@@ -535,20 +557,32 @@ export function validateTenantPackage(files: PackageFiles): TenantPackage {}}}+ const channelIds = new Set<string>();const channels = asList(channelsYaml.channels, "channels.yaml channels").map((value) => {const channel = asRecord(value, "channel");+ const id = requiredString(channel.id, "channel.id");+ // Sync upserts one channel per entry, so a repeated id silently became the last one.+ if (channelIds.has(id)) {+ throw new Error(`channel "${id}" is declared twice in channels.yaml`);+ }+ channelIds.add(id);const permittedAgents = stringArray(channel.permitted_agents,"channel.permitted_agents",).filter((agentId) => !omittedAgentIds.has(agentId));+ // Each becomes a (channel, agent) row under a primary key, so a repeat stopped the server at+ // boot with a duplicate-key error instead of a sentence naming the channel.+ if (new Set(permittedAgents).size !== permittedAgents.length) {+ throw new Error(`channel "${id}" lists the same agent twice`);+ }for (const agentId of permittedAgents) {if (!agentIds.has(agentId)) {throw new Error(`channel references unknown agent "${agentId}"`);}}return {- id: requiredString(channel.id, "channel.id"),+ id,name: requiredString(channel.name, "channel.name"),description: requiredString(channel.description, "channel.description"),permittedAgents,@@ -610,9 +644,15 @@ export function validateTenantPackage(files: PackageFiles): TenantPackage {*/function parseTenantSkills(value: unknown): TenantSkill[] {if (value === undefined || value === null) return [];+ // Sync upserts one skill per entry, so a repeated slug silently became the last one.+ const slugs = new Set<string>();return asList(value, "skills.yaml skills").map((entry) => {const skill = asRecord(entry, "skill");const slug = requiredString(skill.slug, "skill.slug");+ if (slugs.has(slug)) {+ throw new Error(`skill "${slug}" is declared twice in skills.yaml`);+ }+ slugs.add(slug);if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) {throw new Error(`skill.slug "${slug}" must be lowercase letters, digits and hyphens, and start with a letter or digit`,diff --git a/server/tests/tenant-package-duplicates.test.ts b/server/tests/tenant-package-duplicates.test.tsnew file mode 100644index 00000000..6fbc2f69--- /dev/null+++ b/server/tests/tenant-package-duplicates.test.ts@@ -0,0 +1,132 @@+import { describe, expect, test } from "bun:test";+import { validateTenantPackage } from "../src/tenant-package";++/**+ * A package that says the same thing twice.+ *+ * Sync writes one row per entry. Where that is one upsert per entry, a repeat silently became+ * whichever came last; where it is one multi-row INSERT, Postgres refused it and the server stopped+ * at boot with a SQL error naming no file. Each case is refused here instead, with a sentence that+ * says where the repeat is.+ *+ * Kept out of `tenant-package.test.ts` because everything here is validation, and that suite opens a+ * database at import.+ */++const brand = "tenant: { id: fintech, product_name: Ledgerline }";+const model =+ "model: { provider: openai, credential_secret_ref: openai-key, default_model: gpt-5.6-terra }";+const knowledge = "sources: []";+const agent = (id: string, extra = "") =>+ `{ id: ${id}, name: N, title: T, role_description: R., type: built-in, system_prompt: P.${extra} }`;+const skill = (slug: string) =>+ `{ slug: ${slug}, title: T, summary: S, instructions: I }`;++function validate(files: {+ agents: string;+ channels?: string;+ skills?: string;+ agentFiles?: { filename: string; contents: string }[];+}) {+ return validateTenantPackage({+ brand,+ model,+ knowledge,+ themeCss: "",+ channels: "channels: []",+ ...files,+ });+}++describe("a package that repeats itself is refused, not half-applied", () => {+ test("an agent id repeated within agents.yaml", () => {+ expect(() =>+ validate({ agents: `agents: [${agent("x")}, ${agent("x")}]` }),+ ).toThrow('agent "x" is declared twice in agents.yaml');+ });++ test("a skill named twice by one agent", () => {+ expect(() =>+ validate({+ agents: `agents: [${agent("x", ", skills: [s, s]")}]`,+ skills: `skills: [${skill("s")}]`,+ }),+ ).toThrow('agent "x" names skill "s" twice');+ });++ test("a skill slug repeated within skills.yaml", () => {+ expect(() =>+ validate({+ agents: `agents: [${agent("x")}]`,+ skills: `skills: [${skill("s")}, ${skill("s")}]`,+ }),+ ).toThrow('skill "s" is declared twice in skills.yaml');+ });++ test("a channel id repeated within channels.yaml", () => {+ expect(() =>+ validate({+ agents: `agents: [${agent("x")}]`,+ channels:+ "channels: [{ id: c, name: C, description: D, permitted_agents: [x], allowed_groups: [] }, { id: c, name: C2, description: D2, permitted_agents: [x], allowed_groups: [] }]",+ }),+ ).toThrow('channel "c" is declared twice in channels.yaml');+ });++ test("an agent listed twice in one channel", () => {+ expect(() =>+ validate({+ agents: `agents: [${agent("x")}]`,+ channels:+ "channels: [{ id: c, name: C, description: D, permitted_agents: [x, x], allowed_groups: [] }]",+ }),+ ).toThrow('channel "c" lists the same agent twice');+ });++ test("the same agent in two different channels is still fine", () => {+ const { channels } = validate({+ agents: `agents: [${agent("x")}]`,+ channels:+ "channels: [{ id: a, name: A, description: D, permitted_agents: [x], allowed_groups: [] }, { id: b, name: B, description: D, permitted_agents: [x], allowed_groups: [] }]",+ });++ expect(channels.map((channel) => channel.permittedAgents)).toEqual([+ ["x"],+ ["x"],+ ]);+ });+});++describe("an agent left blank in one place and declared in another", () => {+ const blank =+ "agents: [{ id: risk, name: Risk, title: T, role_description: R., type: remote-ag-ui, endpoint: '' }]";+ const declared = `id: risk+name: Risk+title: T+role_description: R.+type: remote-ag-ui+endpoint: https://agents.example.test/ag-ui+`;+ const channels =+ "channels: [{ id: c, name: C, description: D, permitted_agents: [risk], allowed_groups: [] }]";++ test("is declared, so it stays in its channels and is not disabled", () => {+ const result = validate({+ agents: blank,+ channels,+ agentFiles: [{ filename: "risk.yaml", contents: declared }],+ });++ expect(result.agents.map((each) => each.id)).toEqual(["risk"]);+ expect(result.omittedAgentIds).toEqual([]);+ expect(result.channels[0]?.permittedAgents).toEqual(["risk"]);+ });++ test("left blank everywhere, it is still omitted and left out of its channels", () => {+ const result = validate({ agents: blank, channels });++ expect(result.agents).toEqual([]);+ expect(result.omittedAgentIds).toEqual(["risk"]);+ expect(result.channels[0]?.permittedAgents).toEqual([]);+ });+});