Files
codex/prs/bolinfest/study/PR-1899-study.md
2025-09-02 15:17:45 -07:00

2.4 KiB
Raw Blame History

DOs

  • Centralize auth requirement in ModelFamily: add requires_chatgpt_auth flag.
// model_family.rs
pub struct ModelFamily {
    pub family: String,
    pub supports_reasoning_summaries: bool,
    pub requires_chatgpt_auth: bool,
    // ...
}

// When registering a new family:
} else if slug.starts_with("2025-08-06-model") {
    model_family!(
        slug, "2025-08-06-model",
        supports_reasoning_summaries: true,
        requires_chatgpt_auth: true,
    )
}
  • Enforce auth generically in the client using the flag, not the slug.
// client.rs
let auth_mode = auth.as_ref().map(|a| a.mode);
let mf = &self.config.model_family;

if mf.requires_chatgpt_auth && auth_mode != Some(AuthMode::ChatGPT) {
    return Err(CodexErr::UnexpectedStatus(
        StatusCode::BAD_REQUEST,
        format!(
            "{} is only supported with ChatGPT auth, run `codex login status` \
             to check your auth status and `codex login` to login with ChatGPT",
            mf.family
        ),
    ));
}
  • Register concrete model limits in openai_model_info.rs.
// openai_model_info.rs
match model_family.family.as_str() {
    "2025-08-06-model" => Some(ModelInfo {
        context_window: 200_000,
        max_output_tokens: 100_000,
    }),
    _ => None,
}
  • Keep capabilities single-sourced via ModelFamily flags.
// Example: gating a feature on a capability, not on a slug.
let mf = &self.config.model_family;
if mf.supports_reasoning_summaries {
    // produce reasoning summaries
}

DONTs

  • Dont hardcode slug checks in client logic.
// Anti-pattern: brittle and scatters policy across code.
if self.config.model_family.family == "2025-08-06-model"
    && auth_mode != Some(AuthMode::ChatGPT)
{
    /* ... */
}
  • Dont add a new family without declaring all relevant flags.
// Anti-pattern: missing `requires_chatgpt_auth` leads to silent policy gaps.
model_family!(
    slug, "2025-08-06-model",
    supports_reasoning_summaries: true
    // requires_chatgpt_auth: true // <-- forgotten
);
  • Dont duplicate or vary the user guidance string; format it once with the family.
// Anti-pattern: copy-pasted, model-specific message string.
return Err(CodexErr::UnexpectedStatus(
    StatusCode::BAD_REQUEST,
    "2025-08-06-model is only supported with ChatGPT auth...".to_string(),
));

// Prefer the generic, parameterized message shown in the DOs section.