Skip to content

feat(core): validate maxHistory option and document hierarchyDepth: 0 behaviour #254

Closed as not planned

Description

@vamgan

Summary

Two small API hardening improvements surfaced during a code audit:

1. maxHistory accepts invalid values silently

createAskableContext({ maxHistory: -1 }) stores -1 without error. The history cap check then behaves oddly (history.length > -1 is always true, so every push trims the array immediately). Passing NaN falls through to the default of 50 silently.

Fix: Add a runtime guard in the constructor:

if (options?.maxHistory !== undefined && (options.maxHistory < 0 || !Number.isInteger(options.maxHistory))) {
  throw new RangeError('maxHistory must be a non-negative integer');
}

2. hierarchyDepth: 0 is undocumented

Passing hierarchyDepth: 0 to any serialization method returns an empty ancestors array (all ancestor context is suppressed). This is intentional and the implementation is correct, but it is not documented in the type definition or API docs, so users may be confused when their ancestors disappear.

Fix: Add a JSDoc note to AskablePromptContextOptions.hierarchyDepth:

/**
 * Maximum number of ancestor segments to include.
 * Pass `0` to suppress all ancestor context.
 * Defaults to unlimited.
 */
hierarchyDepth?: number;

Acceptance criteria

  • createAskableContext({ maxHistory: -1 }) throws a RangeError
  • createAskableContext({ maxHistory: NaN }) throws a RangeError
  • hierarchyDepth JSDoc clarifies that 0 suppresses all ancestors
  • Existing tests pass; new tests cover the invalid-maxHistory cases

Activity

  1. added
    enhancementNew feature or request
    area: coreCore package and cross-package runtime behavior
    on Jun 1, 2026
  2. added a commit that references this issue on Jun 1, 2026
    b4beb20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore package and cross-package runtime behaviorenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions