Skip to main content

Module wake

Module wake 

Source
Expand description

Sleep and wake (spec 3.2 §7.4).

Asleep is Waiting with a recorded WakeSet and no lease (§6 D-4, K-I2). Every wake produces a NewRun or wakes a parked run; no wake source calls a tool (§6 D-3, K-I1).

How a wake becomes work:

  1. A WakeEvent arrives from a WakeSource. Every source sets WakeEvent::key, the idempotency key, as keys derives it (§13 Q7).
  2. The event becomes its keyed kernel.wake maintenance run (kernel_wake_run): in-process sources through WakeRouter::submit, webhooks and queues through their ingress. The run store keeps one run per key, so a duplicate delivery reaches the router never (K-I3); the key lives until DurableRunStore::prune frees it, so the prune policy is the dedup window.
  3. The maintenance worker’s KernelWakeExecutor hands the event to the WakeRouter, which matches it against the wake sets of Waiting processes and against the kernel’s Triggers.
  4. A matched Waiting process is woken with DurableRunStore::wake and the wake reason recorded on its process row (WakeReason). When no sleeper matched, each matched trigger enqueues its run, its row recording the reason too, with idempotency_key = keys::trigger (the event key and the trigger’s name), concurrency_key = the session or partition, the trigger’s queue, and the principal as a Service subject (NewRun::with_service_subject). NewRun::authenticated is set only when the wake carries an authenticated subject.
  5. The run executes under the harness’s configure_run, as an interactive turn does. Its turn starts with the wake reason as user content (WakeReason::notice): the source, the key, the time and the payload, cut to WAKE_PAYLOAD_LIMIT and marked as data.
SourceBuilt onKey
CronCronWakeSource over CronTriggerkeys::cron: cron:<source>:<scheduled_for>
File changeFileWakeSource over FileWatchTriggerkeys::file: file:<root>:<path>:<modification time>
Webhookwebhook_wake_hook over WebhookIngress (feature webhooks)keys::webhook: hook:<name>:<webhook-id>, set by the ingress
Queuequeue_wake_ingress over QueueIngresskeys::queue: queue:<source>:<message id>, set by the ingress
Visual eventVisionWakeSource, fed by a stream’s watch conditionskeys::vision: queue:<source>:<session>:<track>:<condition>:<event>
ScheduleDurableSchedulerkeys::schedule: schedule:<id>:<time>
Approval decidedApprovalWakeSource, an ApprovalNotifier on StoreApprovalServicekeys::approval: the approval request id
Run finishedRunFinishedWakeSource, the S1 on_finish hookkeys::run_finished: run:<pid>:<final state>
Run nowKernel::run_now, the control plane’s run-nowkeys::run_now: now:<pid or trigger:name>:<request id>

A trigger’s run is keyed keys::trigger, <event key>#<trigger name>, rather than by the bare event key of the §7.4 table, so two triggers that match one event on one queue each run; the kernel.wake run keeps the bare key.

Webhook and queue deliveries become kernel.wake runs (KERNEL_WAKE_TARGET) on the maintenance queue, which the KernelWakeExecutor turns into a routed wake, so their signature checks, keys and back-pressure hold unchanged.

A cron source with a Jitter (CronWakeSource::with_jitter, KernelConfig::with_cron_jitter) still submits each tick at its scheduled time and keyed by it, so watermarks and catch-up are unchanged; the tick’s kernel.wake run carries WakeEvent::not_before, the scheduled time plus the source’s offset, so it is routed no earlier. The offset is under half the gap to the next tick.

Missed wakes while the kernel was down follow MissedFirePolicy for schedules and MissedTickPolicy with watermarks for cron sources; file changes are reconciled by WakeRouter::reconcile on start for every sleeper whose wake set holds a Wake::FileChange. Parked work has no expiry of its own: a process sleeps until its wake set fires or WakeSet::on_expiry acts.

Modules§

keys
The idempotency key of each wake source (spec 3.2 §7.4 key table, §13 Q7).

Structs§

