Skip to content

[Bug] Style-profile generation crashes on schema-invalid JSONL history entries #314

Description

@404-Page-Found

Description

History loading treats any syntactically valid JSON object as a CommitEntry without validating its fields. buildProfile() then assumes entry.message is a string and calls string methods on it.

A single schema-invalid but valid-JSON history row can therefore make suggestion/profile generation fail instead of being ignored like malformed JSON rows are.

Location

  • src/history/store.ts:83-99processHistoryLine()
  • src/history/store.ts:443-485buildProfile()

Relevant code

try {
  entries.push(JSON.parse(line) as CommitEntry);
} catch {
  corruptedLineIndexesFromEnd.push(lineIndexFromEnd);
}
...
for (const entry of entries) {
  const lines = entry.message.split('\n');
  const firstLine = lines[0];
  totalLengths.push(firstLine.length);
}

The JSON parse check proves only syntax validity; it does not establish that message, diff, model, and provider have the expected types.

Steps to Reproduce

  1. Ensure a valid config and at least one normal history entry exist.
  2. Append a syntactically valid but schema-invalid row such as {"timestamp":"2026-09-21T00:00:00Z","message":123,"diff":"","model":"x","provider":"openai"}.
  3. Run commit-echo suggest or commit-echo history.
  4. buildProfile() reaches entry.message.split('\n') and throws a TypeError.

Expected Behavior

History corruption handling should reject schema-invalid rows and continue using valid recent entries, with the same warning behavior used for malformed JSON.

Actual Behavior

Syntactically valid but structurally invalid rows are accepted and can crash profile construction.

Suggested Fix

Validate the decoded value with a runtime type guard before pushing it into entries. Treat invalid shapes as corrupted history rows and continue scanning.

Impact

One bad persistent history row can block the core suggestion/profile path until the user manually edits or repairs history.jsonl. This defeats the existing corruption-tolerance logic.

Reviewed against current main at 6c01ad0a853501e9617a3af0a5db3b515dd8ed53.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingp1High priority; blocks core functionality

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions