[Bug] WorkCompletionLearning: Object.keys(meta.lineage).pop() always returns 'agents_spawned' regardless of actual lineage
Summary
WorkCompletionLearning.hook.ts has a bug in lineage key extraction: Object.keys(meta.lineage).pop() always returns the last key in the object, which due to JavaScript object key insertion order is always agents_spawned. The intent was to get the "current" lineage key, but the implementation is incorrect.
Affected File
hooks/WorkCompletionLearning.hook.ts
Root Cause
// BUGGY CODE (before fix):
const lineageKey = Object.keys(meta.lineage).pop();
// Object.keys() returns keys in insertion order
// .pop() always returns the LAST key = 'agents_spawned'
// This is never the "current" lineage key — it's always the same wrong key
The lineage object has a fixed structure with agents_spawned as the last property. Object.keys().pop() consistently returns agents_spawned regardless of which lineage type is actually current.
Impact
- Learning records always attribute work to
agents_spawnedlineage type - Actual lineage (e.g.,
human,algorithm,hybrid) is never recorded correctly - Work completion analytics/tracking data is consistently wrong
Fix Applied (locally)
Added a currentLineageKey variable that correctly tracks which lineage property to update:
// FIXED: Track the current lineage key explicitly
let currentLineageKey: keyof typeof meta.lineage = 'human'; // default
// Then when updating lineage:
meta.lineage[currentLineageKey]++;
Expected Behavior
The correct lineage type (human/algorithm/hybrid/agents_spawned) is recorded for each work session based on actual session content.
Actual Behavior
Every work session is recorded as agents_spawned lineage regardless of actual session type.
Environment
- PAI v3.0
- Claude Code 2.1.50
Fixed in v4.0.2 — replaced fragile Object.keys(meta.lineage).pop() with a tracked lineageSubKey variable that's set when entering each lineage sub-section. This ensures array items are always pushed to the correct sub-array (tools_used, files_changed, or agents_spawned). Thanks for the catch!