Skip to content

fix(compression): preserve polarity words and newlines in ultra heuristic - #13524

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.51from
KooshaPari:fix-13454-polarity-pruning
Sep 15, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.51from
KooshaPari:fix-13454-polarity-pruning

Conversation

@KooshaPari

Copy link
Copy Markdown
Contributor

Summary

The ultra heuristic pruner scored polarity words (never, always, no, not, must, do) as stopwords (0.1) or short tokens (0.2), making them the first tokens pruned. This inverted instruction meaning:

It also collapsed newlines via replace(/\s{2,}/g, " "), destroying bullet lists, headings, and code fences.

Changes

  1. Remove polarity/modality words from STOPWORDS: do, does, did, should, can, need, nor, always, never — they no longer score 0.1
  2. Add POLARITY_WORDS force-preserve set (score 1.0): never, always, no, not, nor, must, do, can, should, need, and contractions (don't, can't, etc.)
  3. Preserve newlines: pruneByScore now only collapses [ \t]{2,} not \s{2,} — bullet lists, headings, and code fences survive

Tests

Fixes #13454

Copilot AI lite review requested due to automatic review settings September 13, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Koosha Pari and others added 2 commits September 14, 2026 23:36
…stic (diegosouzapw#13454)

The ultra heuristic pruner scored polarity words (never, always, no, not,
must, do) as stopwords (0.1) or short tokens (0.2), making them the first
tokens pruned. This inverted instruction meaning:

  'NEVER run rm -rf' → 'run rm -rf'
  'must never be deleted' → 'must deleted'

Also collapsed newlines via .replace(/\s{2,}/g, ' '), destroying bullet
lists, headings, and code fences.

Changes:
- Remove polarity/modality words from STOPWORDS set (do, does, did,
  should, can, need, nor, always, never)
- Add POLARITY_WORDS force-preserve set (score 1.0) for never, always,
  no, not, nor, must, do, can, should, need, and contractions
- Only collapse spaces/tabs, not newlines, in pruneByScore output

8 tests in tests/unit/compression/ultra-heuristic-polarity.test.ts.

Fixes diegosouzapw#13454
@diegosouzapw
diegosouzapw force-pushed the fix-13454-polarity-pruning branch from e2c0f95 to 0fdd3d3 Compare September 15, 2026 02:44
@diegosouzapw
diegosouzapw merged commit 56fedf9 into diegosouzapw:release/v3.8.51 Sep 15, 2026
2 of 7 checks passed
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…stic (diegosouzapw#13524)

The ultra heuristic no longer prunes polarity and modality words (`never`, `always`, `not`, `must`, `should`, `do`/`does`/`did`, contractions…). They now score 1.0 instead of the 0.1 stopword score, so "must never be deleted" can no longer collapse into "must deleted". It also collapses only runs of spaces and tabs, keeping the newlines that carry bullets, headings and fences (diegosouzapw#13454).

Maintainer fixes: (1) the new test imported `../../open-sse/…` from `tests/unit/compression/`, which does not resolve, so it had never run. It now passes with the rest of the compression suite (1,526 cases). (2) Dropped the unused `STOPWORDS` import. (3) `check:compression-budget` flagged the expected trade-off: ultra tokens-per-task goes prose 92→97, tool-output 116→117, json 117→126, the cost of keeping meaning-bearing words and line structure. The baseline was refreshed with `--update`, which also records a pre-existing caveman tightening (129/127/160 → 119/114/136). (4) The branch also carried the unrelated `feat(sveltekit)` commit and the diegosouzapw#13523 commit, so it was reset to the release tip plus only this commit, authorship preserved.

Validated in one consolidated batch of this series (37 PRs boarded together on `release/v3.8.51`): `typecheck:core`, `check:open-sse-typecheck` and `check:dashboard-typecheck` clean; ESLint clean on every changed file; file-size, complexity, cognitive-complexity, changelog-integrity, docs-counts, docs-sync and migration-numbering gates green (only the pre-existing `open-sse/utils/stream.ts` file-size red remains, inherited from the base); 3,743 focused `node:test` cases plus 34 vitest cases green.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(backend): ultra heuristic prunes polarity/negation words and collapses newlines, inverting instructions

3 participants