Files
logos-cpp-sdk/doctests/cpp-sdk-concurrent-dispatch.test.yaml
Dario LipicarandClaude Opus 5 198f0317ca feat(optional): ?T is two-state, and the generators finally read it (#125)
* feat(optional): ?T is two-state, and the generators finally read it

No generator in any language read the optional flag — it had never been
implemented. `?T` was a HARD REJECT on the cdylib backend ("module not
cdylib-eligible"), `std::optional<T>` in an impl header fell through to the
opaque `any` with no diagnostic, and a `? name: T` field was emitted as a
required `T`. Three real contracts in the workspace already declare optionals
and were silently getting one of those three answers.

`?T` is TWO-state: a value of T, or empty. Never three — "one LIDL type <-> one
type per language" leaves nowhere for a third state, because every target has
exactly one empty inhabitant.

ONE MEANING, TWO SPELLINGS. `? name: T` (the field flag) and `name: ?T` (the
type kind) are the same declaration. Backends no longer answer that themselves:
logos-lidl's fieldIsOptional/fieldValueType are re-exported from lidl_compat.h
and every site THIS COMMIT TOUCHES reads them, so the two spellings emit
byte-identical code on the cdylib and client backends. That
caught a live drift on the way in — lidlRecordCollidesWithBytesTag read `f.type`
and so refused `? _bytes: tstr` while letting `_bytes: ?tstr` straight through,
one declaration with two answers.

THE WIRE RULE DEPENDS ON THE SLOT. Absent and explicit null are the SAME state
on decode and DIFFERENT on encode:
  - decode is liberal, by exactly one inhabitant: in an optional slot absent and
    null both mean empty; in a required slot both stay errors. A present value
    goes through the decoder a required T would get, so a wrong type still fails
    at the same path — optional widens the domain, it does not switch checking
    off. `?bstr` therefore keeps the LENIENT bytes decode a bare `bstr` gets,
    rather than silently becoming stricter in the optional slot.
  - encode has one canonical form: empty OMITS the key where the slot is NAMED
    (a record field) and is spelled null where it is POSITIONAL (an argument, a
    return, an event parameter — no key to omit, and arity must not change). Key
    omission lives in the record emitter because a Codec only ever sees a value,
    never the slot it sits in. A round trip therefore canonicalises.
  - `?any` collapses onto `any`: nlohmann::json already carries null, so
    std::optional<LogosMap> would give the slot two spellings of empty.

The dispatch gate now admits a missing trailing optional argument and
materialises it as null, exactly the way a missing record field already was. A
method with no optional parameter emits the byte-identical gate it always did.

Header-first: `std::optional<T>` <-> `?T`, composing with records and
containers. `std::optional<std::optional<T>>` has NO LIDL type (three C++ states
over a two-state wire), so it maps down to `?T` — which makes the author's own
declaration stop compiling against the generated codec, deliberately — and says
so at derivation time instead of leaving a conversion error in generated code.

The Qt/Lp consumer surface is NOT fixed and does not pretend to be. The wrappers
real modules get come from legacy/main.cpp, where the AST is flattened to a
single Qt type-name string per slot before optionality could be seen; Qt has no
optional metatype, so `?T` lands on QVariant — the right shape (an invalid
QVariant is Qt's empty inhabitant) with no type. The generator now prints a Note
naming every flattened slot so an affected build is never silent, and
docs/project.md records exactly what a Qt consumer will still do with an
optional field.

Verified by output equivalence, not by a green build: the generator was built
before and after and run over every .lidl in the workspace plus the impl-header
fixtures, in cdylib, consumer-qt, consumer-lp, client and header-first modes.
428 of 465 artefacts are byte-identical; all 37 that differ belong to one of the
four contracts that declare an optional (the 38th path is the manifest). The
harness's sensitivity is pinned by a negative control: qt vs lp output differs
in 45 files. The emitted codec was additionally compiled under -Wall -Wextra and
run against the rules above — omission, absent==null, required-still-rejects,
present-but-wrong-still-fails, and canonicalising round trip.

Tests: 199 pass, 0 fail (180 before, 19 new).

Requires logos-lidl's optionality accessors and logos-protocol's
Codec<std::optional<T>>.

NOT FIXED, AND IT IS THE PATH THAT MATTERS MOST. The legacy interface-wrapper
path is untouched, and it is the one every real module builds through
(buildPlugin.nix:145 -> logos-cpp-generator --general-only). There the two
spellings still diverge:

  ? maybe: tstr   ->  QString maybe{};   __m.value("maybe").toString()
  maybe: ?tstr    ->  QVariant maybe{};  __m.value("maybe")

and --api-style lp diverges too, neither side being std::optional. So R3 holds
on the backends below and NOT on the Qt consumer a shipping module actually
gets. logos-chat-module -- the contract that prompted this work -- uses the
field-flag spelling, so it lands on the branch that silently defaults.

The cause is upstream of codegen: legacy/main.cpp's moduleRecordsToJson and
moduleMethodsToJson flatten every TypeExpr to a single Qt TYPE-NAME STRING, so
optionality (along with nesting, map key types and descriptions) is gone before
generator_lib.cpp sees it. Widening that interface is a larger change and is
deliberately not attempted here. The only R3 test on a Qt surface covers
lidl_gen_client.cpp, which is on no live build path.

* chore: re-pin logos-lidl to master for the optionality accessors

lidl_compat.h re-exports typeIsOptional / optionalValueType / fieldIsOptional /
fieldValueType / paramIsOptional / paramValueType, which landed in
logos-lidl#7. The pinned lidl predated it, so CI failed to compile.

logos-lidl 8c95d4f -> 35f33d8. Tests: 199 pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: re-pin logos-protocol to master for Codec<std::optional<T>>

The generated record codecs emit Codec<std::optional<T>> for an optional
field; that specialisation landed in logos-protocol#37 and the pinned
protocol predated it.

Note this repo's own tests would NOT have caught the omission -- the
generator tests string-assert emitted text rather than compiling it, so a
missing codec specialisation only surfaces when a real module compiles
generated optional code (logos-test-modules' ext provider).

logos-protocol 4359557 -> 72754ab. Tests: 199 pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(doctests): override logos-lidl alongside every logos-cpp-sdk override

The doc-tests build downstream repos (logoscore-cli, capability_module,
accounts_module) with --override-input logos-cpp-sdk. Nix does not carry the
overridden input's OWN lock, so those builds got this branch's cpp-sdk source
while still resolving logos-lidl from their own, older locks. The shipped
share/lidl-frontend/lidl_compat.h then calls accessors that lidl does not
have:

  lidl_compat.h:46: error: 'paramValueType' has not been declared in 'lidl'
  lidl_compat.h:92: error: 'fieldValueType' was not declared in this scope

Every --override-input logos-cpp-sdk now has a matching
--override-input <same-path>/logos-cpp-sdk/logos-lidl.

This is specific to the override path. A normal consumer running
'nix flake update logos-cpp-sdk' inherits cpp-sdk's own lock, which pins the
lidl carrying these accessors, and is unaffected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(doctests): move logos-lidl at the qt-sdk nodes, not under logos-cpp-sdk

The doc-tests failed to build logos-qt-generator:

  share/lidl-frontend/lidl_compat.h:46: error: 'paramValueType' has not been
  declared in 'lidl'

MECHANISM. This SDK installs cpp-generator/experimental/lidl_compat.h into
$out/share/lidl-frontend/, and logos-qt-sdk's logos-qt-generator *compiles*
that installed header against qt-sdk's OWN logos-lidl input. Under
logos-qt-sdk, logos-lidl is a SIBLING of logos-cpp-sdk, not a descendant:

  logos-qt-sdk
  |-- logos-cpp-sdk   <- --override-input moves this to the commit under test
  `-- logos-lidl      <- stays on qt-sdk's lock (8c95d4f), lacks the accessors

logos-logoscore-cli and logos-module-builder both declare
`logos-qt-sdk.inputs.logos-cpp-sdk.follows = "logos-cpp-sdk"` but no lidl
follows, so overriding the SDK hands qt-sdk a new lidl_compat.h next to its
old lidl. The failing derivation is logos-qt-generator — not anything in
logos-cpp-sdk, which is why the previous attempt aimed at the wrong node.

THE FIX is one `<path-to-logos-qt-sdk>/logos-lidl` override per qt-sdk node
that ends up on the SDK under test. A tree-walk over the resolved lock found
four in logoscore-cli's closure and two per module build; with the overrides
applied the walk reports zero remaining.

WHAT WAS REMOVED, and why it was doing nothing:

  * The `.../logos-cpp-sdk/logos-lidl` overrides added in bef3ef5 were no-ops.
    With only `--override-input logos-cpp-sdk <sha>`, that node's logos-lidl
    already resolves to 35f33d87 out of cpp-sdk's own lock — nix >= 2.26
    carries an overridden input's lock, and CI runs Determinate Nix. Verified
    by resolving the lock with and without them: byte-identical.
  * The `logos-module-client/...` overrides never matched anything. Nix says so
    out loud ("does not match any input"): logoscore-cli has no such root
    input; module-client only appears under logos-test-modules/, outside the
    runtime closure. The prose claiming it pins the SDK is corrected too.

cpp-sdk-concurrent-dispatch is fixed here as well — it failed the same way and
carried no lidl overrides at all.

VERIFIED locally against bef3ef5, the exact commit CI failed on:

  * accounts .lgx  -> exit 0, logos-accounts_module-module-lib.lgx (5,939,898 B)
  * logoscore CLI  -> exit 0, ./logos/bin/logoscore reports
                      "logos-cpp-sdk bef3ef57d3f489073672e70a786c550df7edd003"
  * negative control (same command minus the single qt-sdk lidl flag) fails
    with CI's exact derivation,
    /nix/store/pf96n2ldvhy6sq39ygkh5zdqx7dcn4df-logos-qt-generator-0.1.0.drv
  * no "does not match any input" warnings remain on any command

The durable fix is a one-line bump of logos-qt-sdk's own flake.lock logos-lidl
to master (logos-lidl#7 is purely additive: six new inline helpers, nothing
removed or renamed). Once qt-sdk carries it, every override added here can go.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 07:19:47 -03:00

392 lines
21 KiB
YAML

name: "Concurrent Dispatch (C++): a single-threaded module driving a concurrent one"
output: cpp-sdk-concurrent-dispatch.md
project_name: cpp-concurrent-dispatch
release: ""
intro: |
By default a Logos module handles calls **one at a time** — every method runs
on the module's event loop, so the author never thinks about thread-safety. A
handler that blocks (a slow download, a slow RPC) then stalls *every other
caller* until it returns.
Setting **`"concurrency": "multi"`** in `metadata.json` opts a module into
**concurrent dispatch**: each incoming call runs on its own worker thread, so
one blocking handler no longer holds up the others. The author takes on
thread-safety in exchange — the impl's methods may run in parallel, so any
shared state must be synchronized (here, `std::atomic`).
This doc-test builds two C++ modules and proves it end-to-end through a headless
`logoscore` daemon:
| Module | `concurrency` | Role |
|---|---|---|
| `slow_worker_module` | **`"multi"`** | `work(ms)` blocks for `ms`, recording the PEAK number of calls running at once |
| `fanout_driver_module` | `"single"` (default) | an ordinary single-threaded module that fires several `work` calls at the worker without waiting between them (the generated `workAsync` client) |
The driver is single-threaded, yet it drives the worker concurrently: it fires
N async calls back-to-back, and because the worker is `multi`, all N run at
once. We then read the worker's observed peak overlap — it equals N. Flip the
worker to `"single"` and the same fan-out would serialize (peak 1).
what_you_build: "Two composed C++ modules — a concurrency:\"multi\" worker and an ordinary single-threaded driver — showing a single module driving concurrent work in a multi module, validated through a logoscore daemon."
what_you_learn:
- "What `concurrency: \"multi\"` does for a C++ module and when to use it"
- "The multi contract for C++: the impl's methods run concurrently, so shared state must be self-synchronized (std::atomic / std::mutex)"
- "How a single-threaded caller drives concurrent work: fire `modules().<dep>.<method>Async(...)` without waiting between calls"
- "That a multi worker overlaps those calls (peak == N) while a single worker would serialize them (peak 1)"
prerequisites:
- |
**Nix** with flakes enabled. Install from [nixos.org](https://nixos.org/download.html), then enable flakes:
```bash
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
```
Verify: `nix flake --help >/dev/null 2>&1 && echo "Flakes enabled"`
- "**A Linux or macOS machine.** Nix provides every toolchain (Qt, CMake) during the builds."
sections:
- title: "Build the tools"
step: true
steps:
- title: "Build logoscore"
run: "nix build 'github:logos-co/logos-logoscore-cli' --out-link ./logos"
code_block: |
nix build 'github:logos-co/logos-logoscore-cli' --out-link ./logos
check_file: "logos/bin/logoscore"
- title: "Build lgpm"
run: "nix build 'github:logos-co/logos-package-manager#cli' -o lgpm"
check_file: "lgpm/bin/lgpm"
- title: "Module 1 — the concurrent worker (`slow_worker_module`)"
step: true
text: |
A universal C++ module whose `work(ms)` blocks for `ms`. The single thing
that makes it concurrent is **`"concurrency": "multi"`** in its metadata.
Under multi dispatch its methods run on worker threads, so the overlap
counter is `std::atomic` — the author owns thread-safety.
steps:
- title: "The implementation — plain C++, header-only"
text: |
Create `slow-worker/src/slow_worker_module_impl.h` — **declarations only**.
The generator parses this header for the method signatures, so the bodies
live in a `.cpp` (next step); inline bodies would let the header→`.lidl`
extraction pick up the calls *inside* them. The counters are atomics
because `work` may run on several threads at once:
file:
path: slow-worker/src/slow_worker_module_impl.h
language: cpp
content: |
#pragma once
#include <atomic>
#include <cstdint>
#include <logos_module_context.h> // LogosModuleContext base
// A concurrency:"multi" worker. work(ms) blocks for ms and records the PEAK
// number of calls running at the same instant. Multi dispatch runs the
// methods on worker threads, so the counters are atomic.
class SlowWorkerModuleImpl : public LogosModuleContext {
public:
int64_t work(int64_t ms);
int64_t peak();
private:
std::atomic<int64_t> m_inFlight{0};
std::atomic<int64_t> m_maxSeen{0};
};
- title: "The impl .cpp — the method bodies"
text: |
The bodies live in the `.cpp` (added to the module's sources via
`extra_sources`), keeping the parsed header a clean list of signatures:
file:
path: slow-worker/src/slow_worker_module_impl.cpp
language: cpp
content: |
#include "slow_worker_module_impl.h"
#include <chrono>
#include <thread>
int64_t SlowWorkerModuleImpl::work(int64_t ms) {
int64_t now = m_inFlight.fetch_add(1) + 1;
int64_t prev = m_maxSeen.load();
while (now > prev && !m_maxSeen.compare_exchange_weak(prev, now)) { /* retry */ }
std::this_thread::sleep_for(std::chrono::milliseconds(ms > 0 ? ms : 0));
m_inFlight.fetch_sub(1);
return ms;
}
int64_t SlowWorkerModuleImpl::peak() { return m_maxSeen.load(); }
- title: "metadata.json — note `concurrency: \"multi\"`"
text: |
`interface: "universal"` is the pure-C++ path; **`concurrency: "multi"`**
turns on concurrent dispatch:
file:
path: slow-worker/metadata.json
language: json
content: |
{
"name": "slow_worker_module",
"version": "1.0.0",
"description": "A concurrency:multi worker: work(ms) blocks and records peak overlap",
"author": "Logos Core Team",
"type": "core",
"interface": "universal",
"concurrency": "multi",
"category": "general",
"main": "slow_worker_module_plugin",
"dependencies": [],
"codegen": { "impl_class": "SlowWorkerModuleImpl", "impl_header": "slow_worker_module_impl.h" },
"nix": { "external_libraries": [], "packages": { "build": [], "runtime": [] }, "cmake": { "find_packages": [], "extra_include_dirs": [], "extra_sources": ["src/slow_worker_module_impl.cpp"] } }
}
- title: "CMakeLists.txt + flake.nix"
file:
path: slow-worker/CMakeLists.txt
language: cmake
content: |
cmake_minimum_required(VERSION 3.14)
project(SlowWorkerModulePlugin LANGUAGES CXX)
if(DEFINED ENV{LOGOS_MODULE_BUILDER_ROOT})
include($ENV{LOGOS_MODULE_BUILDER_ROOT}/cmake/LogosModule.cmake)
else()
message(FATAL_ERROR "LOGOS_MODULE_BUILDER_ROOT is not set.")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/metadata.json
${CMAKE_CURRENT_BINARY_DIR}/metadata.json COPYONLY)
logos_module(NAME slow_worker_module
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/slow_worker_module_impl.cpp
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src)
- title: "flake.nix"
file:
path: slow-worker/flake.nix
language: nix
content: |
{
description = "concurrency:multi C++ worker";
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder{release}";
};
outputs = inputs@{ self, logos-module-builder, ... }:
let
nixpkgs = logos-module-builder.inputs.nixpkgs;
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems f;
in {
packages = forAllSystems (system:
(logos-module-builder.lib.mkLogosModule {
src = ./.;
configFile = ./metadata.json;
flakeInputs = inputs;
}).packages.${system});
};
}
- title: "Build it"
text: |
The `{release}` overrides point the builder's C++ SDK, Qt glue, and
protocol at the commits under test, so the concurrent-dispatch codegen +
runtime are the ones exercised:
run: "sh -c 'cd slow-worker && printf \"result\\nresult-*\\n\" > .gitignore && git init -q && git add -A && nix flake update && git add flake.lock && nix build .#lgx -o worker-lgx --override-input logos-module-builder \"github:logos-co/logos-module-builder{release}\" --override-input logos-module-builder/logos-cpp-sdk \"github:logos-co/logos-cpp-sdk{release}\" --override-input logos-module-builder/logos-qt-sdk \"github:logos-co/logos-qt-sdk{release}\" --override-input logos-module-builder/logos-qt-sdk/logos-lidl \"github:logos-co/logos-lidl\" --override-input logos-module-builder/logos-protocol \"github:logos-co/logos-protocol{release}\"'"
code_block: |
cd slow-worker
git init && git add -A && nix flake update && git add flake.lock
nix build .#lgx -o worker-lgx \
--override-input logos-module-builder/logos-cpp-sdk 'github:logos-co/logos-cpp-sdk' \
--override-input logos-module-builder/logos-qt-sdk 'github:logos-co/logos-qt-sdk' \
--override-input logos-module-builder/logos-qt-sdk/logos-lidl 'github:logos-co/logos-lidl' \
--override-input logos-module-builder/logos-protocol 'github:logos-co/logos-protocol'
check_file: "slow-worker/worker-lgx"
- title: "Module 2 — the single-threaded driver (`fanout_driver_module`)"
step: true
text: |
An ordinary module (no `concurrency` field → single-threaded) that depends on
the worker. `fanOut` fires N `workAsync` calls without waiting between them,
so all N reach the worker before any completes.
steps:
- title: "The impl header — declarations only (the generator parses this)"
file:
path: fanout-driver/src/fanout_driver_module_impl.h
language: cpp
content: |
#pragma once
#include <cstdint>
#include <logos_module_context.h> // LogosModuleContext base + modules()
// A single-threaded driver that drives the multi worker concurrently:
// fanOut fires N workAsync() calls back-to-back.
class FanoutDriverModuleImpl : public LogosModuleContext {
public:
// Fire `n` concurrent work(ms) calls at the worker; returns `n`.
int64_t fanOut(int64_t n, int64_t ms);
// Read the worker's observed peak overlap, THROUGH this driver.
int64_t peak();
};
- title: "The impl .cpp — the cross-module fan-out"
text: |
The `.cpp` includes the generated `logos_sdk.h` (which defines
`LogosModules`), so the cross-module calls live here, not in the header
the generator parses. The async client returns immediately:
file:
path: fanout-driver/src/fanout_driver_module_impl.cpp
language: cpp
content: |
#include "fanout_driver_module_impl.h"
// Generated at build time by logos-cpp-generator. Defines LogosModules with
// a typed accessor per dependency — here slow_worker_module.
#include "logos_sdk.h"
int64_t FanoutDriverModuleImpl::fanOut(int64_t n, int64_t ms)
{
for (int64_t i = 0; i < n; ++i) {
// Async typed client: fire and return immediately. We don't need the
// result here — the point is that all N reach the worker together.
modules().slow_worker_module.workAsync(ms, [](int64_t) {});
}
return n;
}
int64_t FanoutDriverModuleImpl::peak()
{
// Read peak via a SYNC call to the worker. The worker is `multi`, so its
// reply is deferred (a pending marker + completion event); this module's
// generated client awaits it transparently and returns the real number.
// (A protocol-0.1 caller — e.g. the logoscore CLI calling the worker
// directly — would instead see the raw pending marker, so we read peak
// through the driver.)
return modules().slow_worker_module.peak();
}
- title: "metadata.json — depends on the worker, no concurrency field"
file:
path: fanout-driver/metadata.json
language: json
content: |
{
"name": "fanout_driver_module",
"version": "1.0.0",
"description": "Single-threaded driver: fans out concurrent calls to slow_worker_module",
"author": "Logos Core Team",
"type": "core",
"interface": "universal",
"category": "general",
"main": "fanout_driver_module_plugin",
"dependencies": ["slow_worker_module"],
"codegen": { "impl_class": "FanoutDriverModuleImpl", "impl_header": "fanout_driver_module_impl.h" },
"nix": { "external_libraries": [], "packages": { "build": [], "runtime": [] }, "cmake": { "find_packages": [], "extra_include_dirs": [], "extra_sources": ["src/fanout_driver_module_impl.cpp"] } }
}
- title: "CMakeLists.txt + flake.nix"
file:
path: fanout-driver/CMakeLists.txt
language: cmake
content: |
cmake_minimum_required(VERSION 3.14)
project(FanoutDriverModulePlugin LANGUAGES CXX)
if(DEFINED ENV{LOGOS_MODULE_BUILDER_ROOT})
include($ENV{LOGOS_MODULE_BUILDER_ROOT}/cmake/LogosModule.cmake)
else()
message(FATAL_ERROR "LOGOS_MODULE_BUILDER_ROOT is not set.")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/metadata.json
${CMAKE_CURRENT_BINARY_DIR}/metadata.json COPYONLY)
logos_module(NAME fanout_driver_module
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/fanout_driver_module_impl.cpp
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src)
- title: "flake.nix — inputs the worker (its published contract drives the typed client)"
file:
path: fanout-driver/flake.nix
language: nix
content: |
{
description = "single-threaded C++ driver over the multi worker";
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder{release}";
# The worker's flake — its published .lidl drives modules().slow_worker_module.
# Placeholder; locked to the local checkout at build time via --override-input.
slow_worker_module.url = "path:/path/to/slow-worker";
};
outputs = inputs@{ self, logos-module-builder, ... }:
let
nixpkgs = logos-module-builder.inputs.nixpkgs;
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems f;
in {
packages = forAllSystems (system:
(logos-module-builder.lib.mkLogosModule {
src = ./.;
configFile = ./metadata.json;
flakeInputs = inputs;
}).packages.${system});
};
}
- title: "Build it"
run: "sh -c 'cd fanout-driver && printf \"result\\nresult-*\\n\" > .gitignore && git init -q && git add -A && nix flake update --override-input slow_worker_module path:$PWD/../slow-worker && git add flake.lock && nix build .#lgx -o driver-lgx --override-input slow_worker_module path:$PWD/../slow-worker --override-input logos-module-builder \"github:logos-co/logos-module-builder{release}\" --override-input logos-module-builder/logos-cpp-sdk \"github:logos-co/logos-cpp-sdk{release}\" --override-input logos-module-builder/logos-qt-sdk \"github:logos-co/logos-qt-sdk{release}\" --override-input logos-module-builder/logos-qt-sdk/logos-lidl \"github:logos-co/logos-lidl\" --override-input logos-module-builder/logos-protocol \"github:logos-co/logos-protocol{release}\" --override-input slow_worker_module/logos-module-builder/logos-cpp-sdk \"github:logos-co/logos-cpp-sdk{release}\" --override-input slow_worker_module/logos-module-builder/logos-qt-sdk \"github:logos-co/logos-qt-sdk{release}\" --override-input slow_worker_module/logos-module-builder/logos-qt-sdk/logos-lidl \"github:logos-co/logos-lidl\" --override-input slow_worker_module/logos-module-builder/logos-protocol \"github:logos-co/logos-protocol{release}\"'"
code_block: |
cd fanout-driver
git init && git add -A
nix flake update --override-input slow_worker_module path:$PWD/../slow-worker
git add flake.lock
nix build .#lgx -o driver-lgx \
--override-input slow_worker_module path:$PWD/../slow-worker \
--override-input logos-module-builder/logos-cpp-sdk 'github:logos-co/logos-cpp-sdk' \
--override-input logos-module-builder/logos-qt-sdk 'github:logos-co/logos-qt-sdk' \
--override-input logos-module-builder/logos-qt-sdk/logos-lidl 'github:logos-co/logos-lidl' \
--override-input logos-module-builder/logos-protocol 'github:logos-co/logos-protocol' \
--override-input slow_worker_module/logos-module-builder/logos-cpp-sdk 'github:logos-co/logos-cpp-sdk' \
--override-input slow_worker_module/logos-module-builder/logos-qt-sdk/logos-lidl 'github:logos-co/logos-lidl'
check_file: "fanout-driver/driver-lgx"
- title: "Run it: the single driver overlaps the multi worker"
step: true
steps:
- title: "Install the modules"
run: |
mkdir -p modules
cp -RL ./logos/modules/. ./modules/
./lgpm/bin/lgpm --modules-dir ./modules --allow-unsigned install --file slow-worker/worker-lgx/*.lgx
./lgpm/bin/lgpm --modules-dir ./modules --allow-unsigned install --file fanout-driver/driver-lgx/*.lgx
expect_contains:
- "Installed to:"
- title: "Start the daemon"
run: "sh -c './logos/bin/logoscore -D -m ./modules > logs.txt 2>&1 &'"
code_block: "logoscore -D -m ./modules > logs.txt &"
- run: "sleep 6"
- title: "Load the modules"
run: "./logos/bin/logoscore load-module fanout_driver_module"
code_block: "logoscore load-module fanout_driver_module"
expect_contains:
- "fanout_driver_module"
- "slow_worker_module"
- title: "Fan out 4 concurrent calls"
text: "`fanOut(4, 500)` fires four `work(500)` calls at the worker without waiting, and returns `4` immediately:"
run: "./logos/bin/logoscore call fanout_driver_module fanOut 4 500"
code_block: "logoscore call fanout_driver_module fanOut 4 500"
expect_contains:
- '"result":4'
- run: "sleep 2"
- title: "The worker ran them concurrently (peak == 4)"
text: |
`peak` is the most calls the worker saw running at once. Because the
worker is `concurrency: "multi"`, all four overlapped, so the peak is
**4**. Had the worker been `"single"`, the peak would be **1**. We read it
**through the driver** (`fanout_driver_module.peak`), which forwards to the
worker: the driver is a protocol-0.2 consumer, so it awaits the multi
worker's deferred reply and returns the real number:
run: "./logos/bin/logoscore call fanout_driver_module peak"
code_block: "logoscore call fanout_driver_module peak"
expect_contains:
- '"result":4'
- title: "Stop the daemon"
run: "./logos/bin/logoscore stop"
code_block: "logoscore stop"
- run: "sleep 2"
- run: "./logos/bin/logoscore status || true"
code_block: "logoscore status"
expect_contains:
- '"status":"not_running"'