Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- A refused handover's 409 now comes from a typed failure code instead of matching the failure message text, so unrelated failures with similar text no longer (#6239).

- Build: the `-Ddist-mlx-tf-binary` help text and its missing-option message name the qualified Qwen4-enabled `mlx_tf` executable they need (#6392).

- Release notes for 1.3.10 in docs/releases/1.3.10.md (#6384).
Expand Down
1 change: 1 addition & 0 deletions zig/build/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub fn toolHostTests(b: *std.Build, parser: *std.Build.Module, server: *std.Buil
b.step("test-tool-finish-host", "A capped tool reply's finish_reason, whole and streamed, without devices").dependOn(&finish.step);
const windows = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{ "Nemotron window:", "model discovery", "thinking reserve" } }));
b.step("test-nemotron-window-host", "Nemotron advertised capacity and unchanged chat admission without devices").dependOn(&windows.step);
b.step("test-handover-review-host", "Handover request, error mapping and HTTP lifecycle without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{ "handover", "--handover:" } })).step);
b.step("test-thinking-request-host", "Client refusals and internal note and lesson requests without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"thinking request:"} })).step);
b.step("test-thinking-benchmark-host", "Benchmark thinking capability and request bodies without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"thinking benchmark:"} })).step);
const deepseek = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"DeepSeek chat:"} }));
Expand Down
5 changes: 4 additions & 1 deletion zig/src/core/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub const Stats = @import("engine_stats.zig").Stats;
/// ``done`` of a prompt's ``total`` rows are in the cache, ``cached`` of them restored from a kept prefix.
pub const Progress = struct { done: u32, total: u32, cached: u32 };

/// A failed reply's machine-readable cause, independent of its human-facing message.
pub const FailureCode = enum { handover_not_loaded };

