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
Storenamespace holding oneThreadGoalper 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), orNone. - 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
Activegoal (host-driven). A no-op for goals that aren’t active. - resume
- Resume a
Pausedgoal (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_suppressedonly when the thread’s current goal still matchesexpected_goal_idand is still active (compare-and-set). Returns the goal as it stands after the (possibly skipped) write, orNonewhen 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, orNonewhen 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.