SessionRuntimeModule · library/session/src/repos/schedules.ts:44

SchedulesRepo

component

No JSDoc comment in source yet.

API

@Component()
export class SchedulesRepo implements Schedules {
  @Use() private readonly db!: Db;
  find(projectId: string, agentId: string, name: string): ScheduleStateRow | null;
  listByAgent(projectId: string, agentId: string): ScheduleStateRow[];
  registerOrSync(args: {
    projectId: string;
    agentId: string;
    name: string;
    startAtMs: number;
    defHash: string;
    creatorUserId: string | null;
    /** A person's save through the schedules route: the creator is written even when nothing changed. */
    attested?: boolean;
  }): { row: ScheduleStateRow; fresh: boolean };
  markSlot(projectId: string, agentId: string, name: string, slotMs: number): void;
  markFired(projectId: string, agentId: string, name: string, firedAt: string, oneShot: boolean): void;
  markMissed(projectId: string, agentId: string, name: string): void;
  markInvalid(projectId: string, agentId: string, name: string, reason: string): void;
  delete(projectId: string, agentId: string, name: string): void;
  deleteMissing(projectId: string, agentId: string, presentNames: string[]): string[];
  deleteByAgent(projectId: string, agentId: string): void;
  deleteByProject(projectId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (11)

find

find(projectId: string, agentId: string, name: string): ScheduleStateRow | null
@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@returnsScheduleStateRow | null

listByAgent

listByAgent(projectId: string, agentId: string): ScheduleStateRow[]
@paramprojectIdstring
@paramagentIdstring
@returnsScheduleStateRow[]

registerOrSync

registerOrSync(args: { projectId: string; agentId: string; name: string; startAtMs: number; defHash: string; creatorUserId: string | null; attested?: boolean; }): { row: ScheduleStateRow; fresh: boolean }

Register or sync a task's runtime state, returning the synced row plus a fresh flag:

  • Insert if it doesn't exist;
  • A change to start_at resets the trigger state (a new task instance);
  • Otherwise, a change to the file fingerprint only clears the disabled flag.

The creator is who vouches for the file as it stands — the person whose runs it drives (the scheduler's driver). It is written on insert and on every change: the schedules route passes the person who saved it with their own sign-in (null for the local API token) and attested, which writes it even when nothing changed; reconciliation of a file found on disk — written or edited by an Agent, or by hand — passes null, so a schedule nobody signed for has no creator, and editing one a person saved takes theirs away. fresh = this call was an insert or reset — the scheduler only establishes its "missed, don't backfill" baseline at this moment; afterward, last_slot being NULL only means "no scheduled time has been consumed yet", and it must fire normally once reached.

@paramargs{ projectId: string; agentId: string; name: string; startAtMs: number; defHash: string; creatorUserId: string | null; attested?: boolean; }
@returns{ row: ScheduleStateRow; fresh: boolean }

markSlot

markSlot(projectId: string, agentId: string, name: string, slotMs: number): void

Advance the consumed scheduled time (advances whether triggered or skipped; restarts don't re-trigger).

@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@paramslotMsnumber
@returnsvoid

markFired

markFired(projectId: string, agentId: string, name: string, firedAt: string, oneShot: boolean): void

Record an actual send (also sets fired_once for a one-shot task).

@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@paramfiredAtstring
@paramoneShotboolean
@returnsvoid

markMissed

markMissed(projectId: string, agentId: string, name: string): void

Missed marker for a one-shot task (the scheduled time had already passed at startup/registration reconciliation; missed means not backfilled).

@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@returnsvoid

markInvalid

markInvalid(projectId: string, agentId: string, name: string, reason: string): void

Mark as disabled (e.g. the bound Session was deleted); cleared via registerOrSync after the file is modified.

@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@paramreasonstring
@returnsvoid

delete

delete(projectId: string, agentId: string, name: string): void

Deleting the file removes the task: clears its runtime state.

@paramprojectIdstring
@paramagentIdstring
@paramnamestring
@returnsvoid

deleteMissing

deleteMissing(projectId: string, agentId: string, presentNames: string[]): string[]

Reconciliation cleanup: deletes state rows under this Agent that aren't in the current file list, returning the removed names.

@paramprojectIdstring
@paramagentIdstring
@parampresentNamesstring[]
@returnsstring[]

deleteByAgent

deleteByAgent(projectId: string, agentId: string): void
@paramprojectIdstring
@paramagentIdstring
@returnsvoid

deleteByProject

deleteByProject(projectId: string): void
@paramprojectIdstring
@returnsvoid