Skip to content

Source maps phase 3: upload and list API - #122

Merged
unjica merged 13 commits into
developfrom
feature/source-maps-phase3
Jul 2, 2026
Merged

unjica merged 13 commits into
developfrom
feature/source-maps-phase3

Conversation

@unjica

@unjica unjica commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add POST /api/project/source-maps for JSON source map upload (EDITOR+ session auth), upserting on (project, app, release, bundle_url) with 10 MB cap and SHA-256 dedupe metadata
  • Add GET /api/project/source-maps?app=&release= to list uploaded map metadata (no map body) for any project member with read access
  • New lib source-map-upload.ts with validation, parsing, upsert, and list helpers plus unit tests
  • Update docs/source-maps.md and CHANGELOG.md for phase 3 completion

Part of #98 (v1.3.0). No new migrations.

Test plan

  • pnpm --filter api exec vitest run src/lib/source-map-upload.test.ts
  • pnpm run build
  • POST /api/project/source-maps with valid session + EDITOR role returns 201/200
  • GET /api/project/source-maps?app=web&release=1.0.0 returns metadata list
  • VIEWER cannot upload (403); unauthenticated upload rejected

Made with Cursor

Expose POST/GET /api/project/source-maps for JSON map upload keyed by app, release, and bundle URL so CI can register maps before symbolication lands in phase 4.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/lib/source-map-upload.ts Resolved
@unjica unjica mentioned this pull request Jul 2, 2026
2 of 3 tasks
Raise per-route Fastify bodyLimit for POST /project/source-maps above the 10 MB map cap and trim app/release in Zod so whitespace-only keys are rejected before upsert.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/lib/source-map-upload.ts Resolved
Share trim helpers between source map storage and POST /ingest/error so padded SDK labels match uploaded artifacts for retention and symbolication lookups.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/routes/ingest.ts Resolved
unjica and others added 3 commits July 2, 2026 14:12
Use assertIngestAppAllowed and normalizeMapAppLabel for /ingest/batch so padded app fields match restricted API keys the same way as single-event and error ingest.

Co-authored-by: Cursor <[email protected]>
Parse V8 and Firefox stack frames, resolve positions with uploaded source maps, and expose symbolicated_stack fields on GET /api/errors/:id for display-only de-minification.

Co-authored-by: Cursor <[email protected]>
Derive symbolicated_top_stack from the first resolvable frame in occurrence stacks instead of top_stack (error message line), and dedupe concurrent listSourceMapArtifactsForRelease calls per release.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/routes/ingest.ts Resolved
unjica and others added 2 commits July 2, 2026 14:15
Store trimmed app values on /ingest/event and /ingest/session (including session lookup) so padded SDK labels match error, batch, and source-map keys.

Co-authored-by: Cursor <[email protected]>
…ase4

Source maps phase 4: stack symbolication
data: {
project_id: projectId,
app: body.app,
app,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace-only ingest app becomes empty

Medium Severity

Ingest now stores normalizeMapAppLabel(body.app) while Zod still accepts any non-empty string, including whitespace-only values. Those labels trim to "" and are written to events, sessions, and errors. Upload validation rejects the same input, so ingest can persist invalid empty app keys and break scoping, quotas, and map alignment.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 37a7a89. Configure here.

Comment thread apps/api/src/lib/source-map-upload.ts Outdated
ok: true,
artifact: toSourceMapArtifactSummary(row),
created: existing === null,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upload may return wrong status

Low Severity

upsertSourceMapArtifact sets created from a pre-upsert findUnique, not from the upsert result. Concurrent uploads for the same key can both see no row and return 201 even when one request only replaced an artifact another just created.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 37a7a89. Configure here.

Comment thread apps/api/src/lib/stack-symbolicate.ts Resolved
Comment thread apps/api/src/lib/stack-symbolicate.ts Resolved
unjica and others added 2 commits July 2, 2026 14:22
Reject whitespace-only app labels in ingest Zod schemas, normalize app/release on artifact lookup, and use create-then-update on P2002 so concurrent uploads return accurate 201/200 status.

Co-authored-by: Cursor <[email protected]>
Require exact same-origin pathnames for full URLs, normalize ErrorGroup app/release when loading maps for legacy rows, and add regression tests.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/lib/stack-symbolicate.ts Resolved
Compute the group top frame from occurrences_list[0] before parallel per-occurrence enrichment so older stacks cannot win under Promise.all and the newest occurrence without maps leaves symbolicated_top_stack unset.

Co-authored-by: Cursor <[email protected]>
Comment thread apps/api/src/lib/source-map-artifact.ts Resolved
Comment thread apps/api/src/routes/ingest.ts Resolved
Lazy-load source map content by matching stack frames with caps on bundle
refs and content fetches. Reject whitespace-only ingest apps via Zod trim,
and match legacy padded session app labels on close/idempotency.

Co-authored-by: Cursor <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 4 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 01fcea5. Configure here.

Comment thread apps/api/src/lib/stack-symbolicate.ts Resolved
Comment thread apps/api/src/routes/ingest.ts Resolved
Singleflight source map content fetches and enrich occurrences sequentially
so MAX_SOURCE_MAP_CONTENT_LOADS_PER_DETAIL cannot be exceeded under Promise.all.
Count distinct ingest apps with TRIM(app) so legacy padded labels match trimmed ingest keys.

Co-authored-by: Cursor <[email protected]>
@unjica
unjica merged commit d7ab94b into develop Jul 2, 2026
3 checks passed
@unjica
unjica deleted the feature/source-maps-phase3 branch July 2, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant