Repository navigation
fix(node): preserve flag payloads and exception properties - #5747
marandaneto wants to merge 5 commits into
Conversation
Replay incident risk checkThis diff touches code involved in past incidents. This is a heads-up, not a verdict: read the matched sections of INCIDENTS.md and answer their review questions before merging. For a judgment on whether this diff has the same failure mode, run the |
Coherence📄 0 spec file errors · ⛔ 0 broken rules · 🚪 0 unchecked inputs · 🐛 0 bugs that came back What is Coherence?Coherence compares the code with its spec files ( This check read 44 parts of the code and 7 rules. Tip Nothing to fix. |
Node SDK acceptance v2Commit: 8312dd0 Capture v0✅ 247 passed / ❌ 0 non-passing / Drill-down: run artifacts → Harness exit: 0; report validation exit: 0. All selected cases passed and report validation succeeded. Capture v1✅ 312 passed / ❌ 0 non-passing / Drill-down: run artifacts → Harness exit: 0; report validation exit: 0. All selected cases passed and report validation succeeded. |
|
Size Change: +5.32 kB (+0.02%) Total Size: 27.4 MB 📦 View Changed
ℹ️ View Unchanged
|
SDK performance: posthog-node1 change worth reviewing: 1 observed regression. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.
View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
posthog-js Compliance ReportDate: 2026-11-17 13:09:44 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
|
✅ Security review complete — 1 finding posted as a review, in 10 min. Add the |
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 53b354b: 1 Must fix, 1 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
turnipdabeets
left a comment
There was a problem hiding this comment.
Both fixes look right to me. The payload check is the follow-up from #5242, and the exception cleanup now runs after before_send, so the redaction leak is gone. Focused tests pass locally (161 node, 23 core) and CI is green. Two comments, neither blocking.
| 'posthog-node': patch | ||
| --- | ||
|
|
||
| Drop null custom object properties without bypassing before_send redaction or changing array serialization. Prevent caller properties from overriding reserved exception metadata. |
There was a problem hiding this comment.
[question] #5413 left the "caller can't override $exception_level" change for 6.0 (it's on capture-v1). This ships the same change in a 5.x patch. I checked against the built package: captureException(err, id, { $exception_level: 'warning' }) now sends error, and $exception_source is dropped. Do we want that in a patch? If so, can the changeset name $exception_level and say to set it in before_send instead? Keys set there still go through.
| const SHUTDOWN_TIMEOUT = 2000 | ||
|
|
||
| // Copy custom JSON containers only: null array entries and native values keep their meaning. | ||
| function withoutNullObjectProperties(value: any): any { |
There was a problem hiding this comment.
[suggestion] This null cleanup only runs for $exception. Plain capture({ properties: { test: null } }) still sends test: null, even though the capture spec puts this rule at serialization for every event. Since it now runs after the hooks, I think JSON.parse(safeJsonStringify(props)) plus a simple recursive delete would give the same wire output, because the send path already uses safeJsonStringify. That would replace the toJSON wrappers. I haven't run your edge-case tests against it. Doing it once in the shared send serializer would be even better as a follow-up, so we don't end up with two versions.
Problem
Legacy flag responses lose payloads such as
false,0,nulland""when converted to snapshot metadata. Node exception capture also retains null custom object properties and lets generic caller properties replace SDK-owned exception metadata.Changes
before_send, preserving redaction of serializer backing fields. Keep originaltoJSONreceivers/keys, native values, cycles, deep JSON and null array positions. Traverse only array elements, including non-enumerable numeric elements, without reading ignored named getters. Cleanup itself does not mutate caller data.false.sha256:f354f7405c25a03e8c83c7213124241ce43bbb3fe561cd434b68d0eefe49c54c.The behavior follows the published payload, exception capture and exception metadata contracts. No public API shape or browser code changes. Reserved generic exception-key overrides are an intentional behavior change; callers using those keys should review that change. Custom
$exception_fingerprintremains supported.Testing
Fresh validation on Node 24.21.0 / pnpm 11.7.0:
pnpm --filter posthog-node exec vitest run src/__tests__/extensions/error-tracking.spec.ts pnpm turbo run test:unit check-types --filter=posthog-node --filter=@posthog/corebefore_sendhooks complete.before_sendresult dropped the event. The fix uses the allocated array's fixed length and keeps cleaned properties separate from the hook-owned event. All 42 tests now pass.8312dd0f6b10ec59202c9ca06e8b0e01a0a10665passed isolated full-branch autoreview againstorigin/main(fce957b9a965103031cd90d7b2934cad43f010e2), with clean mandatory TruffleHog and no actionable findings. No MCP. The new commit preserves branch history.Released harness validation
Harness 1.32.0 was published successfully from
dde638562d33572b5c8ac3a2eafc98b92ffa2261, bundling sdk-specs53e9bc16d14f973809f80049864866d5b6d9bdff. The immutable V2 image digest issha256:f354f7405c25a03e8c83c7213124241ce43bbb3fe561cd434b68d0eefe49c54c. No browser harness migration is included.Final current-head validation: Node compliance run 44089398306 tests
8312dd0f6b10ec59202c9ca06e8b0e01a0a10665.Both downloaded artifacts match the exact source SHA and clean build, declare packaged harness 1.32.0 with the clean pinned specs, and preserve the selected case-ID sets. Every selected case executed and passed. Actual process/checker exits, not advisory workflow color, establish these results.
All latest hosted checks are green: 82 pass and one expected automatic-changeset skip. The first unit attempt hit the unchanged Convex/esbuild test's five-second limit; all 42 exception tests passed in that attempt. A fresh local SDK build and all six packaging tests passed. One failed-job retry passed without changing code, tests or timeouts. The slow attempt is retained in the logs and is not presented as a source fix. No repeated rerun loop was used.
Release info Sub-libraries affected
Libraries affected
Two existing patch changesets cover the package fixes. No browser release changeset is added.
Checklist
If releasing new changes
pnpm changesetto generate a changeset fileThe two patch changeset files were authored directly in the repository's format.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Pi agents used local shell, Git, gh and the isolated autoreview helper for the user-directed SDK fixes and publication. No MCP tools were used. Native privacy defaults and failed flag filtering were deliberately preserved instead of changing SDK behavior to satisfy stale fixtures. Human review is required before merging. Full monorepo/browser/playground/functional checks were not rebuilt locally for this pin-only follow-up; hosted results are tracked at the exact pushed SHA.
Related PRs
The specs correction and harness changes are published in 1.32.0. This PR pins the real published V2 image digest and validates it without changing native defaults or failed-result semantics.