Repository navigation
fix(server): recover Antigravity sessions after a clean provider close #11719
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
Changes from all commits
f4a5813
477e2b8
339a7d7
356e3bc
ce4d438
a2eedf5
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 |
|---|---|---|
|
|
@@ -1270,17 +1270,44 @@ const makeProviderService = Effect.fn("makeProviderService")(function* ( | |
| const persistedModelSelection = readPersistedModelSelection(input.binding.runtimePayload); | ||
|
|
||
| yield* prepareMcpSession(input.binding.threadId, bindingInstanceId); | ||
|
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. 🟠 High A clean-close resume recovery starts the retry and fresh-session fallback without MCP configuration, so the recovered adapter runs with no 🤖 Copy this AI Prompt to have your agent fix this:
Author
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. Fixed in 339a7d7. The per-attempt
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. Sorry, I'm unable to act on this request because you do not have permissions within this repository.
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. Sorry, I'm unable to act on this request because you do not have permissions within this repository. |
||
| const resumed = yield* adapter | ||
| .startSession({ | ||
| threadId: input.binding.threadId, | ||
| provider: input.binding.provider, | ||
| providerInstanceId: bindingInstanceId, | ||
| ...(persistedCwd ? { cwd: persistedCwd } : {}), | ||
| ...(persistedModelSelection ? { modelSelection: persistedModelSelection } : {}), | ||
| ...(hasResumeCursor ? { resumeCursor: input.binding.resumeCursor } : {}), | ||
| runtimeMode: input.binding.runtimeMode ?? "full-access", | ||
| }) | ||
| .pipe(Effect.onError(() => clearMcpSession(input.binding.threadId))); | ||
| const startSessionAttempt = (cursor?: unknown) => | ||
| Effect.suspend(() => | ||
| adapter.startSession({ | ||
| threadId: input.binding.threadId, | ||
| provider: input.binding.provider, | ||
| providerInstanceId: bindingInstanceId, | ||
| ...(persistedCwd ? { cwd: persistedCwd } : {}), | ||
| ...(persistedModelSelection ? { modelSelection: persistedModelSelection } : {}), | ||
| ...(cursor ? { resumeCursor: cursor } : {}), | ||
| runtimeMode: input.binding.runtimeMode ?? "full-access", | ||
| }), | ||
| ); | ||
|
|
||
| // A clean provider close (websocket 1000, "Failed to rebuild agent") is | ||
| // classified to ProviderAdapterSessionClosedError at the adapter boundary | ||
| // (see mapAcpToAdapterError). Retry the resume once to ride out a transient | ||
| // rebuild and keep the resume cursor, then drop to a fresh session so a | ||
| // stale cursor never fails the turn outright. Clear the MCP session only | ||
| // when the whole recovery fails, so a successful retry or fallback keeps | ||
| // the endpoint and tools prepared above. | ||
| const resumeClosed = (error: ProviderAdapterError) => | ||
| error._tag === "ProviderAdapterSessionClosedError"; | ||
| const { session: resumed, strategy } = yield* startSessionAttempt( | ||
| input.binding.resumeCursor, | ||
| ).pipe( | ||
| Effect.retry({ times: 1, while: resumeClosed }), | ||
| Effect.map((session) => ({ session, strategy: "resume-thread" as const })), | ||
| Effect.catchTag("ProviderAdapterSessionClosedError", (error) => | ||
| Effect.logWarning( | ||
| `Provider session resume closed on agent rebuild for thread '${input.binding.threadId}'; falling back to fresh session.`, | ||
| { error }, | ||
| ).pipe( | ||
| Effect.andThen(startSessionAttempt(undefined)), | ||
| Effect.map((session) => ({ session, strategy: "fresh-session-fallback" as const })), | ||
| ), | ||
| ), | ||
| Effect.onError(() => clearMcpSession(input.binding.threadId)), | ||
| ); | ||
| if (resumed.provider !== adapter.provider) { | ||
| yield* clearMcpSession(input.binding.threadId); | ||
| return yield* toValidationError( | ||
|
|
@@ -1295,7 +1322,7 @@ const makeProviderService = Effect.fn("makeProviderService")(function* ( | |
| ); | ||
| yield* analytics.record("provider.session.recovered", { | ||
| provider: resumed.provider, | ||
| strategy: "resume-thread", | ||
| strategy, | ||
| hasResumeCursor: resumed.resumeCursor !== undefined, | ||
| }); | ||
| return { adapter, session: resumed } as const; | ||
|
|
||
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.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 7103
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 50372
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 36459
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 38582
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 7185
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 12994
Restore the mock and MCP session on every exit.
If
provider.sendTurnfails before lines 1825–1828,routing.codex.startSessionremains overridden.routingis module-scoped, and this suite has noafterEach; the test configuration does not enable mock restoration. The MCP session is also stored in a module-level map and can remain if the turn fails after recovery.Move the mock restoration and
McpProviderSession.clearMcpProviderSession(threadId)calls into anEffect.ensuringfinalizer registered beforeprovider.sendTurn. Keep the successful-path reads and assertions inside the protected effect. Assertions after the current cleanup do not cause this leak because the cleanup already ran.🤖 Prompt for AI Agents