graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Merge #694 into release/v0.0.282: recover poisoned TLS client generations
Cursor Agentd948b778e464
diff --cc docs/adr/0048-model-http-client-recovery-uses-generations.mdindex 00000000,08d19ae2..487e9269mode 000000,100644..100644--- a/docs/adr/0048-model-http-client-recovery-uses-generations.md+++ b/docs/adr/0048-model-http-client-recovery-uses-generations.md@@@ -1,0 -1,35 +1,35 @@@-# 0042. Model HTTP client recovery uses leased generations++# 0048. Model HTTP client recovery uses leased generations++ Status: accepted 2026-08-31++ ## Context++ Issue #691 captured launch-scoped `TlsInitializationFailed` storms: once+ `std.http.Client.request` failed during TLS construction, six retries and every+ later TUI turn reused the same client and failed until process restart. The+ existing #177 connection poison cannot help because no `Request` exists yet.+ The launch client is also shared with concurrent root, compaction, title,+ recap, and subagent traffic, so deinitializing it in place would race users.++ ## Decision++ Model HTTP constructors lease an active launch-level client generation. A+ request-construction `TlsInitializationFailed` retires that generation and+ publishes a prewarmed replacement under one mutex. Existing requests keep the+ retired generation alive through reference-counted leases; later retries and+ turns resolve the original launch pointer to the replacement. Owned retired+ generations are deinitialized only after their final lease releases.++ The original launch client is never reclaimed by the generation manager:+ unrelated launch consumers still holding its pointer remain safe until normal+ shutdown. All managed constructors wait for initial CA prewarm readiness, and+ CA-prewarm plus request-construction failures leave distinct trace evidence.+ Post-construction send/read failures retain #177's per-connection poison.++ ## Consequences++ A recovered network can serve later root, synthetic, compaction, and child+ model trajectories without replacing the process or durable session. Recovery+ adds one mutex operation per model HTTP request and temporarily retains an old+ client while requests from that generation are still in flight. WebSocket+ transport remains independently managed; this record governs HTTP model calls.diff --cc docs/adr/README.mdindex c769cac1,c2943a4e..fd8b7e81--- a/docs/adr/README.md+++ b/docs/adr/README.md@@@ -52,12 -52,7 +52,13 @@@ record only when you need the evidence| [0039](0039-local-tools-are-project-scripts.md) | Agent-authored local tools are project scripts under `.graff/tools/`; skills stay instructions. Runtime catalog extras, not `schema.effectiveRootSpecs`. || [0040](0040-codedb-stays-when-licensed.md) | Ordinary reads use native `codedb` / `read_file`; codedb-pro is extra search, not the default reader. || [0041](0041-tui-is-an-acp-client.md) | The fullscreen TUI is an in-process ACP client: session/prompt in, session/update thought/tool/text out. No child `graff acp`. |-| [0042](0042-model-http-client-recovery-uses-generations.md) | Model HTTP calls lease a recoverable client generation; request-construction TLS failure rotates safely without deinitializing in-flight users. |+| [0042](0042-tui-claims-screen-before-session.md) | `graff tui` / TTY `graff repl` claim the alt-screen before keys/MCP/prompt; leftover boot happens inside the pager. |+| [0043](0043-pi-swe-same-seat.md) | Pi SWE A/B uses `pi-xai` on the SuperGrok seat; do not steal Pi's catalog or heap from the json-stream pass. |+| [0044](0044-oneshot-skips-learn-auto.md) | `-p` and `--json` skip learn auto-init; the Pi SWE wall gap was a 38s `graff-pinned` copy, not their catalog. |+| [0045](0045-glm-flash-swe-codegraff.md) | Codegraff `glm-5.3-flash` SWE: Pi 5/6 in 758s, graff 3/6 with three 300s timeouts; do not steal Pi's heap. |+| [0046](0046-flash-omits-default-effort.md) | Flash / Gemini send `reasoning_effort=low` (omit still thinks); lean `-p` shortens tool prose; `-p` streams. |+| [0047](0047-codegraff-swe-not-glm-only.md) | Codegraff SWE A/B is not GLM-only: Gemini graff 5/6 in 103s; DeepSeek flash still one-shots; do not steal Pi's catalog. |++| [0048](0048-model-http-client-recovery-uses-generations.md) | Model HTTP calls lease a recoverable client generation; request-construction TLS failure rotates safely without deinitializing in-flight users. |## When to write onediff --cc src/agent_request.zigindex 615c0d11,8539cf90..10a54b3f--- a/src/agent_request.zig+++ b/src/agent_request.zig@@@ -360,14 -363,11 +364,11 @@@ pub fn request(self: *Agent, tools_in:// OpenRouter and similar include user ids, BYOK/settings// URLs, and routing docs. Classifiers still read g_5xx_body_buf.try self.say("[{s}{s} — retrying in {d}s ({d}/{d})]\n", .{ what, ra_note, delay_ms / 1000, attempt + 1, max_attempts });- if (self.tracer) |tr| tr.note("retry", what);+ policy.noteRetry(self, what);self.sleepInterruptible(delay_ms) catch return error.Interrupted;} else {- // Transport flake (HttpConnectionClosing, a reset,- // a truncated TLS read): back off before a fresh- // connection. Rapid-fire retries against a- // just-closed keep-alive almost always re-fail- // (#86). 250ms·2ⁿ, capped at 4s over 6 tries; Esc cancels.+ // Transport flakes back off; rapid retries against a+ // just-closed keep-alive re-fail (#86). Cap: 4s/6 tries.const delay_ms = RetryPlan.delayMs(throttled, attempt);@import("turn_chrome.zig").emitRetryNotice(self.io, @errorName(err), attempt + 1, max_attempts);if (showRecoveredTransportRetry(self.call_kind))diff --cc src/test_hooks.zigindex 3830d402,15212124..00e782a7--- a/src/test_hooks.zig+++ b/src/test_hooks.zig@@@ -343,4 -341,4 +343,5 @@@ test_ = @import("channel_worker.zig");_ = @import("session_wake.zig");_ = @import("tui_acp.zig");++ _ = @import("readline_paste.zig"); // #674: semantic paste spans (not reached via readline.zig's runtime import)}