Skip to content

fix(gbrain-sync): cut source-id slugs on hyphen boundaries#1481

Open
Drummerms wants to merge 1 commit into
garrytan:mainfrom
Drummerms:fix/constrain-source-id-no-midword-truncation
Open

fix(gbrain-sync): cut source-id slugs on hyphen boundaries#1481
Drummerms wants to merge 1 commit into
garrytan:mainfrom
Drummerms:fix/constrain-source-id-no-midword-truncation

Conversation

@Drummerms
Copy link
Copy Markdown

@Drummerms Drummerms commented May 13, 2026

Summary

constrainSourceId in bin/gstack-gbrain-sync.ts truncates long slugs with slug.slice(-tailBudget), which cuts mid-word when the budget boundary lands inside a hyphen-separated token. For a repo where prefix-org-repo-pathhash exceeds the 32-char source-id cap, this produces visible artifacts like:

Input Before After
drummerms-av-sow-wiz-skill-270c0001 (from github.com/Drummerms/av-sow-wiz-skill) gstack-code-kill-270c0001-c32152 gstack-code-270c0001-050d83

The kill substring is skill chopped at the 13-char tail boundary. Beyond the cosmetic problem, it surfaces in user-visible citations and source listings.

What changes

Two small edits, both in bin/gstack-gbrain-sync.ts:

  1. constrainSourceId — walk hyphen-separated tokens from the right, accumulating whole tokens until adding the next would exceed tailBudget. When no token fits, falls through to the existing ${prefix}-${hash} form. Pure refactor of the truncation step; no API change.

  2. deriveCodeSourceId — when the full prefix-org-repo-pathhash triggers truncation (suffix no longer ends with -${pathHash}), retry with prefix-repo-pathhash (drop the org). Keeps the repo name readable in cases where dropping the org alone is enough to fit. Falls through to constrainSourceId either way.

What's out of scope

The deeper constraint is gbrain's 32-char source-id cap. For mid-length org+repo combinations, even repo-pathhash doesn't fit — this PR's fallback produces gstack-code-270c0001-050d83 for the example above, which is deterministic + clean but loses the repo name in the ID. Raising the gbrain cap (e.g. to 64) would let gstack-code-av-sow-wiz-skill-270c0001 (37 chars) resolve fully. That's a gbrain-side change not bundled here.

Test plan

  • bun run bin/gstack-gbrain-sync.ts --dry-run against av-sow-wiz-skill produces gstack-code-270c0001-050d83 instead of gstack-code-kill-270c0001-c32152
  • Short repo names unaffected (org+repo+pathhash fits without truncation → same output as before)
  • Unit tests for constrainSourceId if the maintainer wants them — happy to add in a follow-up

🤖 Generated with Claude Code


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

`constrainSourceId` truncated the slug with `slug.slice(-tailBudget)`, which
cut mid-word when the boundary fell inside a token. For a repo where the
combined `prefix-org-repo-pathhash` exceeded 32 chars, this produced
embarrassing artifacts like `gstack-code-kill-270c0001-c32152` (from
`drummerms-av-sow-wiz-skill-270c0001`).

Two changes:

1. `constrainSourceId` now walks hyphen-separated tokens from the right,
   accumulating whole tokens until adding the next would exceed `tailBudget`.
   When no token fits, falls through to the existing `${prefix}-${hash}`
   form.

2. `deriveCodeSourceId` now retries with `repo-only-pathhash` (dropping the
   org segment) when the full `org-repo-pathhash` triggers truncation. Keeps
   the repo name readable when it fits at all.

Before: `gstack-code-kill-270c0001-c32152`
After:  `gstack-code-270c0001-050d83` (repo+pathhash doesn't fit at 32 chars
        even after dropping org; pathhash + collision-hash is the clean
        deterministic fallback)

Note that gbrain's 32-char source-id cap is the actual root constraint for
mid-length org+repo names. Raising the cap on the gbrain side would let
this resolve to `gstack-code-av-sow-wiz-skill-270c0001` (37 chars) or
`gstack-code-drummerms-av-sow-wiz-skill-270c0001` (47 chars). That's a
gbrain-side change not bundled here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant