(ctx context.Context, store database.Store, ownerID uuid.UUID, organizationID uuid.NullUUID)
| 1905 | } |
| 1906 | |
| 1907 | func (p *Server) checkUsageLimit(ctx context.Context, store database.Store, ownerID uuid.UUID, organizationID uuid.NullUUID) error { |
| 1908 | status, err := ResolveUsageLimitStatus(ctx, store, ownerID, organizationID, time.Now()) |
| 1909 | if err != nil { |
| 1910 | // Fail open: never block chat due to a limit-resolution failure. |
| 1911 | p.logger.Warn(ctx, "usage limit check failed, allowing message", |
| 1912 | slog.F("owner_id", ownerID), |
| 1913 | slog.Error(err), |
| 1914 | ) |
| 1915 | return nil |
| 1916 | } |
| 1917 | if status == nil { |
| 1918 | return nil |
| 1919 | } |
| 1920 | // Block when current spend reaches or exceeds limit (>= ensures |
| 1921 | // the user cannot start new conversations once the limit is hit). |
| 1922 | if status.SpendLimitMicros != nil && status.CurrentSpend >= *status.SpendLimitMicros { |
| 1923 | return &UsageLimitExceededError{ |
| 1924 | LimitMicros: *status.SpendLimitMicros, |
| 1925 | ConsumedMicros: status.CurrentSpend, |
| 1926 | PeriodEnd: status.PeriodEnd, |
| 1927 | } |
| 1928 | } |
| 1929 | return nil |
| 1930 | } |
| 1931 | |
| 1932 | func chatdModelConfigLookupContext(ctx context.Context) context.Context { |
| 1933 | //nolint:gocritic // Chat message admission needs daemon-scoped |
no test coverage detected