Skip to main content

Module worker

Module worker 

Source
Expand description

Worker mode (Cloud plan v3 L1, owner decision O1): the person’s own agent pulls tasks through MCP; the engine never starts an agent by itself.

Every claim and every result passes this gate first:

  • The engine’s opt-in lives on the server (GET /v1/me/optin): which vaults its agents may work on, whether it is active, and the daily budget. It is read fresh for every claim; when it cannot be read, nothing is claimed (fail closed).
  • The daily budget has three limits and the first one reached stops the work: tasks per day (checked before a claim), and optionally tokens and USD per day (counted from the usage each result reports; the result that crosses a limit still goes through, the next claim does not).
  • [cloud.worker] may only tighten these limits on this machine, never widen them.
  • cloud worker pause stops claiming here until resume, and held claims are no longer renewed (they end at their expiry); cloud worker stop also switches the opt-in off on the server, which ends every claim of this engine at once. The owner turns it on again on the web, or the person at this computer in LeanCTX Code signing with its own opt-in key (rc4-16, local_read::pickup_part).

Cloud enforces the same rules (C0 1.9 section 4: 403 optin_scope / vetoed, 409 optin_inactive / optin_changed, 429 daily_budget); this gate makes a refusal local and content-free instead of a request that would leak which task was attempted.

Structs§

Admission
An admitted claim: the opt-in it works under and what is left after it.
BudgetLeft
What is left of today’s budget; None is no limit.
CloudWorkerConfig
[cloud.worker]: stricter local caps on top of the server’s budget.
EvidenceSummary
What a result reports it cost, for today’s budget.
TaskScope
The task a claim or result is for.
Usage
What a day has used on this machine.
WorkerState
The local worker state: pause flag and what this machine used today.

Enums§

Limit
The limit a budget refusal hit.
Refusal
Why the gate refused; its text never names the task or its content.

Constants§

OPTIN_PATH
The engine’s own opt-in record (engine auth, own instance only).
PROVIDER_TERMS_NOTE
The provider-terms note every worker opt-in shows (plan X1; the web opt-in form carries the same text). LeanCTX never handles subscription credentials: the agent is one the person started and signed in to.

Functions§

admit_claim
Admit a claim: whether this machine may ask Cloud for it. Nothing is counted yet; count_claim counts it once Cloud granted it, so a claim Cloud refuses costs no task of today’s budget.
admit_claim_for
admit_claim on an opt-in the caller just read.
admit_submit
Add the usage a result reports to today’s.
clear_off
Lift the pause and the explicit off: only after the Cloud took a turn-on LeanCTX Code signed with its opt-in key (rc4-16).
count_claim
Count a claim Cloud granted (or a verification commit it took) against today’s tasks on this machine. A refused claim is never counted: it used to be, and refusals then ate the local budget until this machine refused on its own.
decide_claim
The claim decision on a read opt-in and the local state (no I/O).
fetch_optin
The server’s opt-in for this engine.
fetch_optin_via
The opt-in through client (a bounded client of a tool call).
observe
The local state after reconcile with optin the Cloud just answered: written only when it changed.
parse_optin
An opt-in as Cloud answers it, checked.
read_state
The local state as stored (today’s counters reset on a new day). Fail closed: a file that cannot be read or parsed counts as paused, and so does a missing one on an engine enrolled with Cloud — deleting it never lifts a pause or resets today’s counts. Only enrollment (prepare_enrollment) and cloud worker resume, both of which the person runs (an agent shell refuses them), write it unpaused.
reconcile
Bring the kept off in line with the Cloud’s opt-in (pure; rc4-16 M3): an active opt-in with another id than the one this computer stopped was turned on by the person on the web, and lifts the off and the pause the stop set. The same id keeps the off. An off whose id is not known yet (the stop did not reach the Cloud, or the file was damaged) takes the id seen now as the stopped one: it stays off. Returns whether state changed.
send_turn_on
Send the app-signed turn-on signed (the caller checked its signature) unchanged. Only a 2xx answer carrying a valid opt-in lifts the off and the pause here (clear_off); any other answer, or none, leaves them as they were. A refusal comes back with its status and answer for the caller’s words.
set_paused
Stop or resume claiming on this machine. Resuming never lifts an explicit off.
stop
Stop worker mode for this engine: pause here and switch the opt-in off on the server, which ends every claim of this engine at once. The off is kept here first; the stopped opt-in’s id is kept with it (reconcile). A Cloud without an active opt-in (409 optin_inactive) is already off: that is a success, kept with an empty id, so any opt-in turned on later lifts the off.

Type Aliases§

Optin
The engine’s opt-in (C0 1.9 section 4).
TurnOnRefused
A turn-on the Cloud did not take: its status and answer.