mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
## What changed - Add `SessionModelIdStore` with SQLite and in-memory implementations for looking up and assigning aliases by session, namespace, and external key. - Commit SQLite assignments before returning them, and recheck under a write transaction so concurrent writers reuse the same alias. - Support snapshotting and initializing alias maps from generator state and ordered keys, and remove mappings when their thread is deleted. - Expose alias stores through `ThreadStore` and add distinct types for registered environment IDs and model-facing `env` aliases. ## Testing Add a test using two SQLite runtime instances to verify that concurrent assignments return the same alias, different keys receive different aliases, and lookups and snapshots preserve the assignments. GitOrigin-RevId: 2668f605251ca76d4891f70f94bfb4151ba8142c
57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
//! Distinguishes client executor IDs from aliases accepted in model-facing environment arguments.
|
|
|
|
use std::fmt;
|
|
|
|
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)]
|
|
#[serde(transparent)]
|
|
pub struct RegisteredEnvironmentId(String);
|
|
|
|
impl RegisteredEnvironmentId {
|
|
pub fn new(id: impl Into<String>) -> Self {
|
|
Self(id.into())
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for RegisteredEnvironmentId {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.write_str(self.as_str())
|
|
}
|
|
}
|
|
|
|
/// The environment namespace supplies the prefix when this value is displayed.
|
|
#[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 ModelIdKind for RegisteredEnvironmentId {
|
|
const PREFIX: &'static str = "env";
|
|
type Alias = ModelEnvironmentId;
|
|
}
|
|
|
|
impl From<ModelFacingId> for ModelEnvironmentId {
|
|
fn from(id: ModelFacingId) -> Self {
|
|
Self(id.value)
|
|
}
|
|
}
|