graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: skip learn auto-init on -p and --json
Cursor Agentac2453d89ff0
diff --git a/docs/adr/0044-oneshot-skips-learn-auto.md b/docs/adr/0044-oneshot-skips-learn-auto.mdnew file mode 100644index 00000000..381002fe--- /dev/null+++ b/docs/adr/0044-oneshot-skips-learn-auto.md@@ -0,0 +1,48 @@+# 0044. `-p` and `--json` skip learn auto-init++Status: accepted 2026-08-29++## Context++ADR 0043 ran Pi on the same SuperGrok SWE seat as graff-dev. Tokens and+calls were a wash (30 vs 31). Pi's wall was 276s vs graff's 456s. That+gap is not Pi's 4-tool catalog.++Every graff-dev SWE task made exactly 5 API calls — the+`learn_auto` bootstrap floor — then `startBackgroundLearning` copied+132M `.graff/learn-kit/graff-pinned` and generated suites. `cpu_sample_s`+was 38.3–38.5s on every task; Pi's was ~1s. Subtract that tax and+model-wait (wall − CPU) matches or beats Pi on 5/6 tasks:++| task | graff wall − CPU | Pi wall − CPU |+|---|---:|---:|+| map-conflict | 21s | 15s |+| validated | 26s | 25s |+| label-sort | 39s | 37s |+| json-stream | 42s | 48s |+| cookie-store | 48s | 101s |+| config-parse | 50s | 44s |++Pi's extra pass is still the `json-stream` whitespace-only json-seq+clause (ADR 0024). Both miss `label-sort`. The same 38s copy is why+`test-learn-auto-init.py`'s 45s exit wait flakes on CI.++## Decision++`startBackgroundLearning` is a no-op when `unattended` (`-p`) or+`--json`. Interactive REPL/TUI/ACP still auto-init after 5 model calls.+`GRAFF_LEARN_AUTO=off` still kills the whole trigger. `graff learn init`+is unchanged.++Do not steal Pi's catalog or heap. Do not treat Pi `first_out_s` as a+TUI steal.++## Consequences++- `graff -p` / eval sandboxes no longer write 132M or spend ~38s of+ local CPU on the way out. Interactive workspaces still earn a store.+- The CI learn-auto probe is an interactive PTY session; it still+ copies the pin. A later cut can speed that copy. Do not raise its+ timeout to hide the tax.+- Revisit if a one-shot should ever seed learning (it should not: the+ sandbox is thrown away).diff --git a/docs/adr/README.md b/docs/adr/README.mdindex 8cadd280..a838d6bc 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -54,6 +54,7 @@ record only when you need the evidence or the edge cases.| [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-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. |## When to write onediff --git a/docs/local-learning.md b/docs/local-learning.mdindex 18fc7faa..a0e8647e 100644--- a/docs/local-learning.md+++ b/docs/local-learning.md@@ -11,9 +11,12 @@ active parent → deterministic mutation seeds → paired evaluation## Nothing to run-Learning is on by default. The first session in a workspace that does real-model work (at least 5 calls, so a one-off question never triggers it) sets the-workspace up on its way out:+Learning is on by default for an interactive session. The first REPL/TUI/ACP+session in a workspace that does real model work (at least 5 calls, so a+one-off question never triggers it) sets the workspace up on its way out.+`-p` and `--json` never do this — those exits are not a workspace opting+into a spending cadence (evals hit the 5-call floor and then spent ~38s+copying `graff-pinned` + generating suites).```text↺ setting this workspace up to learn from sessions like this onediff --git a/src/session_run.zig b/src/session_run.zigindex bb7bbf17..acbf4f3b 100644--- a/src/session_run.zig+++ b/src/session_run.zig@@ -506,10 +506,19 @@ fn autoInitLearning(gpa: Allocator, arena: Allocator, io: Io, environ_map: *consreturn true;}+/// One-shots and `--json` are not a workspace opting into a spending cadence.+/// `-p` evals land on exactly 5 model calls (the bootstrap floor) and then+/// copy 132M `graff-pinned` + generate suites (~38s CPU). Interactive+/// REPL/TUI/ACP still auto-init. Off with `GRAFF_LEARN_AUTO=off`.+pub fn shouldAutoLearn(unattended: bool, json_mode: bool) bool {+ return !unattended and !json_mode;+}+/// Closing the learning loop: a session that did real model work counts toward/// this workspace's next trial and, on cadence, starts one in the background./// The first such session in a workspace also creates the store it counts into.pub fn startBackgroundLearning(gpa: Allocator, arena: Allocator, io: Io, environ_map: *const std.process.Environ.Map, budget: *const run_budget_mod.RunBudget, telemetry_allowed: bool) void {+ if (!shouldAutoLearn(main_mod.unattended, main_mod.json_mode)) return;const options: learn_auto.Options = .{.model_calls = budget.used(),// A session launched with --no-telemetry keeps its trial local, even@@ -547,3 +556,10 @@ test "unwrapFencedJson strips a markdown fence and leaves bare JSON alone" {try std.testing.expectEqualStrings("{\"a\":1}", unwrapFencedJson("```json\n{\"a\":1}\n```\n"));try std.testing.expectEqualStrings("{\"a\":1}", unwrapFencedJson("{\"a\":1}"));}++test "one-shot and --json do not auto-init a learning store" {+ try std.testing.expect(!shouldAutoLearn(true, false));+ try std.testing.expect(!shouldAutoLearn(false, true));+ try std.testing.expect(!shouldAutoLearn(true, true));+ try std.testing.expect(shouldAutoLearn(false, false));+}