Skip to content

feat(types): extract duplicated OCI helpers into phenotype-types crate#233

Open
KooshaPari wants to merge 2 commits into
mainfrom
epic/B16-extract-oci-helpers
Open

feat(types): extract duplicated OCI helpers into phenotype-types crate#233
KooshaPari wants to merge 2 commits into
mainfrom
epic/B16-extract-oci-helpers

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Jun 25, 2026

Copy link
Copy Markdown
Owner

User description

Summary

Extract duplicated OCI helper types and functions into a shared phenotype-types crate to eliminate cross-repo duplication across the compute/infra ecosystem.

Context

B16 of the compute/infra cross-repo consolidation DAG (Epic B). Two OCI-related crates (oci-lottery and oci-post-acquire) independently defined structurally identical types and utility functions:

  • AcquiredInstance (oci-lottery) and InstanceFile (oci-post-acquire) — both represent an OCI compute instance record with OCID, region, AD, public IP, and acquisition timestamp.
  • expand() / dirs_home() — identical ~ expansion helpers defined in both crates.
  • LaunchOutcome — the launch result type, only in oci-lottery, but needed by the shared crate to establish a canonical contract.

This extraction allows both crates to depend on phenotype-types and remove their local copies.

Changes

  • New crate crates/phenotype-types/ in the BytePort workspace, containing three modules:
    • instance::OciInstance — unified instance record (replaces AcquiredInstance / InstanceFile)
    • outcome::LaunchOutcome — OCI launch attempt outcome with constructor helpers
    • path::{expand, dirs_home}~-expansion path utilities
  • Registered crates/phenotype-types in the workspace Cargo.toml.

Key Implementation Details

Each type includes:

  • Full Serialize/Deserialize derive for JSON roundtrip compatibility
  • Constructor convenience methods (e.g. LaunchOutcome::success(), LaunchOutcome::failure())
  • Unit tests for serde roundtrip, default/edge cases, and path expansion

Testing

cargo check -p phenotype-types
cargo test -p phenotype-types

No runtime changes to existing agents — the crate provides the canonical types but downstream adoption (migrating oci-lottery and oci-post-acquire) is a follow-up step.

Links

  • DAG unit: B16 (Epic B — Cross-repo consolidation & L1 grading)
  • Area: compute-infra

CodeAnt-AI Description

Add a shared crate for OCI instance records, launch results, and path helpers

What Changed

  • Added a new shared crate that exposes one OCI instance record used across compute and infra tools
  • Added a shared launch result type that captures success, instance OCID, raw CLI output, and out-of-capacity failures
  • Added shared ~ path expansion helpers so both agents can resolve home-based paths the same way
  • Registered the new crate in the workspace so it can be used by other parts of the project

Impact

✅ Consistent OCI instance files across agents
✅ Clearer launch success and failure reporting
✅ Reliable home-directory path handling

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@KooshaPari KooshaPari added the area:compute-infra Phenotype compute/infra epic label Jun 25, 2026
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@codeant-ai

codeant-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai

codeant-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@socket-security

socket-security Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​log@​0.4.3310010093100100
Updatedcargo/​clap@​4.6.1 ⏵ 4.5.619910093100100
Updatedcargo/​http@​1.4.0 ⏵ 1.4.210010093100100
Updatedcargo/​uuid@​1.23.1 ⏵ 1.20.0100 +110093100100

View full report

@socket-security

socket-security Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: cargo zerocopy is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?cargo/tauri-plugin-log@2.8.0cargo/zerocopy@0.8.52

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore cargo/zerocopy@0.8.52. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@github-actions

Copy link
Copy Markdown

Legacy Tooling Scan Report

Severity Count
Critical 0
High 0
Medium 0
Low 0

No violations detected.

This is a WARN-mode scan. Fix before strict enforcement begins.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jun 25, 2026
Comment on lines +13 to +15
pub fn dirs_home() -> Option<PathBuf> {
std::env::var_os("HOME").map(PathBuf::from)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: dirs_home only reads HOME, so on native Windows (where HOME is often unset) home resolution returns None and expand("~/...") silently falls back to an unexpanded relative path. Add Windows fallbacks (USERPROFILE, then HOMEDRIVE + HOMEPATH) so path expansion works consistently across supported platforms. [logic error]

Severity Level: Major ⚠️
- ❌ OCI helper `expand` mis-resolves `~/` paths on Windows.
- ⚠️ OCI config file lookups can fail on Windows hosts.
- ⚠️ Cross-platform agents may behave differently by platform.
Steps of Reproduction ✅
1. Note that `phenotype-types` re-exports `expand`/`dirs_home` from
`crates/phenotype-types/src/lib.rs:17-23`, making them public helpers for downstream OCI
agents.

2. Run any consumer binary on a native Windows host where `HOME` is unset (common; Windows
typically uses `USERPROFILE` / `HOMEDRIVE` + `HOMEPATH`) and call
`phenotype_types::expand("~/.oci/config")` from application code.

3. At `crates/phenotype-types/src/path.rs:25-31`, `expand` evaluates `if let Some(rest) =
p.strip_prefix("~/") && let Some(home) = dirs_home() { ... }`; `strip_prefix("~/")`
succeeds, but `dirs_home()` (lines 13-15) calls `std::env::var_os("HOME")` and returns
`None` because `HOME` is not defined.

4. Because the `if let` pattern fails when `dirs_home()` is `None`, `expand` falls through
to `PathBuf::from(p)` and returns a path containing the literal `~` segment instead of the
user's home directory, so downstream code that expects `~/.oci/config` (per the example in
`path.rs:21-23`) will look for a non-existent `~` directory rather than the intended home
directory config file.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** crates/phenotype-types/src/path.rs
**Line:** 13:15
**Comment:**
	*Logic Error: `dirs_home` only reads `HOME`, so on native Windows (where `HOME` is often unset) home resolution returns `None` and `expand("~/...")` silently falls back to an unexpanded relative path. Add Windows fallbacks (`USERPROFILE`, then `HOMEDRIVE` + `HOMEPATH`) so path expansion works consistently across supported platforms.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3238688a9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +12 to +14
anyhow = "1"
chrono = { version = "0.4", features = ["serde"] }
tokio = { version = "1", features = ["fs"] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove unused runtime dependencies

For this new workspace member, the CI rust-machete job in .github/workflows/ci.yml runs cargo machete .; the cargo-machete README states it returns 1 when unused dependencies are found, and anyhow, chrono, and tokio are not referenced anywhere under crates/phenotype-types/src. This will trip that gate and also forces every downstream consumer of this shared types crate to compile unnecessary transitive dependencies, so these should be removed until the crate actually uses them.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

Legacy Tooling Scan Report

Severity Count
Critical 0
High 0
Medium 0
Low 0

No violations detected.

This is a WARN-mode scan. Fix before strict enforcement begins.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:compute-infra Phenotype compute/infra epic size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant