Skip to content

Conversation

@danielwpz
Copy link
Contributor

@danielwpz danielwpz commented Nov 20, 2025

Fixes #94

The "owned_by" field for all models is returned as "system", instead of the actual user or organization who owns it.

Note

Introduce owned_by for models end-to-end, including DB column with default, API exposure, admin upsert support, and tests for defaulting, preservation, and override.

  • Database:
    • Add owned_by column to models (default nearai) via migration V0026__add_owned_by_to_models.sql.
    • Update queries and INSERT/UPDATE logic to read/write owned_by, with COALESCE/defaulting on insert and preserve-on-update behavior.
  • Services/Repositories:
    • Plumb owned_by through Model/ModelWithPricing, admin UpdateModelAdminRequest, and repository DTOs.
    • Return owned_by in ModelPricing and service responses.
  • API:
    • Extend ModelMetadata and UpdateModelApiRequest with ownedBy.
    • Include owned_by in /v1/model/list, /v1/model/{name}, and OpenAI-compatible /v1/models (no longer hardcoded system).
    • Admin PATCH /v1/admin/models accepts ownedBy and returns it in responses.
  • Tests:
    • Add E2E tests verifying owned_by is populated, defaults to nearai on create, is preserved when omitted on update, and can be overridden.

Written by Cursor Bugbot for commit e733ae2. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 9

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an owned_by field to track model ownership/management across the system. The field is added to database models, service layer structs, API models, and all relevant SQL queries.

Key changes:

  • Database migration adds owned_by column with default value "nearai" for existing models
  • Repository layer updated to include owned_by in all SELECT, INSERT, and UPDATE queries
  • API layer uses actual owned_by value instead of hardcoded "system"

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/services/src/models/ports.rs Added owned_by field to ModelWithPricing struct
crates/services/src/admin/ports.rs Added owned_by to UpdateModelAdminRequest and ModelPricing structs
crates/services/src/admin/mod.rs Added DEFAULT_MODEL_OWNED_BY constant set to "nearai"
crates/database/src/repositories/model.rs Updated all SQL queries to include owned_by field; added default value logic for new model inserts
crates/database/src/repositories/admin_composite.rs Added owned_by field mapping in admin repository
crates/database/src/models.rs Added owned_by to Model and UpdateModelPricingRequest structs
crates/database/src/migrations/sql/V0024__add_owned_by_to_models.sql Migration to add owned_by column and backfill with "nearai"
crates/api/src/routes/completions.rs Changed from hardcoded "system" to actual model's owned_by value
crates/api/src/routes/admin.rs Added owned_by field passthrough in batch upsert endpoint
crates/api/src/models.rs Added owned_by to UpdateModelApiRequest with proper serde rename
Comments suppressed due to low confidence (1)

crates/database/src/repositories/model.rs:327

  • The create_model function's INSERT statement is missing the owned_by field. This will cause the insert to fail since owned_by is a NOT NULL column. The INSERT should include owned_by in both the column list and VALUES, and the RETURNING clause should include it as well. Add owned_by to line 323, &model.owned_by to the parameters array around line 338, and owned_by to the RETURNING clause on line 327.
                INSERT INTO models (
                    model_name, model_display_name, model_description, model_icon,
                    input_cost_per_token, output_cost_per_token,
                    context_length, verifiable, is_active
                ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
                RETURNING id, model_name, model_display_name, model_description, model_icon,
                          input_cost_per_token, output_cost_per_token,
                          context_length, verifiable, is_active, created_at, updated_at

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cursor
Copy link

cursor bot commented Dec 12, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 9.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@danielwpz danielwpz temporarily deployed to Cloud API test env December 12, 2025 01:11 — with GitHub Actions Inactive
@danielwpz danielwpz temporarily deployed to Cloud API test env December 12, 2025 02:10 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Model API endpoints do not record or return the user who made changes

4 participants