Skip to content

Make queued event delivery reliable - #221

Open
ejsmith wants to merge 5 commits into
mainfrom
fix/queue-submission-reliability
Open

ejsmith wants to merge 5 commits into
mainfrom
fix/queue-submission-reliability

Conversation

@ejsmith

@ejsmith ejsmith commented Dec 2, 2026

Copy link
Copy Markdown
Member

Fixes queue and submission bugs that lost, duplicated, or stalled events.

Problem Fix
Events enqueued before the first process() were loaded again from storage and sent twice (React Native always persists) Persisted events load once, skip files already queued, and go first in timestamp order
One unreadable persisted entry stopped every later entry from loading, every session Each entry is read on its own; unreadable ones are removed
Persisted events ignored maxItems Applied after loading
Browser tabs sharing localStorage sent each other's queued events Before sending, skip persisted events another tab already removed; random key suffix so tabs can't overwrite entries created in the same millisecond
Default backoff rounded to the next quarter hour, which is 0 at :00/:15/:30/:45, so a 402 discarded nothing 5-minute default, matching the .NET client
process() called directly (tab hide, startup, processQueue()) ignored backoff Checks the suspension window
Only 202 counted as success, so 200/201 from a proxy retried forever Any 2xx
Only one batch of 50 was sent per run, including on page hide Sends batches until empty or a failure
A 413 permanently shrank config.submissionBatchSize Smaller retry batch is local to the run
No request timeout: one hung fetch blocked the queue for good 30-second abort
Submissions on page hide/unload were cancelled keepalive for bodies inside the browser's 64 KiB budget
A non-JSON error body (HTML 502, captive portal) threw Status is returned and the body ignored
Settings were fetched from serverUrl, so configServerUrl did nothing Uses configServerUrl (as the .NET client does; serverUrl still sets it)
Heartbeat session id was not URL-encoded Encoded

No public API changes. Behavior changes are the bug fixes above. Users who set only configServerUrl will now get settings from it.

Checks: new tests for each row (17 queue tests fail on main, pass here) plus a new DefaultSubmissionClient suite. npm test (370), npm run lint, core build, and type-checks for browser, node and react-native pass. Two existing tests that expected settings from serverUrl were updated.

- Send every queued batch in one process call; treat any 2xx as sent.
- Load persisted events once, oldest first, without duplicating events
  already queued; drop unreadable entries and apply maxItems.
- Skip persisted events another tab already sent and removed, and give
  queue keys a random suffix so tabs can't overwrite each other.
- Back off 5 minutes by default (matches the .NET client). The old
  quarter-hour math produced no delay at :00/:15/:30/:45, which also
  made a 402 discard nothing.
- Respect the suspension window in process(), not only on the timer.
- Retry 413 batches smaller without permanently shrinking
  submissionBatchSize.
- Abort requests after 30 seconds so a hung connection can't stall the
  queue, use keepalive for small submissions so they survive page
  unload, and tolerate non-JSON response bodies.
- Fetch settings from configServerUrl and URL-encode heartbeat ids.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 01:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T12:46:37.406420Z 53121cc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d955dc961

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical queue-handling defects can permanently lose events by marking writes persisted before they succeed and deleting potentially valid entries after transient storage read failures.

2 open issues
What changed in this PR

Improves queued-event delivery in the shared core used by Exceptionless SDKs.

Changes:

  • Updates persisted-event loading, batch draining, retries, and backoff.
  • Adds request timeouts, browser keepalive handling, and endpoint corrections.
  • Adds regression tests and documents delivery behavior.
File Description
packages/​core/​test/​submission/​TestSubmissionClient.test.ts Updates settings-endpoint expectations.
packages/​core/​test/​submission/​DefaultSubmissionClient.test.ts Tests request routing, timeouts, response parsing, and keepalive.
packages/​core/​test/​queue/​DefaultEventQueue.test.ts Adds persistence, batching, and retry regression coverage.
packages/​core/​src/​submission/​DefaultSubmissionClient.ts Updates request reliability, settings routing, and heartbeat encoding.
packages/​core/​src/​queue/​DefaultEventQueue.ts Revises persisted loading, batch processing, and suspension behavior.
.agents/​skills/​exceptionless-javascript/​references/​troubleshooting.md Documents flushing, retry pauses, and unload delivery.

Review effort: Balanced

- Mark an entry persisted only after its write succeeds, and wait for a
  pending write before sending, so a failed or in-flight write isn't
  mistaken for an event another tab already sent.
- Keep entries that couldn't be read for a later session; only remove
  entries whose JSON is malformed.
- Stop sending further batches once the client is disabled.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 405003a683

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- localStorage throws synchronously when its quota is full, which
  rejected enqueue() before the event was queued. Synchronous throws
  are now handled like rejections and the event is sent from memory.
- process() returns the run that is already sending instead of
  resolving immediately, so callers like suspend() and flush() wait for
  in-flight submissions.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d265071fcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The handler runs inside the processing run, so waiting for that run
from the handler never finished.
@ejsmith
ejsmith marked this pull request as draft December 2, 2026 03:20
});

test("waits for a pending write before sending the event", async () => {
const storage = new InMemoryStorage();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we need to update agent rules but nice to have // Arrange, Act, Assert comments here too across the codebase.

vi.spyOn(storage, "setItem").mockImplementationOnce(
(key, value) =>
new Promise((resolve) => {
finishWrite = () => void setItem(key, value).then(resolve);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really hate seeing void and .then callback stuff for modern js

@niemyjski niemyjski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[AGENT] I reproduced two queue concurrency cases on this head with synthetic events.

@niemyjski
niemyjski marked this pull request as ready for review December 3, 2026 12:44
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.

3 participants