Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/developer/build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build

> Last updated: 2026-09-10 · commit `4f29957d2`
> Last updated: 2026-09-12 · commit `1c4670fdf`

How to build every component of Darkbloom from a fresh clone: the Go
coordinator, the Rust prompt-contract sidecar, the Swift provider CLI (with its
Expand Down Expand Up @@ -223,6 +223,11 @@ ATTENTION_REPLAY_SOURCE_ROOT="$REPLAY_SOURCE_ROOT" \
Retain the executable SHA-256, source/dependency inventory, build graph,
`mlx.metallib` and SwiftPM resource bundles. An executable hash alone does not
bind external Metal resources. The Python driver never builds or downloads them.
After building against those reviewed resources, run the host-only input checks
with the same source-root binding and scratch directory using `swift test`
and `--filter ReplayHostTests`
(`scripts/benchmarks/attention-replay/Tests/AttentionReplayTests/ReplayHostTests.swift`,
`fifoInputIsRejectedWithoutWaitingForAWriter`).
Use the [offline NumPy environment](#offline-attention-analysis-environment) for
packet validation and the independent reference. See [replay validation](test.md#attention-operator-replay)
and the [source/test milestone](../reports/2026-09-06-attention-operator-replay.md).
Expand Down
7 changes: 5 additions & 2 deletions docs/developer/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test

> Last updated: 2026-09-11 · commit `d22ad0cf3`
> Last updated: 2026-09-12 · commit `1c4670fdf`

How to run the unit tests for each component, the end-to-end suite that boots a
real coordinator + Swift provider against ephemeral Postgres, and the docs
Expand Down Expand Up @@ -471,7 +471,10 @@ checked after evaluation. Paged dispatch is observed through the existing hook;
the synthetic selection is never marked as a confirmed model sample. Native SDPA
identifies the API invoked, not an instrumented internal MLX kernel variant.

`ReplayHostTests` covers bounded transfer/IO/options. `ReplayOperatorTests` executes
`ReplayHostTests` covers bounded transfer/IO/options, including refusing an owned
FIFO without waiting for a writer
(`scripts/benchmarks/attention-replay/Tests/AttentionReplayTests/ReplayHostTests.swift`,
`fifoInputIsRejectedWithoutWaitingForAWriter`). `ReplayOperatorTests` executes
24 synthetic operator cases plus one host guard, with all three genuine arms in
each operator case. The existing native reference ceiling `1e-2` and paged bound
`max(3 * contiguous relativeL2, 1e-2)` remain unchanged. Exact storage bytes and
Expand Down
2 changes: 2 additions & 0 deletions scripts/benchmarks/attention-replay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This standalone diagnostic consumes one confirmed [attention packet v1](../atten

The Python driver validates the complete packet before creating a fresh output directory, preserves all six native FP16/BF16/FP32 buffers and writes a bounded, hashed transfer. The Swift CLI checks transfer and raw lengths/hashes/packing before constructing an MLX array. Both enforce a 32 MiB input limit and a conservative 256 MiB allocation plan. That plan bounds these arrays and pools; it does not bound process RSS or the framework allocator cache.

`ReplayIO.readBounded` opens inputs without following symlinks or blocking on FIFO writers, then requires a regular file and the exact bounded byte count. `ReplayHostTests` checks this path without invoking any attention operator.

Three arms run sequentially in separate processes:

- `nativeSDPA`: actual `MLXFast.scaledDotProductAttention`, with original Q and the production conversion of stored K/V to Q dtype.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func sha256(_ bytes: Data) -> String {
}

func readBounded(_ url: URL, limit: Int) throws -> Data {
let descriptor = open(url.path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC)
// Non-regular inputs must reach fstat instead of waiting for a FIFO writer.
let descriptor = open(url.path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK)
try require(descriptor >= 0, "cannot open regular input")
let handle = FileHandle(fileDescriptor: descriptor, closeOnDealloc: true)
var status = stat()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import Foundation
import Darwin
import MLX
import Testing
@_spi(Benchmarking) import MLXLMCommon
@testable import attention_replay

/// These fixtures construct only Data and JSON; no operator or model is called.
struct ReplayHostTests {
@Test func fifoInputIsRejectedWithoutWaitingForAWriter() throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false)
defer { try? FileManager.default.removeItem(at: root) }
let fifo = root.appendingPathComponent("input.fifo")
try #require(mkfifo(fifo.path, 0o600) == 0)
let finished = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
defer { finished.signal() }
#expect(throws: (any Error).self) { try readBounded(fifo, limit: 3) }
}
let withoutWriter = finished.wait(timeout: .now() + .seconds(2))
if withoutWriter == .timedOut {
// Keep a writer open until the owned reader has exited, including
// a reader that the scheduler has not started yet. O_RDWR does not
// require that reader to have entered open before recovery begins.
let writer = open(fifo.path, O_RDWR | O_NONBLOCK | O_CLOEXEC)
try #require(writer >= 0)
finished.wait()
close(writer)
}
#expect(withoutWriter == .success)
}

private func options(input: URL, hash: String, output: URL) throws -> ReplayOptions {
try ReplayOptions(["--input", input.path, "--input-sha256", hash,
"--output", output.path, "--arm", "nativeSDPA"])
Expand Down
Loading