Skip to content

fix(runtime): refuse turns and sessions while a bot is clearing - #156

Merged
juancguerrerodev merged 2 commits into
DojoCodingLabs:mainfrom
santinofuentesAI:fix/bot-clearing-race
Nov 28, 2026
Merged

juancguerrerodev merged 2 commits into
DojoCodingLabs:mainfrom
santinofuentesAI:fix/bot-clearing-race

Conversation

@santinofuentesAI

Copy link
Copy Markdown
Contributor

What and why

Closes #108

Closes the concurrency gap between checking busy / running and completing SQLCipher deletes in bots.remove, bots.reset, and clearConversation.

  • Tracks per-bot clearing state in packages/runtime/src/hermit.ts and exposes setClearing through BotsApiDeps (packages/runtime/src/bots.ts), set synchronously before any await and cleared in finally (errors included).
  • Refuses inTurn, startSession, and resumeSession while a bot is clearing; a refused send() returns code's words using HM-BOT-02.clearing (packages/copy/locales/en.json and es-419.json), preventing orphan chat_turns rows or foreign-key failures.
  • Adds three deferred-SQL transaction tests in packages/runtime/test/bots.test.ts covering bots.reset, bots.remove, and clearConversation.

Vision fit

Serves Principle 7 ("Small, typed and tested") and Principle 5 ("Spanish and English, first-class": adds matching HM-BOT-02.clearing copy in both es-419 and en), keeping local encrypted state consistent under concurrent turns.

Non-negotiables

  • This keeps every non-negotiable in AGENTS.md as it is.
  • Or it changes one, and this is the accepted RFC: #

Checklist

  • It closes one issue, linked above, or it's a small fix (a typo, a broken link, a wrong comment). A feature has an accepted proposal.
  • I wrote the failing test first. It fails without this change and passes with it. (Observed FOREIGN KEY constraint failed during bots.remove and missing refusal copy during bots.reset / clearConversation before the fix.)
  • These pass: pnpm check:privacy, pnpm typecheck, pnpm lint, pnpm test and node scripts/guard/check.mjs --base origin/main --patterns scripts/guard/patterns.txt.
  • No new network call, telemetry, analytics, ads or crash reporting. (A new request in an app adapter is explained below, with its host, skill and risk.)
  • No new dependency, or the reason for each one is below.
  • Every UI string is in packages/copy, in es-419 and en, with matching keys and placeholders, and no em or en dashes.
  • Tests, fixtures and screenshots use made-up data only.

Model path

  • This doesn't touch the model path: packages/model, agent, skills or eval, the prompt, the router, tool descriptions, normalizers, examples or the model file.
  • It does. The eval numbers from before and after are below, run as docs/evals.md says. No held-out case was tuned on.

Screenshots

  • No UI change.
  • UI change. Each changed screen is below, in both themes and both languages, with made-up data.

New dependencies and network calls

n/a

AI agents

  • No AI agent wrote any part of this.
  • An AI agent helped. Which one, and what it did: Antigravity wrote the tests and implementation in packages/runtime and packages/copy, ran all five gates against origin/main (6f0d47e), and drafted this PR description.
  • I read and ran everything in this pull request, and I can explain it.

…ocales

Signed-off-by: Santino Fuentes <santinofuentesAI@users.noreply.github.com>
…CodingLabs#108)

Signed-off-by: Santino Fuentes <santinofuentesAI@users.noreply.github.com>
@juancguerrerodev
juancguerrerodev merged commit 6b37497 into DojoCodingLabs:main Nov 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bots: refuse a turn that starts while its bot is being cleared

2 participants