Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(community): echo client nonce on message.create WS event (reply-disappear fix step 1)

Genere5725e799a57
diff --git a/src/shared/src/community-ws-events.ts b/src/shared/src/community-ws-events.ts
index 38aca7730..1b7568b97 100644
--- a/src/shared/src/community-ws-events.ts
+++ b/src/shared/src/community-ws-events.ts
@@ -39,6 +39,20 @@ export type CommunityMessageCreate = {
height?: number | null
}[]
createdAt: string
+ /**
+ * The sender's CLIENT-PROVIDED idempotency nonce, echoed back so the
+ * sender's client can match this broadcast against its optimistic row and
+ * update it in place (tempId→id) instead of inserting a duplicate — the
+ * optimistic row and the echo otherwise share no key (the echo carries the
+ * server id; the optimistic row a `temp_` id). Present ONLY when the client
+ * supplied a nonce (i.e. only when there is an optimistic row to match).
+ * The server-side `srv:`-prefixed fallback nonce is deliberately NEVER put
+ * here: it is a content fingerprint (existence/content-correlation leak on
+ * the broadcast wire) AND a fallback send has no client optimistic row to
+ * match, so it is structurally unneeded. Absent = no client nonce (nothing
+ * to reconcile) — a plain random opaque token when present, safe to fan out.
+ */
+ clientNonce?: string
/** Present only on a friend-approval card (DM channels). Client renders the card when set. */
approval?: FriendApprovalPayload
}
diff --git a/src/web/src/lib/community/message-handler.ts b/src/web/src/lib/community/message-handler.ts
index 20fda69b0..ee083c28a 100644
--- a/src/web/src/lib/community/message-handler.ts
+++ b/src/web/src/lib/community/message-handler.ts
@@ -700,6 +700,12 @@ export async function createCommunityMessage(params: {
const messagePayload = mapMessageForWs(row, {
replyMap,
+ // Raw client nonce (NOT `effectiveNonce`): echoed so the sender's optimistic
+ // row reconciles in place. `undefined` when the client sent none — in which
+ // case `effectiveNonce` is the `srv:` fallback, which must not reach the wire
+ // (content fingerprint; no client optimistic row to match). `mapMessageForWs`
+ // also prefix-guards `srv:` defensively.
+ clientNonce,
attachments: attachments.map((a) => ({
id: a.id,
filename: a.filename,
diff --git a/src/web/src/lib/community/message-payload.ts b/src/web/src/lib/community/message-payload.ts
index 4c9b4bec4..b682abdc8 100644
--- a/src/web/src/lib/community/message-payload.ts
+++ b/src/web/src/lib/community/message-payload.ts
@@ -134,13 +134,29 @@ export function mapMessageForApi(row: MessageRow, ctx: ApiMessageContext) {
export type WsMessageContext = {
replyMap: Map<string, ReplyTargetRow>
attachments: WsAttachment[]
+ /**
+ * The sender's client-provided idempotency nonce, echoed on the broadcast so
+ * the sender's optimistic row can be reconciled in place (see
+ * `CommunityMessageCreate.message.clientNonce`). Pass the RAW client nonce
+ * (undefined when the client sent none); the `srv:`-prefixed server fallback
+ * is filtered out below so a content fingerprint never reaches the wire.
+ */
+ clientNonce?: string
}
export function mapMessageForWs(row: MessageRow, ctx: WsMessageContext) {
const core = coreFields(row)
+ // Echo ONLY a client-provided nonce, and never the `srv:`-prefixed server
+ // fallback (a content fingerprint — a content-correlation leak on the
+ // broadcast wire, and a fallback send has no client optimistic row to match
+ // anyway). The prefix guard is defense-in-depth: callers pass the raw client
+ // nonce, but if a `srv:` value ever reaches here it is dropped, not fanned.
+ const clientNonce =
+ ctx.clientNonce && !ctx.clientNonce.startsWith("srv:") ? ctx.clientNonce : undefined
return {
...core,
...splitType(row.type),
+ ...(clientNonce ? { clientNonce } : {}),
replyTo: resolveReply(row, ctx.replyMap),
// The shared CommunityMessageCreate.embeds is `unknown[]` — narrow here
// rather than widening the wire type.