Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This document exists for non-obvious, error-prone shortcomings in the codebase,
- `timeout` covers two different outcomes and the message is the only thing that separates them: a `--wait` budget that ran out with the job still running server-side (message names the `serverless status` follow-up; do not re-invoke), and a single invoke call that exceeded the per-call `timeout` config key (`health`, a plain `status`, the submit — nothing is left running, a retry is correct). `internal/api/invoke.go`'s `do()` turns *any* context deadline into a `TimeoutError`, so do not narrow the documented meaning to "the work is still running" — the control plane reports the same condition as `network_error`, which is the closest analogue. `model add --wait-for-hash` was `cli_error` before this and is now `timeout`.
- a job payload and the health body are third-party data, so they go out through `output.PrintRaw`, not `output.Print`. `Print` rewrites `gpuTypeId`->`gpuId` (right for the cli's own control-plane structs, wrong for a handler's keys) and round-trips through `map[string]interface{}`, which turns every number into a float64 and corrupts integers above 2^53.
- a 200 from the invoke api is not necessarily a job: a body with neither `id` nor `status` is a bare error object. `api.Job.HasEnvelope` guards it, otherwise `run` would exit 0 on a failed request and print a follow-up `serverless status` command with an empty job id. `HasEnvelope` is satisfied by a bare `status`, so it does *not* cover a submit that returns a status and no id — `invokeJob`'s `--no-wait` branch has its own `NewNoJobIDError` guard for that, and `waitForTerminal` captures the job id once up front rather than re-reading it from each poll response.
- a model version's hash is nonempty from the moment the version exists: the api assigns a `ph-<32 hex>` placeholder while the version is still `NEEDS_HASH`, and `myModels` (what the cli reads) does not filter those out the way the public `models` surface does. so a nonempty hash is not readiness -- deployability is `status` in {`POD_READY`, `READY`}, the exact set the api's endpoint validator accepts (`READY_MODEL_REPO_STATUSES` in its aiApi schema; anything else is rejected with "Model Repo reference is not ready for endpoint deployment"), plus a non-`ph-` hash. and an upload whose bytes already exist server-side is never hashed at all: the api deprecates *this* uuid, leaves its placeholder hash in place forever, and records the version that holds the content in `metadata.dedupedToCanonicalVersion` as `{uuid, hash}` -- so `DEPRECATED` plus that pointer is a successful upload whose canonical hash is the answer, not a failure, and treating it as one makes `--wait-for-hash` burn its whole budget on a healthy dedupe. `FAILED`/`POD_REMOVED`/`DEPRECATED`-without-pointer are terminal and end the wait with `conflict`.
- `saveEndpoint` has no `computeType`: cpu is selected by sending `instanceIds` like `cpu3g-4-16` (gpu is the default when instanceIds is empty). `name` is required (`String!`, min 3) and is never auto-generated server-side — generate one client-side. flashboot is the `flashBootType` enum (`OFF`/`FLASHBOOT`), not a bool. multi-region volumes are `networkVolumeIds: [{networkVolumeId}]`, not a flat string array.
- `--wait` readiness signals are not the obvious fields: a pod's port 22 shows up in `runtime.ports` (graphql; rest leaves `runtime` null) minutes before sshd listens, and prod allocates it even for images with no sshd — so readiness is a tcp connect plus an ssh banner, never the port listing. an endpoint's `includeWorkers` list is historical: every worker on a warm, healthy endpoint reads `desiredStatus: EXITED` while `/health` reports them ready, so worker readiness comes from `/health` (invoke service, `RUNPOD_INVOKE_URL`). neither `/health` counter means "hot handler" and there is no third one: `ready` counts flashboot-cached workers (`ai-api/pkg/api/health.go` `counts()` buckets an `EXITED` pod as ready when `workerstate.IsReady`), and `running` counts `desiredStatus: RUNNING`, which is written when the worker row is created — i.e. at scheduling time, before any container exists (`runpod-backend/model/src/pod/rentPod.ts`). `running` still has to count, because a `workersMin` worker stays `RUNNING` forever and never enters `ready`. `workersMin 0` does **not** mean "no worker ever starts": `finalEndpoint` floors `workersStandby` to 5 whenever `workersMax > 1` (`ai-api/pkg/graphql/aiapi.go`), `worker.Sync` fills it with cache workers (`pkg/worker/sync.go`), and every `/health` read triggers a `Sync` (`pkg/loader/aiapi.go`) — so `--wait` at 0 min workers warns, it is not refused.
- a wait must treat poll errors as "state unknown" and keep going, because the resource already exists and bills; reporting a transport code would tell an agent to retry the create and buy a second one. only these end it early: http `400`/`401`/`403` or the codes `unauthorized`/`forbidden`/`no_credentials`/`bad_request`, a terminal pod status (`conflict`), and a resource missing from **two consecutive** reads (`not_found`) — or, for a resource that has never been readable at all, from twelve consecutive reads (`missesBeforeKnown`, ~1 min at the default interval, and only if `--wait-timeout` is longer than that), so an endpoint deleted or mistyped before `/health` ever answered, or a pod terminated before it was ever listed, does not burn the whole budget and then report `wait_timeout`. both waits enforce it. the status check is load-bearing, not redundant: the pod wait's only api call is graphql, and every graphql failure is an `*api.GraphQLError` whose `ErrorCode()` is the constant `graphql_error`, so a bad key would otherwise burn the whole budget and report `wait_timeout`. `404`/`429`/`5xx` stay transient — `/health` 404s an endpoint id it has not propagated yet. errors that leave a billed resource behind carry its id in the error object's `id` field (`internal/output.WithResourceID`), not only in the message.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ codes the cli generates:
| --- | --- |
| `usage_error` | your invocation was wrong (unknown command/flag, bad or missing args, missing required flags). usage text is printed after the json |
| `not_found` | the api has no such resource. during a `--wait` it can also mean a resource that *was* created has gone (or never became visible), so check for an `id` field and clean up rather than assuming nothing exists |
| `bad_request` `unauthorized` `forbidden` `conflict` `rate_limited` `server_error` `api_error` | derived from the rest status |
| `bad_request` `unauthorized` `forbidden` `conflict` `rate_limited` `server_error` `api_error` | derived from the rest status. `conflict` is also emitted without one, for a resource in a state no amount of waiting fixes: a terminal pod during `--wait`, an endpoint with no workers to read logs from, a model version that failed server-side hashing during `--wait-for-hash` (re-run the upload; do not poll) |
| `graphql_error` | graphql returned an errors array (http 200) |
| `timeout` | the cli stopped waiting. two cases, told apart by the message: a `--wait` / `--wait-for-hash` budget ran out with the work still running server-side (the message names the command to poll it — do that, do not re-invoke), or a single api call exceeded the `timeout` config key (nothing is running; retry) |
| `job_failed` | a serverless job reached a terminal status other than `COMPLETED`. the job payload is still on stdout |
Expand Down
10 changes: 9 additions & 1 deletion api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ type ModelVersion struct {
Metadata map[string]interface{} `json:"metadata,omitempty"`
}

