Genace

abandoned generation job credits: Reconcile jobs after the agent leaves

The abandoned generation job credits problem begins when an application stops observing a task while the gateway or provider continues processing it. An agent ending its turn, a browser tab closing, or a worker process restarting is not itself a cancellation event. Preserve the job so its output and accounting can still be reconciled.

Separate ownership from observation

Give each application task an owner, a local identifier, and any returned gateway job identifier. Store these before relying on an in-memory conversation or process variable. An uncollected output is still associated with the original submitted work even if nobody is currently waiting for it.

Maintain an application collection status separate from the gateway state. For example, a job can be succeeded while its collection status is awaiting download. Calling that job abandoned should describe your workflow ownership, not change the reported provider outcome.

The current gateway service advances jobs through polling or worker activity. Losing a client observer does not by itself invoke its cancellation function or refund helper.

Review the cancellation boundary

The cancellation service changes local state and returns reserved credits for a nonterminal job. It does not call an upstream cancellation API. Upstream work can therefore continue even after local cancellation.

That behavior means your application should not use a closed tab as a proxy for a deliberate cancel action. Record cancellation intent explicitly and preserve the response. If a request has already reached a terminal state, the service returns the terminal record rather than manufacturing a new canceled outcome.

Avoid substituting a new generation request merely because the original collector vanished. Recover the original job identifier first and inspect its state and outputs.

Build an orphan review queue

A practical local report lists tasks with no active owner or no recent collection attempt. Include the job identifier, last observed state, held credits, actual credits when known, output collection status, and the next responsible operator.

For each entry, decide whether to resume observation, collect an available output, investigate a missing reference, or process an explicitly authorized cancellation. A timestamp threshold can prioritize review, but age alone does not prove failure or refund eligibility.

If the job identifier was lost after an uncertain POST, keep the attempt unresolved and gather evidence. A client timeout does not prove rejection, and repeated blind submissions can turn one orphan into several.

Acceptance rehearsal

Use saved fixtures for a succeeded uncollected job, a running job after agent restart, an explicitly canceled job, and an attempt with unknown acceptance. Confirm that restarting the collector does not create another generation.

Approve the workflow when every unowned task has an accountable next action and its credit exposure remains visible. Continue with job resumption, cancellation behavior, and refund receipts before closing the orphan review.

Continue with costs and billing

Where these facts come from

  • codebase: src/ai/api/credits.ts
  • codebase: src/credits/credits.ts
  • codebase: src/ai/jobs/service.ts
  • codebase: src/ai/jobs/db.ts
  • Editorial keyword hypothesis; search volume not measured