mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Signal workspace routing readiness in account updates (#62145)
## Why App-server clients receive `account/updated` both when routing is ready for a saved ChatGPT workspace and when a user logs in, logs out, or switches workspaces. The notification payload gives clients no explicit way to identify the initial routing update. ## What changed Add a nullable `reason` to `account/updated`. Set it to `workspaceRoutingReady` on the initial saved-workspace routing notification when the authenticated owner is unchanged, including when routing is ready before the connection initializes. Login, logout, and workspace-switch updates send `null`. Update the protocol schemas, TypeScript types, and Python SDK models. ## Testing Extend the app-server integration tests to check the reason in the JSON payloads for saved-workspace discovery, login, workspace switching, and logout. GitOrigin-RevId: 96758519985a6bdb07474e48307ed53b125823ee
This commit is contained in:
committed by
copyberry
parent
06789c7618
commit
67d8266e06
@@ -1834,6 +1834,7 @@ mod tests {
|
||||
serde_json::from_value(
|
||||
serde_json::to_value(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -1082,6 +1082,7 @@ mod tests {
|
||||
&event_tx,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
codex_app_server_protocol::AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -50,6 +50,13 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"AccountUpdateReason": {
|
||||
"enum": [
|
||||
"workspaceRoutingReady",
|
||||
"unknown"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AccountUpdatedNotification": {
|
||||
"properties": {
|
||||
"authMode": {
|
||||
@@ -71,6 +78,17 @@
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"reason": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AccountUpdateReason"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Set when initial routing discovery completes for the same authenticated owner."
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
||||
+18
@@ -7285,6 +7285,13 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"AccountUpdateReason": {
|
||||
"enum": [
|
||||
"workspaceRoutingReady",
|
||||
"unknown"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AccountUpdatedNotification": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -7307,6 +7314,17 @@
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"reason": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/v2/AccountUpdateReason"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Set when initial routing discovery completes for the same authenticated owner."
|
||||
}
|
||||
},
|
||||
"title": "AccountUpdatedNotification",
|
||||
|
||||
+18
@@ -349,6 +349,13 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"AccountUpdateReason": {
|
||||
"enum": [
|
||||
"workspaceRoutingReady",
|
||||
"unknown"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AccountUpdatedNotification": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -371,6 +378,17 @@
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"reason": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AccountUpdateReason"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Set when initial routing discovery completes for the same authenticated owner."
|
||||
}
|
||||
},
|
||||
"title": "AccountUpdatedNotification",
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"AccountUpdateReason": {
|
||||
"enum": [
|
||||
"workspaceRoutingReady",
|
||||
"unknown"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AuthMode": {
|
||||
"description": "Authentication mode for OpenAI-backed providers.",
|
||||
"oneOf": [
|
||||
@@ -108,6 +115,17 @@
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"reason": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AccountUpdateReason"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Set when initial routing discovery completes for the same authenticated owner."
|
||||
}
|
||||
},
|
||||
"title": "AccountUpdatedNotification",
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type AccountUpdateReason = "workspaceRoutingReady" | "unknown";
|
||||
+6
-1
@@ -3,5 +3,10 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { AuthMode } from "../AuthMode";
|
||||
import type { PlanType } from "../PlanType";
|
||||
import type { AccountUpdateReason } from "./AccountUpdateReason";
|
||||
|
||||
export type AccountUpdatedNotification = { authMode: AuthMode | null, planType: PlanType | null, };
|
||||
export type AccountUpdatedNotification = { authMode: AuthMode | null, planType: PlanType | null,
|
||||
/**
|
||||
* Set when initial routing discovery completes for the same authenticated owner.
|
||||
*/
|
||||
reason: AccountUpdateReason | null, };
|
||||
|
||||
@@ -11,6 +11,7 @@ export type { AccountSessionWorkspace } from "./AccountSessionWorkspace";
|
||||
export type { AccountSessionWorkspaceKind } from "./AccountSessionWorkspaceKind";
|
||||
export type { AccountTokenUsageDailyBucket } from "./AccountTokenUsageDailyBucket";
|
||||
export type { AccountTokenUsageSummary } from "./AccountTokenUsageSummary";
|
||||
export type { AccountUpdateReason } from "./AccountUpdateReason";
|
||||
export type { AccountUpdatedNotification } from "./AccountUpdatedNotification";
|
||||
export type { ActivePermissionProfile } from "./ActivePermissionProfile";
|
||||
export type { AddCreditsNudgeCreditType } from "./AddCreditsNudgeCreditType";
|
||||
|
||||
@@ -621,6 +621,17 @@ pub enum AccountRoutingOverride {
|
||||
pub struct AccountUpdatedNotification {
|
||||
pub auth_mode: Option<AuthMode>,
|
||||
pub plan_type: Option<PlanType>,
|
||||
/// Set when initial routing discovery completes for the same authenticated owner.
|
||||
pub reason: Option<AccountUpdateReason>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/", rename_all = "camelCase")]
|
||||
pub enum AccountUpdateReason {
|
||||
WorkspaceRoutingReady,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
|
||||
@@ -629,7 +629,7 @@ PAT sessions continue to return no bearer token from `getAuthStatus`.
|
||||
|
||||
The experimental `account/read.workspaceRouting` response field returns the selected ChatGPT workspace's `chatgptAccountId`, resolved HTTPS `backendOrigin`, and backend-provided `accountRoutingOverride`. The routing value is `us`, `us_cr`, or the explicit `NO_CONSTRAINT` value. API-only and signed-out accounts return `null` and do not need `accounts/check`.
|
||||
|
||||
App-server discovers routing for saved ChatGPT logins at startup and for new logins or workspace switches. After requirements and routing are ready, it sends the existing `account/updated` notification. Newly initialized connections also receive this notification once saved-workspace routing is ready, including when discovery finished before the connection initialized. Clients then reread `configRequirements/read` and `account/read`. Saved ChatGPT credentials without a selected workspace ID retain their account information and return `workspaceRouting: null`; app-server does not guess a workspace from the backend's default account. Discovery failures for a selected workspace, including missing or null fields from older backends, return an `account/read` error. They never produce a successful unrestricted result. A later read retries failed discovery. Logout clears the cached routing, and results from earlier authentication owners are discarded. Token refreshes for the same known user and workspace invalidate cached routing without cancelling discovery or failing sign-in. Configuration is reloaded after discovery; a changed backend, model provider, or required backend rejects the result so the next read discovers against current configuration. Account notifications recheck the auth owner generation after waiting for outbound queue capacity. Superseded sign-in attempts emit a failed `account/login/completed` event instead of silently dropping completion. Notifications remain snapshots: clients reread current account and requirements state rather than treating a queued notification as authorization.
|
||||
App-server discovers routing for saved ChatGPT logins at startup and for new logins or workspace switches. After requirements and routing are ready, it sends the existing `account/updated` notification. Newly initialized connections also receive this notification once saved-workspace routing is ready, including when discovery finished before the connection initialized. This initial notification carries `reason: "workspaceRoutingReady"` when the authenticated owner generation is unchanged. Login, logout, and workspace-switch notifications include `reason: null`. Clients then reread `configRequirements/read` and `account/read`. Saved ChatGPT credentials without a selected workspace ID retain their account information and return `workspaceRouting: null`; app-server does not guess a workspace from the backend's default account. Discovery failures for a selected workspace, including missing or null fields from older backends, return an `account/read` error. They never produce a successful unrestricted result. A later read retries failed discovery. Logout clears the cached routing, and results from earlier authentication owners are discarded. Token refreshes for the same known user and workspace invalidate cached routing without cancelling discovery or failing sign-in. Configuration is reloaded after discovery; a changed backend, model provider, or required backend rejects the result so the next read discovers against current configuration. Account notifications recheck the auth owner generation after waiting for outbound queue capacity. Superseded sign-in attempts emit a failed `account/login/completed` event instead of silently dropping completion. Notifications remain snapshots: clients reread current account and requirements state rather than treating a queued notification as authorization.
|
||||
|
||||
Routing compares origins by scheme, host, and effective port, ignoring API paths. A required
|
||||
`chatgpt_base_url` must match discovery; if neither provides an origin, `NO_CONSTRAINT` uses the
|
||||
|
||||
@@ -17,6 +17,7 @@ async fn queued_notifications_follow_auth_owner_changes(owner_generation: u64) {
|
||||
);
|
||||
let (changes, auth_changes) = watch::channel(AuthChangeState::default());
|
||||
let updated = AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
};
|
||||
|
||||
@@ -1250,6 +1250,7 @@ mod tests {
|
||||
#[test]
|
||||
fn verify_account_updated_notification_serialization() {
|
||||
let notification = ServerNotification::AccountUpdated(AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
plan_type: Some(PlanType::SelfServeBusinessProLite),
|
||||
});
|
||||
@@ -1259,7 +1260,8 @@ mod tests {
|
||||
"method": "account/updated",
|
||||
"params": {
|
||||
"authMode": "chatgpt",
|
||||
"planType": "self_serve_business_prolite"
|
||||
"planType": "self_serve_business_prolite",
|
||||
"reason": null
|
||||
},
|
||||
}),
|
||||
serde_json::to_value(notification)
|
||||
|
||||
@@ -258,6 +258,7 @@ impl AccountRequestProcessor {
|
||||
fn current_account_updated_notification(&self) -> AccountUpdatedNotification {
|
||||
let auth = self.auth_manager.auth_cached();
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: auth
|
||||
.as_ref()
|
||||
.map(CodexAuth::api_auth_mode)
|
||||
@@ -1084,6 +1085,7 @@ impl AccountRequestProcessor {
|
||||
.ok()
|
||||
.cloned()
|
||||
.map(|auth_mode| AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode,
|
||||
plan_type: None,
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
use super::*;
|
||||
use codex_app_server_protocol::AccountRoutingOverride;
|
||||
use codex_app_server_protocol::AccountUpdateReason;
|
||||
use codex_backend_client::AccountEntry;
|
||||
use codex_config::ConfigLoadError;
|
||||
use codex_http_client::NetworkPolicyDenied;
|
||||
@@ -244,7 +245,8 @@ impl AccountRequestProcessor {
|
||||
&& response.workspace_routing.is_some()
|
||||
&& auth_changes.borrow().owner_generation == owner_generation
|
||||
{
|
||||
let notification = processor.current_account_updated_notification();
|
||||
let mut notification = processor.current_account_updated_notification();
|
||||
notification.reason = Some(AccountUpdateReason::WorkspaceRoutingReady);
|
||||
processor
|
||||
.outgoing
|
||||
.send_account_notification(
|
||||
|
||||
@@ -234,6 +234,7 @@ async fn assert_account_updated(
|
||||
assert_eq!(
|
||||
payload,
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode,
|
||||
plan_type: None,
|
||||
}
|
||||
@@ -2620,6 +2621,7 @@ async fn login_survives_same_owner_token_refresh(
|
||||
assert_eq!(
|
||||
updated,
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
plan_type: Some(AccountPlanType::Enterprise),
|
||||
}
|
||||
|
||||
@@ -150,6 +150,7 @@ client_id = "enterprise-client""#
|
||||
assert_eq!(
|
||||
account,
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
}
|
||||
|
||||
@@ -383,6 +383,7 @@ async fn workspace_switch_validates_and_preserves_managed_login(
|
||||
notification.params.expect("account/updated params")
|
||||
)?,
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
plan_type: Some(AccountPlanType::Business),
|
||||
}
|
||||
|
||||
@@ -155,7 +155,9 @@ async fn saved_workspace_is_discovered_once_and_not_the_default_account(
|
||||
.await??;
|
||||
assert_eq!(
|
||||
notification.params,
|
||||
Some(json!({"authMode": "chatgpt", "planType": plan_type}))
|
||||
Some(
|
||||
json!({"authMode": "chatgpt", "planType": plan_type, "reason": "workspaceRoutingReady"})
|
||||
)
|
||||
);
|
||||
let expected = json!({
|
||||
"account": {"type": "chatgpt", "email": "user@example.com", "planType": plan_type, "workspaceName": "Selected workspace"},
|
||||
@@ -345,7 +347,9 @@ async fn login_and_workspace_switch_notify_after_routing_is_ready_then_logout_cl
|
||||
.await??;
|
||||
assert_eq!(
|
||||
notification.params,
|
||||
Some(json!({"authMode": "chatgptAuthTokens", "planType": "enterprise"}))
|
||||
Some(
|
||||
json!({"authMode": "chatgptAuthTokens", "planType": "enterprise", "reason": null})
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
read(&mut server).await?["workspaceRouting"],
|
||||
@@ -362,6 +366,15 @@ async fn login_and_workspace_switch_notify_after_routing_is_ready_then_logout_cl
|
||||
}
|
||||
let request = server.send_logout_account_request().await?;
|
||||
let _: LogoutAccountResponse = timeout(READ_TIMEOUT, server.read_response(request)).await??;
|
||||
let notification = timeout(
|
||||
READ_TIMEOUT,
|
||||
server.read_stream_until_notification_message("account/updated"),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
notification.params,
|
||||
Some(json!({"authMode": null, "planType": null, "reason": null}))
|
||||
);
|
||||
assert_eq!(
|
||||
read(&mut server).await?,
|
||||
json!({"account": null, "userId": null, "requiresOpenaiAuth": true, "workspaceRouting": null})
|
||||
|
||||
@@ -219,6 +219,7 @@ async fn selected_usage_is_cached_and_account_changes_discard_old_results() -> R
|
||||
AppServerEvent::Lagged { skipped: 1 },
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -435,6 +435,7 @@ async fn backend_banner_account_changes_invalidate_pending_recovery() -> Result<
|
||||
codex_app_server_client::AppServerEvent::ServerNotification(Box::new(
|
||||
ServerNotification::AccountUpdated(
|
||||
codex_app_server_protocol::AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -172,6 +172,7 @@ async fn foreign_backend_events_leave_thread_cache_and_connection_untouched() ->
|
||||
},
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: None,
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -74,6 +74,7 @@ async fn new_session_refreshes_account_for_the_started_provider() -> Result<()>
|
||||
codex_app_server_client::AppServerEvent::ServerNotification(Box::new(
|
||||
ServerNotification::AccountUpdated(
|
||||
codex_app_server_protocol::AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(codex_app_server_protocol::AuthMode::Chatgpt),
|
||||
plan_type: Some(codex_protocol::account::PlanType::Pro),
|
||||
},
|
||||
|
||||
@@ -113,6 +113,7 @@ async fn security_setup_fetch_with_default_features_uses_authenticated_codex_end
|
||||
&server,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
plan_type: None,
|
||||
},
|
||||
|
||||
@@ -95,6 +95,7 @@ async fn account_updated_with_backend_only_auth_enables_thread_usage() -> Result
|
||||
&app_server,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::AgentIdentity),
|
||||
plan_type: Some(PlanType::Business),
|
||||
},
|
||||
@@ -254,6 +255,7 @@ async fn account_change_discards_thread_usage_deferred_while_overlay_is_open() -
|
||||
&app_server,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
reason: None,
|
||||
auth_mode: Some(AuthMode::AgentIdentity),
|
||||
plan_type: Some(PlanType::Business),
|
||||
},
|
||||
|
||||
@@ -95,6 +95,11 @@ class AccountTokenUsageSummary(BaseModel):
|
||||
peak_daily_tokens: Annotated[int | None, Field(alias="peakDailyTokens")] = None
|
||||
|
||||
|
||||
class AccountUpdateReason(Enum):
|
||||
workspace_routing_ready = "workspaceRoutingReady"
|
||||
unknown = "unknown"
|
||||
|
||||
|
||||
class ActivePermissionProfile(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
@@ -7479,6 +7484,12 @@ class AccountUpdatedNotification(BaseModel):
|
||||
)
|
||||
auth_mode: Annotated[AuthMode | None, Field(alias="authMode")] = None
|
||||
plan_type: Annotated[PlanType | None, Field(alias="planType")] = None
|
||||
reason: Annotated[
|
||||
AccountUpdateReason | None,
|
||||
Field(
|
||||
description="Set when initial routing discovery completes for the same authenticated owner."
|
||||
),
|
||||
] = None
|
||||
|
||||
|
||||
class AdditionalContextEntry(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user