Skip to content

Commit 09ced53

Browse files
luisleo526claude
andcommitted
integration: a runtime block leaves only while it is the one in force -- debug builds hold the LIFO order D2-C's install/uninstall relies on
internal::uninstall_runtime_ambient (R5 lane D2-C) copies the block's values into the block it covered and makes that one current again. That is right only while blocks leave in the reverse order they came: the block removed must be the calling thread's block in force. PumpScope guarantees it by construction -- the outermost scope of the pump that installed a block ends on the thread that installed it, and a pump nested inside (another engine run from a callback) has handed its own block back before -- but nothing checked it. Debug builds (NDEBUG undefined: the debug and sanitizers CI profiles build Debug) now abort when tl_runtime_ambient.installed is not &block, the kernel's own idiom for such checks (native_execution_consumer.cpp's #ifndef NDEBUG std::abort blocks). Release builds compile nothing: no cost, no behaviour change, no value moves. What could violate it: a consumer whose first pump_ambient() of a pump comes while another consumer's block, installed inside that same pump, is still in force -- its block would then cover the inner one and the inner pump's end would remove a block that is not in force. No caller does that: every scope asks its own consumer's block (the host's publication and suppressed tail, both request.security warm-up scopes, dispatch_security_eval), and D2-C's witnesses -- two streams interleaved input by input on one thread, a run nested in another host's calculation (the outer host installs its block before it runs the inner one), two threads at once -- all install and remove in stack order; the debug and sanitizer profiles run every test under the check. Rule 2 (ADR-0001): no behaviour change -- a debug-build check of the library's own per-thread state. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9bb1f7c commit 09ced53

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/ta_extremes_volume.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <algorithm>
1717
#include <cmath>
18+
#include <cstdlib>
1819
#include <numeric>
1920
#include <string>
2021
#include <unordered_map>
@@ -37,6 +38,12 @@ RuntimeAmbient* install_runtime_ambient(RuntimeAmbient& block) noexcept {
3738

3839
void uninstall_runtime_ambient(RuntimeAmbient& block, RuntimeAmbient* covered) noexcept {
3940
ThreadRuntimeAmbient& thread = tl_runtime_ambient;
41+
#ifndef NDEBUG
42+
// Blocks leave in the reverse order they came: the block removed is the
43+
// one in force on this thread (a nested pump has handed its own back).
44+
// Debug builds hold that order; release builds pay nothing for it.
45+
if (thread.installed != &block) std::abort();
46+
#endif
4047
(covered ? *covered : thread.own) = block;
4148
thread.installed = covered;
4249
}

0 commit comments

Comments
 (0)