ApprovalWakeSource
Wakes on decided approvals (spec 3.2 §7.4): an ApprovalNotifier registered on StoreApprovalService::with_notifier whose decisions it publishes as wake events keyed keys::approval.
CronWakeSource
A cron wake source over adk_agent::ambient::CronTrigger (spec 3.2 §7.4); keys keys::cron.
FileWakeSource
A file-change wake source over adk_agent::ambient::FileWatchTrigger (spec 3.2 §7.4); keys keys::file, reading the modification time when the event arrives.
KernelWakeExecutor
Executes kernel.wake runs on the maintenance worker: decodes the WakeEvent a webhook or queue delivery carried and routes it (spec 3.2 §7.4).
RunFinishedWakeSource
Wakes on finished processes (spec 3.2 §7.4): fed by the worker’s S1 on_finish hook, it publishes each finished run as a wake event keyed keys::run_finished.
Trigger
A standing wake that starts a new process each time it fires, when no sleeping process matched (spec 3.2 §7.4 step 3): a sleeper consumes the event, a trigger is the fallback.
WakeEvent
One wake delivered by a WakeSource (spec 3.2 §7.4).
WakeReason
Why a process woke, as its next turn is told (spec 3.2 §7.4 step 3): the event’s source, key and time, and its payload as compact JSON cut to WAKE_PAYLOAD_LIMIT bytes.
WakeReasonHooks
Gives each woken turn its WakeReason (spec 3.2 §7.4 step 5): the WorkerHooks::wake_input of a DurableWorker whose runs a WakeRouter wakes. A Kernel registers the same lookup on its own workers; this is for a worker composed without one.
WakeRouter
The wake matcher (spec 3.2 §7.4 steps 2–3): routes each WakeEvent to the sleeping processes and Triggers it matches.
WakeSet
The conditions that wake a sleeping process: any one of them (spec 3.2 §7.4).

Enums§

ExpiryAction
What happens when a WakeSet expires before any wake fires (spec 3.2 §7.4).
Wake
One condition that wakes a sleeping process (spec 3.2 §7.4).
WakeOutcome
What one routed WakeEvent did to one process (spec 3.2 §7.4, §9.3 kernel.wake).
WakeOverlap
What a standing wake’s firing does while a process it started is unfinished — queued, running, or waiting (on a person, a sleep, a freeze or admission) — (spec 3.2 §7.4, §7.9). A Trigger and a managed wake set take one; skip is the default.

Constants§

COALESCED_LABEL
The label on the row of a trigger’s process waiting to start that counts the firings that joined it (WakeOutcome::Coalesced), as a decimal number; adk-rust ps shows it.
KERNEL_WAKE_TARGET
The target of a kernel.wake run: a webhook or queue delivery the maintenance worker turns into a routed wake (spec 3.2 §7.4).
RUN_NOW_SOURCE
The source of the wake Kernel::run_now submits.
SKIPPED_LABEL
The label on the row of a trigger’s unfinished process that counts the firings its WakeOverlap::Skip skipped while it ran, as a decimal number; adk-rust ps shows it.
WAKE_PAYLOAD_LIMIT
The most bytes of a wake’s payload, as compact JSON, a WakeReason keeps (spec 3.2 §7.4). The kernel.wake run keeps the whole payload.

Traits§

WakeSource
A source of wake events: an adapter over adk_agent::ambient::EventSource where one exists (spec 3.2 §7.4).

Functions§

kernel_wake_run
Builds the kernel.wake run a webhook or queue delivery enqueues: target KERNEL_WAKE_TARGET on the maintenance queue, keyed by event.key, with the event as input, acting as a Service subject (spec 3.2 §7.4).
queue_wake_ingress
Builds the ingress that turns each message of source into a kernel.wake run keyed keys::queue (spec 3.2 §7.4); the kernel runs it with QueueIngress::run.
webhook_wake_hook
Builds the webhook hook served at /hooks/{name} whose verified deliveries become kernel.wake runs keyed keys::webhook by the ingress (spec 3.2 §7.4, feature webhooks). Register it with WebhookIngress::with_hook.