Files
orangecat/scripts/systemd/orangecat-cron@cat-mentions.timer
57431cbaaa feat(cat): answer @cat in private messages (#767)
Tagging the Cat in a conversation now gets an answer in that
conversation, from the Cat's own account.

The shape is a queue with two payers. The write path records that a
reply is owed and returns, because an LLM round trip must not sit inside
the sender's POST; a worker pays the debt. The systemd timer is the
DURABILITY path rather than the latency path — the write also kicks a
run, so a reply normally lands in seconds, and the tick is what
guarantees the question survives a process dying mid-thought. An
assistant that silently drops a question is worse than one that is slow.

Idempotency is the unique key on (source_type, source_id), which is what
makes an at-least-once producer safe, and 23505 is therefore treated as
success rather than failure. Concurrency is FOR UPDATE SKIP LOCKED
inside claim_cat_mentions, so an inline run overlapping a timer tick
cannot answer the same mention twice. Proven on production with two
concurrent sessions: two mentions seeded, "A claimed: 1", "B claimed: 1",
distinct rows claimed 2 of 2, nothing left pending, scratch table
dropped.

The dedupe key is the MESSAGE id, and the first draft got that wrong. It
fell back to the conversation id when no message id was passed, which
would have meant the first question ever asked in a conversation was the
only one ever answered — every later insert colliding with the unique
constraint and being read as "already queued". The parameter is now
required and the fallback is gone, with a test that fails if it returns.

"@cat what do you think about this?" works because "this" means the
conversation. The Cat reads CAT_CONTEXT_MESSAGE_WINDOW recent messages
of the thread it was tagged in and nothing else — no other conversation,
no history beyond the window. That is a stated product promise about
what tagging consents to, which is why the number lives in config and
not in a query.

The Cat STAYS in the conversation once tagged, so a follow-up needs no
second tag and both people can see it is there, and it can be removed
like any participant. That was one of the two open product calls; it is
recorded here as an assumption and is reversible.

A failure to think is still answered. CAT_FALLBACK_REPLY goes out rather
than nothing, because a tag that produces silence is indistinguishable
from a broken feature, and this codebase has shipped exactly that before.

Layering: parse (pure) -> resolve (one query) -> note (the seam a write
path calls) -> queue (durability) -> worker (dispatch) -> reply
(what it says). Nothing was added to chat-orchestrator.ts or memory.ts,
already 837 and 1062 lines. A new surface gains all of this by calling
noteCatMention.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 11:32:01 +00:00

17 lines
551 B
SYSTEMD

# SSOT: repo scripts/systemd/ — installed by deploy-selfhost.sh.
# Instance of the generic orangecat-cron@.service template (curls
# /api/cron/cat-mentions with CRON_SECRET).
#
# This is the DURABILITY path, not the latency path. The write that queued the
# mention also kicks a run, so a reply normally lands in seconds; this tick is
# what guarantees the question is still answered when that process died.
[Unit]
Description=OrangeCat @cat mention worker (every minute)
[Timer]
OnCalendar=*:*:00
Persistent=true
[Install]
WantedBy=timers.target