Cut private Telegram text over to Workshop delivery - #867
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a production authority change
This PR crosses the first user-visible Workshop boundary. For an authenticated Telegram private text message, when canonical inbound recording succeeds and voice mode is off, the final reply is no longer finalized directly by the handler. The handler atomically commits durable Workshop delivery work and the supervised worker edits the streaming preview or sends the planned fragments.
The following paths remain unchanged:
Startup and health
Production startup now:
Unexpected worker exit reaches Kai's fatal top-level path rather than leaving a loaded service unable to deliver replies. Shutdown stops ingress, cooperatively stops the worker, closes its dedicated store, and then closes the Telegram application and shared session database.
Handler authority and duplicate prevention
handle_messagepasses an explicit typed delivery route only when the Telegram chat ID equals the authenticated human's ID._handle_responseadditionally requires:off;After Telegram confirms a streaming-preview message ID, Kai binds it to the canonical inbound message without accepting a destination from the handler. On agent completion, the locked session adapter commits the canonical assistant message, exact-epoch outbox request, and immutable edit/send plan in one transaction.
Once that transaction is confirmed, the handler performs no direct final edit/send and writes no shadow delivery observation. The worker owns finalization.
If an SQLite error may have obscured the commit result, the adapter repeats the deterministic operation while the session write lock remains held. The retry either creates rolled-back work or observes the identical committed state. If the resolution attempt also fails, Kai sends only a bounded operational notice and refuses a direct resend that could duplicate committed work.
A definite preview-binding or finalization-preparation failure retains the current direct delivery path, preserving availability without creating two authorities for a confirmed outbox transaction.
Operator rollback
The implementation map records the rollback sequence. After stopping Kai and reconciling all aggregate delivery counts, the deployed database owner can inspect or deactivate authority with:
python -m kai workshop \ delivery-authority \ statuspython -m kai workshop \ delivery-authority \ deactivateDeactivation refuses pending, leased, or retry-wait work. Terminal failures require the explicit
--acknowledge-terminal-failuresoption. No delivery work is deleted or reassigned, and a later activation creates a new epoch that cannot claim prior-epoch rows.Tests
make checkmake typecheck.venv/bin/python -m pytest -qResult:
5404 passed, 1 skippedFocused and integrated contracts cover:
Installed verification after merge
This cutover remains pending installed qualification until the deployed system demonstrates a short streamed reply finalized in place without a second copy, an all-send reply, ordered fragmentation, restart recovery, clean aggregate authority counts, clean canonical/JSONL parity, and unchanged non-cutover paths.