Skip to content

feat(client-presence): Create Acknowledgment message interface and ackRequested flow #24470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/framework/presence/src/presenceDatastoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,21 @@ interface ClientJoinMessage extends IInboundSignalMessage {
};
}

// Message type identifier for presence acknowledgment messages.
const acknowledgementMessageType = "Pres:Ack";

// Signal message format used to acknowledge receipt of presence-related messages.
// These are lightweight and typically contain only the messageId being acknowledged.
interface AcknowledgementMessage extends IInboundSignalMessage {
type: typeof acknowledgementMessageType;
// TODO: Define what ack content will be shaped like ({ messageId: string }),
// Keeping generic for now to allow evolution of this message type.
content: unknown;
}

function isPresenceMessage(
message: IInboundSignalMessage,
): message is DatastoreUpdateMessage | ClientJoinMessage {
): message is DatastoreUpdateMessage | ClientJoinMessage | AcknowledgementMessage {
return message.type.startsWith("Pres:");
}
/**
Expand Down Expand Up @@ -356,14 +368,26 @@ export class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {
// IExtensionMessage is a subset of IInboundSignalMessage so this is safe.
// Change types of DatastoreUpdateMessage | ClientJoinMessage to
// IExtensionMessage<> derivatives to see the issues.
message: IInboundSignalMessage | DatastoreUpdateMessage | ClientJoinMessage,
message:
| IInboundSignalMessage
| DatastoreUpdateMessage
| ClientJoinMessage
| AcknowledgementMessage,
local: boolean,
): void {
const received = Date.now();
assert(message.clientId !== null, 0xa3a /* Map received signal without clientId */);
if (!isPresenceMessage(message)) {
return;
}

// Here we accept acknowledgement messages passively.
// Once implemented, these will be used for tracking message delivery status.
// For now, we just skip processing these messages.
if (message.type === acknowledgementMessageType) {
return;
}

if (local) {
const deliveryDelta = received - message.content.sendTimestamp;
// Limit returnedMessages count to 256 such that newest message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,32 @@ describe("Presence", () => {
assert.strictEqual(listener.callCount, 1);
});
});

describe("receiving AcknowledgementMessage", () => {
it("accepts passively without failing", () => {
const presence = prepareConnectedPresence(
runtime,
"attendeeId-2",
"client2",
clock,
logger,
);
// This test ensures that PresenceManager can safely receive and process
// a signal of type 'Pres:Ack' without throwing or misbehaving,
// even if the acknowledgment does not correspond to any known pending message.
// We do not assert specific outcomes here — success is defined by the absence of error
presence.processSignal(
"",
{
type: "Pres:Ack",
content: {
messageId: "messageId", // Arbitrary ID that is not expected to match anything
},
clientId: "client1",
},
false,
);
});
});
});
});
Loading