Repository navigation
fix(omni-runner): sequence route status acks — final reaction waits for the pending one #2524
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -740,8 +740,11 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| controller.signal.addEventListener('abort', () => reject(new OneShotTimeoutError()), { once: true }); | ||||||||||
| }); | ||||||||||
| // ⏳ on the inbound message right before the spawn (route-scoped, no-op if the | ||||||||||
| // inbound carried no stanza id) — the first half of the run's ⏳→✅/❌ ack. | ||||||||||
| emitRouteReaction(route, messageId, STATUS_PENDING); | ||||||||||
| // inbound carried no stanza id) — the first half of the run's ⏳→✅/❌ ack. The | ||||||||||
| // settlement promise (always fulfilled — emit errors are swallowed inside) is | ||||||||||
| // kept so the final ✅/❌ can be chained AFTER the ⏳ HTTP call has landed: a run | ||||||||||
| // that finishes before the ⏳ reaches the API must never leave ✅→⏳ reordered. | ||||||||||
| const pendingAck = emitRouteReaction(route, messageId, STATUS_PENDING); | ||||||||||
| try { | ||||||||||
| // Wrap so a SYNCHRONOUS throw from the executor becomes a rejection the | ||||||||||
| // race can observe — and so `aborted` always gets a handler attached | ||||||||||
|
|
@@ -768,11 +771,14 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| ); | ||||||||||
| publish(replySubject, buildRoutedReplyPayload(route.instance, route.chat, content, genId(), now())); | ||||||||||
| // ✅ once a genuine reply is published; ❌ on a non-zero exit or soft error. | ||||||||||
| emitRouteReaction(route, messageId, ok ? STATUS_APPROVED : STATUS_DENIED); | ||||||||||
| // Chained on the ⏳ emit's settlement (fulfilled even when it failed) so the | ||||||||||
| // pair reaches the API in order; still fire-and-forget for this run. | ||||||||||
| pendingAck.finally(() => emitRouteReaction(route, messageId, ok ? STATUS_APPROVED : STATUS_DENIED)); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only chain the final reaction if
Suggested change
|
||||||||||
| } catch (err) { | ||||||||||
| const content = err instanceof OneShotTimeoutError ? timeoutNotice(timeoutMs) : errorNotice(errText(err)); | ||||||||||
| publish(replySubject, buildRoutedReplyPayload(route.instance, route.chat, content, genId(), now())); | ||||||||||
| emitRouteReaction(route, messageId, STATUS_DENIED); // ❌ on timeout / crash | ||||||||||
| // ❌ on timeout / crash — same ordering chain as the success path. | ||||||||||
| pendingAck.finally(() => emitRouteReaction(route, messageId, STATUS_DENIED)); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
| } finally { | ||||||||||
| clearTimeout(timer); | ||||||||||
| controller.abort(); // ensure a still-running child is killed on every path | ||||||||||
|
|
@@ -817,6 +823,10 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| * successful set: a dropped/failed react leaves `last_status_glyph` unchanged so | ||||||||||
| * the reconciliation pass retries it next tick. Never throws — a failed status | ||||||||||
| * reaction is logged and the approval decision still stands. | ||||||||||
| * | ||||||||||
| * Returns the emit's SETTLEMENT promise (always fulfilled — rejections are | ||||||||||
| * swallowed above; no-op emits resolve immediately) so a caller can sequence a | ||||||||||
| * follow-up ack after this one without ever awaiting it on the hot path. | ||||||||||
| */ | ||||||||||
| function emitReaction(params: { | ||||||||||
| instance: string; | ||||||||||
|
|
@@ -827,10 +837,10 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| recordGlyph: boolean; | ||||||||||
| /** Apply the `ackInFlight` double-fire guard (approval reconciliation only). */ | ||||||||||
| guard: boolean; | ||||||||||
| }): void { | ||||||||||
| }): Promise<void> { | ||||||||||
| const { instance, chat, targetId, emoji, recordGlyph, guard } = params; | ||||||||||
| if (!targetId) return; | ||||||||||
| if (guard && ackInFlight.has(targetId)) return; | ||||||||||
| if (!targetId) return Promise.resolve(); | ||||||||||
| if (guard && ackInFlight.has(targetId)) return Promise.resolve(); | ||||||||||
| if (guard) ackInFlight.add(targetId); | ||||||||||
| const react = setReaction({ instance, chat, messageId: targetId, emoji }) | ||||||||||
| .then((res) => { | ||||||||||
|
|
@@ -846,6 +856,7 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| inFlightReactions.delete(react); | ||||||||||
| }); | ||||||||||
| inFlightReactions.add(react); | ||||||||||
| return react; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** Approval-scoped ⏳/✅/❌ ack: scoped to the approval chat, glyph-recorded and | ||||||||||
|
|
@@ -867,10 +878,12 @@ export function createOmniRunner(deps: OmniRunnerDeps): OmniRunner { | |||||||||
| * route's own (instance, chat), NOT the approval chat. No glyph is recorded (a | ||||||||||
| * plain inbound has no approval row) and no reconciliation guard applies (the | ||||||||||
| * ⏳→✅/❌ pair fires exactly once, sequentially, per run). A missing messageId is | ||||||||||
| * a no-op. Fire-and-forget, drained by `whenIdle`; never blocks the run. | ||||||||||
| * a no-op. Fire-and-forget, drained by `whenIdle`; never blocks the run. Returns | ||||||||||
| * the emit's settlement promise so {@link runOneShot} can chain the final ✅/❌ | ||||||||||
| * after the ⏳ has landed (else a fast run could get its acks reordered at the API). | ||||||||||
| */ | ||||||||||
| function emitRouteReaction(route: OmniRoute, messageId: string | undefined, emoji: string): void { | ||||||||||
| emitReaction({ | ||||||||||
| function emitRouteReaction(route: OmniRoute, messageId: string | undefined, emoji: string): Promise<void> { | ||||||||||
| return emitReaction({ | ||||||||||
| instance: route.instance, | ||||||||||
| chat: route.chat, | ||||||||||
| targetId: messageId, | ||||||||||
|
|
||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
messageIdis not provided (which is common for messages that do not support reactions), callingemitRouteReactionand chaining on its promise is unnecessary. We can optimize this by only creating the promise chain whenmessageIdis present, avoiding useless promise allocations and microtask scheduling on the hot path.