Skip to content

feat: add extension-to-BrowserManager finalize ack#1131

Open
vringar wants to merge 1 commit intorefactor/event-driven-completionfrom
refactor/extension-finalize-ack
Open

feat: add extension-to-BrowserManager finalize ack#1131
vringar wants to merge 1 commit intorefactor/event-driven-completionfrom
refactor/extension-finalize-ack

Conversation

@vringar
Copy link
Contributor

@vringar vringar commented Feb 20, 2026

Summary

Replaces the fixed sleep in FinalizeCommand with a bidirectional ack from the WebExtension. When the extension finishes processing a Finalize message (forwarding to StorageController, clearing visitID), it sends a FinalizeAck response back on the same TCP connection. Python reads this ack instead of sleeping.

  • Make the privileged sockets API bidirectional: open outputStream on accepted connections, add sendResponse() API, pass connectionId through onDataReceived
  • Extension sends FinalizeAck after processing Finalize in loggingdb.ts
  • Add receive() method to ClientSocket in socket_interface.py
  • FinalizeCommand waits for ack with timeout fallback (0.5s test / 5s prod)

Stacked on #1128.

Copilot AI review requested due to automatic review settings February 26, 2026 23:47
@vringar vringar force-pushed the refactor/extension-finalize-ack branch from c644753 to c362b94 Compare February 26, 2026 23:47
@vringar vringar force-pushed the refactor/event-driven-completion branch from b896b91 to 6d496a1 Compare February 26, 2026 23:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces a fixed sleep in the FinalizeCommand with a bidirectional acknowledgment from the WebExtension. Instead of sleeping for a fixed duration, Python now waits for the extension to send a FinalizeAck response after processing the Finalize message, improving reliability and reducing unnecessary wait time.

Changes:

  • Added bidirectional socket communication support by implementing response functionality in the privileged sockets API
  • Extension now sends FinalizeAck after processing Finalize messages
  • Python's FinalizeCommand waits for acknowledgment with configurable timeout instead of using fixed sleep

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
openwpm/socket_interface.py Added receive() and _receive_bytes() methods to read acknowledgment messages from the socket
openwpm/commands/browser_commands.py Replaced fixed sleep with receive() call to wait for finalize acknowledgment with timeout fallback
Extension/src/types/browser.d.ts Added TypeScript type definitions for ConnectionId and sendResponse API
Extension/src/socket.ts Modified to pass connectionId and create respond function for sending responses
Extension/src/loggingdb.ts Added logic to send FinalizeAck response after processing Finalize message
Extension/bundled/privileged/sockets/schema.json Added schema definition for sendResponse function and connectionId parameter
Extension/bundled/privileged/sockets/api.js Implemented bidirectional socket support with output streams and connection tracking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

data += chunk
return data

def receive(self, timeout: float = 5.0) -> Any:
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default timeout of 5.0 seconds in receive() is inconsistent with how it's called in FinalizeCommand, where the timeout is explicitly passed based on testing mode. Consider removing the default value to make timeout specification mandatory and prevent accidental misuse with an unintended default.

Suggested change
def receive(self, timeout: float = 5.0) -> Any:
def receive(self, timeout: float) -> Any:

Copilot uses AI. Check for mistakes.
self.visit_id,
ack,
)
except Exception:
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching bare Exception is too broad and will mask unexpected errors like KeyboardInterrupt or programming errors. Catch specific exceptions like socket.timeout or RuntimeError that are expected from the receive() operation.

Copilot uses AI. Check for mistakes.
// Abnormal close, let's log the error.
console.error(e);
}
gManager.connectionMap.delete(connectionId);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connection cleanup only happens when the socket closes abnormally. Normal connection closure (when available bytes becomes 0) should also delete the connectionId from the map to prevent memory leaks from accumulating stale connections.

Copilot uses AI. Check for mistakes.
@vringar vringar added the backlog Not a priorty, but nice to have label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backlog Not a priorty, but nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants