HeyPuter/puter · critical · HttpError

unauthorized

unauthorized

Error message

actor not found in context

What it means

Thrown by ReplicateImageGenerationProvider.generate() (ReplicateImageGenerationProvider.ts:86) when Context.get('actor') is falsy. The Replicate provider needs the actor for credit checks and usage recording. Same root cause as Gemini error 365: the call is executing outside the ALS context that populates `actor`. HTTP 401 unauthorized.

Source

Thrown at src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts:86

    async generate(params: IGenerateParams): Promise<string> {
        const { prompt, test_mode } = params;

        const selectedModel = this.#getModel(params.model);
        const ratio = this.#normalizeRatio(params.ratio);

        if (test_mode) {
            return 'https://puter-sample-data.puter.site/image_example.png';
        }

        if (typeof prompt !== 'string' || prompt.trim().length === 0) {
            throw new HttpError(400, '`prompt` must be a non-empty string', {
                legacyCode: 'bad_request',
            });
        }

        const actor = Context.get('actor');
        if (!actor) {
            throw new HttpError(401, 'actor not found in context', {
                legacyCode: 'unauthorized',
            });
        }

        const filtered = this.#filterAllowedParams(params, selectedModel);
        const aliased = this.#applyParamAliases(filtered, selectedModel);
        const transformed = this.#applyTransforms(aliased, selectedModel);

        const goFast = !!transformed.go_fast;
        const generationMode =
            typeof transformed.generation_mode === 'string'
                ? transformed.generation_mode
                : undefined;

        const inputImages: string[] = [];
        if (selectedModel.imageInputKey) {
            if (params.input_image) inputImages.push(params.input_image);
            if (params.input_images?.length)

View on GitHub (pinned to 908ec23eda)

Solutions

  1. Call generate() only within a context that has set actor (controllers do this normally).
  2. In tests, wrap with Context.run({ actor: testActor }, async () => ...) or use setupPuterTestEnv().
  3. Verify middleware sets actor before the provider is reached.
  4. For background jobs, establish an explicit actor context.

Example fix

// before (test — actor missing)
await provider.generate({ prompt: 'cat' });

// after
import { Context } from '../../core/context.js';
await Context.run({ actor: testActor }, async () => {
  await provider.generate({ prompt: 'cat' });
});
Defensive patterns

Strategy: validation

Validate before calling

import { Context } from '../../core/context.js';
function ensureActor(): Actor {
  const actor = Context.get('actor');
  if (!actor) throw new Error('actor not found in context — wrap call in Context.run');
  return actor;
}

Prevention

When it happens

Trigger: Invoking the Replicate provider outside a request lifecycle that sets Context actor; tests calling generate() directly without Context.run or setupPuterTestEnv; a background task without an established actor; middleware ordering issue.

Common situations: Direct unit tests of the provider missing context setup; refactored code path losing ALS propagation; cron/internal jobs invoking generation without actor context.

Related errors


AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12). Data as JSON: /api/errors/fe4ad104ba1106f6. Report an issue: GitHub.