// ModelVersionStatus constants used when updating a model version's status.
// ModelVersionStatus constants: the statuses the cli writes when updating a
// model version, plus the ones it has to branch on while waiting for an upload.
// POD_READY and READY are the only two the api accepts for endpoint deployment
// (`READY_MODEL_REPO_STATUSES` in its aiApi schema): a version in any other
// status is rejected at deploy time.
const (
ModelVersionStatusReady = "READY"
ModelVersionStatusPodReady = "POD_READY"
ModelVersionStatusNeedsHash = "NEEDS_HASH"
ModelVersionStatusFailed = "FAILED"
ModelVersionStatusDeprecated = "DEPRECATED"
ModelVersionStatusPodRemoved = "POD_REMOVED"
)

Expand Down
12 changes: 7 additions & 5 deletions cmd/model/addModelDeleteAfterUpload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func stubAddModelUploadSeams(t *testing.T) {
Owner: "user-id",
Name: "test-model",
Provider: "LOCAL",
Versions: []*api.ModelVersion{{UUID: "version-uuid", Hash: "hash-123"}},
Versions: []*api.ModelVersion{{UUID: "version-uuid", Hash: "hash-123", Status: api.ModelVersionStatusPodReady}},
}}, nil
}
}
Expand Down Expand Up @@ -169,13 +169,15 @@ func TestRunAddModelDeleteAfterUploadLeavesFilesWhenHashConfirmationFails(t *tes
}

getModelsForAdd = func(input *api.GetModelsInput) ([]*api.Model, error) {
// hash never shows up
// the real hash never shows up: the version keeps the placeholder hash the
// api assigns at creation, which is exactly the state that must NOT count
// as confirmation for deleting local files.
return []*api.Model{{
ID: "model-id",
Owner: "user-id",
Name: "test-model",
Provider: "LOCAL",
Versions: []*api.ModelVersion{{UUID: "version-uuid", Hash: ""}},
Versions: []*api.ModelVersion{{UUID: "version-uuid", Hash: "ph-0123456789abcdef", Status: api.ModelVersionStatusNeedsHash}},
}}, nil
}

Expand All @@ -195,12 +197,12 @@ func TestRunAddModelDeleteAfterUploadLeavesFilesWhenHashConfirmationFails(t *tes
if runErr == nil {
t.Fatal("expected non-zero error when hash confirmation fails")
}
if !strings.Contains(runErr.Error(), "timed out waiting for the model hash") {
if !strings.Contains(runErr.Error(), "timed out waiting for the model version to become deployable") {
t.Fatalf("expected timeout error, got %v", runErr)
}

if _, err := os.Stat(weightsPath); err != nil {
t.Fatalf("expected weights.bin to remain on disk when hash was never confirmed, stat err: %v", err)
t.Fatalf("expected weights.bin to remain on disk when the version never became deployable, stat err: %v", err)
}
}

Expand Down
Loading
Loading