Worker memory
A Worker holds only what something is using. Everything below is read from files again when asked for, so letting it go loses nothing.
| Held in memory | Size | Let go |
|---|---|---|
A conversation read whole (SessionStore._sessions) | 2–38 MB each | 30 minutes after it was last asked for (release_idle), or when 256 are held |
Run rows read beside a session's documents (session_state_file) | 60 MB over 640 conversations | 10 minutes after they were last read (release_idle_run_rows); the documents stay |
Run tables of a session (RunTables) | Up to 5 MB each | An hour after the session's last change or question, when nothing in it is unfinished; the sessions read at start because they held a Job leave at once when nothing in them is unfinished |
| The models.dev catalogue | 7 MB | Never; only the fields that are read are kept, equal values are shared. The file on disk stays whole |
The Job runner's reconcile pass (_reconcile_loop) does the letting go; it runs at least once a minute (Change notification).
The restart pass
reconcile_interrupted_runs marks what a dead Worker left running. It reads a conversation whole, so it reads only the ones that can hold such work:
- those with a log written since the last finished pass began: every node, run row and Goal state is a line of the session's logs;
- those the last pass left with a run, a wait or an attached Job open, or could not lock;
- those with an unfinished-run marker, or a row that says running.
A finished pass records its start and the open conversations in projects/.restart-reconciled.json. Without that file every conversation is read. Each one read leaves memory when its turn in the pass ends (passing_through).
Reads that repeat
| Read | When | How it stays small |
|---|---|---|
| A conversation's resources | When the conversation comes on screen and each time it changes | The branch projection reads the store's own nodes instead of a copy of each, one projection serves the rows and the current branch, and only the conversation's pages are read from the resource tables: 25 ms for a conversation of 1,600 nodes, against 330 ms. Control state is brought up to date for live pages only, and the conversation's executions are worked out once per read: 5 ms with 120 pages |
| Token counts of a conversation's messages | Every open, turn and compaction check | A count is remembered by the text's length and hash, not the text; the context ring of a long conversation takes 0.2 s after it is opened, against 0.5 s |
| A conversation's context breakdown | Three times at once when a conversation is opened: the panel twice and the ring | Callers that ask for the same branch at the same time share one computation and each gets its own copy; nothing is kept afterwards. Three at once take what one takes (0.08 s on a long conversation already read, against 0.25 s). It reads the store's own nodes instead of a copy of each: 0.12 s for a conversation of 3,300 nodes, against 0.17 s |
| Resources of the conversations that own retained web tabs | Once after the App reconnects | Only the conversations on screen are read ahead; a tab whose address the native page reported comes back at that address, and its conversation is read when it is opened. Reading all 22 took 3.8 s of the Worker in the first 13 s after a restart and opened each conversation whole |
| A refresh of the models.dev catalogue | When the copy on disk is over an hour old | One wanted in the first 20 s of a process waits until then: fetching, parsing and rewriting 7 MB took 0.3 s of the interpreter beside the first screen, which is served from the copy on disk either way |
| The page records of a window | Each time the App registers its window again, so after every restart | The window's pages are marked in one transaction instead of one each, the store's tables are prepared once per process instead of at every call, and commits sync at checkpoints. A window of 99 pages kept a thread in this pass for 10 of the first 30 s |
| The stamp of every package and enabled application | When a file under a package or an application changes, by the Programs watcher | Files are read from the directory listing with one stat each and plain strings, not a path object and two stat calls per file: 5 ms a pass, against 80 ms. The pass was the largest use of the processor in an idle Worker |
| The self-update records | Three times at each pass of the job reconciler | A finished update is parsed again only when one of its three files is another file or has changed, and its restart record is passed over, without the lock, once nothing in it is left to continue. Seventeen finished updates took 0.5 s of every 30 s |
| The skill folders | When a file event arrives under a skill root, by the skills watcher | The folders are walked again only when a directory or a SKILL.md has another time or size: 0.1 ms a pass, against 12 ms for two skills that hold 12,000 other files |
| The Git state of each user package | When a Worker starts, and when a package changes | Asked side by side, a process each: 20 ms for five packages, against 70 ms one after another |
| The list of skills | Every turn, context breakdown and skills request | A source is walked again only when one of its directories or SKILL.md files has changed since the last walk: 0.1 ms, against 12 ms for 370 directories holding two skills |
| Which company a provider belongs to | Once per stored credential looked up, dozens of times in one model list | The normalised catalogue is kept until the catalogue changes, and the config file is parsed only when its bytes change: the enabled-model list takes 16 ms, against 62 ms |
| The tokenizer's vocabulary | Once per Worker | Read in beside the start (0.3 s), not inside the first conversation opened |
| Tool output collection | Ten minutes after a start, then daily | Record files are scanned as bytes, one megabyte at a time: 150 MB at its peak over 900 MB of logs, against 2.7 GB when each file was read whole as text |
The Worker log names each startup step that took 50 ms or more ([startup] … took N ms); requests wait for those steps.
An empty file logs/sample-threads asks for a thread sample: for half a minute the Worker notes the call each thread is in, and writes those calls and the processor time each thread used to logs/thread-sample.txt.
A thread listed at a call may be waiting there; its processor time says whether it worked. A request left before the Worker starts is taken as it starts.
Seeing what a Worker holds
Create logs/sample-memory in the state directory. The Worker writes logs/memory-sample.txt within a second and removes the request.
| Section | Shows |
|---|---|
| Process size | Resident memory of the Worker |
| By type | Count and bytes of each object type |
| By holder | What each module-level name reaches, measured alone |
| Sessions in memory | Cached conversations, grouped by the call that first read each in |
| Run tables in memory | Sessions whose run tables are loaded, grouped by the call that read each in |
| Large strings | Strings of 50,000 characters or more, by the chain of objects holding them; never their text |
Measurements behind this design
- The restart pass read all 640 conversations and left them cached: 106 conversations held 260 MB after 45 seconds, and the Worker stayed near 950 MB. Reading them took it to 700 MB in its first seconds even when each was let go.
- The catalogue took 26 MB as parsed; 10,021 models repeat a few hundred distinct values.
- With 640 conversations and 15 open in the App, a Worker 45 seconds after start takes 130 MB, against 950 MB; its peak is 420 MB, against 1.8 GB. What remains is the open conversations: the App reads each one's resources, which reads the conversation and its run tables.
- While the pass read every conversation, the first requests of a page took seconds (resources 3.9 s, enabled models 3.3 s); the same requests take 60–170 ms once it reads only changed ones.
- Forcing a collection after each conversation did not lower the peak (351 MB against 366 MB over 106 conversations), so the pass reads fewer conversations instead.