Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,42 @@ queue URL and leaves `credentials` empty.
default issue triggers. The first acquire snapshots what the project contains,
and every reset deletes only what a run added.

**Those defaults email the whole team, so reset mutes them.** Each default
trigger carries an `email` channel, and the email channel has no recipients of
its own: it goes to every member of the organization who has not turned alerts
off, whenever the project's notification methods include email. Scenarios fail deliveries,
requests and transformations on purpose, so from at least 21 August every run
emailed the people on `evals-ci` about failures we had caused, and it surfaced
on 6 November only because they said so. `muteIssueTriggerNotifications` now sets
`channels: {}` on every issue trigger, on acquire and on release, and leaves
each one enabled and scoped as it was.

Three things to know before touching it:

- **Every trigger, not only the snapshot's.** In CI each fresh checkout takes
its own snapshot, so a trigger leaked by a run that died before release can be
recorded as pristine and is then never deleted. Muting is the one part of
reset that still reaches it.
- **It changes what `alerting-001` starts from.** No scorer reads issues, and
the agent's own work is never muted before it is scored: acquire mutes before
the agent runs, release mutes after scoring. But the agent now finds every
existing trigger at `channels: {}`, which is the silent state that scenario
fails an agent for leaving. A default delivery trigger can no longer be passed
by confirming it, and an agent copying its neighbours' shape fails the channel
check. That is an instrument change, so results either side of it are not
comparable for that scenario, and the next release notes say so.
- **The cleaner switch is out of reach.** Email is only sent when the project's
notification methods include it, and turning that off would leave the
triggers looking like a customer's. It is writable only with a dashboard
session, not a project API key, so the harness cannot set it on a project it
creates.
- **A failed mute warns rather than throws**, because an email is a nuisance
and a failed run is lost spend.
- **A new project starts noisy.** Anything that creates or hands out a project
must call `muteIssueTriggerNotifications` before the first run, and the
`ProjectSource` interface says so. If anyone creates an eval project by hand,
mute it the same way, or the first run emails the team.

The Outpost project's gateway side is reset to empty, and that follows the same
rule: pristine there *is* empty. Platform project creation gives an Outpost project no issue
triggers, and no seed creates gateway resources in it. So that baseline is
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ issue triggers. Deleting them would leave the project unlike any real customer's
first acquire snapshots what the project contains and every reset deletes only what a
run added.

**Every reset turns issue trigger notifications off.** Those default triggers email every
member of the organization, and scenarios fail deliveries, requests and transformations on
purpose, so left alone they email the team about failures a run caused deliberately.
Each acquire and release sets `channels: {}` on every issue trigger in the project. The
triggers stay enabled and scoped as they were, so issues still open; nobody is told.
Anything that creates or hands out a project calls `muteIssueTriggerNotifications`.

