chat: separate create operation identity

Use an explicit chat_create operation_id as the durable bootstrap key while retaining envelope IDs for reply correlation. Legacy requests receive fresh server-scoped identities, so independent cli-1/android-1 requests do not collide; clients that retry retain one operation_id.

Update Android creation state and repository calls to preserve an operation identity across retries, and cover durable reconnect retries, duplicate barriers, changed input, legacy correlation reuse, and protocol serialization.

Checked packaged templates: none describe chat_create. Checked packaged authoring-skill references: the existing description is stale, but shared references and README must not be edited by an item; docs/notes/bootstrap-create-identity.md records the required docs-fold update and rollout compatibility.
This commit is contained in:
2026-10-18 16:50:12 +01:00
parent 134bd0611a
commit 5946f1abc8
14 changed files with 203 additions and 46 deletions
+5 -1
View File
@@ -4,6 +4,8 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"strconv"
"sync/atomic"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
@@ -72,6 +74,8 @@ type operatorRegistry interface {
ReopenOperatorSession(ctx context.Context, sessionID string) error
}
var chatTokenSequence atomic.Uint64
// chatClientToken returns an unguessable per-connection identity. Its only role
// is to key a connection's chat-room subscriptions and to exclude the sender from
// its own fan-out; it carries no ownership. A fresh token per connection means a
@@ -79,7 +83,7 @@ type operatorRegistry interface {
func chatClientToken() string {
var b [8]byte
if _, err := rand.Read(b[:]); err != nil {
return "conn-unknown"
return "conn-fallback-" + strconv.FormatUint(chatTokenSequence.Add(1), 10)
}
return "conn-" + hex.EncodeToString(b[:])
}