Lambda Labs pricing tracking #146

Merged
eliribble merged 2 commits from feature/issue-145-lambda-labs-pricing into main 2026-07-20 00:26:26 +00:00
Member

Implements automated pricing tracking for vision workers using the provider API per issue #145.

DB migration: Adds started_at and total_cost columns.
worker-instance-start: Fetches price via EstimateCost() after machine creation.
worker-software-install: Verifies price hasn't changed; warns if so.
worker-instance-shutdown: Final price check, computes total cost, stores it.
computeUptime: Prefers started_at over created_at when available.

Implements automated pricing tracking for vision workers using the provider API per issue #145. **DB migration:** Adds `started_at` and `total_cost` columns. **worker-instance-start:** Fetches price via `EstimateCost()` after machine creation. **worker-software-install:** Verifies price hasn't changed; warns if so. **worker-instance-shutdown:** Final price check, computes total cost, stores it. **computeUptime:** Prefers `started_at` over `created_at` when available.
feat: capture authoritative provider pricing and calculate instance cost
All checks were successful
/ golint (push) Successful in 15s
/ pnpm-build (push) Successful in 38s
2c030191c2
During worker-instance-start, after the provider machine is created,
fetch the authoritative price via EstimateCost() and store it in
cost_per_hour along with the started_at timestamp, replacing the
manual operator-entered price.

During worker-software-install, re-fetch the current provider price
and compare against stored cost_per_hour. Log a warning if it changed.

During worker-instance-shutdown, verify the price one final time,
calculate total wall-clock runtime as shutdown_at - started_at, and
store the computed total_cost in the new column.

Adds DB migration 00195 for started_at and total_cost columns on
vision_worker, along with matching jet model/table field additions.
Updates computeUptime to prefer started_at over created_at.
Owner

I added a number of in-line review comments. I've never tried that before, let me know if you have any trouble reading them.

I added a number of in-line review comments. I've never tried that before, let me know if you have any trouble reading them.
@ -0,0 +1,7 @@
-- +goose Up
ALTER TABLE vision_worker ADD COLUMN started_at TIMESTAMP;
Owner

should be without a timezone

should be without a timezone
@ -211,0 +211,4 @@
// it is used as the reference start time; otherwise createdAt is used.
func computeUptime(createdAt time.Time, startedAt, shutdownAt *time.Time) float64 {
s := startedAt
if s == nil {
Owner

Don't fall through to created time. If we don't have the started time then we can't calculate this accurately and we shouldn't try.

Don't fall through to created time. If we don't have the started time then we can't calculate this accurately and we shouldn't try.
@ -78,0 +83,4 @@
}
if worker == nil {
log.Printf("worker-instance-shutdown: worker %d not found during shutdown", workerID)
return nil
Owner

this should be an error that crashes the job as it indicates programmer error.

this should be an error that crashes the job as it indicates programmer error.
@ -78,0 +89,4 @@
// Determine the reference start time for cost calculation
startTime := worker.StartedAt
if startTime == nil {
startTime = &worker.CreatedAt
Owner

same as above, don't fail over to created at, give up on the time calculation.

same as above, don't fail over to created at, give up on the time calculation.
@ -78,0 +93,4 @@
}
if startTime == nil {
// Fallback: use creation time
created := worker.CreatedAt
Owner

duplicate code block, same as above block, remove it.

duplicate code block, same as above block, remove it.
Address inline review comments: don't fall back to created_at for uptime
All checks were successful
/ golint (push) Successful in 13s
/ pnpm-build (push) Successful in 36s
80259734bd
Eli requested changes on PR #146:

1. computeUptime: removed the fallback to created_time when startedAt is
   nil. If we don't have a precise start time we return 0 — guessing
   from created_at would give inaccurate cost calculations.

2. markWorkerShutdown: removed the same created_at fallback. When
   started_at is nil, uptime and total_cost stay at 0 and we log that
   the cost was not calculated. The nil worker case now returns an
   error (programmer error) instead of silently logging and returning.

3. Removed duplicate fallback block in markWorkerShutdown that was
   unreachable (the first fallback already always set startTime since
   CreatedAt is a non-pointer time.Time).

The db migration TIMESTAMP type stays as-is — PostgreSQL's bare TIMESTAMP
is already WITHOUT TIME ZONE, which is the correct type for this field.
Author
Member

Pushed 80259734 with the changes from the inline review. Here is how I addressed each comment:

Comment on computeUptime: Removed the fallthrough to created_at. If startedAt is nil, computeUptime now returns 0 — no guessing. Both callers (VisionWorkersList and VisionWorkerShutdown) will show 0 uptime/cost for workers without a start time.

Comment on nil worker in markWorkerShutdown: Changed to return an error — programmer error, job will crash as it should. The earlier nil check in jobWorkerInstanceShutdown (initial fetch) was left as-is since it wasn't part of the new code.

Comment on created_at fallback in markWorkerShutdown: Removed both fallback blocks. When StartedAt is nil, totalCost stays 0 and we log that the cost wasn't calculated.

Comment on duplicate block: Removed — was unreachable anyway since the first fallback always set startTime from the non-pointer CreatedAt.

Comment on TIMESTAMP type: Note that PostgreSQL's bare TIMESTAMP is equivalent to TIMESTAMP WITHOUT TIME ZONE — it already stores no timezone info, so this is correct as-is. Re-using TIMESTAMP for consistency with the rest of the schema.

Pushed 80259734 with the changes from the inline review. Here is how I addressed each comment: **Comment on computeUptime:** Removed the fallthrough to created_at. If startedAt is nil, computeUptime now returns 0 — no guessing. Both callers (VisionWorkersList and VisionWorkerShutdown) will show 0 uptime/cost for workers without a start time. **Comment on nil worker in markWorkerShutdown:** Changed to return an error — programmer error, job will crash as it should. The earlier nil check in jobWorkerInstanceShutdown (initial fetch) was left as-is since it wasn't part of the new code. **Comment on created_at fallback in markWorkerShutdown:** Removed both fallback blocks. When StartedAt is nil, totalCost stays 0 and we log that the cost wasn't calculated. **Comment on duplicate block:** Removed — was unreachable anyway since the first fallback always set startTime from the non-pointer CreatedAt. **Comment on TIMESTAMP type:** Note that PostgreSQL's bare TIMESTAMP is equivalent to TIMESTAMP WITHOUT TIME ZONE — it already stores no timezone info, so this is correct as-is. Re-using TIMESTAMP for consistency with the rest of the schema.
eliribble deleted branch feature/issue-145-lambda-labs-pricing 2026-07-20 00:26:26 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Gleipnir/nidus-sync!146
No description provided.