Skip to content

WorkCompletionLearning hook never generates learnings (2 bugs) #972

@jacobo-ortiz

Description

@jacobo-ortiz

Summary

hooks/WorkCompletionLearning.hook.ts (v4.0.3) has two bugs that prevent it from ever generating learning files in MEMORY/LEARNING/. The hook silently exits on every SessionEnd, meaning the WORK→LEARNING bridge has never functioned.

Bug 1: current-work.json dependency doesn't exist

Location: findStateFile() (line ~64)

The function looks for MEMORY/STATE/current-work.json or current-work-{sessionId}.json:

function findStateFile(sessionId?: string): string | null {
  if (sessionId) {
    const scoped = join(STATE_DIR, `current-work-${sessionId}.json`);
    if (existsSync(scoped)) return scoped;
  }
  const legacy = join(STATE_DIR, 'current-work.json');
  if (existsSync(legacy)) return legacy;
  return null;
}

Problem: Nothing in PAI or Claude Code creates either of these files. The hook always exits with "No active work session" on line 276.

Fix: Replace with a lookup in MEMORY/STATE/work.json (populated by PRDSync hook), matching session_id from stdin to sessionUUID in work.json entries.

Bug 2: Section header mismatch

Location: ISC extraction regex (line ~326)

const iscMatch = prdContent.match(/## IDEAL STATE CRITERIA[\s\S]*?(?=\n## |$)/);

Problem: PAI/PRDFORMAT.md v2.0 defines the section as ## Criteria, not ## IDEAL STATE CRITERIA. The regex never matches, so ISC content is never extracted.

Fix: Update regex to accept both formats:

const iscMatch = prdContent.match(/## (?:IDEAL STATE CRITERIA|Criteria)[\s\S]*?(?=\n## |$)/);

Additional: Field name mismatch

PRD frontmatter uses task: but WorkMeta interface expects title:. Similarly slug:id: and started:created_at:. The parseYaml() output needs field mapping for v4.0 PRDs.

Impact

  • MEMORY/LEARNING/SYSTEM/ and MEMORY/LEARNING/ALGORITHM/ remain permanently empty
  • The learning loop described in MEMORYSYSTEM.md never activates
  • 49 sessions tested, 0 learning files generated

Verification

Both bugs confirmed identical in upstream repo (Releases/v4.0.3/.claude/hooks/WorkCompletionLearning.hook.ts) and local install. Fix applied and tested locally — hook now correctly generates .md learning files with ISC content.

Environment

  • PAI v4.0.3
  • Claude Code on WSL2 (Linux 6.6.87.2)
  • Bun runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions