-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Reconcile stopped provider session projections #3106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import * as Clock from "effect/Clock"; | ||
| import { CommandId } from "@t3tools/contracts"; | ||
| import * as Crypto from "effect/Crypto"; | ||
| import * as Duration from "effect/Duration"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Option from "effect/Option"; | ||
| import * as Schedule from "effect/Schedule"; | ||
|
|
||
| import { OrchestrationEngineService } from "../../orchestration/Services/OrchestrationEngine.ts"; | ||
| import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts"; | ||
| import { ProviderSessionDirectory } from "../Services/ProviderSessionDirectory.ts"; | ||
| import { | ||
|
|
@@ -25,7 +28,9 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) = | |
| Effect.gen(function* () { | ||
| const providerService = yield* ProviderService; | ||
| const directory = yield* ProviderSessionDirectory; | ||
| const orchestrationEngine = yield* OrchestrationEngineService; | ||
| const projectionSnapshotQuery = yield* ProjectionSnapshotQuery; | ||
| const crypto = yield* Crypto.Crypto; | ||
|
|
||
| const inactivityThresholdMs = Math.max( | ||
| 1, | ||
|
|
@@ -36,10 +41,43 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) = | |
| const sweep = Effect.gen(function* () { | ||
| const bindings = yield* directory.listBindings(); | ||
| const now = yield* Clock.currentTimeMillis; | ||
| const nowIso = new Date(now).toISOString(); | ||
| let reapedCount = 0; | ||
|
|
||
| for (const binding of bindings) { | ||
| const thread = yield* projectionSnapshotQuery | ||
| .getThreadShellById(binding.threadId) | ||
| .pipe(Effect.map(Option.getOrUndefined)); | ||
|
|
||
| if (binding.status === "stopped") { | ||
| if (thread?.session?.status === "running" || thread?.session?.status === "starting") { | ||
| const commandUuid = yield* crypto.randomUUIDv4; | ||
| yield* orchestrationEngine.dispatch({ | ||
| type: "thread.session.set", | ||
| commandId: CommandId.make( | ||
| `provider-session-reaper:stopped-reconcile:${binding.threadId}:${commandUuid}`, | ||
| ), | ||
| threadId: binding.threadId, | ||
| session: { | ||
| threadId: binding.threadId, | ||
| status: "stopped", | ||
| providerName: binding.provider, | ||
| ...(binding.providerInstanceId !== undefined | ||
| ? { providerInstanceId: binding.providerInstanceId } | ||
| : {}), | ||
| runtimeMode: thread.session.runtimeMode, | ||
| activeTurnId: null, | ||
| lastError: thread.session.lastError, | ||
| updatedAt: nowIso, | ||
| }, | ||
| createdAt: nowIso, | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconcile dispatch aborts sweepMedium Severity When a stopped binding triggers Reviewed by Cursor Bugbot for commit 4ba2676. Configure here. |
||
| yield* Effect.logInfo("provider.session.reaper.reconciled-stopped-projection", { | ||
| threadId: binding.threadId, | ||
| provider: binding.provider, | ||
| projectionStatus: thread.session.status, | ||
| }); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -58,9 +96,6 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) = | |
| continue; | ||
| } | ||
|
|
||
| const thread = yield* projectionSnapshotQuery | ||
| .getThreadShellById(binding.threadId) | ||
| .pipe(Effect.map(Option.getOrUndefined)); | ||
| if (thread?.session?.activeTurnId != null) { | ||
| yield* Effect.logDebug("provider.session.reaper.skipped-active-turn", { | ||
| threadId: binding.threadId, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shell query before inactivity gate
Medium Severity
Each sweep now calls
getThreadShellByIdat the start of every binding iteration, before the stopped branch and before the inactivity threshold check. Previously, non-stopped bindings below the threshold never hit projection, and stopped bindings skipped the query entirely.Reviewed by Cursor Bugbot for commit 4ba2676. Configure here.