Skip to main content

Module store

Module store 

Source
Expand description

Persistence for the thread-level goal, on the harness Store.

Each thread’s goal is a single serialized ThreadGoal value under the GOALS_NAMESPACE namespace, keyed by the hex-encoded thread id. There is at most one goal per thread.

The Store trait offers no compare-and-set and no cross-key transaction, so every mutation runs load → mutate → put under a per-thread async mutex ([thread_lock]) — the process-local analogue of OpenHuman’s file-rename atomicity. Inside that lock the goal_id compare-and-set guard (see account_usage / set_continuation_suppressed_if) still rejects stale accounting from a replaced goal.

§Single-process only

thread_lock serializes writers within one process. Across multiple processes sharing the same FileStore there is no atomic CAS, so two concurrent read-modify-writes can lose an update. The goal_id guard still prevents logical corruption from stale accounting, but not lost updates. For multi-writer deployments funnel goal mutations through a single process (a clean fix would be a Store::compare_and_swap extension, out of scope here).

Constants§

GOALS_NAMESPACE
The Store namespace holding one ThreadGoal per thread.

Functions§

account_usage
Account token + time usage against the goal, applying the budget constraint.
clear
Delete the goal for thread_id. Returns whether one existed.
complete
Mark the goal Complete (model-driven success). Suppresses further continuation so a completed goal never re-drives.
get
Load the goal for thread_id (read-only), or None.
list_all
Load every persisted thread goal (read-only). Skips values that fail to deserialize so one corrupt entry can’t hide the rest.
pause
Pause an Active goal (host-driven). A no-op for goals that aren’t active.
resume
Resume a Paused goal (host-driven). A no-op for goals that aren’t paused — a completed/budget-limited goal is not reactivated.
set
Create or replace the goal for thread_id.
set_continuation_suppressed_if
Set continuation_suppressed only when the thread’s current goal still matches expected_goal_id and is still active (compare-and-set). Returns the goal as it stands after the (possibly skipped) write, or None when the thread has no goal.
set_if_absent
Set the goal only if the thread has none yet. Returns Some(goal) when a new goal was created, or None when a goal already existed (left untouched). The check and the write run under one lock so a concurrent writer can’t slip into the gap.