Skip to content

Fix delayed hcom message delivery#65

Merged
aannoo merged 2 commits into
aannoo:mainfrom
azkore:fix/hcom-delivery-wake
Jun 10, 2026
Merged

Fix delayed hcom message delivery#65
aannoo merged 2 commits into
aannoo:mainfrom
azkore:fix/hcom-delivery-wake

Conversation

@azkore

@azkore azkore commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Subscription notifications could be logged as [hcom-events] messages without waking the subscribed agent. That left agents waiting until some unrelated status change or message wake made them read the queued notification. OpenCode had a second race where a wake that arrived during an active delivery read or while a prompt injection was waiting for transform ack was ignored.

This fixes both paths. Subscription notifications now wake only the matched subscriber after the message is logged, and OpenCode queues one pending delivery wake and drains it after the current read, after deferred ack, or after promptAsync rejects.

The Rust path adds a TCP-probe test proving only the subscribed target is woken; the OpenCode replay path has no unit test because it depends on plugin runtime sequencing and was validated against a state-machine repro of the in-flight, pending-ack, and rejection sequence. Checked with cargo fmt --check, cargo test db::subscriptions::tests::test_send_sub_notification_wakes_target_instance, and bun build src/opencode_plugin/hcom.ts --external @opencode-ai/plugin --external @opencode-ai/sdk --outfile /tmp/opencode/hcom-plugin.js.

azkore added 2 commits June 9, 2026 16:00
Subscription hits create [hcom-events] system messages through
send_system_message, which logs the message but does not ping notify
endpoints like hcom send does. That left subscription notifications
unread until an unrelated wake reached the subscriber.

Wake the matching caller's notify endpoints after the system message is
logged, guarded by delivered_to so typos or mismatches do not fan out.
Add a TCP probe test proving only the subscribed target is woken.
OpenCode delivery ignored wake attempts while a delivery read was in
flight or while an injected prompt was waiting for the transform ack. A
message created during that window could remain unread until a later
unrelated wake.

Track a queued delivery wake and replay it after the current read
finishes, after deferred ack, or after promptAsync rejects so the wake is
not stranded. Keep the existing single-delivery guard and reset the new
queue state on session deletion.
@aannoo

aannoo commented Jun 10, 2026

Copy link
Copy Markdown
Owner

thanks

@aannoo aannoo merged commit 965d37d into aannoo:main Jun 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants