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

2.1 KiB
Raw Blame History

PR #1865 Review Takeaways

DOs

  • Use match for enums: Prefer exhaustive matches over ad-hoc conditionals to force decisions when new variants are added.
match approval_policy {
    AskForApproval::Never | AskForApproval::OnRequest => {
        // Early return to the model on sandbox error
    }
    AskForApproval::UnlessTrusted | AskForApproval::OnFailure => {
        // Continue with escalation flow
    }
}
  • Encapsulate policy checks: Move repeated branching logic into methods on the enum to centralize behavior.
impl AskForApproval {
    pub fn early_out_on_sandbox_error(self) -> bool {
        matches!(self, AskForApproval::Never | AskForApproval::OnRequest)
    }
}

// Usage
if approval_policy.early_out_on_sandbox_error() {
    // Early return
}
  • Add explanatory text around code blocks: In docs, insert context between examples to explain when to choose each option.
If you want to trust only known-safe commands, use "untrusted":
```toml
approval_policy = "untrusted"

If you want to be prompted only when a sandboxed command fails, use "on-failure":

approval_policy = "on-failure"

To let the model decide when to escalate, use "on-request":

approval_policy = "on-request"

**DONTs**
- **Dont chain equality checks on enums:** Avoid multiple `==` comparisons that are easy to miss when variants change.
```rust
// Avoid
if approval_policy == AskForApproval::Never {
    // ...
} else if approval_policy == AskForApproval::OnRequest {
    // ...
} else {
    // ...
}
  • Dont use a wildcard arm that hides new variants: List variants explicitly so additions cause a compile-time prompt to handle them.
// Avoid
match approval_policy {
    AskForApproval::UnlessTrusted | AskForApproval::OnFailure => { /* ... */ }
    _ => { /* catches Never, OnRequest, and any future variants unintentionally */ }
}
  • Dont stack empty or context-free code fences: Never place fenced blocks back-to-back without narrative; avoid empty fences.
// Avoid (no explanation and an empty block)
```toml
approval_policy = "untrusted"