Replace provider session reaper polling with deadline-driven scheduling #2351
Closedcrafael23(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/2351/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/server/src/provider/Layers/ProviderSessionReaper.ts line 673Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -97,0 +579,21 @@579+ providers: providerBreakdown(dueEntries),580+ });581+ }582+583+ if (dueEntries.length > 0) {584+ const stopResult = yield* stopDueEntries({585+ entries: dueEntries,586+ nowMs: now,587+ });588+ yield* Effect.annotateCurrentSpan({589+ "provider.session_reaper.reaped_count": stopResult.reapedCount,590+ "provider.session_reaper.stop_failed_count": stopResult.stopFailedCount,591+ });592+ if (stopResult.reapedCount > 0 && futureEntries.length > 0) {593+ yield* signalWake({ type: "reconcile-all", reason: "post-stop" });594+ }595+ return {596+ nextDeadlineAtMs: undefined,597+ observedStartupWake: false,598+ };599+ }
crafael23(GitHub profile, opens in a new tab) closed this
crafael23(GitHub profile, opens in a new tab) reopened this
- apps/server/src/provider/Layers/ProviderSessionReaper.ts line 455OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -97 +435,21 @@97435 });436+437+ return {438+ reapedCount,439+ stopFailedCount,440+ } as const;441+ }).pipe(442+ Effect.withSpan("provider.session.reaper.stop_due", {443+ kind: "internal",444+ attributes: {445+ "provider.session_reaper.mode": mode,446+ },447+ }),448+ );449+450+ const runDeadlineScheduler = Effect.gen(function* () {451+ const wake = yield* makeCoalescedWake();452+453+ const signalWake = (signal: ReaperSignal) => wake.signal(signal);454+455+ const forkFeed = (name: string, effect: Effect.Effect<void>) =>
- apps/server/src/provider/Layers/ProviderSessionDirectoryEvents.ts line 30OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +10,21 @@10+ const pubSub = yield* Effect.acquireRelease(11+ PubSub.unbounded<{ readonly threadId: ThreadId }>(),12+ PubSub.shutdown,13+ );14+15+ return {16+ publishChanged: (threadId) => PubSub.publish(pubSub, { threadId }).pipe(Effect.asVoid),17+ get changes(): ProviderSessionDirectoryEventsShape["changes"] {18+ return Stream.fromPubSub(pubSub);19+ },20+ } satisfies ProviderSessionDirectoryEventsShape;21+});22+23+export const ProviderSessionDirectoryEventsLive = Layer.effect(24+ ProviderSessionDirectoryEvents,25+ makeProviderSessionDirectoryEvents,26+);27+28+export function makeProviderSessionDirectoryEventsLive() {29+ return Layer.effect(ProviderSessionDirectoryEvents, makeProviderSessionDirectoryEvents);30+}apps/server/src/provider/Layers/ProviderSessionDirectory.ts line 143Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -128,3 +130,11 @@128130 ),129131 })130132 .pipe(Effect.mapError(toPersistenceError("ProviderSessionDirectory.upsert:upsert")));133+ yield* directoryEvents.publishChanged(resolvedThreadId).pipe(134+ Effect.catchCause((cause) =>135+ Effect.logDebug("provider.session.directory.change-signal-failed", {136+ threadId: resolvedThreadId,137+ cause,138+ }),139+ ),140+ );
- apps/server/src/provider/Layers/ProviderSessionReaper.ts line 739Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -119,5 +722,18 @@119- yield* Effect.logInfo("provider.session.reaper.started", {722+ yield* Effect.logInfo("provider.session.reaper.scheduler-started", {723+ mode,120724 inactivityThresholdMs,121- sweepIntervalMs,725+ fallbackReconcileIntervalMs,726+ stopFailureRetryIntervalMs,122727 });123- });728+ }).pipe(729+ Effect.withSpan("provider.session.reaper.start", {730+ kind: "internal",731+ root: true,732+ attributes: {733+ "provider.session_reaper.mode": mode,734+ "provider.session_reaper.inactivity_threshold_ms": inactivityThresholdMs,735+ "provider.session_reaper.fallback_reconcile_interval_ms": fallbackReconcileIntervalMs,736+ "provider.session_reaper.stop_failure_retry_interval_ms": stopFailureRetryIntervalMs,737+ },738+ }),739+ );apps/server/src/provider/Layers/reaperDeadlines.ts line 113Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +93,21 @@93+ at: latestTurn.completedAt,94+ source: "latest_turn_completed_at",95+ };96+ }97+ if (latestTurn?.startedAt !== null && latestTurn?.startedAt !== undefined) {98+ return {99+ at: latestTurn.startedAt,100+ source: "latest_turn_started_at",101+ };102+ }103+ if (latestTurn !== null && latestTurn !== undefined) {104+ return {105+ at: latestTurn.requestedAt,106+ source: "latest_turn_requested_at",107+ };108+ }109+ return {110+ at: input.lastSeenAt,111+ source: "session_last_seen_at",112+ };113+}
crafael23(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
f6b35326-be8e-47a4-b764-ff0841500d44You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share