Skip to content

Deferred callback responses for cppFunction (#459) - #496

Merged
ambroise-leclerc merged 13 commits into
457-review-followupsfrom
459-deferred-callbacks
Nov 5, 2026
Merged

ambroise-leclerc merged 13 commits into
457-review-followupsfrom
459-deferred-callbacks

Conversation

@ambroise-leclerc

Copy link
Copy Markdown
Collaborator

Part of #448 (system services, step 3). Closes #459. Stacked on #494: the base becomes develop once it is merged.

cppFunction accepts a callback that returns a sender (a webfront::ResultTask<R> coroutine, new public alias of ex::task<R>, or ResultTask<void>). The JavaScript Promise settles when it completes, with the encoded value, or rejects with its message and code (#458); a sender that completes stopped without a stop request rejects with webfront.cancelled.

  • The work is spawned in the server scope and tracked per connection (detail::DeferredCalls): the browser's disconnection stops it and drops the late answer; shutdown stops and joins it. The answer is sent on the server context.
  • Several calls per connection can be in flight, each with the identifier JavaScript chose; an identifier still in flight is refused with webfront.malformed and the running call is untouched. Saturation is JavaScript's existing 65,535 outstanding calls limit.
  • No change to the binary format (existing correlated return).

ADR-004 2.6, docs/ASYNC_EXECUTION.md, AGENTS.md and the ADR-020 example are updated.

Tests

  • Catch2 (DeferredCallTests): deferred result, exception before and after suspension, stopped operation, void task, caller-taking callback, concurrent calls, duplicate identifier, disconnection while waiting, shutdown while waiting.
  • Jasmine: Promise resolved after a delay, rejected with a code, concurrent calls finishing out of order.
  • ctest -L fast passes with CEF off.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 12:08
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cc4ff176-9552-4961-a77a-e303f07ee921

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

A moderate issue remains where a failed responder task spawn can permanently reserve a call ID because DeferredCalls::finish() is never invoked, potentially causing later requests to be rejected as already in use and leaving a promise hanging.

2 open issues
What changed in this PR

Deferred callback responses for cppFunction: extends WebFront’s JavaScript→C++ bridge so cppFunction callbacks can return a sender (e.g., webfront::ResultTask<R> / ResultTask<void>), and the JavaScript Promise settles when that async work completes. In-flight deferred calls are tracked per connection so disconnect/shutdown stops pending work and late answers are dropped, with docs/ADRs and tests updated accordingly.

Changes:

  • Add deferred cppFunction execution path that spawns server-scoped work and correlates responses by per-connection call ID.
  • Introduce public webfront::ResultTask<R> alias for result-bearing coroutine/sender returns.
  • Add Catch2 + Jasmine coverage and update async execution documentation plus ADRs/contributor guidance.

Review notes (must address):

  • (moderate, include/webfront/WebFront.hpp:1032) startDeferred() invokes the callback before reserving the callId; rejected calls may still trigger side effects—reserve first.
  • (moderate, include/webfront/WebFront.hpp:369) makeValueFrame() only catches std::exception; catch unknown exceptions too to avoid terminate() for non-std throws during encoding.
  • (moderate, include/webfront/WebFront.hpp:1054) If responder task spawn is rejected, the call ID can remain reserved indefinitely because finish() is never reached—ensure cleanup on spawn failure.
  • (nit, include/webfront/DeferredCalls.hpp:40) Tighten the deferred sender concept so “at most one value” constraints fail at the concept boundary with the intended diagnostics.
  • (nit, include/webfront/WebFront.hpp:1076) Instantiate detail::deferred_value_t<Sender> to trigger the dedicated static_assert diagnostics for multi-value senders.
File Summary
test/​web/​suite/​specs/​webfront-specs.mjs Adds browser integration specs for deferred Promise resolution/rejection and out-of-order completion.
test/​web/​JasmineTest.cpp Registers deferred C++ callbacks used by the Jasmine suite.
test/​unit/​DeferredCallTests.cpp Adds unit tests for deferred result, exceptions (pre/post-suspension), stop, void task, concurrency, duplicate IDs, disconnect, and shutdown.
test/​unit/​CMakeLists.txt Wires the new unit tests into the build/unity configuration.
include/​webfront/​WebFront.hpp Implements deferred callback dispatch, connection-scoped tracking, and deferred response sending.
include/​webfront/​Task.hpp Adds public webfront::ResultTask<R> alias for result-bearing coroutines/senders.
include/​webfront/​DeferredCalls.hpp Adds per-connection tracking for in-flight deferred calls and cancellation/finish handling.
docs/​ASYNC_EXECUTION.md Documents deferred callback semantics, lifecycle rules, and usage.
docs/​adr/​ADR-020-services-systeme.md Updates ADR-020 example/assumptions to reflect deferred cppFunction support.
docs/​adr/​ADR-004-appels-asynchrones-et-erreurs.md Updates ADR-004 (v2.6) to describe deferred callback responses and error behavior.
AGENTS.md Updates contributor guidance to mention sender-returning cppFunction callbacks and lifecycle behavior.

This pull request requires changes.

Review effort: Balanced

Comment thread include/webfront/WebFront.hpp Resolved
Comment thread include/webfront/WebFront.hpp Resolved
Base automatically changed from 456-bridge-types to develop November 5, 2026 15:35
@ambroise-leclerc
ambroise-leclerc changed the base branch from develop to 457-review-followups November 5, 2026 15:42
@ambroise-leclerc
ambroise-leclerc merged commit 96c956c into 457-review-followups Nov 5, 2026
9 checks passed
@ambroise-leclerc
ambroise-leclerc deleted the 459-deferred-callbacks branch November 5, 2026 17:06
@ambroise-leclerc

Copy link
Copy Markdown
Collaborator Author

Both points are fixed in e068b40 (the deferred-call code lives in this PR):

  • P1: a deferred callback now goes through makeDeferredHandler: the decoded arguments are allocated once and kept in the operation state of the returned sender (let_value(just(arguments), …)), so a coroutine taking const std::string& still reads its argument after the handler returned. A test with a by-reference coroutine and a 60-byte argument passes under ASan.
  • P2: startDeferred claims the identifier before invoking the callback, and releases it if the callback throws; a duplicate is refused without running it. A test whose callback has a side effect before returning its task checks that it ran once.

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.

Callbacks C++ asynchrones : réponse différée du pont

2 participants