ingest: filter BIT-SMOKE- when marker appears in stack_trace only

CRM PHP smoke (BIT-SMOKE-CRM-MAIN-DIRECT) can send the reserved token in
stack_trace while message stays generic, so the prior message-only noise
check missed it. Pass client stack text into evaluateNoise and bump
noise_ruleset_version to 1.0.3.

Paperclip-Agent: 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376
Paperclip-Issue: BIT-957
Paperclip-Run: d61f6d49-e43c-4ff6-a694-cbc8edff0d33
Made-with: Cursor
This commit is contained in:
Peter Spark committed 2026-04-05 07:22:23 +00:00
1 parent 6c01679310
commit b082bc716a
4 files changed
+62 -5

No files matched your search

@@ -258,6 +258,43 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => {
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
});
it("skips BIT-SMOKE- in stack_trace when message omits marker (CRM-style payload)", async () => {
const [before] = await _pool.execute<RowDataPacket[]>(
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
[_projectIdA],
);
const _nBefore = Number((before[0] as { c: number }).c);
const _res = await _app.inject({
method: "POST",
url: "/v1/ingest/events",
headers: { authorization: `Bearer ${_tokenA}` },
payload: {
events: [
{
schema_version: 1,
occurred_at: "2026-04-05T10:05:00.000Z",
level: "error",
message: "Exception",
stack_trace: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke",
},
],
},
});
expect(_res.statusCode).toBe(200);
const _body = JSON.parse(_res.body) as {
noise_filtered_count: number;
results: Array<{ skipped?: boolean; rule_id?: string }>;
};
expect(_body.noise_filtered_count).toBe(1);
expect(_body.results[0]?.skipped).toBe(true);
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
const [after] = await _pool.execute<RowDataPacket[]>(
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
[_projectIdA],
);
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
});
it("replays identical idempotent requests", async () => {
const _payload = {
events: [
+14
View File
@@ -101,4 +101,18 @@ describe("evaluateNoise", () => {
reason: "filtered_intentional_smoke_event",
});
});
it("matches BIT-SMOKE- in stack_trace when message omits the marker (CRM PHP smoke)", () => {
const _r = evaluateNoise({
level: "error",
message: "PHP exception",
stackText: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke",
filePathHint: "/smoke/crm-main.php",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
});
+8 -4
View File
@@ -4,7 +4,7 @@ import { normalizeLevelToSeverity } from "./normalize.js";
* Versioned ruleset id (document in release notes when rules change).
* Rule inventory and validation steps: `docs/operations/ingest-hardening-runbook.md`.
*/
export const NOISE_RULESET_VERSION = "1.0.2";
export const NOISE_RULESET_VERSION = "1.0.3";
export type NoiseEvaluation =
| { matched: false }
@@ -127,17 +127,21 @@ const _RULES: NoiseRule[] = [
/**
* Conservative: never classify fatal/critical ingest levels as noise (avoid hiding real outages).
* Exception: reserved `BIT-SMOKE-` messages are intentional end-to-end probes (e.g. wdmi-store
* `/smoke/wdmi.js`) and are filtered at every ingest level so they do not open incidents.
* Exception: reserved `BIT-SMOKE-` markers are intentional end-to-end probes (e.g. wdmi-store
* `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`) and are filtered at every ingest level so they do
* not open incidents. Some PHP reporters put the marker only in `stack_trace`, not in `message`.
*/
export function evaluateNoise(input: {
level: string;
message: string;
/** Client `stacktrace` / `stack_trace` when present — used only for BIT-SMOKE- detection. */
stackText?: string;
context?: Record<string, unknown>;
filePathHint: string;
}): NoiseEvaluation {
const _msg = input.message.trim();
if (_msg.includes("BIT-SMOKE-")) {
const _stack = (input.stackText ?? "").trim();
if (_msg.includes("BIT-SMOKE-") || _stack.includes("BIT-SMOKE-")) {
return {
matched: true,
ruleId: "bitreport_smoke_marker",
@@ -169,9 +169,11 @@ async function _ingestOneEvent(
const _severity = normalizeLevelToSeverity(_ev.level);
const _message = _ev.message.trim();
const _context = _ev.context && typeof _ev.context === "object" ? _ev.context : null;
const _clientStackEarly = clientProvidedStack(_ev);
const _noise = evaluateNoise({
level: _ev.level,
message: _message,
...(_clientStackEarly !== null ? { stackText: _clientStackEarly } : {}),
context: _context ?? undefined,
filePathHint: extractLocationFromContext(_context).filePath,
});
@@ -184,7 +186,7 @@ async function _ingestOneEvent(
fingerprint_policy_version: FINGERPRINT_POLICY_VERSION,
};
}
const _clientStack = clientProvidedStack(_ev);
const _clientStack = _clientStackEarly;
const _fingerprint = computeFingerprint({
clientFingerprint: _ev.fingerprint,
message: _message,