The recent-errors handler (api/src/routes/public/recentErrors.ts) registers
both GET /api/error-monitoring/recent-errors and the alias
GET /v1/paperclip/recent-errors on the admin API (port 3200). However the
admin-ui Next.js rewrite sent all /v1/* to ingest-api (port 3041), which has
no such route, so the alias returned 404 in production while the
/api/error-monitoring path worked (401 without a key).
Changes:
- admin-ui/next.config.ts: add a specific /v1/paperclip/:path* -> admin API
rewrite before the generic /v1/:path* -> ingest-api rule (rewrite order
matters; first match wins).
- api/src/lib/errorMonitoringAuth.ts: authorizeReadQuery now also accepts an
X-Api-Key header carrying either ERROR_RESOLVE_API_KEY/ERROR_REPORTING_API_KEY
or DEBUG_VIEW_ERRORS_KEY, so programmatic callers avoid leaking keys in
URLs/access logs. Backward compatible with the existing query params.
- api/src/routes/public/recentErrors.test.ts: cover the alias path and the
X-Api-Key header (resolve key, view key, invalid key).
- docs/HTTP_CONTRACTS.md, docs/permission-matrix.md: document the header and
the proxy ordering requirement.
BIT-29730's incident-first fast path still ran ROW_NUMBER() OVER
(PARTITION BY incident_id ...) across ALL occurrences of every
selected incident before filtering rn = 1. MariaDB can't turn a
PARTITION BY window function into a loose index scan, so it
materializes and sorts each partition in full. At fleet-audit scale
(status=open,investigating,resolved,ignored&limit=2000) several
"mega-incidents" with 48k-148k occurrences each landed in the
selected page, and sorting those partitions hung the query for 70s+.
Replace the ROW_NUMBER CTE with a `LIMIT 1` correlated subquery per
selected incident. EXPLAIN confirms this walks
er_incident_occurrences_incident_time_idx (incident_id, occurred_at
DESC) and stops at the first row per incident instead of scanning the
rest of its history.
Verified against MariaDB (docker compose) seeded with the production
shape from the bug report (3235 resolved / 20 open incidents, 5
mega-incidents at 48k-148k occurrences each, ~425k occurrence rows
total): status=open,investigating,resolved,ignored&limit=2000 dropped
from 2.1s to 0.44s with identical result rows, and
status=resolved&limit=10 stayed at ~0.3s untouched by the
mega-incidents.
recent-errors built its result by ranking ALL occurrences of every
matching incident with ROW_NUMBER() before applying LIMIT, so
status=resolved (the majority, longest-lived incident state) forced a
scan of the full historical occurrence log just to return one page.
admin/incidents.ts already filters/orders er_incidents directly for
this reason; apply the same pattern here: page through er_incidents
first (small, indexed by current_state), then rank occurrences only
for that page. The q= search path is kept on the old occurrence-first
query since it needs to match occurrence content across an incident's
full history.
Adds er_incidents_state_seen_idx (current_state, last_seen_at) so the
new incident-first path stays indexed even without a project_slug
filter, and backfills the docker/local migration runners that had
drifted behind deploy/lxc/run-migrate.sh (missing three prior
migrations), since the new migration needs to run through them too.
Verified locally against MariaDB (docker compose) with 3k resolved /
20 open incidents and ~90k synthetic occurrences: the reported repro
curls now return HTTP 200 in <100ms (previously reproduced as a hang
via manual EXPLAIN/timing of the old query, ~2s at this seed size and
scaling with total occurrence history).
Add optional addedAt + expiresAfterDays to FixedPattern so each pattern
has a TTL. The resolve-fixed-patterns handler now skips expired patterns,
letting persistent errors resurface and forcing a real code fix instead
of indefinite suppression.
- Transient infra patterns (WSREP, Google API, session write) carry addedAt
for audit but no expiry — they are permanent noise with no code fix.
- fix-duplicate-logo.js expires 14 days after 2026-07-17; if still firing
after that the deploy or client filter is broken and needs attention.
- Response includes expired_pattern_count and per-pattern expired/expires_at.
- resolveFixedPatterns.ts: add '%fix-duplicate-logo.js%' entry so any
Chrome-style CRM JS error that reaches the hub is auto-resolved on deploy
- webhook-deploy.sh: call resolve-fixed-patterns after every service restart
so code fixes clear stale hub incidents automatically (uses ERROR_RESOLVE_API_KEY
from /etc/error-reporting/env which is already sourced by the script)
The 5 open incidents for ERRCLUSTER:33b4e527d8fd were bulk-resolved directly
(IDs 747145, 747381, 753209, 753550, 753551). Client-side noise filter (CRM PR #684)
prevents new occurrences.
- php-error bridge: accept paperclip_project_id / paperclipProjectId in
CrmPhpPayload and promote into event context alongside project_slug/gitea_repo
- recent-errors: extract paperclip_project_id from context_json and emit as
top-level field so error loop can route issues to the correct project board
column without falling back to PAPERCLIP_ERROR_LOOP_PROJECT_ID_BY_SLUG
- Add tests for include/omit behaviour (mirrors gitea_repo coverage)
- Update ERROR_MONITORING_PUBLIC_API.md to document both optional fields
No DB migration required: field is stored in existing context_json column.
Co-Authored-By: Paperclip <[email protected]>
POST /api/error-monitoring/resolve-fixed-patterns — resolves hub incidents
matching known-fixed/transient patterns from config/resolveFixedPatterns.ts.
Fixes 404 from run-error-loop-with-resolve.sh when CRM_RESOLVE_API_URL points
to the hub (CRM module removed in BIT-24199; hub now owns all error monitoring).
Patterns file is extensible; initial set covers Galera/WSREP transients,
Google API backendError, session_write_close cascades, and storage COMMIT noise.
Paperclip-Issue: BIT-25072
Paperclip-Agent: tiago-neves
Block ingest for retired WDMI slugs, purge project data via migration,
remove WDMI runbooks, and add offboard-project helper for future retirements.
Co-authored-by: Cursor <[email protected]>
Align hub rate-limit error context with @fastify/rate-limit types, parse RATE_*
and body-size env vars via parsePositiveIntEnv, wire POST /admin/auth/login to
the login preset, increment er_api_rate_limit_rejections_total per bucket, and
document ingest_token_id plus Prometheus scraping notes.
Made-with: Cursor
- api: Align rate-limit plugin docs with actual store (in-memory unless wired in
index); type errorResponseBuilder context; augment FastifyRequest with optional
ingest_token_id instead of casting to any.
- web: Upgrade to Next 15 / React 19; add ESLint 9 flat config, tsconfig,
next-env.d.ts; outputFileTracingRoot so file tracing stays within this product tree.
Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-2479
Paperclip-Run: e3292ca4-a7b9-42f1-83ca-bc3d78906532
Extract gitea_repo from context_json and include it as a top-level field
on each row returned by GET /api/error-monitoring/recent-errors.
Supports gitea_repo, giteaRepo, repo_full_name, and repository keys.
Added unit tests covering the include and omit cases.
Paperclip-Issue: BIT-1291
Co-Authored-By: Paperclip <[email protected]>
Add ISO-8601 occurred_at to each row returned by GET /api/error-monitoring/recent-errors
so operators can script post-deploy stability checks (BIT-1048).
Extend verify_pmx_bet_due_time_deploy.sh with a hub mode that queries open CRM
incidents matching ERRSIG 90a47beec0d7 and fails if the latest occurrence is
within HUB_DUE_TIME_STABILITY_SEC (default 7200). Skips with exit 0 when no
resolve key is present.
Document the field in HTTP_CONTRACTS, ERROR_MONITORING_PUBLIC_API, and
RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME §6.2.2.
Paperclip-Agent: 5d084b36-f38f-42a5-a92a-520005afda4f
Paperclip-Issue: BIT-1048
Paperclip-Run: 5138810f-9498-49a1-81eb-291fdeba8abc
When occurrence.stack_trace is null/blank, synthesize the same text as
ingest-api (BIT-796) at read time so CRM / Paperclip always get a stable
contract (BIT-1008, ERRPAYLOAD:5d26a50c83c0). Add unit tests and document
in HTTP_CONTRACTS + ERROR_MONITORING_PUBLIC_API.
Paperclip-Agent: 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376
Paperclip-Issue: BIT-1008
Paperclip-Run: 4c4da0dd-38ab-4f32-86d7-f2502c7cceca
Made-with: Cursor
Add POST /api/error-monitoring/resolve-by-pattern with advanced filters:
severity, project_slug, fingerprint, message_pattern, time range.
Enhance purge-resolved with optional older_than_days threshold so only
stale resolved incidents are deleted.
27 contract tests (vitest) cover all four mutation endpoints: auth gating,
validation, response shapes, and CRM-compatible behaviour.
Paperclip-Agent: peter-spark
Paperclip-Issue: BIT-732
Paperclip-Run: 749dfb41-182b-48c8-b6e7-74f14bdb9d41
Extend GET /v1/stats/trend with granularity=hour (UTC buckets) and granularity=day
response envelope. Enrich GET /v1/stats/summary per-project totals and critical
counts. Add GET /v1/stats/recurrence for top incidents by occurrence volume in
a sliding window. Add index on er_incident_occurrences(occurred_at) for range
queries. Wire admin dashboard to summary, 24h/14d trends, and recurrence table.
Document contract in docs/ADMIN_STATS_API.md.
Paperclip-Agent: Pedro Alves (urlKey pedro-alves; id d706f4e6-5d05-4cec-b6e8-f8fb1f203aae)
Paperclip-Issue: BIT-728
Paperclip-Run: 948904bb-20d7-4d29-9cd7-4c22544f7570
Made-with: Cursor
Document the public CRM-shaped API matrix, emit audit rows for resolve,
bulk-resolve, and purge (including dry run), apply a dedicated per-IP
rate limit on mutation routes, and return 403 when a valid session lacks
RBAC for the action. Add Vitest coverage for authorizeMutation.
Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-731
Paperclip-Run: 7d0edfac-5676-41fa-85c2-86d01a808894
Made-with: Cursor
Add POST /api/error-monitoring/resolve, bulk-resolve, and purge-resolved with
resolve key or admin JWT (errors:triage / errors:delete). Extend GET
recent-errors with status, severity, project_slug, q, offset, and stable
ordering. Document contracts in api/docs/ERROR_MONITORING_PUBLIC_API.md;
add vitest for public auth helpers. Proxy new routes and widen admin-ui
middleware for /api/error-monitoring/*.
Paperclip-Issue: BIT-726
Paperclip-Run: 3fbf92be-736e-4b11-8e90-cf993d8cd5ca
Paperclip-Agent: Pedro Alves (id d706f4e6-5d05-4cec-b6e8-f8fb1f203aae)
Made-with: Cursor
Register the same handler as /v1/paperclip/recent-errors so NPM and direct
API probes (e.g. :3200) match Paperclip default PAPERCLIP_ERROR_API_QUERY.
Admin UI proxy now calls the Fastify path for a single contract end-to-end.
Paperclip-Agent: David Santos (urlKey david-santos; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-702
Paperclip-Run: 4ba525c4-3929-475c-a845-400c49eda817
Made-with: Cursor
Add Fastify GET /v1/paperclip/recent-errors returning CRM-compatible JSON (data
envelope, project_slug per row, status open for open/investigating incidents).
Admin UI proxies the public path /api/error-monitoring/recent-errors to the API
base; middleware bypasses the session redirect for that path only.
Auth matches CRM env names: ERROR_RESOLVE_API_KEY or ERROR_REPORTING_API_KEY for
?api_key=, DEBUG_VIEW_ERRORS_KEY for ?view_errors=.
Paperclip-Agent: David Santos (urlKey david-santos; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-684
Paperclip-Run: cf7cb964-6953-4476-af09-3feb5d10da17
Made-with: Cursor
Replace Postgres with MariaDB 11 in docker-compose; convert all
database/error_reporting and db/migrations SQL to InnoDB-friendly syntax
(DATETIME(6), AUTO_INCREMENT, ON DUPLICATE KEY). Run admin portal DDL in the
same migrate one-shot as error_reporting.
Switch ingest-api, collector-worker, and api from pg to mysql2 (pools,
parameterized queries, transactions). Align ingest writes with
er_incident_occurrences and include project_id on idempotency inserts.
Add scripts/run-mysql-migrations.sh for host-side applies; update LXC
run-migrate/verify, deployment docs, and .env.example (mysql://, ER_MYSQL_*).
Verified: npm run build + npm test in ingest-api and collector-worker;
npm run build in api. Full docker compose not run here (no local daemon).
Co-Authored-By: Paperclip <[email protected]>