Lightpanda: the headless browser designed for AI and automation
fix: resolve agent init crash and mcp stream recovery
Adrià Arrufat04345a5149c2
diff --git a/src/agent/Agent.zig b/src/agent/Agent.zigindex 88de3bf7f..3fad4f15f 100644--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@ -213,12 +213,14 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agentvar providers_buf: [@typeInfo(Config.AiProvider).@"enum".fields.len]Credentials = undefined;const found_providers = settings.availableProviders(&providers_buf);const available_providers = try allocator.alloc([]const u8, found_providers.len);+ var provider_count: usize = 0;errdefer {- for (available_providers) |p| allocator.free(p);+ for (available_providers[0..provider_count]) |p| allocator.free(p);allocator.free(available_providers);}for (found_providers, 0..) |f, i| {available_providers[i] = try allocator.dupe(u8, @tagName(f.provider));+ provider_count = i + 1;}if (opts.task != null and opts.script_file != null) {diff --git a/src/mcp/router.zig b/src/mcp/router.zigindex 3572428d7..286044343 100644--- a/src/mcp/router.zig+++ b/src/mcp/router.zig@@ -23,6 +23,10 @@ pub fn processRequests(server: anytype, reader: *std.io.Reader) !void {error.StreamTooLong => {log.err(.mcp, "Message too long", .{});try server.sendError(.null, .InvalidRequest, "Message too long");+ _ = reader.discardDelimiterInclusive('\n') catch |e| switch (e) {+ error.EndOfStream => break,+ else => return e,+ };continue;},else => return err,