**Scope scorer queries to `ctx.acquiredAt`.** Events and requests cannot be deleted
through the API, so a shared project accumulates history, and a scorer that just asks
"did an event arrive?" will eventually say yes because of an earlier run.
Expand Down
5 changes: 4 additions & 1 deletion packages/hookdeck/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export type {
HookdeckResource,
HookdeckClientOptions,
} from './client.js';
export { FixedProjectSource } from './project-source.js';
export {
FixedProjectSource,
muteIssueTriggerNotifications,
} from './project-source.js';
export type {
ProjectSource,
LeasedProject,
Expand Down
95 changes: 95 additions & 0 deletions packages/hookdeck/src/project-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,77 @@ export interface LeasedProject {
client: HookdeckClient;
}

/**
* Implementations MUST call `muteIssueTriggerNotifications` on every project
* they hand out, including one they have just created: a new project ships with
* issue triggers that email every member, and runs set them off on purpose.
*/
export interface ProjectSource {
readonly id: string;
acquire(): Promise<LeasedProject>;
release(project: LeasedProject): Promise<void>;
}

/**
* Clear the notification channels on every issue trigger in the project.
*
* A new project's default issue triggers carry an `email` channel, and the email
* channel has no recipients of its own: it goes to every member of the
* organization who has not turned alerts off (admins, owners and project members
* only, if the project is private), whenever the project's notification methods
* include email. That project setting would be the cleaner switch, because it
* leaves the triggers looking like a customer's, but it is only writable with a
* dashboard session, not a project API key — so the triggers are the lever the
* harness can reach.
* Scenarios fail deliveries, requests and transformations deliberately, so with
* the defaults left alone every run emails the people on the eval project's
* team. It had been happening since at least 21 August when it was raised, on
* 6 November.
*
* The triggers are kept, enabled and scoped as they were, so issues still open.
* Only who is told changes. `channels: {}` is the API's own "notify no one".
*
* **This changes what `alerting-001` starts from**, and is an instrument change
* rather than housekeeping. No scorer reads issues, and acquire mutes before the
* agent runs while release mutes after scoring, so no agent's own work is
* altered. But the agent now finds every existing trigger with `channels: {}` —
* exactly the silent state that scenario fails an agent for leaving — so a
* default delivery trigger can no longer be passed by confirming it, and an agent
* copying its neighbours' shape fails the channel check. Results either side of
* this change are not comparable for that scenario.
*
* Every trigger, not only the snapshot's. In CI the snapshot is taken by each
* fresh checkout, so a trigger leaked by a run that died before release can be
* recorded as pristine and then never deleted; muting it is the only reset that
* still reaches it. Every channel, not only email: a Slack or PagerDuty channel
* on an eval project would page a person for a failure we caused on purpose.
*
* Returns the ids it changed, so a caller can log them.
*/
export async function muteIssueTriggerNotifications(
client: HookdeckClient
): Promise<string[]> {
const muted: string[] = [];
for (const trigger of await client.list('issue-triggers')) {
// Skip only an empty object. A missing or null `channels` is not muted: the
// notification service falls through to emailing the team when a trigger
// has no channels at all.
const channels = trigger.channels as Record<string, unknown> | null;
if (
channels &&
typeof channels === 'object' &&
Object.keys(channels).length === 0
) {
continue;
}
await client.request('PUT', `/issue-triggers/${trigger.id}`, {
channels: {},
});
muted.push(trigger.id);
}
return muted;
}

/**
* The set of resources a project contains before the harness first touches it.
*
Expand Down Expand Up @@ -207,6 +272,7 @@ export class FixedProjectSource implements ProjectSource {
async acquire(): Promise<LeasedProject> {
const snapshot = await this.loadOrCaptureSnapshot();
await this.resetToPristine(this.client, snapshot);
await this.muteNotifications('acquire');
// Before the seed, not only on release: a run that dies before release
// must not hand its gateway resources in the Outpost project to the next
// one, and in CI the next one is usually a different job. Throws, like the
Expand Down Expand Up @@ -240,6 +306,7 @@ export class FixedProjectSource implements ProjectSource {
// Swallowed deliberately: a failed release must not fail the run, and
// the next acquire will clean up regardless.
}
await this.muteNotifications('release');
if (snapshot) {
try {
await this.resetOutpostGateway(snapshot);
Expand All @@ -255,6 +322,34 @@ export class FixedProjectSource implements ProjectSource {
await this.restoreOutpostConfig();
}

/**
* See `muteIssueTriggerNotifications`. On acquire and on release: acquire is
* the guarantee, so a trigger a dead run left behind is muted before the next
* scenario's seeded failures can fire it, and release keeps the project quiet
* between runs.
*
* Warns rather than throws, unlike the reset beside it. A trigger left
* notifying sends someone an email; it does not make a result wrong, and
* failing a run over it would trade a nuisance for lost spend. The Outpost
* project needs no call: its gateway side is reset to empty, triggers included.
*/
private async muteNotifications(when: 'acquire' | 'release'): Promise<void> {
try {
const muted = await muteIssueTriggerNotifications(this.client);
if (when === 'acquire' && muted.length > 0) {
console.warn(
`issue triggers: cleared notification channels on ${muted.join(', ')}, ` +
'which would have emailed the project team about failures runs cause on purpose'
);
}
} catch (error) {
console.warn(
`issue triggers: could not clear notification channels on ${when}, so this ` +
`project may email its team about failures runs cause on purpose (${(error as Error).message})`
);
}
}

/**
* Delete Outpost tenants this lease created.
*
Expand Down
189 changes: 189 additions & 0 deletions packages/hookdeck/test/project-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,192 @@ describe('FixedProjectSource Outpost project gateway reset', () => {
await expect(source().acquire()).rejects.toThrow(/500/);
});
});

/**
* A new project's default issue triggers email every member, and scenarios fail
* deliveries on purpose, so every run emailed the eval project's team. Reset has
* to leave every trigger notifying no one, whoever created it.
*/
describe('FixedProjectSource issue trigger notifications', () => {
beforeEach(() => vi.restoreAllMocks());

function fakeTriggers(triggers: Record<string, Record<string, unknown>>) {
const state = new Map(Object.entries(triggers));
const puts: Array<{ id: string; body: unknown }> = [];
const fetchImpl = vi.fn(async (url: string | URL, init?: RequestInit) => {
const path = new URL(String(url)).pathname.replace(/^\/[^/]+/, '');
const method = init?.method ?? 'GET';
const [, kind, id] = path.split('/');
if (kind !== 'issue-triggers') {
return new Response(JSON.stringify({ models: [] }), { status: 200 });
}
if (method === 'PUT') {
const body = JSON.parse(String(init?.body)) as Record<string, unknown>;
puts.push({ id, body });
state.set(id, { ...state.get(id), ...body });
return new Response(JSON.stringify({ id, ...state.get(id) }), {
status: 200,
});
}
if (method === 'DELETE') {
state.delete(id);
return new Response('', { status: 200 });
}
const models = [...state].map(([rid, t]) => ({ id: rid, ...t }));
return new Response(JSON.stringify({ models }), { status: 200 });
});
return { fetchImpl, state, puts };
}

it('clears the email channel on the default triggers at acquire, and keeps them', async () => {
const { fetchImpl, state, puts } = fakeTriggers({
it_delivery: { type: 'delivery', channels: { email: {} } },
it_request: { type: 'request', channels: { email: {} } },
});
vi.stubGlobal('fetch', fetchImpl);
vi.spyOn(console, 'warn').mockImplementation(() => {});

await new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
}).acquire();

expect(puts).toEqual([
{ id: 'it_delivery', body: { channels: {} } },
{ id: 'it_request', body: { channels: {} } },
]);
expect([...state.keys()]).toEqual(['it_delivery', 'it_request']);
expect(state.get('it_delivery')?.type).toBe('delivery');
});

it('leaves an already muted trigger alone', async () => {
const { fetchImpl, puts } = fakeTriggers({
it_quiet: { type: 'delivery', channels: {} },
});
vi.stubGlobal('fetch', fetchImpl);

await new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
}).acquire();

expect(puts).toEqual([]);
});

