---
title: "Apocrypha: what broke when we drove a local model from a phone, and how we sized its context"
date: 2026-10-24
project: apocrypha
commit: 71e5ec0b0
summary: "Lessons from four days on the app around Apoc, our local model: what a phone client needs to survive bad connections (no full-list polling, idempotent sends, stall watchdogs, a push that knows when a turn ended), why the context window is now what fits on the card, how we stopped context leaks, and a slowdown that only a relaunch cured."
canonical: https://www.apocky.com/posts/2026-10-24-apocrypha-remote-context-csl/
gates: [["Apoc Remote regression gates, 7 files","all pass","152 of 152 checks, run 2026-10-24","PASS"],["Live text vs the transport","exact","959/959 chars, ratio 1.00","PASS"],["Message typed while the bridge is down","sent exactly once","sent on try 4, 0 duplicates","PASS"],["\"Apoc finished\" push after a real turn","push service accepts","201 in 258 ms; shown on the phone","PASS"],["Context meter on a hosted-model session","under 100%","17% (old meter: 232%)","PASS"],["CSL-mode tool-free turns canon (grammar + adapter)","all","2 of 2","PASS"],["CSL-mode tool turns canon (no grammar)","all","0 of 9","FAIL"],["Engine decode and spill, 10-23 evening process vs fresh launches","same","17.5 vs 32.4-36.0 tok/s short; 27 vs 31.0-33.6 tok/s real turn; 380 vs 125 MiB shared","FAIL"],["MTP head round 2 (trained) vs the untrained Q8 head","beats it in the live check","38.40-41.93 vs 38.51-43.20 tok/s; acceptance 0.7016/0.8000 vs 0.7016/0.7778; untrained kept","FAIL"]]
---
# Apocrypha: what broke when we drove a local model from a phone, and how we sized its context

Lessons from four days on the app around Apoc, our local model: what a phone client needs to survive bad connections (no full-list polling, idempotent sends, stall watchdogs, a push that knows when a turn ended), why the context window is now what fits on the card, how we stopped context leaks, and a slowdown that only a relaunch cured.

**Update 2026-10-25:** "the model always thinks" below is no longer true. Apocrypha's thinking selector now has an Off variant (commit 57de17259, 2026-10-25 02:04): it sends enable_thinking:false, and the memory plugin honours it and skips the effort and reasoning-budget settings. We have not measured what Off does to speed or quality. Also, the engine behind Apoc was updated on 2026-10-25; see [the 2026-10-25 post](/posts/2026-10-25-apoc-stochastic-spec-and-paused-lanes/).

Apocrypha is our OpenCode fork running Apoc, a local 27B model, on one 16 GB Arc card. Last time it was the model; this one is about the app, 10-20 to 10-23.

## What you can take from this

If you put a phone, or any thin client, in front of a model running on your own PC:

- **Never poll the whole conversation.** Our page fetched the full message list, up to 2.4 MB, every 1.5 s: 11,528 times between 10-21 and 10-23. An ETag with a 304 reply for an unchanged list fixed it.
- **Make every send idempotent.** Give each message a client id and keep it in an outbox until the server confirms it. A message typed while the bridge was down went out on the fourth try, exactly once.
- **Watch for silence, not just errors.** A stream can stall without failing. Restart it after 35 s with no event, and pass the server's heartbeats through so a model that is thinking looks different from a dead socket.
- **"Finished" can look like "gone".** Our desktop removes a session from its status list when the turn ends, so the push watcher has to treat busy-then-absent as finished. The first real turn sent no push until it did.
- **Use each model's own limit.** A context meter computed against the local model's limit read 232 percent on a hosted-model session; reading the limit per model, it reads 17 percent.
- **A text-only model can still use photos.** Downscale on the phone, run OCR on the PC (Windows OCR: 333 ms on a 900x300 test image, 578 ms for 122 lines of a full-screen screenshot) and send the text with the message.
- **Test Web Push against the RFC's own test vectors.** RFC 8291 encryption is easy to get subtly wrong. Checking ours against the bytes in the RFC's Appendix A meant the one live failure was a logic bug (the "finished" case above), not the encryption.

And for a large model on one card:

- **Size the context to what fits on the card.** A 262,144-token window with the KV cache in system RAM lasted about eight hours; we run 81,920 tokens with the cache on the card.
- **Cap and prune what goes into the context.** Tool output capped at 6k characters and pruned every step, each instruction block sent once, and a memory resume block cut from 19,697 to 1,376 tokens stopped the overflows that broke compaction.
- **If the server gets slow, relaunch and re-measure before changing anything else.** One long-running process decoded at 17.5 tok/s; fresh launches of the same setup ran at 32.4 to 36.0. Log buffer sizes at load, so a slow process can be compared with a fresh one before you restart it.

