From eecf8895aae318dc5b6a57844ddc87b63e77bf56 Mon Sep 17 00:00:00 2001 From: BaaRai <130491490+BaaRai@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:03:18 +0100 Subject: [PATCH] docs(context-telemetry): correct built-in prompt volatility and Phase C worker/planner analysis --- docs/context-telemetry.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/context-telemetry.md b/docs/context-telemetry.md index 52854af..b17ff94 100644 --- a/docs/context-telemetry.md +++ b/docs/context-telemetry.md @@ -119,9 +119,18 @@ ORDER BY input_tokens DESC; - **Risk**: Aggressive trimming of earlier tool outputs can drop credentials, endpoints, or exact error lines needed for exploit chaining or evidence binding, and mutating earlier messages inside a live multi-turn session **invalidates the prompt cache prefix** (turning cheap `cache_read` turns into uncached re-prefills if triggered too frequently). Bound only at explicit compaction boundaries or spill large `tool_result` bodies at insertion time before they enter the cached prefix. #### Phase C — Cache Prefix Stabilization (`ARTEX_CACHE_PREFIX` / `ARTEX_COMPACTION_MEMO`) -- **Recommendation: Proceed with high-confidence surgical prefix split (`ARTEX_CACHE_PREFIX`); defer `ARTEX_COMPACTION_MEMO` until live telemetry confirms compaction frequency.** -- **Codebase finding & expected gain**: Static inspection shows `system_dynamic` is **0.0%** across all lanes today because `agent/deferred.go` sets `DynamicBoundary = 0` (no deferred MCP) or `len(system)` (everything before the boundary), while **volatile per-call / per-intent strings sit inside the static system prompt**: - - `{{.Now}}` (`agent/prompt.go:46`, `time.Now().Format("2006-01-02 15:04:05 MST")`, changing every second) is rendered inside both `plannerSystem` and `workerSystem`. - - `workerArtifactSpec(runDir)` embeds the per-intent `tasks//i` path inside `workerSystem`. - - Moving `{{.Now}}`, `runDir`, and per-round constraints/lessons **after** `DynamicBoundary` (into `system_dynamic`) makes the `system_static` + `tools` prefix (**68.6%** of planner input, **36.0%** of worker turn-1 input) byte-identical across planner rounds and across sibling workers within the same task — lifting planner `cache_read_ratio` from ~48.5% toward ~75–85% and eliminating turn-1 cache misses on every worker spawn. -- **Risk**: Low for `ARTEX_CACHE_PREFIX` (pure prompt-segment relocation using `norma`'s existing `DynamicBoundary` contract, though custom user-edited prompts containing `{{.Now}}` need a clean fallback). Medium for `ARTEX_COMPACTION_MEMO` (injecting compaction memos alters model reasoning continuity and only pays off on tasks that actually hit compaction repeatedly — verify with `ARTEX_CONTEXT_TELEMETRY=1` on real runs first). +- **Recommendation: Proceed with a surgical `worker` prefix split (`ARTEX_CACHE_PREFIX`); verify `planner` cross-round cache behavior and `ARTEX_COMPACTION_MEMO` with live `ARTEX_CONTEXT_TELEMETRY=1` data before changing them.** +- **Actual system-prompt volatility by lane (built-in prompts)**: + + `system_dynamic` is **0.0%** across all lanes today because `agent/deferred.go` sets `DynamicBoundary = 0` (no global deferred MCP) or `len(system)` (everything before the boundary). Auditing the built-in templates and assembly in `agent/worker.go` and `agent/planner.go` shows what actually varies: + + | Lane | Stable per task | Volatile per intent / round | + |---|---|---| + | `worker` | Base `workerDefaultTmpl` (`ProxyAddr`, `DataDir`), `untrustedContentTail`, `workerTrafficBlock`, `noiseProfileBlock`, `frameLessonsBlock` (task-level), `constraintBlock` (task-level, stable unless operator edits constraints), `def.FindingGuidance`, `` | `workerArtifactSpec(runDir)` (`tasks//i`), `renderIntentTask(intent)`, intent target-assets JSON block, closing launch instruction | + | `planner` | `plannerSystem` (`goal`, `dataDir`, `workDir`/`taskDir`, `untrustedDataRules`, `artifactSpec(taskDir)`, `noiseProfileBlock`), `frameLessonsBlock`, `def.FindingGuidance`, `` | `constraintBlock(ts)` is recomputed each round (stable unless operator changes constraints; situational graph overview already lives in the user turn) | + | Custom prompts only | — | `{{.Now}}` (`agent/prompt.go:46`, 1-second resolution). Built-in templates do **not** reference `{{.Now}}` (Go's `text/template` ignores the unused `Now` field); it only affects operator-customized prompts that explicitly use `{{.Now}}`. | + +- **Expected gain**: + - **`worker` turn-1 cache reuse (real, code-backed)**: Today `workerArtifactSpec(runDir)` is concatenated into the single `sysBody` before `noiseProfileBlock`, lessons, constraints, `renderIntentTask(intent)`, and the target-assets block, so every sibling worker spawn busts the prompt cache from `runDir` onward. Splitting `worker` system segments at `DynamicBoundary` — placing the task-stable prefix (`workerDefaultTmpl` + `untrustedContentTail` + `workerTrafficBlock` + `noiseProfileBlock` + `frameLessonsBlock` + `constraintBlock` + `def.FindingGuidance` + ``) **before** `DynamicBoundary` (`system_static`) and the per-intent suffix (`workerArtifactSpec(runDir)` + `renderIntentTask(intent)` + target assets JSON + closing launch line) **after** `DynamicBoundary` (`system_dynamic`) — keeps the intent protected from compaction inside `System` while allowing sibling workers in the same task to share the cached `system_static + tools` prefix (~36% of turn-1 input in the fixture) on turn 1. + - **`planner` cross-round cache ratio (unverified hypothesis)**: The fixture above assumed a turn-1 cache miss on every planner round (yielding 48.5%), which is **not** demonstrated by the built-in code because `plannerSystem` is stable per task. Real cross-round misses could still happen from provider cache TTL expiry between rounds, constraint edits, or tool-RAG tool-list churn — treat any planner cache gain as a hypothesis to measure with `ARTEX_CONTEXT_TELEMETRY=1` on real tasks rather than a proven savings. +- **Risk**: Low for the `worker` `ARTEX_CACHE_PREFIX` split (pure segment reordering using `norma`'s existing `DynamicBoundary` contract; custom prompts using `{{.Now}}` stay an explicit edge case). Medium for `ARTEX_COMPACTION_MEMO` (injecting compaction memos alters model reasoning continuity and only pays off on tasks that repeatedly trigger compaction — verify with live `ARTEX_CONTEXT_TELEMETRY=1` data first).