improve watch history reliability

- Reduced view threshold from 12s to 5s in watchHistoryTelemetry.js
- Enabled immediate watch history republishing (0ms delay) for the first attempt in watchHistory.js
- Updated watchHistoryService.js to recursively schedule queue flushes if items accumulate during an inflight sync
This commit is contained in:
google-labs-jules[bot] committed 2026-01-21 22:07:23 +00:00
1 parent 6b1ce04af6
commit a484fb8f36
3 files changed
+24 -9

No files matched your search

+19 -7
View File
@@ -1101,13 +1101,25 @@ class WatchHistoryManager {
if (attempt > WATCH_HISTORY_REPUBLISH_MAX_ATTEMPTS) {
return;
}
const exponentialDelay = WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS * Math.pow(2, attempt);
const cappedDelay = Math.min(exponentialDelay, WATCH_HISTORY_REPUBLISH_MAX_DELAY_MS);
const jitter = Math.random() * cappedDelay * WATCH_HISTORY_REPUBLISH_JITTER;
const delay = Math.max(
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS,
Math.floor(cappedDelay + jitter),
);
let delay = 0;
if (attempt === 0) {
delay = 10;
} else {
const exponentialDelay =
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS * Math.pow(2, attempt);
const cappedDelay = Math.min(
exponentialDelay,
WATCH_HISTORY_REPUBLISH_MAX_DELAY_MS,
);
const jitter =
Math.random() * cappedDelay * WATCH_HISTORY_REPUBLISH_JITTER;
delay = Math.max(
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS,
Math.floor(cappedDelay + jitter),
);
}
if (onSchedule) {
try {
onSchedule({ taskId: key, attempt: attempt + 1, delay });
+1 -1
View File
@@ -5,7 +5,7 @@ import {
ingestLocalViewEvent as defaultIngestLocalViewEvent,
} from "../viewCounter.js";
const DEFAULT_VIEW_THRESHOLD_SECONDS = 12;
const DEFAULT_VIEW_THRESHOLD_SECONDS = 5;
function normalizeString(value) {
return typeof value === "string" ? value.trim() : "";
+4 -1
View File
@@ -615,12 +615,15 @@ function scheduleRepublishForQueue(actorKey) {
actorKey,
queue,
keysToClear,
snapshotStartTime
snapshotStartTime,
);
await updateFingerprintCache(
actorKey,
publishResult.items || latestItems,
);
if (queue.items.size > 0) {
scheduleRepublishForQueue(actorKey);
}
} else if (!publishResult?.retryable) {
// If not retryable, we clear the scheduled flag to allow new attempts later
queue.republishScheduled = false;