## Apoc Remote

Apoc Remote is a phone web app on our private network; a bridge on the PC proxies allowlisted calls to the desktop app's session server.

- **Bad connections.** The bridge log (26,820 lines, 10-21 to 10-23) showed the page fetching the whole message list, up to 2.4 MB, every 1.5 s, 11,528 times, hanging after drops, losing offline messages, dropping heartbeats. Now: 15 s timeouts, 304 on an unchanged list, an outbox with ids so a retry never sends twice, restart after 35 s silent, Stop after 3 min quiet. Doubled live words came from a second stream per page, not the transport (959/959 chars).
- **Logs, diagnostics, controls.** Every client event carries its session and turn; a filtered log view and a diagnostics screen reach the engine slot. Rename, jump, copy, Retry, Regenerate, a reasoning chooser, quick prompts, the desktop's 15 slash commands, voice input, a context meter with Compact now at 70 and 85 percent.
- **Images, honestly.** The model has no image input, so a photo never reaches it as pixels: the phone downscales to 1600 px, the PC runs Windows OCR (333 ms on a 900x300 test), the text travels with the message. PC screenshot: 1920x1080 in 301 ms, 122 OCR lines in 578 ms.
- **A meter that knows which model answered.** A hosted-model session read 232 percent of the local compact point. The bridge now reads each model's limit from the desktop; that session reads 17 percent (171,707 of 1,015,808 tokens).
- **Real Web Push.** RFC 8291 encryption, tested against the RFC's Appendix A bytes. The first live turn ended with no push: a finished session vanishes from the desktop's status list, so busy to absent never read as finished. Fixed; the next real turn's "Apoc finished" reached the push service (201, 258 ms) and the phone.

Seven test files run the page's real scripts: 152 of 152 pass, each with a control for the old failure.

## Context and compaction

The last post said 262,144 tokens. It lasted about eight hours: the KV cache had to live in system RAM, and that evening it went back on the card. The window is now what fits: 81,920 since 10-22, 8,192 for output, compaction at 73,728.

The app leaked too: a session hit 48.6k tokens on a 41k limit, compaction's summary request overflowed, the core instructions went in twice (7.3k chars). Now tool output is capped at 6k chars and pruned every step against the usable window, the memory resume block is 1,376 tokens (was 19,697), all 12 sections kept, each instruction block goes in once, work turns run medium effort with a 3,072-token reasoning cap, and the model always thinks, sampled 0.6/0.95/20/0 after 0.3 looped.

## CSL mode in the gateway

In the proxy between app and engine, CSL mode is a per-request toggle: append the CSL instruction to the system message, select the SFT adapter at scale 1 (engine default 0), attach the strict grammar on tool-free turns, gate every reply. 12 gated replies: both tool-free turns since adapter and grammar went live (10-23 21:14, 10-24 08:36) are canon; the one before them, without grammar, was not; all 9 turns with tools fail: 4 bare tool calls, 3 ping checks answered PONG, 2 CSL replies with English words inside.

## Engine slowdown

On 10-23 evening: 17.5 tok/s short, 27 tok/s median on real turns, 380 MiB spilled to shared memory. Fresh launches next morning: 32.4 to 36.0 tok/s short, 31.0 to 33.6 tok/s on a 22,679-token turn, 125 MiB shared. The model file made no difference within noise; the relaunch did. Not uptime: the launch log puts that process's start at 21:38, after a reboot, about 45 minutes before the probe. Cause not isolated. The launcher now logs buffer sizes at load (model 10,064 plus 398 MiB on the CPU, KV 1,440 plus 320 MiB, compute 101 plus 74 plus 74 MiB). MTP head round 2 finished today: live decode about 1 tok/s slower, acceptance +0.022 on one of two prompts; production keeps the untrained head.

## What was not measured

Camera, gallery, reconnect, outbox and stall handling on the physical phone (gated in a phone-sized desktop browser); Regenerate and voice against the model; which reasoning_effort the engine honours; OCR accuracy; CSL on tool turns with grammar; the slowdown's cause.

## Next

Grammar on tool turns, or a CSL form the tool schema allows. Hourly decode and spill probes against the buffer log. Camera and voice on the device.