Skip to content

v1.59.0.0 feat(learn): semantic dedup for the learnings store (/learn refine) - #2029

Closed
tonyjzhou wants to merge 4 commits into
garrytan:mainfrom
tonyjzhou:learnings-semantic-dedup
Closed

tonyjzhou wants to merge 4 commits into
garrytan:mainfrom
tonyjzhou:learnings-semantic-dedup

Conversation

@tonyjzhou

Copy link
Copy Markdown

What

gstack-learnings-search collapses learnings by exact key+type only, so the same
lesson relogged under a different key accumulates forever. This adds
bin/gstack-learnings-refine and a /learn refine subcommand that find semantic
near-duplicates and merge them, keeping the highest-confidence survivor and unioning
their files lists. It is the "grow-and-refine" step the log/search pair never had.

How

Deterministic and file-only, so it runs with gbrain off (no embeddings DB, no model,
no network). It blends word-level TF-IDF cosine (precision: rare shared terms carry
the signal) with character-trigram cosine (recall: survives rewording and sessions
vs session). Neither signal alone catches a reworded duplicate. The larger of the
two does.

Safe by default:

  • Dry-run unless --apply. --apply writes atomically, leaves a .bak, and never
    rewrites a file that has an unparseable line.
  • A --review band surfaces gray-zone pairs in [--review-floor, --sim) for manual
    inspection and never auto-merges them. Because --apply deletes a row, the 0.70
    default bar is tuned for precision and the REVIEW band catches the rest without
    deleting on a guess.
  • Scope mirrors the sibling tools: current project via gstack-slug by default,
    --slug SLUG, or --all. Survivor selection uses the same confidence-decay model
    as gstack-learnings-search.

/learn refine

New subcommand in the learn skill: runs the dry-run, presents the auto-mergeable and
REVIEW bands, and applies only after AskUserQuestion confirmation.

Tests

test/gstack-learnings-refine.test.ts adds 10 tests (mirroring the
gstack-learnings-search harness): near-dup clustering, exact-dup compaction,
cross-type gating, --apply (file union, confidence bump, idempotency, parse-error
safety), the --review band, and --min-entries lazy-on-overflow.

Every suite this change touches is green: learnings, skill-validation, gen-skill-docs,
and the package.json-to-VERSION sync. The remaining failures in a full local
bun test test/ run are pre-existing and environmental (resolve-user-slug sandbox
timeouts, an iOS XCTest-toolchain test, a hook-install test). They fail identically on
main (c7ae632) without this branch.

Numbers

On the test fixtures a reworded duplicate scores 0.58 on words alone, under any
threshold safe enough to use, but 0.77 blended once the character-trigram signal lifts
it. Unrelated same-domain pairs stay under 0.20. Reproduce with
bun test test/gstack-learnings-refine.test.ts and
gstack-learnings-refine --all --review --debug-scores.

VERSION 1.58.1.0 -> 1.59.0.0 (MINOR, new capability), with a CHANGELOG entry.

Note for CI

This is a fork PR, so the eval and E2E jobs will not receive base-repo secrets and
will fail on empty-env auth. The free unit tier (bun test, skill validation,
gen-skill-docs, the new dedup tests) runs without secrets. Happy to have the branch
re-pushed to a base-repo branch if you would rather run the full eval suite.

gstack-learnings-search only collapses exact key+type duplicates, so the same
lesson relogged under a different key accumulates. gstack-learnings-refine finds
semantic near-duplicates and merges them, keeping the highest-confidence survivor
and unioning files[].

Deterministic and file-only (works with gbrain off): blends word-level TF-IDF
cosine with character-trigram cosine, so a reworded duplicate that either signal
alone would miss is still caught while unrelated pairs stay low. Dry-run by
default; --apply is atomic, leaves a .bak, and never rewrites a file with an
unparseable line. --review surfaces gray-zone pairs without merging them. Scope
mirrors the sibling tools (current slug via gstack-slug, --slug, --all).
Runs the dry-run, presents the auto-mergeable and REVIEW bands, and applies only
after AskUserQuestion confirmation. SKILL.md regenerated from the template.
10 tests: near-dup clustering, exact-dup compaction, cross-type gating, --apply
(file union, confidence bump, idempotency, parse-error safety), the --review
gray-zone band, and --min-entries lazy-on-overflow.
@trunk-io

trunk-io Bot commented Jun 16, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions github-actions Bot changed the title feat(learn): semantic dedup for the learnings store (/learn refine) v1.59.0.0 feat(learn): semantic dedup for the learnings store (/learn refine) Jun 16, 2026
time-attack pushed a commit to time-attack/gstack that referenced this pull request Jul 14, 2026
…e + /learn refine subcommand (garrytan#2029)

Deterministic TF-IDF + char-trigram blend, dry-run by default, atomic
--apply with .bak, parse-error rewrite guard, gray-zone --review band
never auto-merged. Generated learn/SKILL.md excluded (regenerated by
the assembler).
time-attack pushed a commit to time-attack/gstack that referenced this pull request Jul 14, 2026
garrytan#2029's rewrite built output only from rows with key+type, so legacy
category/summary/detail rows (the ones garrytan#940 makes searchable again)
would be silently deleted by the first refine --apply. Legacy rows now
pass through the rewrite unchanged, and the timestamp sort tolerates
rows with missing/invalid ts. Regression test added.

Co-Authored-By: Claude Fable 5 <[email protected]>
@time-attack

Copy link
Copy Markdown
Contributor

@tonyjzhou Redesign as schema-lossless, dry-run-first conservative refinement with stable IDs, containment, locking, unique durable atomic writes, recovery, and adversarial chain/concurrency probes.

@capy-ai

capy-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for this, @tonyjzhou. It's a reasonable idea, but not one we can take right now: Duplicate learnings are a real annoyance, but this is a new helper and subcommand. It could fold into /learn prune once the learnings and gbrain memory direction is settled. We're parking it: closing the PR and recording the idea in TODOS.md under its theme, so it isn't lost. When we pick that theme up we'll reference this PR and credit you.

@capy-ai capy-ai Bot closed this Oct 8, 2026
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.

2 participants