Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Respect configured rule approval authority and linked accounts (#3336)

harness-for-autonomous[bot]4ffd913f8eda
diff --git a/backend/integration/superTabInstructions.test.ts b/backend/integration/superTabInstructions.test.ts
index d5f56e967..763793ac3 100644
--- a/backend/integration/superTabInstructions.test.ts
+++ b/backend/integration/superTabInstructions.test.ts
@@ -19,7 +19,9 @@ import { roleVersion } from '../src/superTabs/projects.js'
import { DEFAULT_ROUTING_POLICY } from '../src/superTabs/routingPolicy.js'
import { INSTRUCTIONS_TEMPLATE } from '../src/superTabs/instructionsTemplate.js'
import { rosterRows } from './hostRows.test-support.js'
+import { SEED_RULES } from '../src/superTabs/policy.js'
import { PM_SCHEDULE_TEXT } from '../src/superTabs/pmSchedule.js'
+import { plan, profiled, reads } from './plans.test-support.js'
// A fresh loopback replica set, created here. This suite never reads DATABASE_URL or an existing database.
// Project instructions, phase 2 (docs/plans/2026-10-30-project-instructions-plan.md): the document, its revisions, the
@@ -135,6 +137,54 @@ describe('project instructions storage', () => {
// Task #3151: a save that drops a person's rule is refused, and goes through on that person's own message, read by the store,
// which tells them in their Buddy chats.
+describe('configured rule approvals through the store', () => {
+ it('uses the saved decider and linked accounts, while refusing absent, agent and stale approvals', async () => {
+ const { tab, lead } = await withLead()
+ await invite(tab)
+ const invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })
+ await run(tab, { type: 'invite.accept', inviteId: String(invitation.result.inviteId) }, host)
+ await run(tab, { type: 'rules.set', projectId: 'lead', baseRevision: 0, rules: { ...structuredClone(SEED_RULES),
+ instructionApprovals: { topDeciderId: peer.sub, people: [{ name: 'Ken', accountIds: [owner.sub, host.sub] }] } }, summary: 'Explicit approval authority' })
+ const text = '# Rules\n\n- Always test before merging (Ken, 2026-11-04).'
+ await run(tab, save(1, text))
+ const drop = (revision: number, approvals: string[] = []) => run(tab, { ...save(revision, '# Rules\n'), askedBy: owner.sub, approvals } as Command, host, lead)
+ const message = async (user: AuthUser, asAgentId?: string) => String((await run(tab, { type: 'message.send', conversationId: 'lead', text: 'I approve removing this rule.', replyTo: null, recipientIds: [] }, user, asAgentId)).result.messageId)
+ await expect(drop(2)).rejects.toMatchObject({ code: 'INSTRUCTIONS_RULES_DROPPED' })
+ const agent = await message(host, lead)
+ await expect(drop(2, [agent])).rejects.toMatchObject({ code: 'INSTRUCTIONS_RULES_DROPPED' })
+ const stale = await message(peer)
+ const saved = await db.superTabInstructions.findFirstOrThrow({ where: { tabId: tab, projectId: 'lead' } })
+ await db.superTabMessage.update({ where: { id: stale }, data: { createdAt: new Date(saved.updatedAt.getTime() - 1) } })
+ await expect(drop(2, [stale])).rejects.toMatchObject({ code: 'INSTRUCTIONS_RULES_DROPPED' })
+ const decider = await message(peer)
+ const entries = await profiled(db, async () => expect((await drop(2, [decider])).result.revision).toBe(3))
+ const policyReads = plan(reads(entries, 'SuperTabProjectRules', ['tabId', 'projectId']))
+ expect(policyReads.length).toBeGreaterThan(0)
+ for (const read of policyReads) {
+ expect(read.plan).toContain('IXSCAN')
+ expect(read.docsExamined).toBe(1)
+ expect(read.returned).toBe(1)
+ }
+ const notices = await db.superTabMessage.findMany({ where: { tabId: tab, text: { contains: 'approved by peer' } } })
+ // Dee's approval tells the decider and both affected author accounts, through each person's two private Buddy chats.
+ expect(notices).toHaveLength(6)
+ for (const account of [owner, host, peer]) {
+ const visible = new Set((await store.read(account, tab)).state.conversations.map(c => c.id))
+ expect(notices.filter(n => visible.has(n.conversationId))).toHaveLength(2)
+ }
+ for (const notice of notices) {
+ expect(notice.text).toContain('Always test before merging')
+ expect(notice.text).not.toContain('as you approved')
+ }
+ for (const [index, account] of [owner, host].entries()) {
+ const revision = 4 + index * 2
+ await run(tab, save(revision - 1, text))
+ const approval = await message(account)
+ expect((await drop(revision, [approval])).result.revision).toBe(revision + 1)
+ }
+ })
+})
+
describe('a person\'s rules in a save', () => {
it('refuses the PM\'s drop, then saves it on the person\'s own approval and tells them privately', async () => {
const { tab, lead } = await withLead()
diff --git a/backend/integration/superTabProjectRules.test.ts b/backend/integration/superTabProjectRules.test.ts
index e97a4a43f..45b76b90b 100644
--- a/backend/integration/superTabProjectRules.test.ts
+++ b/backend/integration/superTabProjectRules.test.ts
@@ -168,6 +168,49 @@ describe('a project\'s rules record', () => {
expect(await currentRules(db, tab, 'lead')).toEqual({ revision: 2, rules: rules('10:00') })
})
+ it('seeds approval authority only for the exact Harness project, including old saved records', async () => {
+ const harnessTab = 'c51479bd73b59e58176ad9e4', harnessProject = '5701099db2a04f605ac0d4d4'
+ const expected = { topDeciderId: '6a8fe4fcf1a6b5972eed0103', people: [{ name: 'Ken', accountIds: ['6a86d24c2ea251076eb4eebe', '6ae980b6215612e2be51c35b'] }] }
+ expect((await currentRules(db, harnessTab, harnessProject)).rules).toMatchObject({ instructionApprovals: expected })
+ expect((await currentRules(db, harnessTab, 'another-project')).rules).not.toHaveProperty('instructionApprovals')
+ expect((await currentRules(db, randomUUID(), harnessProject)).rules).not.toHaveProperty('instructionApprovals')
+ const { tab } = await swarm()
+ await run(tab, set(0, rules('10:00')))
+ const row = await db.superTabProjectRules.findFirstOrThrow({ where: { tabId: tab } })
+ await db.superTabProjectRules.create({ data: { ...row, id: '100000000000000000000099', tabId: harnessTab, projectId: harnessProject } })
+ expect((await currentRules(db, harnessTab, harnessProject)).rules).toMatchObject({ instructionApprovals: expected })
+ })
+
+ it('protects approval authority changes but keeps ordinary edits and omitted fields compatible', async () => {
+ const { tab, lead } = await swarm()
+ const authority = { topDeciderId: peer.sub, people: [{ name: 'Ken', accountIds: [owner.sub, peer.sub] }] }
+ const configured = { ...rules('10:00'), instructionApprovals: authority }
+ expect(await refusal(run(tab, set(0, configured), peer))).toMatchObject({ code: 'RULES_APPROVAL_EDITOR_REQUIRED' })
+ const ask = await run(tab, { type: 'message.send', conversationId: 'lead', text: 'Make me the decider.', replyTo: null, recipientIds: [] }, peer)
+ expect(await refusal(run(tab, set(0, configured, { askedIn: { conversationId: 'lead', messageId: String(ask.result.messageId) } }), host, lead)))
+ .toMatchObject({ code: 'RULES_APPROVAL_EDITOR_REQUIRED' })
+ await run(tab, set(0, configured))
+ // An old client's ordinary edit does not silently drop authority.
+ await run(tab, set(1, rules('11:00')), peer)
+ expect((await currentRules(db, tab, 'lead')).rules).toMatchObject({ instructionApprovals: authority })
+ // The currently named decider may deliberately disable it.
+ await run(tab, set(2, { ...rules('11:00'), instructionApprovals: null }), peer)
+ expect((await currentRules(db, tab, 'lead')).rules).toMatchObject({ instructionApprovals: null })
+ })
+
+ it('refuses authority changes from the PM even when quoting the owner or current decider', async () => {
+ const { tab, lead } = await swarm()
+ const authority = { topDeciderId: peer.sub, people: [{ name: 'Ken', accountIds: [owner.sub] }] }
+ await run(tab, set(0, { ...rules('10:00'), instructionApprovals: authority }))
+ for (const user of [owner, peer]) {
+ const ask = await run(tab, { type: 'message.send', conversationId: 'lead', text: 'An ordinary project message.', replyTo: null, recipientIds: [] }, user)
+ expect(await refusal(run(tab, set(1, { ...rules('11:00'), instructionApprovals: null },
+ { askedIn: { conversationId: 'lead', messageId: String(ask.result.messageId) } }), host, lead)))
+ .toMatchObject({ code: 'RULES_APPROVAL_EDITOR_REQUIRED' })
+ }
+ expect(await currentRules(db, tab, 'lead')).toMatchObject({ revision: 1, rules: { instructionApprovals: authority } })
+ })
+
it('keeps one of two saves on the same revision, refusing the other', async () => {
const { tab } = await swarm()
const outcomes = await Promise.allSettled([run(tab, set(0, rules('10:00'))), run(tab, set(0, rules('11:00')), peer)])
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 8493b8291..92672ec76 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -29,7 +29,7 @@ import { recordCheckVerdict } from './checkVerdicts.js'
import { routeRecordSchema, routeTitle, startedAs, type KeptCandidate, type RouteDecision, type RouteFinal, type RouteOverride } from './routeRecord.js'
import { routingOverrideSaveSchema } from './routingPolicy.js'
import { askedInSchema, RULE_MESSAGE_MS, ruleSchema, ruleTextSchema } from './rules.js'
-import { projectRulesSchema, rulesDiff, rulesEqual, SEED_RULES, type ProjectRules } from './policy.js'
+import { projectRulesSchema, rulesDiff, rulesEqual, seedRules, SEED_RULES, type ProjectRules } from './policy.js'
import { isReview, machineRuleRefusal } from './machineRules.js'
import { accessRefusal, changeAccess, expireAccess, taskAccess } from './machineAccess.js'
import { MAX_ATTACHMENTS, type Attachment } from './attachments.js'
@@ -2204,18 +2204,18 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
const summary = because && command.summary.length + because.length > 200 ? `${command.summary.slice(0, 199 - because.length)}…${because}` : command.summary + because
// No part grows past its size budget: core, each role section, people notes, the whole (#3392).
refuseOverBudget(before, command.text)
- // A person's rule, or who gave it, is dropped only by that person or with their own message approving it (#3151).
- const { told, rules } = allowedDrops(state, project, before, command.text, sender, command.approvals ?? [], context.approvals ?? [],
- context.instructions?.at ?? 0, context.pullRequestMerges ?? {})
+ // A person's rule, or who gave it, needs their approval or the configured top decider's own message (#3151, #3710).
+ const { told, rules, deciderId } = allowedDrops(state, project, before, command.text, sender, command.approvals ?? [], context.approvals ?? [],
+ context.instructions?.at ?? 0, context.pullRequestMerges ?? {}, context.projectRules?.rules.instructionApprovals)
// Every line it dropped, with its kind and who gave it, kept with the revision for the History (River, 11-05).
saveInstructions(project, current, command.text, summary, askedBy, droppedLines(before, command.text, command.dropped ?? [], rules))
// The coordinator's save that says it is the tidy is that tidy done (pmSchedule.ts tidyRequest); a correction it saves
// meanwhile is not (review of #3112).
if (actor.kind === 'agent' && command.tidy) tidySaved(projectOf(state, project.id), current + 1)
- // Each approver is told in one line, privately, as person.tell does: in their one Buddy chat and their older one here.
+ // Approvers and authors affected by a decider's override hear privately, in their one Buddy chat and older one here.
for (const [personId, rules] of told) {
const to = person(state, personId)
- const text = approvedDropNotice(who, project, rules)
+ const text = approvedDropNotice(who, project, rules, deciderId ? agentWrittenNameOf(state, deciderId) ?? 'the project top decider' : undefined)
const id = stableId(operationId, 'rule-approved', personId)
message(defaultBuddyChat(state, to).id, text, [], null, { kind: PM_LINE_KIND, projectId: project.id }, undefined, undefined, undefined, id)
Object.assign(effects.messages.at(-1)!, { buddyProject: project.id })
@@ -2246,16 +2246,23 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
askedIn = { conversationId: command.askedIn!.conversationId, messageId: command.askedIn!.messageId }
} else askedBy = (actor as Extract<Actor, { kind: 'person' }>).userId
if (context.projectRules === undefined) fail('RULES_UNAVAILABLE', 'This project\'s rules cannot be read now. Try again in a moment.', 503)
- const current = context.projectRules ?? { revision: 0, rules: SEED_RULES }
+ const current = context.projectRules ?? { revision: 0, rules: seedRules(state.id, project.id) }
if (command.baseRevision !== current.revision) {
// Refused with the record it missed, to merge and save again: never two writers' records kept silently.
fail('RULES_STALE', `The project rules changed since revision ${command.baseRevision}. Merge your change into revision ${current.revision} and save again.`,
409, { revision: current.revision, rules: current.rules })
}
- // A writer that does not know machine rules (an older client) leaves them as they are; one that sends a list sets it.
- const kept = command.rules.machines === undefined && current.rules.machines ? projectRulesSchema.safeParse({ ...command.rules, machines: current.rules.machines }) : null
+ // Old clients omit the additive authority section. Preserve it; an explicit null removes it.
+ const next = command.rules.instructionApprovals === undefined && current.rules.instructionApprovals !== undefined
+ ? { ...command.rules, instructionApprovals: current.rules.instructionApprovals } : command.rules
+ if (JSON.stringify(current.rules.instructionApprovals ?? null) !== JSON.stringify(next.instructionApprovals ?? null)
+ && (actor.kind !== 'person' || (actor.userId !== project.ownerId && actor.userId !== current.rules.instructionApprovals?.topDeciderId))) {
+ fail('RULES_APPROVAL_EDITOR_REQUIRED', 'Only the project owner or its current top decider, acting directly, may change who approves instruction rules or link their accounts.', 403)
+ }
+ // A writer that does not know machine rules leaves them as they are; one that sends a list sets it.
+ const kept = next.machines === undefined && current.rules.machines ? projectRulesSchema.safeParse({ ...next, machines: current.rules.machines }) : null
if (kept && !kept.success) fail('RULES_INVALID', `The project's machine rules do not fit this record: ${kept.error.issues[0]?.message ?? 'invalid'}`, 400)
- const rules = kept?.data ?? command.rules
+ const rules = kept?.data ?? next
if (rulesEqual(current.rules, rules)) {
Object.assign(result, { projectId: project.id, revision: current.revision, unchanged: true })
break
diff --git a/backend/src/superTabs/policy.test.ts b/backend/src/superTabs/policy.test.ts
index e2f12553f..67e990e5c 100644
--- a/backend/src/superTabs/policy.test.ts
+++ b/backend/src/superTabs/policy.test.ts
@@ -65,6 +65,22 @@ describe('the project rules record', () => {
expect(projectRulesSchema.parse(rules)).toEqual(rules)
})
+ it('accepts optional approval authority with explicit linked account IDs and rejects ambiguous links', () => {
+ const authority = { topDeciderId: 'dee-id', people: [{ name: 'Ken', accountIds: ['ken-id', 'other-ken-id'] }] }
+ expect(projectRulesSchema.parse({ ...copy(), instructionApprovals: authority })).toMatchObject({ instructionApprovals: authority })
+ expect(projectRulesSchema.parse({ ...copy(), instructionApprovals: null })).toMatchObject({ instructionApprovals: null })
+ expect(projectRulesSchema.parse(copy())).not.toHaveProperty('instructionApprovals')
+ const bad = [
+ { ...authority, people: [{ name: 'Ken', accountIds: [] }] },
+ { ...authority, people: [{ name: 'Ken', accountIds: ['a', 'a'] }] },
+ { ...authority, people: [{ name: 'Ken', accountIds: ['a'] }, { name: 'KEN', accountIds: ['b'] }] },
+ { ...authority, people: [{ name: 'Ken', accountIds: ['a'] }, { name: 'Other', accountIds: ['a'] }] },
+ { ...authority, people: [{ name: 'Ken', accountIds: Array.from({ length: 11 }, (_, i) => `a${i}`) }] },
+ { ...authority, people: Array.from({ length: 51 }, (_, i) => ({ name: `Person ${i}`, accountIds: [`a${i}`] })) },
+ ]
+ for (const instructionApprovals of bad) expect(projectRulesSchema.safeParse({ ...copy(), instructionApprovals }).success).toBe(false)
+ })
+
it('refuses bad values', () => {
expect(refused({ ...copy(), extra: 1 })).toBe(true)
expect(refused({ ...copy(), releaseWindow: { ...SEED_RULES.releaseWindow, start: '25:00' } })).toBe(true)
@@ -437,6 +453,26 @@ describe('who changes the rules', () => {
expect(effects.messages).toEqual([])
})
+ it.each(['owner', 'peer'])('refuses authority changes through the PM quoting %s, while allowing that person directly', id => {
+ const f = fixture()
+ f.invite()
+ const lead = f.add('lead', 'lead', true)
+ const authority = { topDeciderId: 'peer', people: [{ name: 'Ken', accountIds: ['owner'] }] }
+ const current = { revision: 1, rules: { ...copy(), instructionApprovals: authority } }
+ const context = { projectRules: current, askedIn: personAsked(id) }
+ for (const instructionApprovals of [null, { ...authority, topDeciderId: 'owner' },
+ { ...authority, people: [{ name: 'Ken', accountIds: ['owner', 'peer'] }] }]) {
+ expect(code(() => f.run(set(1, { ...later(), instructionApprovals }, asked('lead')), as(lead), context)))
+ .toBe('RULES_APPROVAL_EDITOR_REQUIRED')
+ }
+ // The PM may still make ordinary edits with either omitted or unchanged authority.
+ for (const rules of [later(), { ...later(), instructionApprovals: authority }]) {
+ expect(f.run(set(1, rules, asked('lead')), as(lead), context).projectRules?.rules.instructionApprovals).toEqual(authority)
+ }
+ expect(f.run(set(1, { ...later(), instructionApprovals: null }), id === 'owner' ? owner : peer, { projectRules: current })
+ .projectRules?.rules.instructionApprovals).toBeNull()
+ })
+
it('refuses every other agent, the PM of another project and a Buddy', () => {
const f = fixture()
f.invite()
@@ -479,6 +515,23 @@ describe('machine rules in the record', () => {
expect(projectRulesSchema.parse(copy()).machines).toBeUndefined()
})
+ it('preserves approval authority and machine rules together without letting an ordinary member change authority', () => {
+ const f = fixture()
+ f.invite()
+ const authority = { topDeciderId: 'owner', people: [{ name: 'Ken', accountIds: ['owner', 'peer'] }] }
+ const current = { revision: 1, rules: { ...withMachines(RULES), instructionApprovals: authority } }
+ const kept = f.run(set(1, later()), peer, { projectRules: current })
+ expect(kept.projectRules?.rules).toMatchObject({ machines: RULES, instructionApprovals: authority })
+ expect(kept.projectRules?.diff).toEqual([{ path: 'releaseWindow.start', before: '09:00', after: '08:00' }])
+ expect(f.run(set(1, copy()), peer, { projectRules: current }).result.unchanged).toBe(true)
+ expect(code(() => f.run(set(1, { ...later(), instructionApprovals: null }), peer, { projectRules: current })))
+ .toBe('RULES_APPROVAL_EDITOR_REQUIRED')
+ const cleared = f.run(set(1, { ...later(), instructionApprovals: null, machines: [] }), owner, { projectRules: current })
+ expect(cleared.projectRules?.rules).toMatchObject({ instructionApprovals: null, machines: [] })
+ expect(code(() => f.run(set(1, { ...copy(), lanes: [{ name: 'phone', owns: ['mobile/'] }] }), owner, { projectRules: current })))
+ .toBe('RULES_INVALID')
+ })
+
it('keeps the current machine rules when a save leaves them out, and clears them only when it says so', () => {
const f = fixture()
const current = { revision: 1, rules: withMachines(RULES) }
diff --git a/backend/src/superTabs/policy.ts b/backend/src/superTabs/policy.ts
index 464b6c0a8..a7b6374be 100644
--- a/backend/src/superTabs/policy.ts
+++ b/backend/src/superTabs/policy.ts
@@ -6,6 +6,7 @@
* the server and shown to people. Revision 0 is the seed below, never stored until the first save (policyStore.ts).
*/
import { z } from 'zod'
+import { personKey } from './instructionsDiff.js'
/** The record as stored, as JSON: small enough that a reader reads every revision kept. */
export const MAX_RULES_BYTES = 16_384
@@ -35,6 +36,17 @@ const globs = z.array(glob).max(MAX_LIST)
const distinct = <T extends z.ZodTypeAny>(item: T, key: (entry: z.infer<T>) => string, what: string) =>
z.array(item).max(MAX_LIST).refine(list => new Set(list.map(e => key(e).toLowerCase())).size === list.length, `Each ${what} once.`)
+const accountId = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,159}$/)
+const instructionApprovals = z.object({
+ topDeciderId: accountId.nullable(),
+ people: distinct(z.object({ name: line(80).refine(name => !!personKey(name), 'Name a person.'),
+ accountIds: z.array(accountId).min(1).max(10) }).strict(), person => personKey(person.name), 'person')
+ .refine(people => {
+ const ids = people.flatMap(person => person.accountIds)
+ return new Set(ids).size === ids.length
+ }, 'An account belongs to only one named person, once.'),
+}).strict()
+
/** Defaults for projects predating configurable dispatch (#3601); kept here with the rest of the project policy. */
export const SEED_DISPATCH = deepFreeze({ everyMs: 30_000, maxHanded: 3, nudgeAfterMs: 7_200_000, returnAfterMs: 10_800_000 })
export const SEED_LANES = deepFreeze([
@@ -79,6 +91,8 @@ const machineRuleSchema = z.object({
'A machine rule says when the machine is away, which engines or Reviewers it refuses, or which lanes go there first.')
export const projectRulesSchema = z.preprocess(legacyDispatch, z.object({
+ /** Explicit authority for instruction-rule changes; absent on older records, null deliberately disables it. */
+ instructionApprovals: instructionApprovals.nullable().optional(),
/** When releases go out, in a local time of day; the end comes after the start, the same day. */
releaseWindow: z.object({ start: clock, end: clock, timeZone }).strict()
.refine(w => w.start < w.end, 'The release window ends after it starts, the same day.'),
@@ -199,6 +213,17 @@ export const SEED_RULES: ProjectRules = deepFreeze({
dispatch: SEED_DISPATCH,
})
+/** Task #3710: only this Harness project asked for Dee's authority and Ken's linked accounts.
+ * Stable account IDs, never a project/display name or an email-prefix guess; no other project inherits them. */
+const HARNESS_APPROVALS = deepFreeze({
+ topDeciderId: '6a8fe4fcf1a6b5972eed0103',
+ people: [{ name: 'Ken', accountIds: ['6a86d24c2ea251076eb4eebe', '6ae980b6215612e2be51c35b'] }],
+})
+export function seedRules(tabId: string, projectId: string, rules: ProjectRules = SEED_RULES): ProjectRules {
+ return rules.instructionApprovals === undefined && tabId === 'c51479bd73b59e58176ad9e4' && projectId === '5701099db2a04f605ac0d4d4'
+ ? { ...rules, instructionApprovals: HARNESS_APPROVALS } : rules
+}
+
/** One change a save made: a leaf of an object section, or a whole list. */
export interface RulesChange { path: string; before: unknown; after: unknown }
diff --git a/backend/src/superTabs/policyStore.ts b/backend/src/superTabs/policyStore.ts
index 0bd80f88e..d749f388a 100644
--- a/backend/src/superTabs/policyStore.ts
+++ b/backend/src/superTabs/policyStore.ts
@@ -4,7 +4,7 @@
*/
import type { Prisma } from '@prisma/client'
import { fail, stableId } from './model.js'
-import { MAX_RULES_REVISIONS, projectRulesSchema, SEED_RULES, type ProjectRules, type RulesChange, type RulesWrite } from './policy.js'
+import { MAX_RULES_REVISIONS, projectRulesSchema, seedRules, type ProjectRules, type RulesChange, type RulesWrite } from './policy.js'
type Transaction = Prisma.TransactionClient
@@ -30,13 +30,13 @@ export async function readRules(tx: Transaction, tabId: string, projectId: strin
// Normalize legacy dispatch; only the repair path may read an invalid saved record.
const parsed = projectRulesSchema.safeParse(row.rules)
if (!parsed.success && !forEdit) fail('RULES_INVALID', `Project ${projectId} rules revision ${row.revision} does not pass the schema; repair the project rules by saving them again.`, 409)
- return { revision: row.revision, rules: parsed.success ? parsed.data : row.rules as unknown as ProjectRules }
+ return { revision: row.revision, rules: seedRules(tabId, projectId, parsed.success ? parsed.data : row.rules as unknown as ProjectRules) }
}
/** The record a project runs on now, for a server worker (the merge train, the release schedule): its newest revision, or
* the seed at revision 0. Takes the client or a transaction. */
export async function currentRules(tx: Transaction, tabId: string, projectId: string): Promise<{ revision: number; rules: ProjectRules }> {
- return await readRules(tx, tabId, projectId) ?? { revision: 0, rules: SEED_RULES }
+ return await readRules(tx, tabId, projectId) ?? { revision: 0, rules: seedRules(tabId, projectId) }
}
/** Every kept revision, newest first: at most MAX_RULES_REVISIONS rows of the same index.
diff --git a/backend/src/superTabs/ruleApprovalAuthority.test.ts b/backend/src/superTabs/ruleApprovalAuthority.test.ts
new file mode 100644
index 000000000..92f7fe207
--- /dev/null
+++ b/backend/src/superTabs/ruleApprovalAuthority.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest'
+import { createSuperTab, type Author } from './model.js'
+import { projectsOf } from './projects.js'
+import { allowedDrops } from './ruleGuard.js'
+
+// Task #3710: changing the guard to trust a name, a relayed message or an old approval must fail these tests.
+const authority = { topDeciderId: 'dee', people: [{ name: 'Ken', accountIds: ['ken-a', 'ken-b'] }] }
+const before = '# Rules\n\n- Always test before merging (Ken, 2026-11-04).'
+const after = '# Rules\n'
+const row = (id = 'yes', person = 'dee', extra = {}) => ({ id, author: { kind: 'person', id: person, name: person } as Author,
+ source: false, createdAt: 900, conversationId: 'lead', ...extra })
+function fixture() {
+ const state = createSuperTab('tab', 'Pilot', { id: 'owner', email: '[email protected]' }, 'prod')
+ const first = state.people[0]!
+ state.people.push(...['dee', 'ken-a', 'ken-b', 'stranger'].map(id => ({ ...first, id, email: `${id}@example.com`, username: id, role: 'collaborator' as const })))
+ const project = projectsOf(state)[0]!
+ const check = (approvals = [row()], named = ['yes'], config: typeof authority | null = authority, sender = { kind: 'agent' as Author['kind'], id: 'pm' }, text = after) =>
+ allowedDrops(state, project, before, text, sender, named, approvals, 500, {}, config)
+ return { state, project, check }
+}
+
+describe('configured instruction approval authority', () => {
+ it('accepts only the named decider’s own recent approval for another person’s removed or reworded rule', () => {
+ const f = fixture()
+ expect([...f.check().told.keys()]).toEqual(['dee', 'ken-a', 'ken-b'])
+ expect(f.check([row()], ['yes'], authority, undefined, before.replace('before', 'after')).rules).toHaveLength(1)
+ expect(() => f.check([], [])).toThrow(/dee/i)
+ expect(() => f.check([row('yes', 'stranger')])).toThrow(/rules people gave/)
+ expect(() => f.check([row()], ['yes'], null)).toThrow(/rules people gave/)
+ })
+
+ it('notifies affected accounts only while they can still read the project', () => {
+ const f = fixture()
+ f.project.visibility = 'private'
+ f.project.members = ['owner', 'dee', 'ken-a'].map(id => ({ id, generation: f.state.people.find(p => p.id === id)!.generation }))
+ expect([...f.check().told.keys()]).toEqual(['dee', 'ken-a'])
+ expect([...f.check([row()], ['yes'], authority, { kind: 'person', id: 'ken-a' }).told.keys()]).toEqual(['dee'])
+ })
+
+ it.each(['ken-a', 'ken-b'])('accepts %s for the explicit Ken attribution and tells only the account that approved', id => {
+ const f = fixture()
+ expect([...f.check([row('yes', id)]).told.keys()]).toEqual([id])
+ expect(f.check([], [], authority, { kind: 'person', id }).rules).toHaveLength(1)
+ })
+
+ it('never expands a similar display name into the explicit account group', () => {
+ const f = fixture()
+ f.state.people.find(p => p.id === 'stranger')!.name = 'Ken'
+ expect(() => f.check([row('yes', 'stranger')])).toThrow(/rules people gave/)
+ // An alias from a different project is not present here.
+ expect(() => f.check([row('yes', 'ken-b')], ['yes'], null)).toThrow(/rules people gave/)
+ })
+
+ it('does not add an unrelated exact display-name match when resolving a linked account attribution', () => {
+ const f = fixture()
+ f.state.people.find(p => p.id === 'stranger')!.name = 'ken-a'
+ const attributed = before.replace('(Ken,', '(ken-a,')
+ const check = (id: string) => allowedDrops(f.state, f.project, attributed, after, { kind: 'agent', id: 'pm' },
+ ['yes'], [row('yes', id)], 500, {}, authority)
+ expect(() => check('stranger')).toThrow(/rules people gave/)
+ expect([...check('ken-b').told.keys()]).toEqual(['ken-b'])
+ })
+
+ it.each([
+ ['agent', row('yes', 'dee', { author: { kind: 'agent', id: 'dee', name: 'dee' } })],
+ ['Buddy relay', row('yes', 'dee', { source: true })],
+ ['old', row('yes', 'dee', { createdAt: 499 })],
+ ['another project', row('yes', 'dee', { conversationId: 'elsewhere' })],
+ ])('rejects a %s approval even when it carries the decider ID', (_name, approval) => {
+ expect(() => fixture().check([approval])).toThrow(/rules people gave/)
+ })
+
+ it('rejects missing, unlisted and removed-member approvals', () => {
+ const f = fixture()
+ expect(() => f.check([], ['yes'])).toThrow(/rules people gave/)
+ expect(() => f.check([row()], [])).toThrow(/rules people gave/)
+ f.state.people = f.state.people.filter(p => p.id !== 'dee')
+ expect(() => f.check()).toThrow(/rules people gave/)
+ f.state.people = f.state.people.filter(p => p.id !== 'ken-b')
+ expect(() => f.check([row('yes', 'ken-b')])).toThrow(/rules people gave/)
+ })
+})
diff --git a/backend/src/superTabs/ruleGuard.ts b/backend/src/superTabs/ruleGuard.ts
index ff12d4e20..e05d87ad2 100644
--- a/backend/src/superTabs/ruleGuard.ts
+++ b/backend/src/superTabs/ruleGuard.ts
@@ -10,6 +10,8 @@ import { attributedRules, budgetParts, droppedRules, INSTRUCTIONS_BUDGET, ITEM_C
import { fail, type Author, type Conversation, type SuperTabState } from './model.js'
import { canReadProject, projectRules, type SwarmProject } from './projects.js'
import { isSwarmBuddyChat } from './buddies.js'
+import type { ProjectRules } from './policy.js'
+import { agentWrittenNameOf } from './personNames.js'
import { swarmUsernames } from './usernames.js'
/** Approval messages one save may name: one per person whose rules it drops is plenty. */
@@ -22,10 +24,18 @@ export interface ApprovalRow { id: string; author: Author; source: boolean; crea
/** The members a written name is: by username, shown name or email, else by one word of a shown name ("Leo" is Leo Tran),
* honorifics and a possessive aside (instructionsDiff.ts personKey). */
-export function membersNamed(state: SuperTabState, name: string): string[] {
+export function membersNamed(state: SuperTabState, name: string, authority?: ProjectRules['instructionApprovals']): string[] {
const key = personKey(name)
if (!key) return []
+ // Explicit identity links outrank mutable display names. Only listed IDs gain the extra identity.
+ const present = new Set(state.people.map(p => p.id))
+ const linked = authority?.people.find(p => personKey(p.name) === key)
+ if (linked) return linked.accountIds.filter(id => present.has(id))
const usernames = swarmUsernames(state)
+ // A linked account's unique handle/email may name the group too. Display names never add an account to that group.
+ const account = state.people.find(p => [usernames.get(p.id), p.email].some(n => n && personKey(n) === key))
+ const accountLink = account && authority?.people.find(p => p.accountIds.includes(account.id))
+ if (accountLink) return accountLink.accountIds.filter(id => present.has(id))
const whole = state.people.filter(p => [usernames.get(p.id), p.name, p.email, p.email.split('@')[0]].some(n => n && personKey(n) === key))
if (whole.length) return whole.map(p => p.id)
return state.people.filter(p => p.name?.split(/\s+/).some(word => personKey(word) === key)).map(p => p.id)
@@ -64,9 +74,9 @@ const codeTasks = (state: SuperTabState, project: SwarmProject): Conversation[]
&& c.id !== project.leadConversationId && !c.kind && !c.reviewOf && !c.step && !c.audience && !!c.brief)
/** How the guard tells people apart in this Swarm: a written name as the members it is, so "0xken15" and "Ken" are one. */
-function identifier(state: SuperTabState): (name: string) => string {
+function identifier(state: SuperTabState, authority?: ProjectRules['instructionApprovals']): (name: string) => string {
const membersOf = new Map<string, string[]>()
- return name => (membersOf.get(name) ?? membersOf.set(name, membersNamed(state, name)).get(name)!).slice().sort().join(',') || `?${personKey(name)}`
+ return name => (membersOf.get(name) ?? membersOf.set(name, membersNamed(state, name, authority)).get(name)!).slice().sort().join(',') || `?${personKey(name)}`
}
/**
@@ -92,29 +102,33 @@ export function tasksHoldingMoves(state: SuperTabState, project: SwarmProject, b
* several people needs each of them. A name that is no member is the project owner's to allow.
*/
export function allowedDrops(state: SuperTabState, project: SwarmProject, before: string, after: string, sender: { kind: Author['kind']; id: string },
- named: readonly string[], approvals: readonly ApprovalRow[], since: number, merges: Readonly<Record<string, number | null>> = {}): { told: Map<string, DroppedRule[]>; rules: DroppedRule[] } {
+ named: readonly string[], approvals: readonly ApprovalRow[], since: number, merges: Readonly<Record<string, number | null>> = {}, authority?: ProjectRules['instructionApprovals']): { told: Map<string, DroppedRule[]>; rules: DroppedRule[]; deciderId?: string } {
const told = new Map<string, DroppedRule[]>()
const membersOf = new Map<string, string[]>()
- const members = (name: string) => membersOf.get(name) ?? membersOf.set(name, membersNamed(state, name)).get(name)!
- const dropped = droppedRules(before, after, identifier(state), rulePlaces(state, project, merges))
+ const members = (name: string) => membersOf.get(name) ?? membersOf.set(name, membersNamed(state, name, authority)).get(name)!
+ const dropped = droppedRules(before, after, identifier(state, authority), rulePlaces(state, project, merges))
if (!dropped.length) return { told, rules: [] }
const saver = sender.kind === 'person' ? sender.id : undefined
// Written after the revision this save replaces, in a conversation of this project: an old "thanks" approves nothing (review
// of #3112). A person's one Buddy chat belongs to no project.
const here = (conversationId: string) => conversationId === project.leadConversationId || state.conversations.some(c => c.id === conversationId
&& !isSwarmBuddyChat(c) && (c.projectId ?? 'lead') === project.id)
+ const eligible = (id: string) => state.people.some(p => p.id === id && canReadProject(state, { kind: 'person', userId: p.id, email: p.email }, project))
const approvers = new Set(approvals.filter(a => named.includes(a.id) && a.author.kind === 'person' && !a.source && a.createdAt >= since
&& here(a.conversationId)).map(a => a.author.id)
- .filter(id => state.people.some(p => p.id === id && canReadProject(state, { kind: 'person', userId: p.id, email: p.email }, project))))
+ .filter(eligible))
+ const decider = authority?.topDeciderId && approvers.has(authority.topDeciderId) ? authority.topDeciderId : undefined
const refused: DroppedRule[] = []
for (const rule of dropped) {
- const by = rule.people.map(name => {
+ const by = decider ? [decider] : rule.people.map(name => {
const ids = members(name).length ? members(name) : [project.ownerId]
if (saver && ids.includes(saver)) return saver
return ids.find(id => approvers.has(id))
})
if (by.some(id => !id)) { refused.push(rule); continue }
- for (const id of new Set(by as string[])) if (id !== saver) told.set(id, [...told.get(id) ?? [], rule])
+ // With a decider override the rule's authors did not approve it themselves: tell their current, permitted accounts too.
+ const notify = decider ? [...by, ...rule.people.flatMap(members).filter(eligible)] : by
+ for (const id of new Set(notify as string[])) if (id !== saver) told.set(id, [...told.get(id) ?? [], rule])
}
if (refused.length) {
const unknown = (rule: DroppedRule) => rule.people.filter(name => !members(name).length)
@@ -123,13 +137,15 @@ export function allowedDrops(state: SuperTabState, project: SwarmProject, before
+ 'people notes or its role section, into the project\'s rules record, or into a code task, whose line stays until the '
+ 'Swarm sees that task\'s pull request merged on GitHub (name a quiet one in tasks). Otherwise ask that person and name their own message approving the change '
+ '(approvals). Never drop or weaken a person\'s rule on your own judgment, even one you think cannot be done.',
+ ...(authority?.topDeciderId ? [`The project's top decider ${agentWrittenNameOf(state, authority.topDeciderId) ?? 'named in its rules record'} may also approve any rule with their own recent message in this project.`] : []),
...refused.map(rule => `- "${cut(rule.text)}" (${rule.people.join(', ')}): ${WHY[rule.why]}`
+ (rule.movedTo ? ` (${rule.movedTo}): keep its line until it merges.` : '.')
- + (unknown(rule).length ? ` ${unknown(rule).join(', ')} is no member here, so the project's owner decides.` : '')),
+ + (unknown(rule).length ? ` ${unknown(rule).join(', ')} is no member here, so the project's owner decides.`
+ : ` Ask ${rule.people.map(name => members(name).map(id => agentWrittenNameOf(state, id) ?? name).join(' or ')).join(' and ')} for approval.`)),
].join('\n'), 409, { dropped: refused.map(rule => ({ rule: rule.text, people: rule.people, why: rule.why,
...rule.movedTo ? { movedTo: rule.movedTo } : {} })) })
}
- return { told, rules: dropped }
+ return { told, rules: dropped, ...decider ? { deciderId: decider } : {} }
}
/**
@@ -205,9 +221,9 @@ export function droppedLines(before: string, after: string, sorted: readonly Sor
})
}
-/** The one line a person is told when [who] changed their [rules] in [project]'s instructions with their approval. */
-export function approvedDropNotice(who: string, project: SwarmProject, rules: readonly DroppedRule[]): string {
+/** The one line a person is told when [who] changed [rules], naming the decider when someone else approved the change. */
+export function approvedDropNotice(who: string, project: SwarmProject, rules: readonly DroppedRule[], decider?: string): string {
const each = rules.map(rule => `${rule.why === 'removed' ? 'removed' : 'changed'} "${cut(rule.text)}"`).join('; ')
- return `${who} changed your ${rules.length === 1 ? 'rule' : `${rules.length} rules`} in the ${project.name} instructions, as you approved: ${each}.`
+ return `${who} changed ${decider ? 'the' : 'your'} ${rules.length === 1 ? 'rule' : `${rules.length} rules`} in the ${project.name} instructions, ${decider ? `approved by ${decider}` : 'as you approved'}: ${each}.`
.replace(/\s*[\r\n]+\s*/g, ' ')
}
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index 645a0122b..2f247019e 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -67,7 +67,7 @@ import { lostReasonWithoutMachine } from './lostReason.js'
import { LEAD_NAME } from './leadStart.js'
import { deleteInstructions, instructionsId, readNotes, revisionId, writeInstructions, writeNotes } from './instructionsStore.js'
import { currentRules, deleteRules, readRules, readRulesHistory, writeRules } from './policyStore.js'
-import { SEED_RULES, validMachineRules, type MachineRule } from './policy.js'
+import { SEED_RULES, seedRules, validMachineRules, type MachineRule } from './policy.js'
import { coordinatorNameOf, FIRST_INSTRUCTIONS, FIRST_SUMMARY, liveNotes, MAX_REVISIONS } from './instructions.js'
import { INSTRUCTIONS_TEMPLATE } from './instructionsTemplate.js'
import { confidentialSessions, otherRegistrations, recordConfidential } from './confidential.js'
@@ -2023,7 +2023,11 @@ export class SuperTabStore {
// When it was saved, too: a person's approval of a dropped rule must come after it (ruleGuard.ts).
const stored = await tx.superTabInstructions.findUnique({ where: { id: stableId(tabId, projectId) }, select: { revision: true, text: true, updatedAt: true } })
context.instructions = stored && { revision: stored.revision, text: stored.text, ...stored.updatedAt ? { at: stored.updatedAt.getTime() } : {} }
- if (command.type === 'instructions.save' && command.approvals?.length) context.approvals = await readApprovals(tx, tabId, command.approvals)
+ if (command.type === 'instructions.save') {
+ authorizeCommandAccess(original, actor, command)
+ context.projectRules = await currentRules(tx, tabId, projectId)
+ if (command.approvals?.length) context.approvals = await readApprovals(tx, tabId, command.approvals)
+ }
if (command.type === 'instructions.save' && pullRequestMerges) context.pullRequestMerges = pullRequestMerges
}
if (command.type === 'note.add' || command.type === 'note.remove') context.notes = await readNotes(tx, tabId, command.projectId)
@@ -3375,7 +3379,7 @@ export class SuperTabStore {
return this.instructionHistory(user, tabId, projectId, asAgentId, async tx => {
const history = await readRulesHistory(tx, tabId, projectId)
const newest = history[0]
- return { projectId, revision: newest?.revision ?? 0, rules: newest?.rules ?? SEED_RULES, seeded: !newest, history }
+ return { projectId, revision: newest?.revision ?? 0, rules: seedRules(tabId, projectId, newest?.rules), seeded: !newest, history }
})
}
diff --git a/docs/plans/2026-11-06-rule-approval-authority-plan.md b/docs/plans/2026-11-06-rule-approval-authority-plan.md
new file mode 100644
index 000000000..adf9dc5dd
--- /dev/null
+++ b/docs/plans/2026-11-06-rule-approval-authority-plan.md
@@ -0,0 +1,94 @@
+# Rule approval authority implementation plan
+
+> Implement natively, task by task, with a committed failing test before each fix; two independent security reviews at the final head.
+
+**Goal:** Let the project's named top decider approve any instruction-rule change, and recognize explicitly linked accounts of a rule's author.
+
+**Architecture:** Add optional `instructionApprovals` to the existing project rules JSON: `{topDeciderId: string|null, people: [{name, accountIds}]}` or null to disable. Use stable person IDs, never fuzzy names, for the additional authority. Load the policy in the instructions-save transaction and keep existing message-author, source, project, membership and revision-time checks. Seed only the exact Harness tab/project with Dee and Ken's two known account IDs; every other project has no extra authority.
+
+**Tech Stack:** TypeScript, Zod, Prisma/MongoDB, Vitest; no new dependencies.
+
+**Spec:** Task #3710, conversation `6efd6cdba079af3928d94421`: Dee's own recent approval may change anyone's rule; Ken's attribution resolves to ken15 and 0xken15; refusals name who can approve. Existing approval protections remain.
+
+## Global Constraints
+
+- Only a person's own message since the last instruction save counts; never an agent, Buddy relay, old message or another project's message.
+- Explicit account links use IDs; similar display names cannot add an unrelated account.
+- Only the project owner or its currently configured top decider may change this authority section, acting directly as a person; the PM may not change authority by quoting a message. Other rules edits retain existing access.
+- An older client omitting the new field preserves the current authority. Explicit null disables it through the same protected edit.
+- First PR body line: Requested by dee through Harness.
+- No production writes, secrets, sign-outs, dependency installs or CLI core changes. Temp files only in mktemp -d folders.
+- Run affected tests locally; full backend/integration suites run in ready PR CI. Record red/green in a PR comment. Two security reviews; minor findings wait.
+
+## Design
+
+- **Growth/concurrency:** At most 50 named people, 10 accounts each, inside the existing 16 KB record and 50-revision retention. Same Swarm write transaction/revision fence; no new collection or index.
+- **Read cost/scale:** One existing indexed latest-policy read on instruction saves; approvals retain at most 20 equality reads by message ID. In-memory matching is bounded. Profile the real-store policy read with its existing integration query-plan support. Production read-only environment is absent on this Team machine.
+- **Compatibility/migration/rollback:** Optional additive JSON; no schema migration/backfill. Scoped Harness seed applies when absent, including a saved old record; explicit null opts out. Roll back backend to restore prior approval semantics; saved additive JSON remains readable by the old repair path but must be removed before strict worker reads on the old binary.
+- **Audience/identity:** Project access is checked before policy reads/changes. Only stable configured account IDs confer authority. Existing project membership checks apply to each linked account's approval; only the account that actually approved is notified.
+- **Failure/platforms:** Refuse visibly with eligible approvers; malformed stored authority fails closed. Shared backend behavior on every client/platform. No screen changes.
+
+## Review Focus
+
+- A collaborator must not install themselves as top decider or forge a link to someone else's attribution (Task 1).
+- Canonical Harness seeding must not grant Dee authority in a second project/tab with a similar name (Task 1).
+- An agent/Buddy, stale approval, removed member or another project's approval must never inherit the configured person's authority (Task 2).
+- Explicit alias names/IDs must take precedence over a similar display name; no prefix or partial-name expansion (Task 2).
+- An omitted policy field must not disable a saved authority, and old unconfigured projects retain their current approval semantics (Tasks 1/2).
+
+### Task 1: Store and protect scoped approval policy
+
+**Files:** policy.ts, policyStore.ts, commands.ts, store.ts; policy.test.ts, superTabProjectRules.test.ts.
+**Interfaces:** `ProjectRules.instructionApprovals?`; `seedRules(tabId, projectId): ProjectRules`; bound section schema, scoped Harness defaults and protected rules.set edits.
+
+- [x] Commit tests for optional/disabled policy, bounds/ambiguous aliases, exact Harness seed scope, old saved records and indexed read; reject a collaborator/PM quoted collaborator changing authority, permit owner/current decider, preserve omitted field.
+- [x] Observe failures before implementation (`506ba8250`).
+- [x] Add optional section and scoped seed/read normalization; authorize section changes against the previous policy, not the proposed one. Keep existing rules revision/history semantics.
+- [x] Run affected policy/command/integration tests and typecheck, commit and push (`eb3316329`).
+
+### Task 2: Apply approval authority and exact linked accounts
+
+**Files:** ruleGuard.ts, commands.ts, store.ts; instructions.test.ts, superTabInstructions.test.ts.
+**Interfaces:** `allowedDrops(..., merges, instructionApprovals?)`; `membersNamed(..., instructionApprovals?)` resolves explicit names and linked IDs. The same resolver identifies attribution moves. Store loads the project's current policy for saves.
+
+- [x] Commit regressions: Dee's recent own message approves dropping/rewording Ken's rule; either Ken account approves; unrelated similar name, no approval, agent/Buddy, old/missing/foreign approval and removed account fail; original unconfigured behavior remains.
+- [x] Observe the authority/alias failures before implementation (`cef9654a7`: four unit failures and the store approval failure).
+- [x] Thread validated current policy into the guard; preserve all existing approval filters and notifications; explain who can approve in refusals (`d7b2a4e67`).
+- [x] Run changed/importer unit tests, affected real-store integration tests and typecheck. The save's new policy read uses IXSCAN, one document returned and examined. Red/green evidence is in the PR comment; full suites and two independent security reviews run at Ready.
+
+### Follow-up: Bound aliases must outrank display-name collisions
+
+**Files:** ruleGuard.ts, ruleApprovalAuthority.test.ts, superTabInstructions.test.ts.
+**Interfaces:** The configured canonical name or a linked account's unique handle/email expands to configured IDs; another account's display name never joins the group.
+
+- [x] Commit the exact-handle/display-name collision regression and observe it incorrectly accept the stranger (`e9460c1f3`).
+- [x] Give linked handles priority over display names, preserve unconfigured resolution, and pass the regression plus affected guard/importer tests (`2487d397b`).
+- [x] Profile the actual instructions.save policy read: IXSCAN, one document examined/returned; typecheck clean.
+
+## Validation notes
+
+### Security review repair: Tell the affected authors
+
+**Files:** ruleGuard.ts, commands.ts, ruleApprovalAuthority.test.ts, superTabInstructions.test.ts.
+**Interfaces:** allowedDrops returns the verified decider ID when used; its notification map includes affected author accounts still permitted to read the project, excluding the saver. Notices attribute the approval to the decider, never to a person who did not approve.
+
+- [x] Commit and observe failing author-notification/private-audience tests (`e47bd2fd3`: two unit failures and zero real-store notices instead of six).
+- [x] Notify the decider and affected eligible author accounts once each; keep ordinary author approval notices unchanged.
+- [x] Run affected unit/integration tests and typecheck: 500 guard/instructions/commands tests, all 23 instructions integrations and typecheck pass. The other 157 unit tests and seven policy integrations cover unchanged source.
+- [ ] Obtain both security reviews again at the new head.
+
+- Task 1: policy tests 25/25; project-rules real-store tests 7/7; typecheck clean.
+- Task 2: authority/instructions/commands/policy tests 523/523 before the extra collision regression; real-store instructions/project-rules tests 30/30 after restoring Buddy refusal order. The first combined run hit an ephemeral Mongo port collision and exposed that Buddy refusal-order regression; the retry passed after the access check reused authorizeCommandAccess.
+- Collision follow-up: authority/instructions/commands tests 499/499 (including all 10 authority cases); the real-store authority/index-plan case passes; typecheck clean. Review-table/steps tests 27/27; merge-train/release importers 105/105.
+- No collection/index changes, backfill or production writes. Production read-only environment absent on this Team machine; no production counts or latency measurements claimed.
+
+### Security review repair: Only direct people change approval authority
+
+**Files:** commands.ts, policy.test.ts, superTabProjectRules.test.ts.
+**Interfaces:** rules.set retains its existing message-based PM flow for ordinary rules. Changing instructionApprovals requires the actor to be the project owner or current top decider, acting directly.
+
+- [x] Commit and observe failing tests (`59e2a6133`: two unit failures and real-store save not refused) for the PM quoting either the owner or current decider to replace the decider, relink accounts or disable authority; cover real-store refusal and unchanged revision.
+- [x] Require a direct person actor for authority changes, preserving direct owner/decider edits and omitted or unchanged authority on ordinary PM saves.
+- [ ] Run affected tests, real-store policy integrations and typecheck; record red/green and obtain both security reviews at the final head.
+
+- Repair validation: 471 affected policy/authority/command unit tests, 11 project-rules real-store tests and backend typecheck pass. Two independent final-head confirmations and automatic CI remain pending.