From 1cc9f2565fbba1b4f233d48e2fd204f49c13041c Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 16 Nov 2026 22:24:18 +1100 Subject: [PATCH 1/2] fix(sources): show a capped hunt run's summary row as its counts A rule that fills its per-run detection cap leaves one summary row with the nil matched_uuid and the counts in _json. In Hunt Results that row read as a match with a zero UUID. The hunts source's default select shows a `match` column. Summary rows show counts, such as "capped: 27 matched, 20 written". Match rows show the UUID. --- .../api/src/dfe/__tests__/org-connection.test.ts | 14 +++++++++++--- packages/api/src/dfe/controllers/org-connection.ts | 10 +++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/api/src/dfe/__tests__/org-connection.test.ts b/packages/api/src/dfe/__tests__/org-connection.test.ts index 71618f77..11da4fda 100644 --- a/packages/api/src/dfe/__tests__/org-connection.test.ts +++ b/packages/api/src/dfe/__tests__/org-connection.test.ts @@ -416,10 +416,18 @@ describe('ensureOrgConnection', () => { }), ); const hunts = mockCreateSource.mock.calls.find(c => c[1].name === 'hunts'); - expect(hunts?.[1].defaultTableSelectExpression).toBe( - '_timestamp,severity,hunt_name,rule_name,source_table,matched_uuid,rule_id,_json', + const select = hunts?.[1].defaultTableSelectExpression as string; + expect( + select.startsWith( + '_timestamp,severity,hunt_name,rule_name,source_table,', + ), + ).toBe(true); + expect(select.endsWith(',rule_id,_json')).toBe(true); + expect(select).not.toContain('_org_id'); + // The cap's summary row renders as its counts, a match as its UUID. + expect(select).toContain( + "if(matched_uuid = toUUID('00000000-0000-0000-0000-000000000000'), concat('capped: ', toString(_json.matched), ' matched, ', toString(_json.written), ' written'), toString(matched_uuid)) AS match", ); - expect(hunts?.[1].defaultTableSelectExpression).not.toContain('_org_id'); }); test('both DFE sources sit in the engine data database', async () => { diff --git a/packages/api/src/dfe/controllers/org-connection.ts b/packages/api/src/dfe/controllers/org-connection.ts index 1dc16591..ff4986e6 100644 --- a/packages/api/src/dfe/controllers/org-connection.ts +++ b/packages/api/src/dfe/controllers/org-connection.ts @@ -197,10 +197,18 @@ function huntsSource(connectionId: string, m: OrgConnection) { // Detection payload only -- drop the _org_id/_source header plumbing, keep // the analyst-facing match columns plus the structured `_json`. defaultTableSelectExpression: - '_timestamp,severity,hunt_name,rule_name,source_table,matched_uuid,rule_id,_json', + '_timestamp,severity,hunt_name,rule_name,source_table,' + + `${HUNT_MATCH_COLUMN},rule_id,_json`, }; } +// A rule that fills its per-run cap leaves one summary row: nil matched_uuid, counts in _json. +const NIL_UUID = '00000000-0000-0000-0000-000000000000'; +export const HUNT_MATCH_COLUMN = + `if(matched_uuid = toUUID('${NIL_UUID}'), ` + + "concat('capped: ', toString(_json.matched), ' matched, ', toString(_json.written), ' written'), " + + 'toString(matched_uuid)) AS match'; + // PLATFORM-ONLY otel sources. The three below (log/trace/metric) are seeded ONLY // on the platform/admin team - operator telemetry the standard OTel collector // schema writes into the data database. Expressions match the columns upstream infers From 28de11359e6e90066f5eab5906182bf317e2dc7d Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 16 Nov 2026 22:36:44 +1100 Subject: [PATCH 2/2] fix(sources): say "capped: 20 of 21 kept" so both counts fit the cell The results cell truncates at about 20 characters, which hid the cap behind "capped: 21 matched, ...". The shorter form shows both numbers at the default width. --- packages/api/src/dfe/__tests__/org-connection.test.ts | 2 +- packages/api/src/dfe/controllers/org-connection.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api/src/dfe/__tests__/org-connection.test.ts b/packages/api/src/dfe/__tests__/org-connection.test.ts index 11da4fda..8576fa95 100644 --- a/packages/api/src/dfe/__tests__/org-connection.test.ts +++ b/packages/api/src/dfe/__tests__/org-connection.test.ts @@ -426,7 +426,7 @@ describe('ensureOrgConnection', () => { expect(select).not.toContain('_org_id'); // The cap's summary row renders as its counts, a match as its UUID. expect(select).toContain( - "if(matched_uuid = toUUID('00000000-0000-0000-0000-000000000000'), concat('capped: ', toString(_json.matched), ' matched, ', toString(_json.written), ' written'), toString(matched_uuid)) AS match", + "if(matched_uuid = toUUID('00000000-0000-0000-0000-000000000000'), concat('capped: ', toString(_json.written), ' of ', toString(_json.matched), ' kept'), toString(matched_uuid)) AS match", ); }); diff --git a/packages/api/src/dfe/controllers/org-connection.ts b/packages/api/src/dfe/controllers/org-connection.ts index ff4986e6..eff6c5dc 100644 --- a/packages/api/src/dfe/controllers/org-connection.ts +++ b/packages/api/src/dfe/controllers/org-connection.ts @@ -206,7 +206,7 @@ function huntsSource(connectionId: string, m: OrgConnection) { const NIL_UUID = '00000000-0000-0000-0000-000000000000'; export const HUNT_MATCH_COLUMN = `if(matched_uuid = toUUID('${NIL_UUID}'), ` + - "concat('capped: ', toString(_json.matched), ' matched, ', toString(_json.written), ' written'), " + + "concat('capped: ', toString(_json.written), ' of ', toString(_json.matched), ' kept'), " + 'toString(matched_uuid)) AS match'; // PLATFORM-ONLY otel sources. The three below (log/trace/metric) are seeded ONLY