DEV Community

Krish Verma
Krish Verma

Posted on

How I built resume for my desktop AI companion: 2 attempts, 1 blocked write, and 0 repeated effects

How I built resume for my desktop AI companion: 2 attempts, 1 blocked write, and 0 repeated effects

Ankita AI is a desktop AI assistant by Krish Verma — a little companion, a lot more possible — and it does real work on your machine: it writes files, edits code, sends messages. That is the whole point of it, and it is also the reason a crash used to be dangerous. If the process died halfway through a job and you asked it to continue, the honest thing to do was start over — and starting over meant replaying effects that had already happened. A file written twice, a message sent twice, a payment step retried blind. I built durable tasks so that never happens again: every foreground request becomes a checkpointed task, and on resume the completed work is blocked from running again, not repeated.

The mechanism lives in src/assistant/tasks.mjs, a 242-line AssistantTaskStore. Every request gets one task record — one task.json inside a folder named by a random UUID — holding the original goal, the owner, the project, the workspace, a persistent checklist, and a receipt for every tool call. The record is written atomically: temp file, fsync, rename, 0o600 permissions, 0o700 directories. The record is capped at 512 KB and 240 steps; admission fails before work starts if the record is full, rather than halfway through.

Each step moves through five phases: requested, started, settled, uncertain, not_run. Admission is saved before the action runs, and the start is saved only after ordinary approval — so a denial never becomes a started effect, and a failed admission prevents native and MCP execution outright. The record is the source of truth about what happened, not the conversation transcript, which can be trimmed, compacted, or lost.

The replay guard is a hash. taskActionHash takes the tool name and its arguments — keys sorted recursively, so argument order cannot disguise a repeat — and SHA-256s them. Before any mutation runs, guard() checks the record: if the same hash already settled without error in an earlier attempt, it throws — "This exact action already completed in this task. Read current state and continue only the remaining work." If a step with the same hash is sitting in started or uncertain, it throws too: check its effect and resolve that receipt before retrying. An uncertain step blocks all further changes in the task until the owner reviews it with observed evidence — resolve() takes the owner, an outcome of completed or not_done, and the evidence, and only then flips the receipt.

Interruption has its own path. When a task finishes, any step still in started becomes uncertain if it was a mutation, and the task lands in needs_review instead of completed whenever anything is unfinished. And recovery is careful about ownership: recoverInterrupted() only touches tasks whose owning process is actually dead — it checks the PID is alive and that the runtime ID differs from its own. A live process keeps its lease; a second process cannot steal a running task by declaring it interrupted.

I tested it the way the failure actually happens. The CLI test starts a real process against a local model fixture, saves a real file, gets killed while its next decision is pending, then starts again as a new process and resumes the same task. The result line reads: ASSISTANT_CLI_RESTART_OK original_goal=kept completed_write=blocked remaining_file=saved attempts=2. The goal survived, the completed write was blocked instead of repeated, and the one remaining file was saved. The focused gates pass clean: 17/17 on the task store and execution tests, 23/23 on the assistant/CLI/voice-worker gate, 87/87 on the shared core gate, 36/36 on desktop assistant/phone/voice, and 46/46 on core assistant/skills.

Where you see it: the Today page lists unfinished and recent requests with Continue and review, and the terminal has ankita work list, ankita work show <task-id>, and --resume-task <task-id>, which restores the goal, project, and workspace under ordinary tool permissions. Resume validates the owner and the original project first — a task belongs to one conversation. The same store backs the opt-in daily briefing, which creates a paused draft, injects fresh saved commitments plus an explicit "not checked" notice for external sources, and posts the finished briefing directly instead of paying for a second model rewrite.

The honest limits. The guard hashes exact arguments, so a reworded equivalent call — same file, same intent, different argument spelling — has a different hash and runs again. A ChatGPT Browser request with no saved native operation ID cannot resume automatically at all; it needs a fresh reviewed request, which is a deliberate safety limit, not a silent replay. The recovery prompt handed to the model on resume is labelled untrusted historical data, never instructions — but the model still has to be trusted to follow that label. And this is process-and-filesystem evidence, not a live-model quality benchmark; the full repository suite was not rerun to completion after the last fixture fix.

Tell me I'm wrong: should the guard hash the effect instead of the arguments — check the file's current state and skip the write if it already matches — or is an exact-argument match the only honest line, since anything looser lets the model decide what counts as "the same" write? The hash is cheap and certain; the effect check is smarter and guessier. Which failure would you rather ship?

Ankita is open source (MIT) at github.com/akyourowngames/A.N.K.I.T.A, and the site is ankita-sable.vercel.app.

— Krish Verma, creator of Ankita AI

Top comments (0)