it('mutes a trigger with null or missing channels, which still emails', async () => {
// The notification service emails the team when a trigger has no channels
// at all, so null is not the same as {}.
const { fetchImpl, puts } = fakeTriggers({
it_null: { type: 'request', channels: null },
it_missing: { type: 'backpressure' },
});
vi.stubGlobal('fetch', fetchImpl);
vi.spyOn(console, 'warn').mockImplementation(() => {});

await new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
}).acquire();

expect(puts).toEqual([
{ id: 'it_null', body: { channels: {} } },
{ id: 'it_missing', body: { channels: {} } },
]);
});

it('still mutes on release when the reset throws', async () => {
const { fetchImpl, state, puts } = fakeTriggers({
it_default: { type: 'delivery', channels: {} },
});
vi.stubGlobal('fetch', fetchImpl);
const source = new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
});
const lease = await source.acquire();
state.set('it_default', { type: 'delivery', channels: { email: {} } });
vi.stubGlobal(
'fetch',
vi.fn(async (url: string | URL, init?: RequestInit) =>
new URL(String(url)).pathname.includes('/connections')
? new Response('boom', { status: 500 })
: fetchImpl(url, init)
)
);

await source.release(lease);

expect(puts).toEqual([{ id: 'it_default', body: { channels: {} } }]);
});

it('mutes a trigger recorded in the snapshot that a run gave a channel', async () => {
// In CI each checkout captures its own snapshot, so a trigger leaked by a
// run that died is recorded as pristine and never deleted. Muting is the
// only part of reset that still reaches it.
const snapshotPath = tempSnapshotPath();
writeFileSync(
snapshotPath,
JSON.stringify({
capturedAt: '2026-11-06T00:00:00.000Z',
ids: { 'issue-triggers': ['it_leaked'] },
})
);
const { fetchImpl, puts } = fakeTriggers({
it_leaked: {
type: 'delivery',
channels: { email: {}, slack: { channel_name: '#ops' } },
},
});
vi.stubGlobal('fetch', fetchImpl);
vi.spyOn(console, 'warn').mockImplementation(() => {});

await new FixedProjectSource({ apiKey: 'k', snapshotPath }).acquire();

expect(puts).toEqual([{ id: 'it_leaked', body: { channels: {} } }]);
});

it('mutes a channel added during the lease on release', async () => {
const { fetchImpl, state, puts } = fakeTriggers({
it_default: { type: 'delivery', channels: {} },
});
vi.stubGlobal('fetch', fetchImpl);
const source = new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
});
const lease = await source.acquire();
// an agent repairs the default and gives it email, which alerting-001 scores
state.set('it_default', { type: 'delivery', channels: { email: {} } });

await source.release(lease);

expect(puts).toEqual([{ id: 'it_default', body: { channels: {} } }]);
});

it('does not fail an acquire when muting fails', async () => {
const { fetchImpl } = fakeTriggers({
it_default: { type: 'delivery', channels: { email: {} } },
});
vi.stubGlobal(
'fetch',
vi.fn(async (url: string | URL, init?: RequestInit) =>
init?.method === 'PUT'
? new Response('boom', { status: 500 })
: fetchImpl(url, init)
)
);
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});

await expect(
new FixedProjectSource({
apiKey: 'k',
snapshotPath: tempSnapshotPath(),
}).acquire()
).resolves.toBeDefined();
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
'could not clear notification channels on acquire'
)
);
});
});
Loading