Skip to main content

vibe/
task_scheduler.rs

1//! Bounded local deferred tasks. Execution is synchronous on the admitted AST engine.
2//!
3//! No remote execution, continuation suspension or human delegation is implied.
4//! TaskScope is runtime state; record fields never confer ownership. Env clones share
5//! the scope (including committed effects); independently defaulted environments do not.
6#[path = "task_scheduler/execution.rs"]
7mod execution;
8#[cfg(test)]
9#[path = "task_scheduler/host_tests.rs"]
10mod host_tests;
11#[path = "task_scheduler/registry.rs"]
12mod registry;
13#[path = "task_scheduler/retention.rs"]
14mod retention;
15#[cfg(test)]
16#[path = "task_scheduler/tests.rs"]
17mod tests;
18
19pub use execution::await_scheduled_value;
20pub(crate) use execution::dispatch_on_engine;
21pub(crate) use registry::checkpoint;
22pub use registry::{
23    advance_logical_clock_ms, extract_task_id, is_task_record, logical_clock_ms,
24    registry_summary, TaskRegistrySummary, TaskScope,
25};
26
27use crate::{
28    error::{DiagCode, Diagnostic},
29    span::Span,
30    value::Value,
31};
32use std::collections::BTreeMap;
33
34fn unavailable(span: Span) -> Diagnostic {
35    Diagnostic::new(DiagCode::E400, span,
36        "task operation requires an admitted AST Engine and runtime TaskScope; standalone/bytecode execution is unsupported")
37}
38
39/// Legacy facade: callers without an admitted runtime scope fail before execution.
40pub fn spawn_scheduled_task(
41    _: &str,
42    _: &str,
43    _: Value,
44    _: i64,
45    span: Span,
46) -> Result<Value, Diagnostic> {
47    Err(unavailable(span))
48}
49pub fn cancel_scheduled_task(_: &BTreeMap<String, Value>, span: Span) -> Result<Value, Diagnostic> {
50    Err(unavailable(span))
51}
52pub fn apply_task_timeout(
53    _: &BTreeMap<String, Value>,
54    _: i64,
55    span: Span,
56) -> Result<BTreeMap<String, Value>, Diagnostic> {
57    Err(unavailable(span))
58}
59pub fn query_task_status(_: &Value, span: Span) -> Result<Value, Diagnostic> {
60    Err(unavailable(span))
61}
62pub fn await_value_standalone(value: Value, span: Span) -> Result<Value, Diagnostic> {
63    match value {
64        Value::Record(ref record) if is_task_record(record) => Err(unavailable(span)),
65        Value::Lambda { .. } => Err(unavailable(span)),
66        other => Ok(other),
67    }
68}