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:
@@ -33,7 +33,7 @@ type OperatorSession struct {
|
||||
}
|
||||
|
||||
// ChatCreateBootstrap is the durable progress record for one chat_create
|
||||
// request. It lets a retried request resume after endpoint activation or a
|
||||
// operation. It lets a retried operation resume after endpoint activation or a
|
||||
// registry write failed, without creating or activating another session.
|
||||
type ChatCreateBootstrap struct {
|
||||
RequestID string
|
||||
@@ -72,23 +72,24 @@ directory TEXT NOT NULL, state TEXT NOT NULL, created_at INTEGER NOT NULL, updat
|
||||
return s.migrateOperatorSessions()
|
||||
}
|
||||
|
||||
// BeginChatCreate reserves a request id or returns its prior progress. The
|
||||
// request id is the client retry key and is never reused for different input.
|
||||
func (s *Store) BeginChatCreate(ctx context.Context, requestID, title, directory string) (ChatCreateBootstrap, error) {
|
||||
// BeginChatCreate reserves an operation id or returns its prior progress. The
|
||||
// operation id is the client retry key and is never reused for different input.
|
||||
// It remains stored in request_id for compatibility with existing bootstrap rows.
|
||||
func (s *Store) BeginChatCreate(ctx context.Context, operationID, title, directory string) (ChatCreateBootstrap, error) {
|
||||
now := time.Now().UnixMilli()
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO chat_create_bootstraps(request_id,title,directory,state,created_at,updated_at)
|
||||
VALUES(?,?,?,?,?,?) ON CONFLICT(request_id) DO NOTHING`, requestID, title, directory, "created", now, now)
|
||||
VALUES(?,?,?,?,?,?) ON CONFLICT(request_id) DO NOTHING`, operationID, title, directory, "created", now, now)
|
||||
if err != nil {
|
||||
return ChatCreateBootstrap{}, err
|
||||
}
|
||||
var b ChatCreateBootstrap
|
||||
err = s.db.QueryRowContext(ctx, `SELECT request_id,session_id,title,directory,state FROM chat_create_bootstraps WHERE request_id=?`, requestID).
|
||||
err = s.db.QueryRowContext(ctx, `SELECT request_id,session_id,title,directory,state FROM chat_create_bootstraps WHERE request_id=?`, operationID).
|
||||
Scan(&b.RequestID, &b.SessionID, &b.Title, &b.Directory, &b.State)
|
||||
if err != nil {
|
||||
return ChatCreateBootstrap{}, err
|
||||
}
|
||||
if b.Title != title || b.Directory != directory {
|
||||
return ChatCreateBootstrap{}, errors.New("chat_create request id was reused with different input")
|
||||
return ChatCreateBootstrap{}, errors.New("chat_create operation id was reused with different input")
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user