xonecas.io
79113
Ma

mini-coding-agent / commit 016a8a5

chore: use less memory and less threads.

xonecas2026-10-09 016a8a5ac59af98e3729fbd993521fc52a64db11 parent ed177c5

3 files changed

known-issues.md+14−7
@@ -1,6 +1,7 @@
11 # User reports
22
3-These come from other people using mini
3+These come from other people using mini. Each report keeps its text and carries
4+the state we last verified it in.
45
56 ---
67
@@ -13,14 +14,20 @@ At the same time, same model, same provider, same build, with a context of 6%, t
1314
1415 using `btop` to monitor usage during these longs waiting for provider show almost no network activity, 0 cpu and 30mb of memory, seems like the process is just idle. But a curl to the same provider/model/key responds immediatly.
1516
16-> High frequency of errors using muse models.
17-
18-More than one person said they kept getting `! stream read failed`, over and over. I was able to reproduce it with muse-1.3
17+Open, not ours. `waiting for provider` covers body build, connect and the
18+provider's time to first token; the counter next to it keeps running, so the
19+process is idle on the socket, not stuck in the agent. curl to
20+opencode-go/deepseek-v4.1-flash: 68k uncached prompt tokens, first token at 2.7s.
21+The same request in the TUI at 75k tokens (8% of 1M) leaves that state in ~2s.
22+A curl that "responds immediately" and a fresh session both carry a small prompt.
23+Pre-fill time at a given context is the provider's, and it grows with the context.
1924
2025 > Ocasional TUI freeze during bash calls.
2126
2227 Several reports of the TUI freezing on some bash calls not all.
2328
24-> Editor area is unstyled/uses the host terminal colors.
25-
26-I've confirmed this in our stress script runs screenshots. We keep having issues with background coverage regressions, we need to pay attention to this when doing TUI runs during verification. Looking at the text output is clearly not working.
29+Open, not reproduced. Tool output is read with poll() on the turn thread and
30+streamed to the event queue, so the frame loop keeps running while a command is
31+alive: a 4M line `seq`, and snapshots of a 71MB tree, both stayed animated at the
32+capture rate with peak RSS at 61MB. The status line does distinguish the call from
33+the snapshot that brackets it. A report with the command and cwd would help.
src/platform.zig+13−1
@@ -1,15 +1,27 @@
11 const std = @import("std");
22
3+/// The default `std.Io.Threaded` grows its worker pool to one less than the CPU
4+/// count. That pool is only exercised by the net stack, which races DNS answers
5+/// and connections through `Io.async`; a handful of workers covers the agent.
6+const max_io_threads = 4;
7+
38 pub var io: std.Io = undefined;
49 pub var gpa: std.mem.Allocator = undefined;
510 pub var env: *std.process.Environ.Map = undefined;
611 pub var args: std.process.Args = undefined;
712
13+var threaded: std.Io.Threaded = undefined;
14+
815 pub fn setup(init: std.process.Init) void {
9- io = init.io;
1016 gpa = init.gpa;
1117 env = init.environ_map;
1218 args = init.minimal.args;
19+ threaded = std.Io.Threaded.init(init.gpa, .{
20+ .argv0 = .init(init.minimal.args),
21+ .environ = init.minimal.environ,
22+ .async_limit = .limited(max_io_threads),
23+ });
24+ io = threaded.io();
1325 }
1426
1527 pub fn getEnv(key: []const u8) ?[]const u8 {
src/tui/highlight.zig+47−54
@@ -51,46 +51,35 @@ fn syntax(a: std.mem.Allocator, language: *const ts.Language, sources: []const [
5151
5252 var grammars: ?Grammars = null;
5353
54+const Lang = enum { javascript, typescript, tsx, markdown, markdown_inline, python, go, zig, bash, diff };
55+
56+fn load(a: std.mem.Allocator, lang: Lang) Syntax {
57+ return switch (lang) {
58+ .javascript => syntax(a, tree_sitter_javascript(), &.{JS_QUERIES}) orelse unreachable,
59+ .typescript => syntax(a, tree_sitter_typescript(), &.{ JS_QUERIES, TS_QUERIES }) orelse unreachable,
60+ .tsx => syntax(a, tree_sitter_tsx(), &.{ JS_QUERIES, TS_QUERIES }) orelse unreachable,
61+ .markdown => syntax(a, tree_sitter_markdown(), &.{ MD_QUERIES, MD_TABLES }) orelse unreachable,
62+ .markdown_inline => syntax(a, tree_sitter_markdown_inline(), &.{MD_INLINE_QUERIES}) orelse unreachable,
63+ .python => syntax(a, tree_sitter_python(), &.{PY_QUERIES}) orelse unreachable,
64+ .go => syntax(a, tree_sitter_go(), &.{GO_QUERIES}) orelse unreachable,
65+ .zig => syntax(a, tree_sitter_zig(), &.{ZIG_QUERIES}) orelse unreachable,
66+ .bash => syntax(a, tree_sitter_bash(), &.{BASH_QUERIES}) orelse unreachable,
67+ .diff => syntax(a, tree_sitter_diff(), &.{DIFF_QUERIES}) orelse unreachable,
68+ };
69+}
70+
5471 const Grammars = struct {
55- javascript: Syntax,
56- typescript: Syntax,
57- tsx: Syntax,
58- markdown: Syntax,
59- markdown_inline: Syntax,
60- python: Syntax,
61- go: Syntax,
62- zig: Syntax,
63- bash: Syntax,
64- diff: Syntax,
65-
66- fn init(a: std.mem.Allocator) Grammars {
67- const js = tree_sitter_javascript();
68- const ts_lang = tree_sitter_typescript();
69- const tsx_lang = tree_sitter_tsx();
70- const md = tree_sitter_markdown();
71- const md_inline = tree_sitter_markdown_inline();
72- const py = tree_sitter_python();
73- const go_lang = tree_sitter_go();
74- const zig_lang = tree_sitter_zig();
75- const bash_lang = tree_sitter_bash();
76- const diff_lang = tree_sitter_diff();
77- return .{
78- .javascript = syntax(a, js, &.{JS_QUERIES}) orelse unreachable,
79- .typescript = syntax(a, ts_lang, &.{ JS_QUERIES, TS_QUERIES }) orelse unreachable,
80- .tsx = syntax(a, tsx_lang, &.{ JS_QUERIES, TS_QUERIES }) orelse unreachable,
81- .markdown = syntax(a, md, &.{ MD_QUERIES, MD_TABLES }) orelse unreachable,
82- .markdown_inline = syntax(a, md_inline, &.{MD_INLINE_QUERIES}) orelse unreachable,
83- .python = syntax(a, py, &.{PY_QUERIES}) orelse unreachable,
84- .go = syntax(a, go_lang, &.{GO_QUERIES}) orelse unreachable,
85- .zig = syntax(a, zig_lang, &.{ZIG_QUERIES}) orelse unreachable,
86- .bash = syntax(a, bash_lang, &.{BASH_QUERIES}) orelse unreachable,
87- .diff = syntax(a, diff_lang, &.{DIFF_QUERIES}) orelse unreachable,
88- };
72+ slots: [@typeInfo(Lang).@"enum".fields.len]?Syntax = @splat(null),
73+
74+ fn get(self: *Grammars, a: std.mem.Allocator, lang: Lang) *Syntax {
75+ const slot = &self.slots[@intFromEnum(lang)];
76+ if (slot.* == null) slot.* = load(a, lang);
77+ return &slot.*.?;
8978 }
9079 };
9180
92-fn getGrammars(a: std.mem.Allocator) *Grammars {
93- if (grammars == null) grammars = Grammars.init(a);
81+fn getGrammars() *Grammars {
82+ if (grammars == null) grammars = .{};
9483 return &grammars.?;
9584 }
9685
@@ -295,17 +284,21 @@ fn emit(a: std.mem.Allocator, out: *std.ArrayList(u8), active: *std.ArrayList(us
295284 at.* = end;
296285 }
297286
298-fn syntaxFor(g: *Grammars, lang: []const u8) ?*Syntax {
299- if (std.mem.eql(u8, lang, "js") or std.mem.eql(u8, lang, "javascript") or std.mem.eql(u8, lang, "jsx")) return &g.javascript;
300- if (std.mem.eql(u8, lang, "ts") or std.mem.eql(u8, lang, "typescript")) return &g.typescript;
301- if (std.mem.eql(u8, lang, "tsx")) return &g.tsx;
302- if (std.mem.eql(u8, lang, "py") or std.mem.eql(u8, lang, "python")) return &g.python;
303- if (std.mem.eql(u8, lang, "go") or std.mem.eql(u8, lang, "golang")) return &g.go;
304- if (std.mem.eql(u8, lang, "zig")) return &g.zig;
305- if (std.mem.eql(u8, lang, "bash") or std.mem.eql(u8, lang, "sh") or std.mem.eql(u8, lang, "shell")) return &g.bash;
287+fn langFor(lang: []const u8) ?Lang {
288+ if (std.mem.eql(u8, lang, "js") or std.mem.eql(u8, lang, "javascript") or std.mem.eql(u8, lang, "jsx")) return .javascript;
289+ if (std.mem.eql(u8, lang, "ts") or std.mem.eql(u8, lang, "typescript")) return .typescript;
290+ if (std.mem.eql(u8, lang, "tsx")) return .tsx;
291+ if (std.mem.eql(u8, lang, "py") or std.mem.eql(u8, lang, "python")) return .python;
292+ if (std.mem.eql(u8, lang, "go") or std.mem.eql(u8, lang, "golang")) return .go;
293+ if (std.mem.eql(u8, lang, "zig")) return .zig;
294+ if (std.mem.eql(u8, lang, "bash") or std.mem.eql(u8, lang, "sh") or std.mem.eql(u8, lang, "shell")) return .bash;
306295 return null;
307296 }
308297
298+fn syntaxFor(g: *Grammars, a: std.mem.Allocator, lang: []const u8) ?*Syntax {
299+ return g.get(a, langFor(lang) orelse return null);
300+}
301+
309302 fn infoLang(info: []const u8) []const u8 {
310303 const trimmed = std.mem.trim(u8, info, " \t\r\n");
311304 var end: usize = 0;
@@ -314,9 +307,9 @@ fn infoLang(info: []const u8) []const u8 {
314307 }
315308
316309 pub fn spansFor(a: std.mem.Allocator, info: []const u8, text: []const u8) []const Span {
317- const g = getGrammars(a);
310+ const g = getGrammars();
318311 const lang = std.ascii.allocLowerString(a, infoLang(info)) catch infoLang(info);
319- const s = syntaxFor(g, lang) orelse return &.{};
312+ const s = syntaxFor(g, a, lang) orelse return &.{};
320313 const u = utf16(a, text) orelse return &.{};
321314 const root = parse(s.parser, u) orelse return &.{};
322315 defer root.destroy();
@@ -359,9 +352,9 @@ fn collectDiffNodes(a: std.mem.Allocator, node: ts.Node, u: Utf16, out: *std.Arr
359352 }
360353
361354 pub fn diffSpans(a: std.mem.Allocator, text: []const u8) []NodeSpan {
362- const g = getGrammars(a);
355+ const g = getGrammars();
363356 const u = utf16(a, text) orelse return &.{};
364- const root = parse(g.diff.parser, u) orelse return &.{};
357+ const root = parse(g.get(a, .diff).parser, u) orelse return &.{};
365358 defer root.destroy();
366359 var out: std.ArrayList(NodeSpan) = .empty;
367360 collectDiffNodes(a, root.rootNode(), u, &out);
@@ -373,12 +366,12 @@ pub fn highlightCode(a: std.mem.Allocator, info: []const u8, text: []const u8) [
373366 }
374367
375368 pub fn highlightMarkdown(a: std.mem.Allocator, text: []const u8) []const u8 {
376- const g = getGrammars(a);
369+ const g = getGrammars();
377370 const u = utf16(a, text) orelse return text;
378- const root = parse(g.markdown.parser, u) orelse return text;
371+ const root = parse(g.get(a, .markdown).parser, u) orelse return text;
379372 defer root.destroy();
380373 var spans: std.ArrayList(Span) = .empty;
381- spans.appendSlice(a, spansOf(a, &g.markdown, root.rootNode(), u, text, 0)) catch {};
374+ spans.appendSlice(a, spansOf(a, g.get(a, .markdown), root.rootNode(), u, text, 0)) catch {};
382375
383376 var inline_nodes: std.ArrayList(ts.Node) = .empty;
384377 collectByKind(a, root.rootNode(), &.{ "inline", "pipe_table_cell" }, &inline_nodes);
@@ -386,9 +379,9 @@ pub fn highlightMarkdown(a: std.mem.Allocator, text: []const u8) []const u8 {
386379 const start = byteOf(u, node.startByte() / 2);
387380 const inline_text = text[start..byteOf(u, node.endByte() / 2)];
388381 const iu = utf16(a, inline_text) orelse continue;
389- const inline_root = parse(g.markdown_inline.parser, iu) orelse continue;
382+ const inline_root = parse(g.get(a, .markdown_inline).parser, iu) orelse continue;
390383 defer inline_root.destroy();
391- spans.appendSlice(a, spansOf(a, &g.markdown_inline, inline_root.rootNode(), iu, inline_text, start)) catch {};
384+ spans.appendSlice(a, spansOf(a, g.get(a, .markdown_inline), inline_root.rootNode(), iu, inline_text, start)) catch {};
392385 var code_spans: std.ArrayList(ts.Node) = .empty;
393386 collectByKind(a, inline_root.rootNode(), &.{"code_span"}, &code_spans);
394387 for (code_spans.items) |code| spans = std.ArrayList(Span).fromOwnedSlice(recolor(
@@ -506,7 +499,7 @@ fn formatTable(a: std.mem.Allocator, text: []const u8, u: Utf16, table: ts.Node)
506499
507500 pub fn formatTables(a: std.mem.Allocator, text: []const u8) []const u8 {
508501 const u = utf16(a, text) orelse return text;
509- const root = parse(getGrammars(a).markdown.parser, u) orelse return text;
502+ const root = parse(getGrammars().get(a, .markdown).parser, u) orelse return text;
510503 defer root.destroy();
511504 var tables: std.ArrayList(ts.Node) = .empty;
512505 collectByKind(a, root.rootNode(), &.{"pipe_table"}, &tables);