-
Notifications
You must be signed in to change notification settings - Fork 61
fix(codex): refresh provider on thread resume #302
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 3 commits
d5cee00
00de2f8
d0b05e9
1e7ea72
db97d6c
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 |
|---|---|---|
|
|
@@ -563,6 +563,9 @@ async def _start_or_resume_thread( | |
| "threadId": persisted, | ||
| "developerInstructions": self._build_thread_developer_instructions(request), | ||
| } | ||
| model_provider = await self._resolve_resume_model_provider_override(transport, request, persisted) | ||
| if model_provider: | ||
| resume_params["modelProvider"] = model_provider | ||
| resp = await transport.send_request( | ||
| "thread/resume", | ||
| resume_params, | ||
|
|
@@ -585,6 +588,72 @@ async def _start_or_resume_thread( | |
|
|
||
| return await self._start_thread(transport, request) | ||
|
|
||
| async def _resolve_resume_model_provider_override( | ||
| self, | ||
| transport: CodexTransport, | ||
| request: AgentRequest, | ||
| thread_id: str, | ||
| ) -> Optional[str]: | ||
| """Return a provider override only when a persisted thread is stale. | ||
|
|
||
| Codex preserves a thread's latest model / reasoning effort on resume | ||
| unless the client sends a model/provider override. Vibe Remote only | ||
| needs to override the provider after the user changes Codex auth mode | ||
| or project provider settings, so inspect the stored thread first and | ||
| leave normal resumes on Codex's persisted fallback path. | ||
| """ | ||
| current_provider = await self._read_effective_model_provider(transport, request) | ||
| if not current_provider: | ||
| return None | ||
|
|
||
| try: | ||
| resp = await transport.send_request( | ||
| "thread/read", | ||
| { | ||
| "threadId": thread_id, | ||
| "includeTurns": False, | ||
| }, | ||
| ) | ||
| except Exception as exc: | ||
| logger.warning("Failed to read Codex thread %s provider before resume: %s", thread_id, exc) | ||
| return None | ||
|
|
||
| thread_obj = resp.get("thread") if isinstance(resp, dict) else None | ||
| if not isinstance(thread_obj, dict) and isinstance(resp, dict) and resp.get("id") == thread_id: | ||
| thread_obj = resp | ||
| stored_provider = thread_obj.get("modelProvider") if isinstance(thread_obj, dict) else None | ||
| if not isinstance(stored_provider, str) or not stored_provider.strip(): | ||
| return None | ||
|
|
||
| if stored_provider.strip() == current_provider: | ||
| return None | ||
| return current_provider | ||
|
|
||
| async def _read_effective_model_provider( | ||
| self, | ||
| transport: CodexTransport, | ||
| request: AgentRequest, | ||
| ) -> Optional[str]: | ||
| """Ask Codex app-server for the provider it resolves for this request.""" | ||
| params: Dict[str, Any] = {"includeLayers": False} | ||
| working_path = getattr(request, "working_path", None) | ||
| if working_path: | ||
| params["cwd"] = working_path | ||
|
|
||
| try: | ||
| resp = await transport.send_request("config/read", params) | ||
| except Exception as exc: | ||
| logger.warning("Failed to read effective Codex model provider before resume: %s", exc) | ||
| return None | ||
|
|
||
| config_obj = resp.get("config") if isinstance(resp, dict) else None | ||
| if not isinstance(config_obj, dict): | ||
| return None | ||
| model_provider = config_obj.get("modelProvider") | ||
| if isinstance(model_provider, str) and model_provider.strip(): | ||
|
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.
Useful? React with 👍 / 👎.
Owner
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. Addressed in 1e7ea72. |
||
| return model_provider.strip() | ||
| return None | ||
|
|
||
| def _build_thread_developer_instructions(self, request: AgentRequest) -> Optional[str]: | ||
| """Build Codex thread-level developer instructions for start/resume. | ||
|
|
||
|
|
||
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.
Only overriding
modelProviderbased on current config when it differs from the stored thread provider can break valid cross-provider resumes: this path now forcesthread/resumeonto the current provider for any mismatch, even when the persisted thread was created under a different provider and must continue there. In those cases, resume can fail or misroute history because the provider affinity encoded in the stored thread is discarded at resume time.Useful? React with 👍 / 👎.
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.
Addressed in db97d6c. The provider override is now limited to transitions between Vibe Remote-managed Codex provider IDs (
openaiandopenai-managed). Other mismatches are treated as intentional cross-provider sessions and resume withoutmodelProvider, preserving Codex persisted provider affinity. Added a regression test for an unmanagedanthropicthread while the current config points atopenai-managed.