Skip to content

🐛 recover orphaned .tmp batch files on init#104

Merged
bcaudan merged 2 commits into
mainfrom
bcaudan/issue-103_oprphaned_batch_files
May 4, 2026
Merged

🐛 recover orphaned .tmp batch files on init#104
bcaudan merged 2 commits into
mainfrom
bcaudan/issue-103_oprphaned_batch_files

Conversation

@bcaudan

@bcaudan bcaudan commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Cf #103. When the app crashes or exits abruptly, events buffered in .tmp batch files are never uploaded on the next launch. They accumulate on disk across sessions, leading to silent data loss and unbounded disk usage.

Diagnostic: BatchProducer.create() called flush() on init, but flush() only rotates the current in-memory batch reference, which is null on a fresh instance. Orphaned .tmp files from prior sessions were invisible to BatchConsumer (which only picks up .log files).

Changes

  • Add rotateOrphanedBatches() to BatchProducer: scans the track directory on init and renames leftover .tmp files to .log
  • Extract shared renameBatchFile() method, reused by both rotateBatch() and rotateOrphanedBatches()
  • Replace the no-op flush() call in create() with rotateOrphanedBatches()
  • Isolate e2e and integration tests with a per-test temp userData directory via --user-data-dir, preventing cross-test data pollution from recovered orphaned files

Test instructions

  • Unit tests cover: orphaned rotation, .tmp-only filtering, graceful handling of readdir/rename failures
  • Manual: create .tmp files in <userData>/rum/, restart the SDK, verify they are renamed to .log and uploaded

Checklist

  • Tested locally (playground)
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated related documentation.

@bcaudan

bcaudan commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 83e9f36cd2

ℹ️ 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".

Comment thread src/transport/batch/BatchProducer.ts
@bcaudan bcaudan force-pushed the bcaudan/issue-103_oprphaned_batch_files branch from 83e9f36 to 8a3624c Compare April 24, 2026 12:49
- Extract renameBatchFile() and reuse in rotateBatch() and new rotateOrphanedBatches()
- Scan track directory for leftover .tmp files on create and rotate them to .log
- Replace no-op flush() call with rotateOrphanedBatches() in create()
@bcaudan bcaudan force-pushed the bcaudan/issue-103_oprphaned_batch_files branch 2 times, most recently from 96eaa08 to add467c Compare April 24, 2026 13:24
@bcaudan bcaudan force-pushed the bcaudan/issue-103_oprphaned_batch_files branch from add467c to c76a63f Compare April 24, 2026 13:35
@bcaudan

bcaudan commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: c76a63f482

ℹ️ 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".

Comment thread src/transport/batch/BatchProducer.ts
@bcaudan bcaudan marked this pull request as ready for review April 24, 2026 13:44
@bcaudan bcaudan requested a review from a team as a code owner April 24, 2026 13:44
@bcaudan bcaudan merged commit 12ff26a into main May 4, 2026
15 checks passed
@bcaudan bcaudan deleted the bcaudan/issue-103_oprphaned_batch_files branch May 4, 2026 08: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.

2 participants