diff --git a/artifacts/api-server/src/routes/jobs.ts b/artifacts/api-server/src/routes/jobs.ts index 07bf848..2607ca4 100644 --- a/artifacts/api-server/src/routes/jobs.ts +++ b/artifacts/api-server/src/routes/jobs.ts @@ -333,18 +333,20 @@ async function advanceJob(job: Job): Promise { streamRegistry.register(job.id); // Fire AI work in background — poll returns immediately with "executing" + // isFree is true ONLY for fully-free jobs (user paid nothing, workAmountSats=0). + // Partial jobs (freeTier=true but workAmountSats>0) must use the paid accounting path. + const isFreeExecution = (job.workAmountSats ?? 0) === 0; setImmediate(() => { void runWorkInBackground( job.id, job.request, job.workAmountSats ?? 0, job.btcPriceUsd, - job.freeTier ?? false, + isFreeExecution, job.nostrPubkey ?? null, - // For partial free-tier jobs (freeTier=true but user paid chargeSats), - // pass absorbedSats so the grant is recorded post-payment in runWorkInBackground. - // For fully-free jobs (isFree=true, workAmountSats=0), grant was already recorded at eval time. - (job.freeTier && (job.workAmountSats ?? 0) > 0) ? (job.absorbedSats ?? 0) : 0, + // For partial jobs: pass absorbedSats so grant is recorded post-payment. + // For fully-free jobs: grant was already recorded at eval time, pass 0. + (!isFreeExecution && job.freeTier) ? (job.absorbedSats ?? 0) : 0, ); });