From b708ea6b9a9124fab38c4b2ea9358620ba9736a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=93=D1=83?= =?UTF-8?q?=D1=81=D0=B5=D0=B2?= Date: Mon, 23 Nov 2026 01:32:07 +0300 Subject: [PATCH] fix(llmrec): context size telemetry ON by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The llm_context table carries the per-call context breakdown (system, tools, tool_result, assistant) but was EMPTY on a stand that had already run 15 tasks: the flag was opt-in and off. Context size was therefore discussed from per-task token sums, and any fix to it was a guess. limits: telemetry row 1 per model call - byte counting only, no content kept; наблюдаемо до ~300 вызовов на прогон, то есть до ~300 строк limits: disable via explicit falsy value only (0|false|off|no) - the point of the change is that an unset env means ON Tests: default-on and explicit-off are both asserted (RED first: the old test asserted the opposite default). --- llmrec/context_telemetry.go | 21 +++++++++++++-------- llmrec/context_telemetry_test.go | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/llmrec/context_telemetry.go b/llmrec/context_telemetry.go index 92b1fbd..1d067d0 100644 --- a/llmrec/context_telemetry.go +++ b/llmrec/context_telemetry.go @@ -10,19 +10,24 @@ import ( "github.com/Autumn-27/norma/llm" ) -// ContextTelemetryEnv is the opt-in environment flag enabling per-call context -// size telemetry into llm_context. Off by default: when unset/false, no sizing -// work runs and no rows are written. +// ContextTelemetryEnv switches per-call context size telemetry into llm_context. +// +// ON by default. Замер: на стенде, где прошло 15 прогонов, таблица llm_context была +// ПУСТА (0 строк), потому что флаг выключен по умолчанию — то есть размер контекста +// воркера обсуждали по суммарным токенам задачи, а не по разбивке (2026-11-22). +// Стоимость: одна строка на вызов модели и подсчёт длин, содержимое не сохраняется +// (по логам стенда — до ~300 вызовов на прогон, то есть до ~300 строк). +// Выключение явное: ARTEX_CONTEXT_TELEMETRY=0|false|off|no. const ContextTelemetryEnv = "ARTEX_CONTEXT_TELEMETRY" -// ContextTelemetryEnabled reports whether ARTEX_CONTEXT_TELEMETRY is enabled -// (1, true, on, yes; case-insensitive). Default is false. +// ContextTelemetryEnabled reports whether context telemetry is on. Default true; +// only an explicit falsy value (0, false, off, no; case-insensitive) turns it off. func ContextTelemetryEnabled() bool { switch strings.ToLower(strings.TrimSpace(os.Getenv(ContextTelemetryEnv))) { - case "1", "true", "on", "yes": - return true + case "0", "false", "off", "no": + return false } - return false + return true } // ContextMetrics holds size-only measurements of an assembled CompletionRequest diff --git a/llmrec/context_telemetry_test.go b/llmrec/context_telemetry_test.go index c3b5129..85a651b 100644 --- a/llmrec/context_telemetry_test.go +++ b/llmrec/context_telemetry_test.go @@ -233,11 +233,21 @@ func TestContextTelemetryFlagOffAndOnPostgres(t *testing.T) { wantMetrics := MeasureContext(req) wantUsage := llm.Usage{InputTokens: 1200, OutputTokens: 150, CacheReadTokens: 800, CacheWriteTokens: 100} - // 1. Flag OFF (default): zero rows in llm_context on both Stream and Complete, - // identical behavior regardless of recordBodies. + // 0. Default is ON: unset means enabled, only an explicit falsy value disables. t.Setenv(ContextTelemetryEnv, "") + if !ContextTelemetryEnabled() { + t.Fatal("expected telemetry enabled by default when env unset") + } + t.Setenv(ContextTelemetryEnv, "off") if ContextTelemetryEnabled() { - t.Fatal("expected telemetry disabled when env unset") + t.Fatal("expected telemetry disabled when ARTEX_CONTEXT_TELEMETRY=off") + } + + // 1. Flag OFF explicitly: zero rows in llm_context on both Stream and Complete, + // identical behavior regardless of recordBodies. + t.Setenv(ContextTelemetryEnv, "0") + if ContextTelemetryEnabled() { + t.Fatal("expected telemetry disabled when ARTEX_CONTEXT_TELEMETRY=0") } recOff := Wrap(syntheticTelemetryProvider{usage: wantUsage}, pg, "claude-test", "prof-a", "", "", func() bool { return false }) ctxOff := transcript.WithSessionID(WithTaskID(context.Background(), taskOff), "exp1-worker-i1")