/api/v1, next to the
Memory API and the Memory Drive API. They use the
normal signed-in session; a request with no user gets 401.
Every stage is off by default except
disputes, which is on by default for the Dream
and the dispute routes (they need no master switch; turn it off with
PUT /memory/sleep/settings). The orchestrator stage (cycles from the unit queue)
runs once you turn it on;
the other stages are still contract only. Read routes return real empty states, never
501. Write routes that need a later stage check their input, then refuse (see
Refused writes). The status column below says which stage makes each
route live.Routes
Errors
Refused writes
run (with the orchestrator stage off, or for deep and rem),
pages/load, and disputes/:id/resolve (with the disputes stage off) answer 409.
signal answers 200, because the runtime sends it on every idle, compaction and
session end, whether Sleep is on or not.
Status
GET /memory/sleep/status
enabledis the master switch. A stage runs only whenenabledand its own flag are bothtrue.stagesholds each stage’s own flag.debtis sleep debt: memories added since your last finished nap (at most the last 7 days), divided bydebt_scale. At or abovedebt_pause_thresholddecay pauses and new extracted facts underdebt_intake_min_attentionare not stored. See How a cycle runs.last_cycleis the newest cycle row andspend_today_usdthe sum of today’s cycle spend.tracks.track2(pages) isonwhenenabledandstages.pagesare both on.tracks.track1(personal adapters) is the same forstages.track1.
Cycles
GET /memory/sleep/cycles?limit=
limit is 1 to 200, default 50.
GET /memory/sleep/cycles/:id
{ "cycle": { ... }, "report": { ... } | null }, with the same cycle fields as the list
(including summary, the same line status.last_cycle carries). report is null while
the cycle is running.
stages lists every stage of the cycle’s plan (a daydream lists capture and
consolidation) in order. outcome is ran, skipped (with the reason, for example
spend_cap, not_due or stage_off: strengths), failed (the error), held (a clean
stop left it for the next signal) or not_run. counts per stage: capture has
captured; consolidation has scanned, candidates, merged, decayed; fit has
events, fitted, kept_owner; dream has the Dream summary; curation has bots.
Spend is real. A stage’s spend_usd is the cost the usage ledger holds for your
memory surface calls during that stage (Dream and curation). The ledger can write after
the stage returns, so this route reads it again and raises the stage and cycle spend when
more arrived; that is the number the daily cap counts. The configured estimates
(dream_cost_estimate_usd, curation_cost_estimate_usd) only decide whether a stage may
start. Other memory model calls of yours in the same minutes (for example fact
extraction) fall in the same window and count too.
POST /memory/sleep/cycles/:id/undo
No body. Works for a finished or stopped cycle of yours, with or without the
orchestrator stage on.
- The Dream part is undone with Dream’s own undo: it reverses only the lines the Dream changed and keeps anything you added or edited since.
- The page manifest is rolled back to
manifest_before. Cycles write no manifest until pages land (step 4.1), so today this part is recorded asrecorded_no_op. - Consolidation merges and decays and curation edits have no undo. They are listed in
cannot_undo; nothing pretends to reverse them.
200: { "undone": true, "undone_at": "...", "cycle": { ... }, "parts": [ { "part": "dream", "status": "undone", "detail": "...", "revision": "..." } ], "cannot_undo": [ ... ] }, and the
cycle’s state becomes undone. A part status is undone, nothing_to_undo,
recorded_no_op or cannot_undo.
POST /memory/sleep/run
Optional body { "kind": "nap" }, where kind is daydream, nap, deep or rem.
Leave it out for a nap. With the orchestrator stage on, a nap or daydream is
queued and the worker runs it within worker_poll_s seconds:
202. queued is empty when a manual run of that kind is already waiting
or running. deep and rem answer 409 with reason: "stage_not_built".
POST /memory/sleep/signal
Sent by the runtime, never by a person.
session_id is required. cache_ttl_s is optional and must be above 0.
With the orchestrator stage on, a signal writes units to the queue and answers:
There is at most one open (
queued or leased) unit per session and kind, so a repeated
signal never queues twice. With the stage off the signal is refused as shown above and
nothing is written. nap_after_ttl_multiple (default 1.0) is in the thresholds list.
Who sends what: Gizzi
Gizzi sends these signals from both of its loops: the terminal app (gizzi) and the
runtime that Allternit Desktop and other hosts run (gizzi serve). It sends them only
for your own top-level chat, never for subagents. It sends nothing when you are signed
out, when GET /memory/sleep/status says Sleep is off, or when the runtime is older
and answers 404. Gizzi checks the status once per process and keeps the answer for
five minutes.
There is no timer job behind these signals. Each one follows something the session did.
When Sleep is on, Gizzi’s local
autoDream stays off, so only one consolidator runs.
How a cycle runs
Withenabled and stages.orchestrator on, one background worker in the Allternit
API takes queued daydream and nap units one at a time (one per user at once) and
runs each as a cycle. Nothing is scheduled by launchd or cron.
A nap runs these stages in this order. A daydream runs the first two only.
The cycle row stores each stage with
status (done, skipped or failed), a note
(for example not_due, spend_cap, stage_off: strengths), spend_usd and the job’s
own result. The sleep.cycle.stage event uses the same fields. The report route
(GET sleep/cycles/:id, see Cycle report) turns them into outcome and reason.
- Daily spend cap. A spending stage runs only when
daily_spend_cap_usdis above 0 and today’s spend plus the stage’s estimate (dream_cost_estimate_usd,curation_cost_estimate_usd) fits under it. Otherwise it is skipped withspend_cap. With the default cap of 0, no stage spends quota and the others still run. - Clean stop. A
resumesignal stops the cycle after the stage that is running. The cycle endsstoppedand the remaining stages wait as aheldunit; the session’s next signal queues it again and the next cycle starts from the next stage. The per-cycle stop rule (cycle_max_stages,cycle_max_minutes) stops a cycle the same way. - Failures. A stage error ends the cycle
failedand counts one attempt. Afterunit_max_attemptsfailures (or expired leases) the unit isdeferred: it is not retried until your next cycle opens, then it gets fresh attempts. - Sleep debt. While
debtis at or abovedebt_pause_threshold, consolidation skips its decay step, so nothing fades while a nap is overdue. Extraction also gets a stricter intake: a new fact whose attention score is underdebt_intake_min_attentionis not stored (the turn itself is still logged). Updates, forgets, explicit saves and facts flagged with a remember marker are never held. - The old clocks. The consolidation tick, the nightly Dream and the weekly bot
curation still run on their own for users with the orchestrator off, exactly as
before. With it on, they only queue a
nap(sessionclock, at most one waiting) and the cycle runs the job.
sleep_units: queued, leased, done, cancelled, deferred
(failed unit_max_attempts times this cycle) and held (the rest of a stopped cycle,
with resume_from_stage in its payload).
Context and pages
GET /memory/sleep/context?session_id=&model=
enabledis the router stage.overlayholds your corrections that are not applied to a page yet. Each one is{ id, topic_id, claim_id, correction, as_of }.disputesholds the open disputes, in the same shape asGET /memory/disputes.intentionsholds reminders that fired since the last read:{ id, content, cue_kind, cue, due_at, fired_at }. Each is returned once.intentions_opencounts the ones still waiting. Both are empty unless theintentionsstage is on.budget.shareis the share of the model’s context window pages may use.
POST /memory/sleep/pages/load
topic_id is required. Once live, it returns the page and records a router miss.
GET /memory/sleep/pages?limit=
sha256. The manifest is signed, and the runtime
checks the hash and the signature every time it loads a page.
GET /memory/sleep/pages/:topic
state is active, weak, gist or untethered. An untethered topic is
left out of the index but can still be loaded directly.
Source types
Every claim, and every fact Sleep scores, carries asource_type:
A claim must point back to an observation or a fact. A claim without that pointer is refused.
Disputes
With thedisputes stage on, two memories that contradict each other are both kept, and
a dispute records them. Nothing is fixed silently, and a dispute never stops an answer.
When a dispute opens
When the model that saves memories says a message changes an existing memory, Sleep checks what kind of change it is:
A refinement keeps every word of the old memory and adds no “not” or “no longer”. A
correction is a message from you with a change word in it, such as “moved”, “now”, “no
longer”, “switched”, “changed”, “used to”, “instead” or “actually”. Anything else is a
contradiction. The nightly Dream follows the same rule: when it finds two memories that
disagree, it removes nothing and opens a dispute between the memory it wanted to drop
(side a) and the one it kept (side b). Side a is the older memory, side b the newer one.
The same pair never gets a second dispute.
How the arbiter picks
The arbiter decides with fixed rules and no model call, so the same dispute always gets the same answer.- Scope. If both memories name a different situation (“at work” and “at home”, “on
weekends”) or belong to different agents, both can be true: the pick is
both_scoped. - Support. Each side gets
dispute_w_credence × credence + dispute_w_recency × recency, plusdispute_w_goal × goal fitwhen your current goal is known (no goal is stored yet, so this part is skipped today). Credence comes from where the memory came from: something you said beats something the model inferred. Recency moves from 0.5 towards 1 for the newer side and towards 0 for the older one, in full at a gap ofdispute_recency_days. The side with more support is picked.marginis the gap between the two, divided by the weights used, so it is between 0 and 1. A tie picks side b. - Stakes. Money, health and legal words give high stakes (0.8 to 0.9); deadlines 0.6; anything else 0.2. Stakes never change the pick. They decide whether to ask you.
margin is under dispute_ask_margin and stakes is at or above
dispute_ask_stakes, the dispute is needs_user and no pick is applied. Otherwise it is
resolved with picked_by: "arbiter", and the other memory is not deleted: it stays,
with the dispute pointing at it. reason is one short sentence, for example “It is the
more recent of the two.” or “It comes from what you said, the other from the assistant’s
guess.”
At recall
When a recalled memory is a side of a dispute that is not resolved, or was resolved with both sides still kept, its result carries an extradispute field: both sides with their
text, which side this memory is, the pick and the reason. Results are never removed or
reordered because of a dispute, and results with no dispute have no dispute field, so
older clients see the same shape.
GET /memory/disputes?state=&limit=
state is open, needs_user or resolved. Leave it out to get all of them. Each side
carries its memory’s text and current (false once it was replaced).
needs_user means the two sides were close and the stakes were high, so Sleep asks
you instead of picking.
POST /memory/disputes/:id/resolve
choice is a, b, both_scoped (both are true in different scopes) or neither.
Your pick wins: the dispute becomes resolved with picked_by: "user".
Returns
200 with { "accepted": true, "dispute": { ... } }, 404 for an unknown
dispute, 409 with reason: "sleep_disabled" when the disputes stage is off, and 409
with reason: "already_settled" when you, or your own correction, already settled it.
Spaced checks and the tether ladder
Withstages.checks on, the checks stage of a nap tests old memories with no model call. A
check asks three things of one current fact: (a) its own words find it in the top
checks_recall_k search hits, (b) no newer current fact contradicts it without a dispute
record, (c) its source observation still exists. pass is 3 of 3, fail is (a) or (b) failing,
and weak is only (c) failing. Each check is a row in sleep_checks (check_kind is spaced,
changed, neighbour or sample; a failed memory also gets a queued_reconsolidation row).
Spacing. The first check is due checks_spacing_base_days after the fact was written. After
n passes in a row the next one is base x checks_spacing_growth^n days away (at most 365). A
check that is not a pass comes back after base days.
The bounded set. Each nap checks at most checks_max_per_cycle memories, however many you
have: today’s changes (written since the last nap), their neighbours (shared relation edges),
due spaced checks (the most faded and highest-stakes first), and checks_sample_size slots of a
fixed sample spread over tether state and age. The general-skill probe is recorded
skipped: no pages yet.
The ladder. memory_facts.tether goes tethered, weak, gist, untethered. A fail
moves a memory one step down; a pass on a weak memory moves it back up. gist marks the
memory for a shorter form on pages. untethered memories leave recall results but nothing is
deleted: loading the fact by its id still returns it. With the stage off, recall and
memory_facts.tether are untouched and no check row is written.
REM and the hypothesis queue
Dream lessons and REM links are guesses, so withstages.rem on they do not write
anything until a metric says they help. Each guess is a row in sleep_hypotheses
(kind lesson or link, a metric, score_before, score_after, and a state of
pending, kept or rejected). A guess that does not score a gain is rejected and
writes nothing. With stages.rem off, Dream writes its lessons exactly as before.
No model call is made to score a guess.
- Dream lessons (metric
evidence_reach). For each turn the lesson cites, the query is that turn’s own content words. A turn is reached when the keyword index returns, in the topchecks_recall_k, a fact drawn from that turn.score_beforecounts the turns reached today.score_aftercounts them with the lesson added as a temporary fact in a transaction that is rolled back. A kept lesson is written as today and then markedsource_type = dream_generatedwith the lowcredence_dream_generated, plus acaused_byedge (origindream_lesson) to each evidence turn. - REM links (metric
seed_reach_gain). REM starts from failed recalls (a recall log withlabel_used = []), corrections (disputes resolved byuser_said_update) and open disputes. It finds memories that share words with the seed but sit below the top results, and proposes anabout_entitylink (originrem) from a top result to each. The score is how many useful memories (sharing the seed’s words) the seed’s recall reaches with neighbour expansion, before and after the link is inserted in a rolled-back transaction. A link is kept, and written for real, only on a gain of at leasthypothesis_keep_margin. - An insight is a link that gets used. When a kept link’s memory is later labelled
used,
rem.note_link_usedraisesinsight_scoreandattentionon both ends. - Self-off. When the keep rate over the last
rem_window_cyclescycles that decided a link is underrem_min_keep_rate, REM writes afittedrowrem_auto_off = 1and skips itself. Setrem_auto_offto 0 as the owner to turn it back on.
rem stage counts links_proposed, links_kept, links_rejected,
lessons_kept, lessons_rejected and keep_rate.
Reminders (prospective memory)
With theintentions stage on, a user turn that says “remind me …” is kept as a reminder
and brought back at the right moment. It needs no model call and no scheduler.
What it catches.
- Event cues: “remind me when I mention Acme”, “next time we talk about pricing, …”,
“when I open the billing project, …”. The cue words are stored and matched later as
whole words in a turn. An event reminder expires after
intention_event_expiry_days. - Time cues: “remind me tomorrow at 9”, “remind me on Friday to send the deck”, “remind me in two weeks”, “remind me at 5pm”, “remind me on 2026-12-01”. Times are read as UTC, and a day with no clock means 09:00. A date this parser cannot place exactly (“next month”, “on March 3rd”, “soon”) is kept as an event cue on those words instead of a due time.
expired and is dropped.
Delivery. A fired reminder comes back once, in intentions on
GET /memory/sleep/context, so the runtime can preload it on its next request. Reading it
marks it done. States: open, fired, done, expired. With the stage off nothing is
captured, fired or delivered.
Settings and thresholds
Every value has a default in code. Your own value overrides it. Each value reports itssource:
GET /memory/sleep/settings
0, which means Sleep spends nothing.
PUT /memory/sleep/settings
Send only the fields you change. Returns the same object as GET.
labels_live, strengths, pages, router, orchestrator,
disputes, checks, intentions, rem and track1. An unknown stage or a cap outside
0 to 1000 returns 400, and nothing is written.
labels_live works now. When it and enabled are both on, each assistant reply sent to
POST /memory/retain labels the session’s most recent recall from the last 30 minutes. The
recall’s memory_recall_logs row gets label_used, a JSON array of the result ids the reply
used (every other id in results counts as unused), plus label_source set to answer and
labeled_at. A recall is labelled only once. With the flag off, nothing is written.
GET /memory/sleep/config
{ "values": { "<key>": { "value", "source", "default", "updated_at", "group", "about" } } }
Write-time scores
When the Sleep master switch is on, every new memory fact is scored as it is written, with no model call.attention (0 to 1) says how much the fact deserves keeping. It
rises for a “remember this” flag, a first-person statement about you, a near-duplicate
already stored, an update to an existing memory, and money, health, legal or deadline
words. credence (0 to 1) says how likely the fact is true and comes only from where it
came from: you said it, a tool reported it, it was imported, the model inferred it, or a
dream produced it. flashbulb is 1 when you flagged the fact. A flag raises attention
and never credence. source_type names the source. With Sleep off these four columns
stay empty. The goal-link signal is not scored yet.
PUT /memory/sleep/config
400, and nothing is written.
Two strengths
With thestrengths stage on, each memory keeps two numbers. Storage strength says how
well it is learned and only rises. Retrieval strength says how reachable it is now: it
fades with time and a recall resets it to 1. Time never deletes or retires a memory. A
recall raises storage strength by more when it is spaced out and when the memory had
faded. A repeat recall seconds later earns almost nothing. For a user with the stage on,
the old 90-day decay no longer runs. The consolidation pass logs which memories it would
have decayed (shadow_old_decay) and changes nothing. With the stage off, nothing here
runs and decay works as before. Recall ranking does not use the strengths yet.
Fitted decay
Once you have at leastfit_min_labeled_events recalls with answer-used labels, Sleep can
fit how fast your memories fade from your own history. For each memory shown in a labelled
recall it takes the days since that memory was last recalled and whether the reply used it,
then fits used chance = a x 0.5^(days / h) by a grid search. The fitted h is saved as
strength_half_life_days with source fitted. Below the label minimum, or when the labels
show no clear decay, nothing is written and the default stays. A value you set yourself is
never replaced. strength_spacing_credit is not fitted: the labels do not show it, so it
keeps its default. Nothing runs this fit on a schedule yet.
Events
These events go on the memory activity stream (GET /memory/drive/activity, the same rows
Memory Drive shows). Each event is its own kind, spelled with the dotted name below, so
?kind=sleep.cycle.finished filters to one of them and ?after=<cursor> follows them live
with everything else. The API writes them; agents cannot report a sleep.* kind
(POST /memory/drive/activity refuses it). Writing is best effort and never fails the nap,
dispute or request that caused it. Rows for incognito sessions are not written.
Cycle rows carry the cycle id as
run (filter with ?run=) and the chat session when the
nap came from a chat. sleep.debt.changed is written only when the debt crosses the
threshold, never on every read of GET /memory/sleep/status. It is checked when a cycle
starts and when it ends; the last event row tells whether the debt was above or below.