Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

PromptProcessing.hook.ts emitAdditionalContext() hardcodes "SOURCE: classifier" — fail-safe path mislabeled, executor cannot honor v6.3.0 source-detection

Open eccentricnode opened this issue 6 months ago • 1 comments

Summary

hooks/PromptProcessing.hook.ts emits a single additionalContext line that the Algorithm executor reads to decide whether mode/tier came from the classifier or the fail-safe path. The line hardcodes SOURCE: classifier regardless of which path produced it. The JSONL telemetry correctly labels source: 'fail-safe'; only the executor-facing context line is wrong.

Algorithm doctrine v6.3.0 OBSERVE phase (effort-detection step 2-4, lines ~304-310) instructs the executor to set effort_source: classifier | fail-safe | context-override | auto based on this line. The mislabel makes "classifier" indistinguishable from "fail-safe" from the executor's POV, breaking the conversation-context override hierarchy specified at step 3.

Reproduce

Releases/v5.0.0/.claude/hooks/PromptProcessing.hook.ts lines 58-65:

function emitAdditionalContext(mode: Mode, tier: number | null, reason: string): void {
  const additionalContext = (mode === 'ALGORITHM' && tier !== null)
    ? `MODE: ALGORITHM | TIER: E${tier} | REASON: ${reason} | SOURCE: classifier`
    : `MODE: ${mode} | REASON: ${reason} | SOURCE: classifier`;
  console.log(JSON.stringify({
    hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext },
  }));
}

SOURCE: classifier is unconditional. The fail-safe paths (lines ~1035 and ~1055 — the else branch and the catch block of the inference call) call this same function:

emitAdditionalContext('ALGORITHM', 3, `inference failed: ${result.error ?? 'unknown'}`);

…producing context like:

MODE: ALGORITHM | TIER: E3 | REASON: inference failed: Timeout after 25000ms | SOURCE: classifier

while the parallel JSONL log line correctly records:

{"...", "mode":"ALGORITHM", "tier":3,
 "mode_reason":"inference failed: Timeout after 25000ms",
 "source":"fail-safe", "latency_ms":25006}

Concrete example

A user prompt today, asking about tool errors, hit the fail-safe path:

JSONL telemetry (correct):

{"timestamp":"2026-05-12T08:47:57.487Z",
 "session_id":"34eb1a29-7a2c-41a9-9ead-51dc91c89105",
 "prompt_excerpt":"there have been more tool errors than ever, today, for whatever reason...",
 "mode":"ALGORITHM","tier":3,
 "mode_reason":"inference failed: Timeout after 25000ms",
 "source":"fail-safe","latency_ms":25006}

System-reminder injected into the model context (wrong):

MODE: ALGORITHM | TIER: E3 | REASON: inference failed: Timeout after 25000ms | SOURCE: classifier

SOURCE: classifier ≠ source: fail-safe.

Impact

  • v6.3.0 OBSERVE step 2 says "honor classifier output verbatim" if SOURCE: classifier. The fail-safe path currently masquerades as classifier output, so the executor treats default E3 as a real classification.
  • The effort_source: context-override path can never fire on a fail-safe because the executor doesn't know the classifier failed.
  • On installs with the classifier-timeout bug (separate filing — see #931 still-open), this affects ~45-54% of prompts daily on Linux.

Suggested fix

Minimal — derive source from the reason string:

 function emitAdditionalContext(mode: Mode, tier: number | null, reason: string): void {
+  const source = reason.startsWith('inference failed') || reason.startsWith('inference error')
+    ? 'fail-safe'
+    : 'classifier';
   const additionalContext = (mode === 'ALGORITHM' && tier !== null)
-    ? `MODE: ALGORITHM | TIER: E${tier} | REASON: ${reason} | SOURCE: classifier`
-    : `MODE: ${mode} | REASON: ${reason} | SOURCE: classifier`;
+    ? `MODE: ALGORITHM | TIER: E${tier} | REASON: ${reason} | SOURCE: ${source}`
+    : `MODE: ${mode} | REASON: ${reason} | SOURCE: ${source}`;
   console.log(JSON.stringify({
     hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext },
   }));
 }

Cleaner — make source an explicit caller-passed parameter. Fast-path callsites (rating / praise / system-text / too-short / prompt-length) already know they took the fast path and could pass 'fast-path' instead of falling under the inferred default.

Cleanest — let the JSONL-write path be the single source of truth that produces both the log line and the additionalContext line from one object, eliminating the divergence by construction.

Environment

  • PAI: v5.0.0 (verified against main HEAD 2026-05-12)
  • Algorithm doctrine: v6.3.0
  • Platform-independent (logic bug in hook output formatting)

Related: #931 (root cause of high fail-safe rate that surfaces this mislabel), #1158 (slash-command classifier failures — same hook)

eccentricnode avatar May 12 '26 08:05 eccentricnode

Fixed in the 5.1.0-era refactor. The classifier output emission moved out of PromptProcessing.hook.ts into a dedicated hooks/EffortRouter.hook.ts. The new hook defines a typed Source enum:

type Source = 'classifier' | 'fail-safe' | 'fast-path' | 'cache' | 'explicit';

…and emits SOURCE: ${decision.source} from the decision object rather than hardcoding the string (lines 91-92). The fail-safe constructors at lines 426/429/431 set source: 'fail-safe', so the additionalContext line now correctly self-identifies and the executor can honor the v6.3.0/v6.4.0/v6.5.0 source hierarchy.

PromptProcessing.hook.ts is still wired in settings.json but it only handles satisfaction/rating capture now. Its file header reads: "emits MODE/TIER to additionalContext via hookSpecificOutput [is handled before this hook]. Satisfaction/rating capture is handled by [this one]."

Closing as fixed in next release. The diagnosis was sharp — the parallel-JSONL-correct-but-executor-context-wrong split was exactly the failure mode that made it hard to spot from the outside.

danielmiessler avatar May 14 '26 17:05 danielmiessler