fix: reduce mutation auto-flush threshold from 5 to 2

Lower the auto-flush threshold for workflow mutations from 5 to 2 to ensure
more timely data persistence. Since mutations are less frequent than regular
telemetry events, a lower threshold provides:

- Faster data persistence (don't wait for 5 mutations)
- Better testing experience (easier to verify with fewer operations)
- Reduced risk of data loss if process exits before threshold
- More responsive telemetry for low-volume mutation scenarios

This complements the existing 5-second periodic flush and process exit
handlers, ensuring mutations are persisted promptly.

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en
This commit is contained in:
czlonkowski
2025-11-12 17:24:30 +01:00
parent 0ae8734148
commit 00a2e77643
2 changed files with 3 additions and 2 deletions

Binary file not shown.

View File

@@ -166,9 +166,10 @@ export class TelemetryManager {
// Queue for batch processing
this.eventTracker.enqueueMutation(mutationRecord);
// Auto-flush if queue is large
// Auto-flush if queue reaches threshold
// Lower threshold (2) for mutations since they're less frequent than regular events
const queueSize = this.eventTracker.getMutationQueueSize();
if (queueSize >= 5) { // Flush after 5 mutations
if (queueSize >= 2) {
await this.flushMutations();
}
}