Repository navigation
feat: single-writer per role — read-only second sessions with NOT_WRITER (#46) - #60
Merged
Merged
Conversation
…TER (#46) - Write verbs (send/reply/ack) carry an optional sessionId as the writer-session proof; when the role has a registered session, writes without it or with a non-matching one are refused with NOT_WRITER (HTTP 403), naming the active writer and pointing to replace-session - Roles without a registered session keep token-only writes (hook-style channels); the operator is exempt; replace-session flips ownership and the previous writer's next write fails closed - Channel tooling injects the proof automatically: MCP tools take the writer session id from the channel config (kimiWork.conversationKey, opencode.sessionId, or an explicit top-level sessionId), never from agent input - Refusals are audited via the existing recordDeny path; NOT_WRITER added to the error code union, the HTTP mapping, and the client schema - Tests: relay-level single-writer suite (7), HTTP 403/accept round-trip, MCP tools injection, reference e2e updated to pass writer proofs - Docs: protocol v1 §2.4 + error-code mapping row, README writer section, ADR-0005 implementation status
6 tasks
OBenner
commented
Nov 15, 2026
OBenner
left a comment
Owner
Author
There was a problem hiding this comment.
CTO-ревью #60 (#46 single-writer): ПРИНЯТО по коду, мерж — после wire-вердикта arch (делегировано по договорённости).
Проверено по diff:
- requireWriter: operator exempt; поиск writer по project+agentId (per-project scope подтверждён тестом «сессия в другом проекте не гейтит» — хорошо стыкуется с #51); отказ несёт id активного writer'а и указание на replace-session; deny аудируется.
- Гигиена sessionId: в performSend поле удаляется из wire до parseSendMessageInput — proof не персистится в сообщение. Неблокирующая несимметрия: reply() явного delete не делает (работает, тесты зелёные, но форма разная — можно подчистить при касании).
- MCP tools: writer proof инъектируется из конфига канала (conversationKey → opencode.sessionId → top-level sessionId), в tool-схемах агента поля нет — агент не может подделать чужую сессию, это ключевое свойство.
- Legacy-gap задокументирован в protocol/v1 §2.4 (моё условие выполнено) + README; класс «старый клиент без sessionId против роли с сессией → NOT_WRITER» назван в PR body.
- Тесты: 7 relay-кейсов (writer/mirror/token-only-after-registration/legacy/operator/takeover/per-project) + audit×3 + http 403-vs-200 + tools-инъекция. Края закрыты.
- CI 3/3 зелёные.
Мерж после APPROVE arch по wire-хунку.
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.
Closes #46.
Что делает
Класс багов «два чата отвечают как одна роль» закрыт на уровне relay: у роли один writer — зарегистрированная сессия. Остальные чаты с токеном роли читают (
inbox/list/wait), но их записи (send/reply/ack) отклоняются сNOT_WRITER(HTTP 403) и указателем на активного writer'а +synloq replace-sessionкак единственный путь takeover. Работает поверх существующего claim/replace (#42), новых protocol verbs нет, миграции storage нет.Реализация
sessionId?в схемахPOST /v1/messages,/v1/replies,/v1/ack;NOT_WRITERдобавлен в union кодов, HTTP-маппинг (403) и клиентскую схему ошибок.RelayService.requireWriter: нет сессии у роли → токенных записей достаточно (hook-стиль, задокументированный legacy-gap); есть сессия →sessionIdобязан совпадать; operator exempt. Отказы аудируются существующимrecordDeny.registerSynloqTools(server, client, writerSessionId)— writer id берётся из конфига канала (kimiWork.conversationKey→opencode.sessionId→ явный top-levelsessionIdв MCP-конфиге для hook-хостов), агент его не видит и не задаёт.replace-sessionменяет writer'а → следующая запись старого чата падает сNOT_WRITER.Тесты
test/relay/single-writer.test.ts(7): writer пишет (send/reply/ack); зеркало получает NOT_WRITER по всем трём verb'ам + 3 audit-записи с указателем на replace-session; token-only write при живом writer'е отклонён; роль без сессии пишет (legacy); operator не гейтится; replace-session флипает; writer скоупится по проекту.test/transport/http.test.ts: 403 NOT_WRITER по HTTP, writer — 200, чтение зеркала работает.test/mcp/tools.test.ts: инъекция writerSessionId в tool-вызовы (без — NOT_WRITER, с — ок).test/e2e/reference.e2e.test.ts: обновлён — tool-серверы получают writer proof зарегистрированных сессий.pnpm verifyзелёный: 85 файлов / 759 тестов, format/typecheck/build чистые.Документация
docs/protocol/v1.md— новая §2.4 «Writer-session proof (single-writer)» + строка NOT_WRITER в таблице маппинга кодов.Ограничения
sessionIdв write-запросах — опционален на wire (совместимость), обязателен де-факто при наличии writer'а.