From 509a0bfa23d0de3f69a53f99b74c835bafd10152 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:03:33 +0000 Subject: [PATCH 1/2] Reset the Outpost project's Event Gateway side before every seed OUTPOST_API_KEY is an ordinary project API key, so it also works on api.hookdeck.com and the CLI, and agents have created Event Gateway resources in the Outpost project with it. FixedProjectSource reset the gateway project, Outpost tenants, operator event destinations and managed config, but nothing on the Outpost project's gateway side. A source, two destinations, two connections and two issue triggers were left there on 24 and 25 August. In run 42044644850 an outpost-005 attempt on codex-gpt-5.4-mini-no-skills found the `hookdeck -> hookdeck-acme` connection, added a `$nin` body filter to it instead of changing the Outpost destination's topics, and attempts 2 and 3 of the same cell started from that edit. FixedProjectSource now deletes every gateway resource in the Outpost project on acquire, before the seed is applied, and again on release. The baseline (OUTPOST_GATEWAY_PRISTINE) is declared empty rather than captured: - An Outpost project is created without the gateway's default issue triggers, and no Outpost seed creates gateway resources, so pristine there is empty. - A captured snapshot would be taken from whatever the previous CI job left, because every job is a fresh checkout. It would have recorded the August leftovers as pristine and protected them. The reset is skipped when both keys are the same string. It is also skipped, with a warning, when the Outpost key can see any resource id in the gateway project's snapshot, because that means both keys reach one project and an empty baseline would delete its defaults. A failed reset fails the acquire, matching the gateway reset; on release it warns. Every deletion is logged, so a leftover shows up in the job log. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 30 ++- packages/hookdeck/src/project-source.ts | 157 ++++++++++- packages/hookdeck/test/project-source.test.ts | 247 ++++++++++++++++++ 3 files changed, 419 insertions(+), 15 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1e27bef..41243e3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1145,12 +1145,23 @@ concurrency group: a group holds one running and one pending job and cancels the rest. Shard instead. **Outpost state is not reset between runs.** `FixedProjectSource` snapshots and -restores the Hookdeck project, and knows nothing about Outpost. Tenants and -destinations an Outpost run creates survive into the next one, so the second run -of a scenario finds `acme` already there and may score a previous run's work. -`FixedProjectSource` now deletes tenants that were not present when it acquired -the lease, on release — but that runs in a `catch`-and-ignore, so a run that dies -before release still leaks and the next run inherits it. +restores the Hookdeck project, and Outpost has no snapshot to restore from. +Tenants and destinations an Outpost run creates survive into the next one, so +the second run of a scenario finds `acme` already there and may score a previous +run's work. `FixedProjectSource` now deletes tenants that were not present when +it acquired the lease, on release — but that runs in a `catch`-and-ignore, so a +run that dies before release still leaks and the next run inherits it. + +**The Outpost project has an Event Gateway side, and agents write to it.** +`OUTPOST_API_KEY` is an ordinary project key, so it works on `api.hookdeck.com` +and the CLI too. A source, two connections, two destinations and two issue +triggers were left there on 24 and 25 August and nothing removed them. On 5 +November an `outpost-005` attempt added a topic filter to one of those connections instead of changing the +Outpost destination's topics. The filter carried into the cell's next two +attempts, because nothing reset that side. `FixedProjectSource` now deletes every +gateway resource in the Outpost project on acquire, before the seed, and again +on release. It refuses if the Outpost key can see anything in the gateway +project's snapshot, because that means both keys reach one project. So cleanup on release is not enough on its own, and `applyOutpostSeed` deletes each tenant it is about to create. That makes seeding idempotent without @@ -1258,6 +1269,13 @@ 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. +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 +declared in code (`OUTPOST_GATEWAY_PRISTINE`), not captured. A captured one +would come from whatever the last CI job left, because every job is a fresh +checkout, and it would have recorded the August leftovers as pristine. + **Never sleep for ingestion, poll for it.** Every scorer that sends something and reads it back used a fixed `setTimeout`, 8 or 12 seconds. Ingestion is asynchronous, so when the platform is slower than the sleep the scorer reads too diff --git a/packages/hookdeck/src/project-source.ts b/packages/hookdeck/src/project-source.ts index eb072b0..08de935 100644 --- a/packages/hookdeck/src/project-source.ts +++ b/packages/hookdeck/src/project-source.ts @@ -60,6 +60,46 @@ export interface PristineSnapshot { ids: Record; } +/** + * What the Event Gateway side of the Outpost project contains when nothing has + * touched it: nothing. + * + * `OUTPOST_API_KEY` is an ordinary project API key, so it authenticates + * `api.hookdeck.com` and the CLI as well as the Outpost subdomain, and an agent + * can create sources and connections in the Outpost project with it. Agents + * did: on 24 and 25 August a source, two destinations, two connections and two + * issue triggers appeared there — one destination on `outpost-003`'s alert URL, + * the other on a `mock.hookdeck.com` path of the kind `outpost-001` accepted + * before its endpoint was fixed — and nothing reset them; three of them were + * updated again in September. On 5 November `outpost-005` found one of those + * connections, added a topic filter to it instead of changing the Outpost + * destination's topics, and the filter survived from attempt 1 into attempts 2 + * and 3 of the same cell. + * + * **Declared rather than captured.** The gateway project is reset to a snapshot + * taken on first acquire, but in CI every job is a fresh checkout, so a captured + * snapshot is taken from whatever the last job left — here it would have + * recorded those leftovers as pristine and protected them. The tenant cleanup + * below gives the same reason for not persisting a tenant baseline. A declared + * baseline cannot be poisoned by a run that died. + * + * **Empty, unlike the gateway project, and that is not a contradiction of + * "pristine, not empty".** A new Event Gateway project ships with four issue + * triggers; an Outpost project ships with none, because the platform's project + * creation sets up an Outpost project without the gateway defaults (read in the + * Event Gateway implementation, not inferred from the API). Consistent with + * that, the two issue triggers found here were created within a minute of + * the leftover source and connection. No Outpost seed creates gateway + * resources either. So for this + * project, pristine *is* empty. If a scenario ever needs a gateway resource in + * the Outpost project, its seed creates it, and the reset before the next seed + * removes it. + */ +export const OUTPOST_GATEWAY_PRISTINE: PristineSnapshot = { + capturedAt: 'declared', + ids: {}, +}; + export interface FixedProjectSourceOptions { apiKey: string; projectId?: string; @@ -85,6 +125,7 @@ export class FixedProjectSource implements ProjectSource { private readonly outpostConfigPath: string; private cachedClient?: HookdeckClient; private cachedOutpostClient?: OutpostClient; + private cachedOutpostGatewayClient?: HookdeckClient; private outpostTenantsAtAcquire?: Set; private outpostConfigAtAcquire?: Record; private operatorEventDestinationsAtAcquire?: OperatorEventDestination[]; @@ -143,9 +184,35 @@ export class FixedProjectSource implements ProjectSource { return this.cachedOutpostClient; } + /** + * The Event Gateway API, authenticated as the Outpost project. + * + * Same host as `client`, different key, so a different project. Undefined + * when Outpost is off, and when the two keys are the same string — that is + * one project, already reset by `client`, and resetting it again to the + * Outpost baseline would delete the gateway project's default issue triggers. + */ + private get outpostGatewayClient(): HookdeckClient | undefined { + const apiKey = this.options.outpostApiKey ?? process.env.OUTPOST_API_KEY; + if (!apiKey || apiKey === this.options.apiKey) return undefined; + if (!this.cachedOutpostGatewayClient) { + this.cachedOutpostGatewayClient = new HookdeckClient({ + apiKey, + baseUrl: this.options.baseUrl, + }); + } + return this.cachedOutpostGatewayClient; + } + async acquire(): Promise { const snapshot = await this.loadOrCaptureSnapshot(); - await this.resetToPristine(snapshot); + await this.resetToPristine(this.client, snapshot); + // 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 + // reset above, because a scenario started on top of a leftover produces a + // result that looks valid and is not, and nothing has been paid for yet. + await this.resetOutpostGateway(snapshot); this.outpostTenantsAtAcquire = await this.listOutpostTenants(); this.outpostConfigAtAcquire = await this.loadOrCaptureOutpostConfig(); this.operatorEventDestinationsAtAcquire = @@ -165,13 +232,24 @@ export class FixedProjectSource implements ProjectSource { * rather than from a per-run timestamp. */ async release(_project: LeasedProject): Promise { + let snapshot: PristineSnapshot | undefined; try { - const snapshot = await this.loadOrCaptureSnapshot(); - await this.resetToPristine(snapshot); + snapshot = await this.loadOrCaptureSnapshot(); + await this.resetToPristine(this.client, snapshot); } catch { // Swallowed deliberately: a failed release must not fail the run, and // the next acquire will clean up regardless. } + if (snapshot) { + try { + await this.resetOutpostGateway(snapshot); + } catch (error) { + // Same reasoning, and the next acquire resets this side too. + console.warn( + `outpost project gateway reset: release did not complete (${(error as Error).message})` + ); + } + } await this.releaseOutpostTenants(); await this.restoreOperatorEventDestinations(); await this.restoreOutpostConfig(); @@ -502,19 +580,80 @@ export class FixedProjectSource implements ProjectSource { } } - /** Delete everything the snapshot does not list, in dependency order. */ - private async resetToPristine(snapshot: PristineSnapshot): Promise { + /** + * Delete everything the snapshot does not list, in dependency order, and + * return what was deleted. + */ + private async resetToPristine( + client: HookdeckClient, + snapshot: PristineSnapshot + ): Promise> { + const deleted: Array<{ kind: ResourceKind; resource: HookdeckResource }> = + []; // Connections reference sources and destinations, so they go first. for (const kind of RESOURCE_KINDS) { const keep = new Set(snapshot.ids[kind] ?? []); - const existing: HookdeckResource[] = await this.client.list( - kind as ResourceKind - ); + const existing: HookdeckResource[] = await client.list(kind); for (const resource of existing) { if (keep.has(resource.id)) continue; - await this.client.delete(kind as ResourceKind, resource.id); + await client.delete(kind, resource.id); + deleted.push({ kind, resource }); + } + } + return deleted; + } + + /** + * Reset the Event Gateway side of the Outpost project to + * `OUTPOST_GATEWAY_PRISTINE`, which is empty. + * + * Refuses when the Outpost key turns out to reach the gateway project after + * all — two different keys for one project, say. The baseline here is "delete + * everything", so pointing it at the gateway project would delete its default + * issue triggers. The test is whether + * anything this key can see is in the gateway project's own snapshot: two + * projects never share a resource id. + * + * Says what it deleted. Release normally leaves nothing for acquire to find, + * so a deletion at acquire means a run died before releasing or something + * outside the harness wrote to the project — both worth seeing in a log. + */ + private async resetOutpostGateway( + gatewaySnapshot: PristineSnapshot + ): Promise { + const client = this.outpostGatewayClient; + if (!client) return; + + const gatewayIds = new Set(Object.values(gatewaySnapshot.ids).flat()); + for (const kind of RESOURCE_KINDS) { + const shared = (await client.list(kind)).filter((r) => + gatewayIds.has(r.id) + ); + if (shared.length > 0) { + console.warn( + `outpost project gateway reset: skipped, because OUTPOST_API_KEY can see ${kind} ` + + `${shared.map((r) => r.id).join(', ')} from the gateway project's pristine ` + + 'snapshot. The two keys appear to belong to one project, and resetting it ' + + "to the Outpost baseline would delete that project's defaults." + ); + return; } } + + const deleted = await this.resetToPristine( + client, + OUTPOST_GATEWAY_PRISTINE + ); + if (deleted.length > 0) { + console.warn( + `outpost project gateway reset: deleted ${deleted + .map( + ({ kind, resource }) => + `${kind} ${resource.id}${resource.name ? ` (${resource.name})` : ''}` + ) + .join(', ')}` + ); + } } } diff --git a/packages/hookdeck/test/project-source.test.ts b/packages/hookdeck/test/project-source.test.ts index 19a051a..d5493a8 100644 --- a/packages/hookdeck/test/project-source.test.ts +++ b/packages/hookdeck/test/project-source.test.ts @@ -387,3 +387,250 @@ describe('FixedProjectSource Outpost cleanup', () => { expect(outpost.deleted).toEqual([]); }); }); + +/** + * `OUTPOST_API_KEY` is a project API key, so it reaches `api.hookdeck.com` as + * well as the Outpost subdomain, and an agent can build Event Gateway resources + * in the Outpost project with it. One such connection, left from August, was + * edited by an `outpost-005` attempt and the edit was still there two attempts + * later. These tests model `api.hookdeck.com` as two projects told apart by the + * bearer token, which is all that separates them on the real API. + */ +describe('FixedProjectSource Outpost project gateway reset', () => { + beforeEach(() => vi.restoreAllMocks()); + + const GATEWAY_KEY = 'gateway-key'; + const OUTPOST_KEY = 'outpost-key'; + + function fakeTwoProjects(projects: Record>) { + const state = new Map>>(); + for (const [key, kinds] of Object.entries(projects)) { + const byKind = new Map>(); + for (const [kind, ids] of Object.entries(kinds)) { + byKind.set(kind, new Set(ids)); + } + state.set(key, byKind); + } + const deleted: Array<{ key: string; kind: string; id: string }> = []; + + const fetchImpl = vi.fn(async (url: string | URL, init?: RequestInit) => { + const u = new URL(String(url)); + if (u.hostname.includes('outpost')) { + // Tenants, operator event destinations and config: none, for these + // tests, which are about the gateway side. + if (u.pathname.endsWith('/config')) { + return new Response(JSON.stringify({}), { status: 200 }); + } + return new Response(JSON.stringify({ models: [] }), { status: 200 }); + } + const key = String( + (init?.headers as Record | undefined)?.Authorization + ).replace(/^Bearer /, ''); + const project = state.get(key) ?? new Map>(); + state.set(key, project); + const [, kind, id] = u.pathname.replace(/^\/[^/]+/, '').split('/'); + if ((init?.method ?? 'GET') === 'DELETE') { + project.get(kind)?.delete(id); + deleted.push({ key, kind, id }); + return new Response('', { status: 200 }); + } + const models = [...(project.get(kind) ?? [])].map((rid) => ({ + id: rid, + })); + return new Response(JSON.stringify({ models }), { status: 200 }); + }); + + const add = (key: string, kind: string, id: string) => { + const project = state.get(key) ?? new Map>(); + state.set(key, project); + const ids = project.get(kind) ?? new Set(); + project.set(kind, ids); + ids.add(id); + }; + const ids = (key: string, kind: string) => [ + ...(state.get(key)?.get(kind) ?? []), + ]; + return { fetchImpl, deleted, add, ids }; + } + + function source(snapshotPath = tempSnapshotPath()) { + return new FixedProjectSource({ + apiKey: GATEWAY_KEY, + outpostApiKey: OUTPOST_KEY, + snapshotPath, + outpostConfigPath: join( + mkdtempSync(join(tmpdir(), 'hd-evals-')), + 'outpost-config.json' + ), + }); + } + + it('deletes gateway resources an earlier run left in the Outpost project, before the seed', async () => { + // The state run 42044644850 found: a source, destination and connection + // from August, plus issue triggers, which an Outpost project does not ship + // with. A fresh snapshot path is a fresh CI checkout. + const api = fakeTwoProjects({ + [GATEWAY_KEY]: { 'issue-triggers': ['it_default'] }, + [OUTPOST_KEY]: { + connections: ['web_leftover'], + sources: ['src_leftover'], + destinations: ['des_leftover'], + 'issue-triggers': ['it_leftover'], + }, + }); + vi.stubGlobal('fetch', api.fetchImpl); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + + await source().acquire(); + + expect( + api.deleted.filter((d) => d.key === OUTPOST_KEY).map((d) => d.kind) + ).toEqual(['connections', 'sources', 'destinations', 'issue-triggers']); + // The gateway project keeps its defaults: the Outpost baseline is empty, + // the gateway one is not. + expect(api.ids(GATEWAY_KEY, 'issue-triggers')).toEqual(['it_default']); + }); + + it('does not let a crashed attempt hand its edits to the next attempt', async () => { + // Attempts 1 -> 2 -> 3 of one cell: each is a new acquire, and none of + // them released. The reset has to happen on the way in. + const api = fakeTwoProjects({ [GATEWAY_KEY]: {}, [OUTPOST_KEY]: {} }); + vi.stubGlobal('fetch', api.fetchImpl); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + const snapshotPath = tempSnapshotPath(); + + await source(snapshotPath).acquire(); + api.add(OUTPOST_KEY, 'connections', 'web_attempt_1'); + // no release + + await source(snapshotPath).acquire(); + expect(api.ids(OUTPOST_KEY, 'connections')).toEqual([]); + }); + + it('deletes what the lease created on release', async () => { + const api = fakeTwoProjects({ [GATEWAY_KEY]: {}, [OUTPOST_KEY]: {} }); + vi.stubGlobal('fetch', api.fetchImpl); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + const s = source(); + + const lease = await s.acquire(); + api.add(OUTPOST_KEY, 'sources', 'src_agent'); + await s.release(lease); + + expect(api.ids(OUTPOST_KEY, 'sources')).toEqual([]); + }); + + it('says what it deleted, so a leftover is visible in the log', async () => { + const api = fakeTwoProjects({ + [GATEWAY_KEY]: {}, + [OUTPOST_KEY]: { connections: ['web_leftover'] }, + }); + vi.stubGlobal('fetch', api.fetchImpl); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + await source().acquire(); + + expect(warn.mock.calls.flat().join('\n')).toContain( + 'connections web_leftover' + ); + }); + + it('refuses to reset when the Outpost key reaches the gateway project', async () => { + // Two keys, one project. The Outpost baseline is "delete everything", which + // would take the gateway project's default issue triggers with it. + const api = fakeTwoProjects({ + [GATEWAY_KEY]: { 'issue-triggers': ['it_default'] }, + [OUTPOST_KEY]: { 'issue-triggers': ['it_default', 'it_other'] }, + }); + vi.stubGlobal('fetch', api.fetchImpl); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + await source().acquire(); + + expect(api.deleted.filter((d) => d.key === OUTPOST_KEY)).toEqual([]); + expect(warn.mock.calls.flat().join('\n')).toContain('skipped'); + }); + + it('does nothing extra when both keys are the same', async () => { + const api = fakeTwoProjects({ + [GATEWAY_KEY]: { 'issue-triggers': ['it_default'] }, + }); + vi.stubGlobal('fetch', api.fetchImpl); + const s = new FixedProjectSource({ + apiKey: GATEWAY_KEY, + outpostApiKey: GATEWAY_KEY, + snapshotPath: tempSnapshotPath(), + }); + + const lease = await s.acquire(); + await s.release(lease); + + expect(api.deleted).toEqual([]); + expect(api.ids(GATEWAY_KEY, 'issue-triggers')).toEqual(['it_default']); + }); + + it('touches no Outpost project when no Outpost key is configured', async () => { + const api = fakeTwoProjects({ + [GATEWAY_KEY]: {}, + [OUTPOST_KEY]: { connections: ['web_leftover'] }, + }); + vi.stubGlobal('fetch', api.fetchImpl); + const prior = process.env.OUTPOST_API_KEY; + delete process.env.OUTPOST_API_KEY; + try { + const s = new FixedProjectSource({ + apiKey: GATEWAY_KEY, + snapshotPath: tempSnapshotPath(), + }); + await s.release(await s.acquire()); + } finally { + if (prior !== undefined) process.env.OUTPOST_API_KEY = prior; + } + + expect(api.ids(OUTPOST_KEY, 'connections')).toEqual(['web_leftover']); + }); + + it('does not throw when the release-time reset fails', async () => { + const api = fakeTwoProjects({ [GATEWAY_KEY]: {}, [OUTPOST_KEY]: {} }); + vi.stubGlobal('fetch', api.fetchImpl); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + const s = source(); + const lease = await s.acquire(); + + vi.stubGlobal( + 'fetch', + vi.fn(async (url: string | URL, init?: RequestInit) => { + const auth = (init?.headers as Record | undefined) + ?.Authorization; + if (auth === `Bearer ${OUTPOST_KEY}`) { + return new Response('boom', { status: 500 }); + } + return api.fetchImpl(url, init); + }) + ); + + await expect(s.release(lease)).resolves.toBeUndefined(); + }); + + it('fails the acquire when the Outpost project cannot be reset', async () => { + // Before the agent runs, nothing has been paid for, and a scenario started + // on top of a leftover scores as though it were valid. + const api = fakeTwoProjects({ [GATEWAY_KEY]: {} }); + vi.stubGlobal( + 'fetch', + vi.fn(async (url: string | URL, init?: RequestInit) => { + const auth = (init?.headers as Record | undefined) + ?.Authorization; + if ( + auth === `Bearer ${OUTPOST_KEY}` && + !new URL(String(url)).hostname.includes('outpost') + ) { + return new Response('boom', { status: 500 }); + } + return api.fetchImpl(url, init); + }) + ); + + await expect(source().acquire()).rejects.toThrow(/500/); + }); +}); From e8a7cf526d084523ee91059093d573fb1d64a1c9 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:20:55 +0000 Subject: [PATCH 2/2] Say that OUTPOST_API_KEY's project is wiped, and log each deletion The previous commit resets the Event Gateway side of the project OUTPOST_API_KEY belongs to on every acquire, for every scenario, not only Outpost ones, and deletes resources that existed before the run. README.md and .env.example still said Outpost state was not reset and that Event Gateway scenarios do not touch the Outpost project. Both now say the key must belong to a dedicated Outpost project and that its Event Gateway side is wiped on every run. Deletions are now logged as each one happens. They were logged once after the reset returned, so a reset that failed partway lost the record of what it had already deleted. AGENTS.md: the Outpost trap's heading contradicted its own paragraph and now says tenants are only reset on release. The filter is described as a body `$nin` filter, the long line is rewrapped, and the paragraph says a gateway API error on the Outpost key now fails the acquire of every cell. README.md no longer says a new project ships with four default issue triggers. Platform project creation makes four, but review found three on the gateway project today, so the count is dropped rather than asserted. Co-Authored-By: Claude Opus 5.5 --- .env.example | 16 ++++-- AGENTS.md | 19 ++++--- README.md | 15 ++++-- packages/hookdeck/src/project-source.ts | 51 +++++++++---------- packages/hookdeck/test/project-source.test.ts | 25 +++++++++ 5 files changed, 83 insertions(+), 43 deletions(-) diff --git a/.env.example b/.env.example index e9f8dc0..89e9b32 100644 --- a/.env.example +++ b/.env.example @@ -26,10 +26,18 @@ ANTHROPIC_API_KEY= # harness produced the run. OPENAI_API_KEY= -# A managed Outpost project on the Hookdeck platform, for the Outpost scenarios -# (BM12, BM13). Separate from HOOKDECK_API_KEY: Outpost has its own API, and the -# Event Gateway scenarios do not touch it. Scenarios that need it are skipped -# when it is unset, so leaving it blank costs nothing. +# A project key for a dedicated Outpost project on the Hookdeck platform, for +# the Outpost scenarios. Separate from HOOKDECK_API_KEY: Outpost has its own API. +# Scenarios that need it are skipped when it is unset, so leaving it blank costs +# nothing. +# +# Use a project that holds nothing you want to keep. When this is set, every +# run of every scenario, Event Gateway ones included, deletes all Event Gateway +# resources in this project (sources, destinations, connections, transformations +# and issue triggers) before the seed and again on release, including resources +# that were there before the run. Runs also delete the tenants they create, and +# on release put the project's operator event destinations and managed config +# back as they found them. OUTPOST_API_KEY= # Vercel AI Gateway. The opencode harness routes through this. Not needed until diff --git a/AGENTS.md b/AGENTS.md index 41243e3..bc87ab2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1144,8 +1144,8 @@ collide. Do not try to serialise via a GitHub Actions concurrency group: a group holds one running and one pending job and cancels the rest. Shard instead. -**Outpost state is not reset between runs.** `FixedProjectSource` snapshots and -restores the Hookdeck project, and Outpost has no snapshot to restore from. +**Outpost tenants are only reset on release.** `FixedProjectSource` snapshots +and restores the Hookdeck project, and Outpost has no snapshot to restore from. Tenants and destinations an Outpost run creates survive into the next one, so the second run of a scenario finds `acme` already there and may score a previous run's work. `FixedProjectSource` now deletes tenants that were not present when @@ -1156,12 +1156,15 @@ run that dies before release still leaks and the next run inherits it. `OUTPOST_API_KEY` is an ordinary project key, so it works on `api.hookdeck.com` and the CLI too. A source, two connections, two destinations and two issue triggers were left there on 24 and 25 August and nothing removed them. On 5 -November an `outpost-005` attempt added a topic filter to one of those connections instead of changing the -Outpost destination's topics. The filter carried into the cell's next two -attempts, because nothing reset that side. `FixedProjectSource` now deletes every -gateway resource in the Outpost project on acquire, before the seed, and again -on release. It refuses if the Outpost key can see anything in the gateway -project's snapshot, because that means both keys reach one project. +November an `outpost-005` attempt added a body `$nin` filter to one of those +connections instead of changing the Outpost destination's topics. The filter +carried into the cell's next two attempts, because nothing reset that side. +`FixedProjectSource` now deletes every gateway resource in the Outpost project +on every acquire, for every scenario, before the seed, and again on release. It +refuses if the Outpost key can see anything in the gateway project's snapshot, +because that means both keys reach one project. So `OUTPOST_API_KEY` must +belong to a dedicated project, and a gateway API error on that key now fails +the acquire of every cell, Event Gateway scenarios included. So cleanup on release is not enough on its own, and `applyOutpostSeed` deletes each tenant it is about to create. That makes seeding idempotent without diff --git a/README.md b/README.md index 8751aa3..95ebb9b 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ Every run follows the same shape: Runs need a Docker daemon, and `HOOKDECK_API_KEY` for the project scoring runs against. See `.env.example`. -**Reset is to pristine, not to empty.** A new Hookdeck project ships with four default +**Reset is to pristine, not to empty.** A new Hookdeck project ships with default issue triggers. Deleting them would leave the project unlike any real customer's. The first acquire snapshots what the project contains and every reset deletes only what a run added. @@ -245,9 +245,16 @@ is deliberately separate from `ctx.api`: Outpost inverts the gateway's model, in tenant is your customer, the tenant owns destinations, and events are published to topics rather than routed from sources. -**Outpost state is not reset between runs yet.** The provisioner restores the Hookdeck -project and does not touch Outpost, so tenants an Outpost run creates persist. See -`AGENTS.md`. +**`OUTPOST_API_KEY` must belong to a dedicated Outpost project, because every run +wipes its Event Gateway side.** The key is an ordinary project key, so it also works on +`api.hookdeck.com` and agents can create sources and connections there with it. When +the key is set, every run of every scenario, not only the Outpost ones, deletes all +Event Gateway resources in that project before the seed and again on release, including +ones that existed before the run. + +**Outpost's own state is only partly reset.** A run deletes the tenants it created and +restores operator event destinations and managed config on release. A run that dies +before release can still leave a tenant behind. See `AGENTS.md`. ## Skills diff --git a/packages/hookdeck/src/project-source.ts b/packages/hookdeck/src/project-source.ts index 08de935..9f7b6a1 100644 --- a/packages/hookdeck/src/project-source.ts +++ b/packages/hookdeck/src/project-source.ts @@ -84,7 +84,7 @@ export interface PristineSnapshot { * baseline cannot be poisoned by a run that died. * * **Empty, unlike the gateway project, and that is not a contradiction of - * "pristine, not empty".** A new Event Gateway project ships with four issue + * "pristine, not empty".** A new Event Gateway project ships with default issue * triggers; an Outpost project ships with none, because the platform's project * creation sets up an Outpost project without the gateway defaults (read in the * Event Gateway implementation, not inferred from the API). Consistent with @@ -581,15 +581,17 @@ export class FixedProjectSource implements ProjectSource { } /** - * Delete everything the snapshot does not list, in dependency order, and - * return what was deleted. + * Delete everything the snapshot does not list, in dependency order. + * + * `onDelete` is called after each deletion rather than once at the end, so a + * reset that fails partway still leaves a record of what it had already + * removed. */ private async resetToPristine( client: HookdeckClient, - snapshot: PristineSnapshot - ): Promise> { - const deleted: Array<{ kind: ResourceKind; resource: HookdeckResource }> = - []; + snapshot: PristineSnapshot, + onDelete?: (kind: ResourceKind, resource: HookdeckResource) => void + ): Promise { // Connections reference sources and destinations, so they go first. for (const kind of RESOURCE_KINDS) { const keep = new Set(snapshot.ids[kind] ?? []); @@ -597,10 +599,9 @@ export class FixedProjectSource implements ProjectSource { for (const resource of existing) { if (keep.has(resource.id)) continue; await client.delete(kind, resource.id); - deleted.push({ kind, resource }); + onDelete?.(kind, resource); } } - return deleted; } /** @@ -610,13 +611,13 @@ export class FixedProjectSource implements ProjectSource { * Refuses when the Outpost key turns out to reach the gateway project after * all — two different keys for one project, say. The baseline here is "delete * everything", so pointing it at the gateway project would delete its default - * issue triggers. The test is whether - * anything this key can see is in the gateway project's own snapshot: two - * projects never share a resource id. + * issue triggers. The test is whether anything this key can see is in the + * gateway project's own snapshot: two projects never share a resource id. * - * Says what it deleted. Release normally leaves nothing for acquire to find, - * so a deletion at acquire means a run died before releasing or something - * outside the harness wrote to the project — both worth seeing in a log. + * Logs each deletion as it happens. Release normally leaves nothing for + * acquire to find, so a deletion at acquire means a run died before releasing + * or something outside the harness wrote to the project — both worth seeing + * in a log. */ private async resetOutpostGateway( gatewaySnapshot: PristineSnapshot @@ -640,20 +641,16 @@ export class FixedProjectSource implements ProjectSource { } } - const deleted = await this.resetToPristine( + await this.resetToPristine( client, - OUTPOST_GATEWAY_PRISTINE + OUTPOST_GATEWAY_PRISTINE, + (kind, resource) => { + console.warn( + `outpost project gateway reset: deleted ${kind} ${resource.id}` + + (resource.name ? ` (${resource.name})` : '') + ); + } ); - if (deleted.length > 0) { - console.warn( - `outpost project gateway reset: deleted ${deleted - .map( - ({ kind, resource }) => - `${kind} ${resource.id}${resource.name ? ` (${resource.name})` : ''}` - ) - .join(', ')}` - ); - } } } diff --git a/packages/hookdeck/test/project-source.test.ts b/packages/hookdeck/test/project-source.test.ts index d5493a8..23cadff 100644 --- a/packages/hookdeck/test/project-source.test.ts +++ b/packages/hookdeck/test/project-source.test.ts @@ -535,6 +535,31 @@ describe('FixedProjectSource Outpost project gateway reset', () => { ); }); + it('keeps the record of what it deleted when the reset fails partway', async () => { + const api = fakeTwoProjects({ + [GATEWAY_KEY]: {}, + [OUTPOST_KEY]: { connections: ['web_leftover'], sources: ['src_stuck'] }, + }); + vi.stubGlobal( + 'fetch', + vi.fn(async (url: string | URL, init?: RequestInit) => { + if ( + init?.method === 'DELETE' && + String(url).endsWith('/sources/src_stuck') + ) { + return new Response('boom', { status: 500 }); + } + return api.fetchImpl(url, init); + }) + ); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + await expect(source().acquire()).rejects.toThrow(/500/); + expect(warn.mock.calls.flat().join('\n')).toContain( + 'connections web_leftover' + ); + }); + it('refuses to reset when the Outpost key reaches the gateway project', async () => { // Two keys, one project. The Outpost baseline is "delete everything", which // would take the gateway project's default issue triggers with it.