pub const Event = union(enum) {
/// The prompt is in the cache: ``cached`` of its tokens came from a kept prefix.
prefilled: u32,
Expand All @@ -99,7 +102,7 @@ pub const Event = union(enum) {
tokens: []const u32,
audio: usize,
/// The reply ended; nothing follows. ``message`` says why a failed reply failed.
finished: struct { reason: Reason, stats: Stats = .{}, message: []const u8 = "" },
finished: struct { reason: Reason, stats: Stats = .{}, message: []const u8 = "", failure_code: ?FailureCode = null },
};

/// Where a request's events go. Called on the engine's thread: it must return at once and not re-enter the engine.
Expand Down
8 changes: 7 additions & 1 deletion zig/src/core/lane_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub const LaneHost = struct {
if (job.started and job.delivered > 0 and job.request.max_tokens > 0 and
!job.request.background and !job.request.untaught and (reason == .stop or reason == .length))
if (job.request.usage) |u| u.done(u.ctx, job.stream.pocket_usage);
emit(job, .{ .finished = .{ .reason = reason, .stats = told, .message = message } });
emit(job, .{ .finished = .{ .reason = reason, .stats = told, .message = message, .failure_code = if (reason == .failed and job.handover_refused) .handover_not_loaded else null } });
if (job.started) {
if (s.grammar) |g| g.deinit(h.gpa);
s.deinit(h.gpa);
Expand Down Expand Up @@ -510,6 +510,12 @@ pub const LaneHost = struct {
return x.text(x.ctx, e) orelse @errorName(e);
}

/// A missing or lost handed-over state fails with its typed cause, never a fresh-prefill fallback.
pub fn dropHandover(h: *LaneHost, job: *Job, message: []const u8) bool {
job.handover_refused = true;
return h.drop(job, message);
}

pub fn drop(h: *LaneHost, job: *Job, message: []const u8) bool {
h.remove(job);
if (job.started and !job.stream.finished) h.core.discard(&job.stream);
Expand Down
40 changes: 40 additions & 0 deletions zig/src/core/lane_host_pressure_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,43 @@ test "memory pressure: under warning a request still runs when none does, one at
try std.testing.expectEqual(@as(usize, 0), r.snaps.live.load(.acquire));
try std.testing.expectEqual(@as(u64, 0), r.store.counts.kept);
}

test "memory pressure: a populated scoped store shares the budget and sheds under warning" {
const a = std.testing.allocator;
const Tiny = struct {
fn bytes(_: *anyopaque, _: u32) u64 {
return 512;
}
fn save(_: *anyopaque, _: ?*anyopaque, _: u32) anyerror!pc.Saved {
return try std.testing.allocator.create(u8);
}
fn restore(_: *anyopaque, _: ?*anyopaque, _: pc.Saved) anyerror!void {}
fn drop(_: *anyopaque, saved: pc.Saved) void {
std.testing.allocator.destroy(@as(*u8, @ptrCast(saved)));
}
};
var cfg = try lanes.Config.init(a, .{}, 1, 0);
defer cfg.deinit(a);
var target: lanes.fake.Fake = .{ .gpa = a };
defer target.deinit();
var clock: lanes.fake.FixedClock = .{};
var core = lanes.Engine.init(a, &cfg, target.backend(), clock.clock());
defer core.deinit();
var none: u8 = 0;
var store = pc.Store.init(a, .{ .ptr = &none, .vtable = &.{ .bytes = Tiny.bytes, .save = Tiny.save, .restore = Tiny.restore, .drop = Tiny.drop } }, .{ .min_prompt = 0, .min_gap = 1 }, 4096);
defer store.deinit();
var host = LaneHost.init(a, io, &core, .{ .lanes = 1 });
host.cache = &store;
defer host.scoped.deinit(a, &store);
const scope = try host.scoped.open(a, &store, 7);
try std.testing.expectEqual(@as(u64, 4096), store.budget + scope.store.budget);
try std.testing.expect(scope.store.keep(&.{ 11, 12, 13, 14, 15, 16 }, 4, null, &.{}, &.{}));
try std.testing.expectEqual(@as(usize, 1), scope.store.entries.items.len);
var dial: Dial = .{};
dial.set(.warning);
host.pressure = .{ .source = .{ .ctx = &dial, .read = Dial.read }, .percent = 50, .every_ns = 0 };
@import("lane_host_pressure.zig").step(&host);
try std.testing.expect(store.hold and scope.store.hold);
try std.testing.expectEqual(@as(usize, 0), scope.store.entries.items.len);
try std.testing.expectEqual(@as(u64, 1), scope.store.counts.evicted);
}
6 changes: 3 additions & 3 deletions zig/src/core/lane_stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub fn open(h: *LaneHost, job: *Job) bool {
if (!h.core.backend.warm_images and h.info_.warm_turns and r.background and r.max_tokens == 0 and r.images.len > 0) return !h.cancel(job);
if (r.scope != 0) { // #2349: the scope's own store or nothing, held before any lookup, keep or warm pass
if (job.scoped) |x| { // readmitted after a requeue: it holds its reference already, but the scope may be gone
if (x.dropped) return !h.drop(job, "handover_not_loaded: this handover was dropped while the request waited");
if (x.dropped) return !h.dropHandover(job, "handover_not_loaded: this handover was dropped while the request waited");
} else {
const x = h.scoped.find(r.scope) orelse return !h.drop(job, "handover_not_loaded: no state of this handover is loaded here");
const x = h.scoped.find(r.scope) orelse return !h.dropHandover(job, "handover_not_loaded: no state of this handover is loaded here");
@import("handover_stores.zig").Stores.acquire(x); // once per job; finish releases it
job.scoped = x;
}
if (job.scoped.?.gone()) return !h.drop(job, "handover_not_loaded: this handover's state failed to restore or is gone; nothing prefills in its place");
if (job.scoped.?.gone()) return !h.dropHandover(job, "handover_not_loaded: this handover's state failed to restore or is gone; nothing prefills in its place");
}
var reuse: lanes.stream.Reuse = .{};
var effective_prompt: []const u32 = r.prompt;
Expand Down
2 changes: 1 addition & 1 deletion zig/src/server/chat_generation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub const Generation = struct {
.failed => {
const said = if (m.message.len > 0) try a.dupe(u8, m.message) else "the reply failed";
// #2349: a scope known here whose store isn't (dropped while the request waited) is a 409, not a 400
if (std.mem.startsWith(u8, said, "handover_not_loaded")) return cx.handover(409, "handover_not_loaded", said);
if (m.failure_code == .handover_not_loaded) return cx.handover(409, "handover_not_loaded", said);
return cx.other(said);
},
};
Expand Down
14 changes: 14 additions & 0 deletions zig/src/server/completion_prompt_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const ByteText = struct {
/// Copies the prompt the server submits, then finishes at once.
const Capture = struct {
prompt: []u32 = &.{},
failure_message: ?[]const u8 = null,

fn engine(e: *@This()) api.Engine {
return .{ .ctx = e, .vtable = &.{ .info = info, .submit = submit, .cancel = cancel, .status = status, .memory = memory } };
Expand All @@ -65,6 +66,10 @@ const Capture = struct {

fn submit(ctx: *anyopaque, id: api.Id, request: *const api.Request, sink: api.Sink) api.SubmitError!void {
const e: *Capture = @ptrCast(@alignCast(ctx));
if (e.failure_message) |message| {
sink.event(sink.ctx, id, &.{ .finished = .{ .reason = .failed, .message = message } });
return;
}
std.testing.allocator.free(e.prompt);
e.prompt = std.testing.allocator.dupe(u32, request.prompt) catch return error.Busy;
sink.event(sink.ctx, id, &.{ .prefilled = 0 });
Expand Down Expand Up @@ -150,3 +155,12 @@ test "a completion prompt's boolean ids get a 400, nested or not" {
}
try std.testing.expectEqual(@as(usize, 0), backend.prompt.len);
}

test "handover-like engine text never changes an ordinary completion failure status" {
var backend: Capture = .{ .failure_message = "ordinary backend failure" };
defer std.testing.allocator.free(backend.prompt);
const normal = try complete(&backend, "[11,12,13]");
try std.testing.expectEqual(@as(?u16, 500), normal);
backend.failure_message = "handover_not_loaded_unrelated: backend annotation";
try std.testing.expectEqual(normal, try complete(&backend, "[11,12,13]"));
}
15 changes: 15 additions & 0 deletions zig/src/server/handover_cli_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ test "--handover: POSIX hosts keep it" {
if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
try @import("handover.zig").platform();
}

test "--handover: learn daily budget parses independently in either flag order" {
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
var u: cli.Usage = .{};
for ([_][]const []const u8{
&.{ "m", "--prompt-cache-disk=cache", "--handover", "--learn-daily-gib", "2.5" },
&.{ "m", "--prompt-cache-disk=cache", "--learn-daily-gib", "2.5", "--handover" },
}) |argv| {
const got = try cli.parse(a, argv, &u);
try std.testing.expect(got.handover);
try std.testing.expectEqual(@as(f64, 2.5), got.learn_daily_gib);
}
}
2 changes: 2 additions & 0 deletions zig/src/server/mailbox.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const Mailbox = struct {
prefilled_ns: ?i96 = null,
finished: bool = false,
reason: api.Reason = .stop,
failure_code: ?api.FailureCode = null,
stats: api.Stats = .{},
widths: []u32 = &.{},
raised: []bool = &.{},
Expand All @@ -45,6 +46,7 @@ pub const Mailbox = struct {
.finished => |f| {
m.finished = true;
m.reason = f.reason;
m.failure_code = f.failure_code;
m.stats = f.stats;
m.widths = m.gpa.dupe(u32, f.stats.prefill_widths) catch &.{};
m.raised = m.gpa.dupe(bool, f.stats.prefill_raised) catch &.{};
Expand Down
2 changes: 1 addition & 1 deletion zig/tests/fixtures/gradient-serving.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ zig/src/families/qwen27/attention_plan.zig e64049d6bc0e5d252a6503d8023ad9ee32128
zig/src/families/qwen27/decode_round.zig 74dea48cd60124220727498a1636b81beb1811747c1effce91d5947822d5d3ce raw main 1eed88bb09 (public attentionPlan and lane-core Drafter/tail state retained), #2916 (solo prompt frames; decode and shared limits retained); #3868 (SenseNova-Loop-9B, its wide prompt on the solo plan); #2955 (mixed Q/K projections and one Q/K norm/RoPE dispatch)
zig/src/native/qwen27_prompt_rows.zig 5e137f7966c0b725994bc613266be2d83a47800b211dcb7b742455066ed33887 raw #2916 (solo prompt frames; decode and shared limits retained)
zig/src/native/qwen27_slots.zig 16aed3398b2857dac31f0166655bd4a084895bb65bd8d2d632a878fe0c19970f raw #2916 (solo prompt frames; decode and shared limits retained); #3868 (SenseNova-Loop-9B, its wide prompt on the solo plan); #5171 re-pinned after its exact A/B
zig/src/core/lane_host.zig ef05057c3d95113352386fee81a12073ef1a8647b51b01324830dc1d4a6d16a7 raw main #4937 scoring, learn and folded-memory behavior retained; #5040 idle weight release hooks ported; #5312: passes the prefill timestamp to the prompt-cache pressure report, decisions unchanged; #5688: opt-in shared-page disk tier; #5729 handover scope store and refusal, inert for requests with no handover scope
zig/src/core/lane_host.zig fe6965c272ae87099ad6d4b6ba7227338b3a75faa5d82c3e166ba70ecead6f84 raw main #4937 scoring, learn and folded-memory behavior retained; #5040 idle weight release hooks ported; #5312: passes the prefill timestamp to the prompt-cache pressure report, decisions unchanged; #5688: opt-in shared-page disk tier; #5729 handover scope store and refusal, inert for requests with no handover scope; #5729 typed handover failure metadata; source identity only, arithmetic unchanged
zig/src/core/lane_host_run.zig 72c287fd129c9154ddd647a9320363c0587cc0160fb009e62f7756fc317737c0 raw main #4937 scoring, learn and folded-memory behavior retained; #5040 idle weight release hooks ported
zig/src/core/lane_rounds.zig aa2c7ed73eb271ca6630d2d860705c41889712883c24b515c5cca3828747fd94 raw main #4937 scoring, learn and folded-memory behavior retained; #5040 idle weight release hooks ported
zig/src/native/qwen27_served.zig 631a14811f189437cbea5cb7706483ef30837f69e8a35eebc7dd967dee1afa35 raw main #4937 scoring, learn and folded-memory behavior retained; #5040 idle weight release hooks ported; #5188 (environment settings through the registry; accepted values and replies unchanged); #4158 startup margin and 128-row frame step; #1835 (glp); #5881: allocator.create field defaults set explicitly; #3378 (its outgrown host test imported beside the others); #2886: a startup warning from live memory (log only)
Expand Down
Loading