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:
- A
WakeEventarrives from aWakeSource. Every source setsWakeEvent::key, the idempotency key, askeysderives it (§13 Q7). - The event becomes its keyed
kernel.wakemaintenance run (kernel_wake_run): in-process sources throughWakeRouter::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 untilDurableRunStore::prunefrees it, so the prune policy is the dedup window. - The maintenance worker’s
KernelWakeExecutorhands the event to theWakeRouter, which matches it against the wake sets ofWaitingprocesses and against the kernel’sTriggers. - A matched
Waitingprocess is woken withDurableRunStore::wakeand 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, withidempotency_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 aServicesubject (NewRun::with_service_subject).NewRun::authenticatedis set only when the wake carries an authenticated subject. - 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 toWAKE_PAYLOAD_LIMITand marked as data.
| Source | Built on | Key |
|---|---|---|
| Cron | CronWakeSource over CronTrigger | keys::cron: cron:<source>:<scheduled_for> |
| File change | FileWakeSource over FileWatchTrigger | keys::file: file:<root>:<path>:<modification time> |
| Webhook | webhook_wake_hook over WebhookIngress (feature webhooks) | keys::webhook: hook:<name>:<webhook-id>, set by the ingress |
| Queue | queue_wake_ingress over QueueIngress | keys::queue: queue:<source>:<message id>, set by the ingress |
| Visual event | VisionWakeSource, fed by a stream’s watch conditions | keys::vision: queue:<source>:<session>:<track>:<condition>:<event> |
| Schedule | DurableScheduler | keys::schedule: schedule:<id>:<time> |
| Approval decided | ApprovalWakeSource, an ApprovalNotifier on StoreApprovalService | keys::approval: the approval request id |
| Run finished | RunFinishedWakeSource, the S1 on_finish hook | keys::run_finished: run:<pid>:<final state> |
| Run now | Kernel::run_now, the control plane’s run-now | keys::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§
- Approval
Wake Source - Wakes on decided approvals (spec 3.2 §7.4): an
ApprovalNotifierregistered onStoreApprovalService::with_notifierwhose decisions it publishes as wake events keyedkeys::approval. - Cron
Wake Source - A cron wake source over
adk_agent::ambient::CronTrigger(spec 3.2 §7.4); keyskeys::cron. - File
Wake Source - A file-change wake source over
adk_agent::ambient::FileWatchTrigger(spec 3.2 §7.4); keyskeys::file, reading the modification time when the event arrives. - Kernel
Wake Executor - Executes
kernel.wakeruns on the maintenance worker: decodes theWakeEventa webhook or queue delivery carried and routes it (spec 3.2 §7.4). - RunFinished
Wake Source - Wakes on finished processes (spec 3.2 §7.4): fed by the worker’s S1
on_finishhook, it publishes each finished run as a wake event keyedkeys::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.
- Wake
Event - One wake delivered by a
WakeSource(spec 3.2 §7.4). - Wake
Reason - 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_LIMITbytes. - Wake
Reason Hooks - Gives each woken turn its
WakeReason(spec 3.2 §7.4 step 5): theWorkerHooks::wake_inputof aDurableWorkerwhose runs aWakeRouterwakes. AKernelregisters the same lookup on its own workers; this is for a worker composed without one. - Wake
Router - The wake matcher (spec 3.2 §7.4 steps 2–3): routes each
WakeEventto the sleeping processes andTriggers it matches. - WakeSet
- The conditions that wake a sleeping process: any one of them (spec 3.2 §7.4).
Enums§
- Expiry
Action - What happens when a
WakeSetexpires before any wake fires (spec 3.2 §7.4). - Wake
- One condition that wakes a sleeping process (spec 3.2 §7.4).
- Wake
Outcome - What one routed
WakeEventdid to one process (spec 3.2 §7.4, §9.3kernel.wake). - Wake
Overlap - 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
Triggerand a managed wake set take one;skipis 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 psshows it. - KERNEL_
WAKE_ TARGET - The target of a
kernel.wakerun: 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_nowsubmits. - SKIPPED_
LABEL - The label on the row of a trigger’s unfinished process that counts the firings its
WakeOverlap::Skipskipped while it ran, as a decimal number;adk-rust psshows it. - WAKE_
PAYLOAD_ LIMIT - The most bytes of a wake’s payload, as compact JSON, a
WakeReasonkeeps (spec 3.2 §7.4). Thekernel.wakerun keeps the whole payload.
Traits§
- Wake
Source - A source of wake events: an adapter over
adk_agent::ambient::EventSourcewhere one exists (spec 3.2 §7.4).
Functions§
- kernel_
wake_ run - Builds the
kernel.wakerun a webhook or queue delivery enqueues: targetKERNEL_WAKE_TARGETon the maintenance queue, keyed byevent.key, with the event as input, acting as aServicesubject (spec 3.2 §7.4). - queue_
wake_ ingress - Builds the ingress that turns each message of
sourceinto akernel.wakerun keyedkeys::queue(spec 3.2 §7.4); the kernel runs it withQueueIngress::run. - webhook_
wake_ hook - Builds the webhook hook served at
/hooks/{name}whose verified deliveries becomekernel.wakeruns keyedkeys::webhookby the ingress (spec 3.2 §7.4, featurewebhooks). Register it withWebhookIngress::with_hook.