Skip to content

runMemoryReflection missing isInvalidAgentIdFormat guard (inconsistent with other hook sites) #686

@jlin53882

Description

@jlin53882

Issue: runMemoryReflection missing isInvalidAgentIdFormat guard

Problem

The runMemoryReflection command hook in index.ts lacks a isInvalidAgentIdFormat() guard before calling isAgentOrSessionExcluded(). This creates an inconsistency with the other 5 hook sites that all have this guard.

Affected location: index.ts:3507 (approximate line, within runMemoryReflection)

Current code:

const sourceAgentId = parseAgentIdFromSessionKey(sessionKey) || "main";
// ⚠️  Missing isInvalidAgentIdFormat guard here
const excludePatterns = config.memoryReflection?.excludeAgents;
if (excludePatterns && isAgentOrSessionExcluded(sourceAgentId, sessionKey, excludePatterns)) {
  api.logger.debug?.(`memory-reflection: command hook skipped (excluded agent=...)`);
  return;
}

Why this matters

  • All other 5 hook sites (before_prompt_build × 4, before_reset × 1) have isInvalidAgentIdFormat() as a前置 guard
  • runMemoryReflection is the only site that jumps directly to isAgentOrSessionExcluded() without the format check
  • Currently protected by || "main" fallback, but this is fragile defense-in-depth
  • A future refactor removing the fallback would expose a potential issue

Proposed fix

Add isInvalidAgentIdFormat guard before isAgentOrSessionExcluded:

const sourceAgentId = parseAgentIdFromSessionKey(sessionKey) || "main";
// ✅  Add format validation guard (consistent with other hook sites)
if (isInvalidAgentIdFormat(sourceAgentId, config.declaredAgents)) {
  api.logger.debug?.(
    `memory-reflection: command hook skipped — invalid agentId '${sourceAgentId}'`,
  );
  return;
}
const excludePatterns = config.memoryReflection?.excludeAgents;
if (excludePatterns && isAgentOrSessionExcluded(sourceAgentId, sessionKey, excludePatterns)) {
  api.logger.debug?.(
    `memory-reflection: command hook skipped (excluded agent=${sourceAgentId}, sessionKey=${sessionKey ?? "(none)"})`,
  );
  return;
}

Context

Labels

bug, good first issue

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions