Interface: IRunStore
Defined in: internal/run-store/types.ts:25
Tenant-scoped persistence of runs.
Implemented by RunStore; the type of IAIGatewayDeps.runStore, so a host may pass its own in overrides.
Methods
anonymizeByUser()
anonymizeByUser(
args):Promise<number>
Defined in: internal/run-store/types.ts:180
anonymizeByUser -- keeps a user's runs as skeletons under a pseudonym
About
The record that a run happened stays; what the user said in it goes.
The repository replaces userId with the pseudonym and empties messages, request.system, skills, pending and
answer; id, status, steps and dates stay. An open run (RUNNING or PAUSED) becomes CANCELLED, since nobody can resume
it. Returns how many.
Who needs it
forgetUser, behind AIGateway.anonymizeUserData (D54).
Parameters
args
pseudonym
string
tenantId
string
userId
string
Returns
Promise<number>
delete()
delete(
args):Promise<number>
Defined in: internal/run-store/types.ts:159
delete -- hard-deletes the runs of threads
About
The threads go, their runs go with them (D119).
Removes the runs of the listed thread ids, or of every thread of the tenant with "all", narrowed to one user when
userId is given. Returns how many.
Who needs it
deleteThreads (behind AIGateway.deleteThreads) and forgetUser (behind AIGateway.deleteUserData, D54).
Parameters
args
tenantId
string
threadIds
userId?
string
Returns
Promise<number>
listPaused()
listPaused(
args):Promise<IRun[]>
Defined in: internal/run-store/types.ts:75
listPaused -- the runs waiting for a human
About
The inbox.
The tenant's PAUSED runs, narrowed to one user when userId is given.
Who needs it
HumanGate.listPaused and expirePaused; AIProfileStore.removeProfile, which refuses while a paused run uses the
profile.
Parameters
args
tenantId
string
userId?
string
Returns
Promise<IRun[]>
listRunning()
listRunning(
args):Promise<IRun[]>
Defined in: internal/run-store/types.ts:93
listRunning -- the runs marked RUNNING
About
A live call's run, or one an instance that died left behind.
The tenant's RUNNING runs. A RUNNING run whose thread has no live lease is stuck (D97).
Who needs it
AIGateway.recoverStuckRuns, from a scheduled job of the application.
Parameters
args
tenantId
string
Returns
Promise<IRun[]>
load()
load(
args):Promise<IRun>
Defined in: internal/run-store/types.ts:56
load -- one run of the tenant
About
The run, or a 404.
Throws a 404 (error 5372577355245) when the run is missing or belongs to another tenant; the repository's null never reaches a caller.
Who needs it
HumanGate.resume and cancel; AIGateway.getPausedRun, cancelRun and the resume path; closeRun.
Parameters
args
runId
string
tenantId
string
Returns
Promise<IRun>
save()
save(
args):Promise<void>
Defined in: internal/run-store/types.ts:40
save -- creates or replaces a run
About
The whole run, as it is now.
Passes the run to the repository, which replaces it by id.
Who needs it
HumanGate.pause (the first write of a run that pauses), the settlement of a review (settleReview), and the resume
path when the run switches profile (D65).
Parameters
args
run
Returns
Promise<void>
setStatus()
setStatus(
args):Promise<void>
Defined in: internal/run-store/types.ts:139
setStatus -- changes the status of a run
About
For the status changes nobody races for.
Loads the run (a 404 when missing) and saves it with the new status and updatedAt now; nothing else changes.
Who needs it
settleRun (DONE, FAILED after a resumed run finished), closeRun, AIGateway.closeFailedRun.
Pitfalls
Read-then-save: a concurrent writer can be overwritten. PAUSED to anything is transition's job.
Parameters
args
runId
string
status
tenantId
string
Returns
Promise<void>
transition()
transition(
args):Promise<IRun|null>
Defined in: internal/run-store/types.ts:115
transition -- moves a run from one status to another, atomically
About
Compare-and-set on the status: the run moves only if it is still in
from.
Returns the moved run, or null when the run is missing or already left from. Of several callers racing for the
same run, exactly one gets it (D69); the others read null and must refuse.
Who needs it
HumanGate.resume (PAUSED to RUNNING) and HumanGate.cancel (PAUSED to CANCELLED).
Usage
When shouldn't use it
A status change that nobody can race for: setStatus.
Parameters
args
from
runId
string
tenantId
string
to
Returns
Promise<IRun | null>