mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Add session-scoped aliases for registered environment IDs (#65140)
## What changed Pair each registered executor ID with a model-facing alias assigned on first use by the session's model ID store. Turn environment snapshots can resolve these pairs in selection order, including for executors that are still starting or have failed. Environment context snapshots and rendering continue to use registered IDs. ## Testing Cover alias assignment in selection order, stability across readiness updates, and reuse of the same ID pair after reopening the SQLite store. GitOrigin-RevId: e5fa6e5549ebb12fcf651e5bf7413402fb4db1b3
This commit is contained in:
committed by
copyberry
parent
55ea9a4620
commit
e1e967cd46
@@ -10,11 +10,16 @@ use crate::ModelFacingIdGenerator;
|
||||
use crate::ModelFacingIdGeneratorState;
|
||||
use crate::RestoreError;
|
||||
|
||||
/// The key type selects the alias type and a unique, stable prefix. Its JSON encoding must
|
||||
/// distinguish unequal keys and remain stable across releases.
|
||||
pub trait ModelIdKind: Eq + Hash + Serialize + DeserializeOwned {
|
||||
/// Associates a mapped ID with its external key and model-facing alias.
|
||||
/// The prefix must uniquely identify the kind. Key encodings must remain stable across
|
||||
/// releases and distinguish unequal keys.
|
||||
pub trait ModelIdKind: Sized {
|
||||
const PREFIX: &'static str;
|
||||
type Key: Eq + Hash + Serialize + DeserializeOwned;
|
||||
type Alias: From<ModelFacingId>;
|
||||
|
||||
/// Pair the key with the alias assigned by the session store.
|
||||
fn from_parts(key: Self::Key, alias: Self::Alias) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -24,11 +29,11 @@ pub struct ModelIdKey {
|
||||
}
|
||||
|
||||
impl ModelIdKey {
|
||||
pub fn new<K: ModelIdKind>(key: &K) -> serde_json::Result<Self> {
|
||||
pub fn new<I: ModelIdKind>(key: &I::Key) -> serde_json::Result<Self> {
|
||||
let mut key = serde_json::to_value(key)?;
|
||||
key.sort_all_objects();
|
||||
Ok(Self {
|
||||
kind: K::PREFIX,
|
||||
kind: I::PREFIX,
|
||||
key: key.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,10 +6,9 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::ModelFacingId;
|
||||
use crate::ModelIdKind;
|
||||
|
||||
/// An ID assigned to an executor by the client.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct RegisteredEnvironmentId(String);
|
||||
|
||||
@@ -33,20 +32,14 @@ impl fmt::Display for RegisteredEnvironmentId {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ModelEnvironmentId(u64);
|
||||
|
||||
impl fmt::Display for ModelEnvironmentId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}{}",
|
||||
RegisteredEnvironmentId::PREFIX,
|
||||
crate::padded_digits(self.0)
|
||||
)
|
||||
}
|
||||
impl ModelEnvironmentId {
|
||||
pub const PREFIX: &'static str = "env";
|
||||
}
|
||||
|
||||
impl ModelIdKind for RegisteredEnvironmentId {
|
||||
const PREFIX: &'static str = "env";
|
||||
type Alias = ModelEnvironmentId;
|
||||
impl fmt::Display for ModelEnvironmentId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}{}", Self::PREFIX, crate::padded_digits(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ModelFacingId> for ModelEnvironmentId {
|
||||
|
||||
Reference in New Issue
Block a user