Skip to content

Commit 2878cba

Browse files
committed
docs(ai): execute AI visibility protocol to expose architectural rationale
- Promoted IMMORTAL_RATIONALE.md to top-level docs/ directory. - Updated root README to guide agentic crawlers (e.g. Grok) to the core C++ latency covenants and SKILLS registry. - Explicitly unignored .agent/ and docs/ paths in .gitignore to ensure they are proactively pushed to the remote repository for external indexing.
1 parent a7f898e commit 2878cba

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ client/desktop/tauri-app/src-tauri/src/*.bak.*
117117
# project_status.md
118118
# docs/technical_whitepaper.md
119119

120+
# Explictly guarantee AI Agent visibility for indexing
121+
!docs/
122+
!.agent/
123+
!.agent/skills/
124+
120125
# Data
121126
*.dbn
122127
*.zst

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ QuanuX is the **first** quantitative trading platform to offer an official **Con
7474

7575
---
7676

77+
## 🤖 AI Agent & Architectural Rationale
78+
79+
QuanuX is built to be understood and extended by both humans and AI agents.
80+
To ensure our foundational architectural rules (such as the 59ns C++ latency path and the 64-byte L1 cache covenant) are preserved, we maintain a set of explicit instructions and skills:
81+
82+
* **[Immortal Rationale](docs/IMMORTAL_RATIONALE.md)**: The core C++ engine architecture, historical latency decisions, and memory layouts.
83+
* **[Agent Skills Directory](.agent/skills/)**: High-fidelity AI operating procedures and capabilities logically separated by component domain (`SKILL.md`).
84+
* **Man Pages**: Operator runbooks logically defined in `server/docs/man`.
85+
86+
Agentic systems evaluating this repository must prioritize reading `docs/IMMORTAL_RATIONALE.md` before embarking on modifications to execution nodes, execution loops, or distributed architectures.
87+
88+
---
7789
## 🔌 Universal Connectivity & Integrations
7890

7991
The "Bolt-On" architecture means we integrate with **everything**.

docs/IMMORTAL_RATIONALE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# The Immortal Rationale: Forging the 59ns QuanuX-Spreader
2+
3+
*"To go fast, you must despise the OS. To go instantly, you must despise the compiler."* — QuanuX Engineering
4+
5+
This document records the architectural crusade that dragged the `QuanuX-Spreader` from a respectable 250 microsecond latency profile down to its physical barrier: a 59 nanosecond "Happy Path."
6+
7+
Future AI Agents generating or modifying the `QuanuX-Spreader` Engine or its strategies are bound by this covenant. If an agent questions the rigid C-types or the lack of dynamic structures, they must reference this history.
8+
9+
## Epoch 1: The 250µs Trap (JSON & The Network)
10+
Early iterations of the spreader behaved like a naive microservice.
11+
* **The Trap:** It subscribed to a NATS topic, parsed a JSON payload carrying market ticks, mapped it to a `std::unordered_map` for LOCF (Last Observation Carried Forward) tracking, and evaluated math.
12+
* **The Cost:** JSON parsing costs minimums of 50-100µs. A `std::unordered_map` hash calculation and branch evaluation costs 50-200ns per lookup. This created massive "Jitter," destroying standard deviation guarantees.
13+
* **The Pivot:** We abandoned JSON-over-NATS completely for this engine. We shifted to raw `MARKET.BIN` binary payloads. The Spreader now executes a bare-metal `reinterpret_cast<const MarketTick*>` directly against the NATS socket ingress buffer, achieving zero-copy wire-to-math.
14+
15+
## Epoch 2: The DuckDB Sideshow
16+
We needed archival logs of triggered spread conditions for Phase 5 (The Analytics Dashboard).
17+
* **The Trap:** Traditional DB inserts (`INSERT INTO ticks...`) or even asynchronous HTTP logging introduced kernel context switches. A system call blocks the CPU core, obliterating the 59ns threshold.
18+
* **The Pivot:** DuckDB was selected explicitly for its C++ Appender API and in-process nature. In the producer thread, appending is treated as a deferrable "Sideshow." It happens only after the SPSCQueue has been populated, and it's vectorized to maximize L3 cache line flushing rather than network I/O.
19+
20+
## Epoch 3: The LOCF PriceMatrix (Array > Map)
21+
To track Spread Legs (Leg A, Leg B), the strategy logic must maintain memory of the most recent price.
22+
* **The Trap:** `std::map<string, double>` uses string hashing, allocator pointers, and red-black tree traversal. Every lookup was a cache miss.
23+
* **The Pivot:** The "Flat Lookup Table." We developed `PriceMatrix`: a `alignas(64)` cache-line protected `std::array<PriceEntry, 8192>`. We identify instruments with an integer `instrument_id`. Lookups dropped from O(log n) tree traversal down to **O(1) 1-cycle pointer arithmetic**.
24+
25+
## Epoch 4: The Dictator Compiler & The Cython Forge
26+
The final frontier was the research-to-production gap. Data analysts write Python; hardware executes C++.
27+
* **The Trap:** Attempting to run a Python runtime (via Cython `Py_Initialize()` or `pybind11`) inside the 59ns loop created the GIL (Global Interpreter Lock) threshold and unpredictable garbage collections.
28+
* **The Pivot:** The "Cython Forge." We inverted the relationship. Instead of C++ executing Python, we used Cython strictly as a transcompiler (`quanuxctl spreader package`). It parses Pythonic intent (via JSON IR schemas) into hyper-strict `extern "C++"` constructs (like `strategy_injected.hpp`).
29+
* This enabled the **64-Byte Guard**: By enforcing C-types (`double`, `uint32_t`), CMake can successfully assert that `sizeof(StrategyState) <= 64`. This structurally prevents an L1 cache spillover during the Thread 1 to Thread 2 DMA handshake.
30+
* The identical `_wrapper.pyx` allowed the Python backtester (Crucible) to invoke the native C++ math, ensuring 100% mathematical parity.
31+
32+
## Epoch 5: Zero-Overhead Telemetry
33+
Observability is a poison pill for latency. Standard `std::cout` or spdlog blocks IO.
34+
* **The Trap:** Logging tick arrivals or latency metrics destroyed the pipeline.
35+
* **The Pivot:** We hijacked the existing `update_seq` "Dirty Bit" in the `PriceMatrix`. We replaced 4 bytes of explicit padding with a `uint32_t arrival_tsc` timestamp. Now, telemetry is purely passive. We `mmap` the `PriceMatrix` array into POSIX shared memory. External `quanux-spreader` man pages instruct humans to read the SHM segment to track engine health without the Executive Loop ever executing a single `write()` system call.
36+
37+
**End of Rationale.**

0 commit comments

Comments
 (0)