vxcontrol/pentagi · error

resource %d not found

Error message

resource %d not found

What it means

After fetching the referenced rows, validateServiceResources builds a map and verifies every requested ID actually resolved to a UserResource row. If any requested ID is missing from the database it fails with 'resource %d not found'. Note the query does not pre-filter by user, so existence and ownership are separate checks — this one is pure existence.

Source

Thrown at backend/pkg/server/services/assistants.go:674

	if !isAdmin && !slices.Contains(privs, "resources.view") && len(ids) > 0 {
		return nil, fmt.Errorf("permission 'resources.view' required to use resource IDs")
	}

	var recs []models.UserResource
	if err := db.Model(&models.UserResource{}).Where("id IN (?)", ids).Find(&recs).Error; err != nil {
		return nil, fmt.Errorf("failed to fetch resources: %w", err)
	}

	found := make(map[uint64]models.UserResource, len(recs))
	for _, r := range recs {
		found[r.ID] = r
	}

	result := make([]database.UserResource, 0, len(ids))
	for _, id := range ids {
		r, ok := found[id]
		if !ok {
			return nil, fmt.Errorf("resource %d not found", id)
		}
		if !isAdmin && r.UserID != uid {
			return nil, fmt.Errorf("resource %d not accessible", id)
		}
		result = append(result, database.UserResource{
			ID:        int64(r.ID),
			UserID:    int64(r.UserID),
			Hash:      r.Hash,
			Name:      r.Name,
			Path:      r.Path,
			Size:      r.Size,
			IsDir:     r.IsDir,
			CreatedAt: database.TimeToNullTime(r.CreatedAt),
			UpdatedAt: database.TimeToNullTime(r.UpdatedAt),
		})
	}

	return result, nil

View on GitHub (pinned to ea665308ba)

Solutions

  1. Refresh the resource list (GET resources) and resend valid IDs.
  2. Remove the stale ID from the request payload.
  3. If the resource was deleted intentionally, update dependent flows/assistants to drop the reference.
  4. Check for environment mismatch if the ID exists in another database.
  5. Verify no recent migration or cleanup job purged user_resources rows.
Defensive patterns

Strategy: validation

Validate before calling

// fetch current valid resource IDs for the caller before referencing them
var valid []int64
db.Model(&models.UserResource{}).Where("id IN ?", ids).Pluck("id", &valid)
missing := setDifference(ids, valid)
if len(missing) > 0 {
    return fmt.Errorf("unknown resource IDs: %v — refresh the resource list", missing)
}

Type guard

func allResourcesExist(ids []uint64, found map[uint64]models.UserResource) bool {
    for _, id := range ids {
        if _, ok := found[id]; !ok {
            return false
        }
    }
    return true
}

Try / catch

_, err := validateServiceResources(ctx, uid, privs, ids)
if err != nil {
    var nf resourceNotFoundError
    if strings.Contains(err.Error(), "not found") && errors.As(err, &nf) {
        return nil, fmt.Errorf("resource %d no longer exists; refresh your resource list", nf.ID)
    }
    return nil, err
}

Prevention

When it happens

Trigger: CreateFlowAssistant, PatchAssistant, CreateFlow, or PatchFlow called with a resource ID that does not exist in the user_resources table (already deleted, wrong ID from another environment, or typographical error).

Common situations: Resource deleted by another user/session while the client kept a stale ID; copying IDs between dev/staging/prod databases; frontend caching an old resource list; hard-coded IDs in automation scripts after a DB reset.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/dc6352b5aa5d6e93. Report an issue: GitHub.