Repository navigation
fix: deduplicate ChatRole type across lm and trl packages - #17
Merged
Merged
Conversation
Import ChatRole from @mlx-node/lm instead of redefining it in @mlx-node/trl, establishing a single source of truth. Co-Authored-By: Claude Opus 4.6 <[email protected]>
📝 WalkthroughWalkthroughThe ChatRole type definition was moved from a local union type to an external import from '@mlx-node/lm', centralizing type definitions across the codebase while maintaining the same public interface through re-export. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Brooooooklyn
added a commit
that referenced
this pull request
Apr 11, 2026
Import ChatRole from @mlx-node/lm instead of redefining it in @mlx-node/trl, establishing a single source of truth. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Type-only change that centralizes a shared enum-like union; risk is limited to potential compile-time incompatibilities if downstream code relied on the old local definition. > > **Overview** > `packages/trl` no longer defines its own `ChatRole` union type; it now imports and re-exports `ChatRole` from `@mlx-node/lm` so consumers use a single shared type. > > All `ChatMessage`/completion typing in `trl` continues to reference `ChatRole`, but the source of the type is centralized to `lm` to avoid drift between packages. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit bf50bf6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Restructured internal type declarations for improved code organization and maintainability. No changes to public APIs or user-facing functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude Opus 4.6 <[email protected]>
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…weep, no-follow reap, no-follow deferred walk Fix-delta review of the review-#16 fixes surfaced two more symlink-safety defects adjacent to those fixes. Both verified via control-flow analysis. - Finding 1 (download.ts, data-loss): processJob ran sweepStaging BEFORE the no-follow ownership preflight, and the sweep's dead-owner backup reap decided via isModelInstalled(finalDir), which FOLLOWS symlinks. A live finalDir symlink into an external complete marked model therefore made the sweep permanently delete a recoverable rollback backup before the preflight could reject the symlink. Fixed two ways: (a) hoisted the no-follow ownership preflight to the top of the try body, before assertRealDirOrAbsent / mkdir / sweepStaging, so a foreign finalDir is refused before any recovery work; and (b) hardened the reap site to classify finalDir no-follow — reap only a proven owned-complete real directory, restore only when finalDir is absent, otherwise (foreign symlink / unowned / incomplete-owned) retain the backup untouched (this also closes the job.overwrite=true path that bypasses the preflight). - Finding 2 (models.ts walkDirStats): the iterative walker lstat'd a popped path for the dev:ino guard but never rejected a non-directory before opendirSync, which follows symlinks — so a queued real directory swapped to a symlink between enqueue and pop was followed into its external target. Added `if (!self.isDirectory()) continue;` after the lstat. No regression: discoverLocalModels already filters symlink roots, so every walk root is a real directory. Gate: typecheck 0; dashboard 200/200 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…eflight after restore, document display-only sizing Fix-delta review of the review-#17 fixes surfaced two recovery-ordering defects (one a regression from the #17 preflight hoist) plus one display-only residual. All verified via control-flow analysis. - Finding 3 (download.ts, regression): the #17 hoist put the ownership preflight above sweepStaging, so a preflight-refused job (unowned/foreign finalDir) threw before the only dead-private-staging-tree reap ran, leaking crashed multi-GB staging indefinitely. Split sweepStaging into reapDeadStagingTrees() (process-wide, pid-gated dead-`<slug>@<sha>.<pid>` reap, run BEFORE the preflight so a refused job still frees its tree) and recoverBackup(slug, finalDir) (slug-scoped backup restore/reap, run AFTER the preflight so a foreign finalDir link is already refused and never followed). - Finding 1 (download.ts): the backup restore branch renamed any backup back onto an absent finalDir; a foreign-symlink backup (from a prior overwrite crash) would be restored after the only ownership check and then followed by skip-detection. Restore now requires the backup itself be an owned real directory (no-follow lstat + our marker), and the no-follow ownership preflight is re-run after recovery, before skip-detection. - Finding 2 (models.ts + docs, document-and-accept): walkDirStats traverses lexical paths, so a concurrent ancestor/TOCTOU symlink swap during the walk can redirect sizing. Its output is display-only (the Models table + the delete-confirmation "(X GB)" hint) and never drives a destructive decision (deletion uses the path-safe name, not the size), so the worst case is a wrong size number under adversarial mutation of the user's own store. A robust fix needs descriptor-relative traversal node:fs does not expose; documented as an accepted residual in code and docs/dashboard.md. Gate: typecheck 0; dashboard 202/202 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…weep, no-follow reap, no-follow deferred walk Fix-delta review of the review-#16 fixes surfaced two more symlink-safety defects adjacent to those fixes. Both verified via control-flow analysis. - Finding 1 (download.ts, data-loss): processJob ran sweepStaging BEFORE the no-follow ownership preflight, and the sweep's dead-owner backup reap decided via isModelInstalled(finalDir), which FOLLOWS symlinks. A live finalDir symlink into an external complete marked model therefore made the sweep permanently delete a recoverable rollback backup before the preflight could reject the symlink. Fixed two ways: (a) hoisted the no-follow ownership preflight to the top of the try body, before assertRealDirOrAbsent / mkdir / sweepStaging, so a foreign finalDir is refused before any recovery work; and (b) hardened the reap site to classify finalDir no-follow — reap only a proven owned-complete real directory, restore only when finalDir is absent, otherwise (foreign symlink / unowned / incomplete-owned) retain the backup untouched (this also closes the job.overwrite=true path that bypasses the preflight). - Finding 2 (models.ts walkDirStats): the iterative walker lstat'd a popped path for the dev:ino guard but never rejected a non-directory before opendirSync, which follows symlinks — so a queued real directory swapped to a symlink between enqueue and pop was followed into its external target. Added `if (!self.isDirectory()) continue;` after the lstat. No regression: discoverLocalModels already filters symlink roots, so every walk root is a real directory. Gate: typecheck 0; dashboard 200/200 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…eflight after restore, document display-only sizing Fix-delta review of the review-#17 fixes surfaced two recovery-ordering defects (one a regression from the #17 preflight hoist) plus one display-only residual. All verified via control-flow analysis. - Finding 3 (download.ts, regression): the #17 hoist put the ownership preflight above sweepStaging, so a preflight-refused job (unowned/foreign finalDir) threw before the only dead-private-staging-tree reap ran, leaking crashed multi-GB staging indefinitely. Split sweepStaging into reapDeadStagingTrees() (process-wide, pid-gated dead-`<slug>@<sha>.<pid>` reap, run BEFORE the preflight so a refused job still frees its tree) and recoverBackup(slug, finalDir) (slug-scoped backup restore/reap, run AFTER the preflight so a foreign finalDir link is already refused and never followed). - Finding 1 (download.ts): the backup restore branch renamed any backup back onto an absent finalDir; a foreign-symlink backup (from a prior overwrite crash) would be restored after the only ownership check and then followed by skip-detection. Restore now requires the backup itself be an owned real directory (no-follow lstat + our marker), and the no-follow ownership preflight is re-run after recovery, before skip-detection. - Finding 2 (models.ts + docs, document-and-accept): walkDirStats traverses lexical paths, so a concurrent ancestor/TOCTOU symlink swap during the walk can redirect sizing. Its output is display-only (the Models table + the delete-confirmation "(X GB)" hint) and never drives a destructive decision (deletion uses the path-safe name, not the size), so the worst case is a wrong size number under adversarial mutation of the user's own store. A robust fix needs descriptor-relative traversal node:fs does not expose; documented as an accepted residual in code and docs/dashboard.md. Gate: typecheck 0; dashboard 202/202 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…weep, no-follow reap, no-follow deferred walk Fix-delta review of the review-#16 fixes surfaced two more symlink-safety defects adjacent to those fixes. Both verified via control-flow analysis. - Finding 1 (download.ts, data-loss): processJob ran sweepStaging BEFORE the no-follow ownership preflight, and the sweep's dead-owner backup reap decided via isModelInstalled(finalDir), which FOLLOWS symlinks. A live finalDir symlink into an external complete marked model therefore made the sweep permanently delete a recoverable rollback backup before the preflight could reject the symlink. Fixed two ways: (a) hoisted the no-follow ownership preflight to the top of the try body, before assertRealDirOrAbsent / mkdir / sweepStaging, so a foreign finalDir is refused before any recovery work; and (b) hardened the reap site to classify finalDir no-follow — reap only a proven owned-complete real directory, restore only when finalDir is absent, otherwise (foreign symlink / unowned / incomplete-owned) retain the backup untouched (this also closes the job.overwrite=true path that bypasses the preflight). - Finding 2 (models.ts walkDirStats): the iterative walker lstat'd a popped path for the dev:ino guard but never rejected a non-directory before opendirSync, which follows symlinks — so a queued real directory swapped to a symlink between enqueue and pop was followed into its external target. Added `if (!self.isDirectory()) continue;` after the lstat. No regression: discoverLocalModels already filters symlink roots, so every walk root is a real directory. Gate: typecheck 0; dashboard 200/200 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn
added a commit
that referenced
this pull request
Jul 28, 2026
…eflight after restore, document display-only sizing Fix-delta review of the review-#17 fixes surfaced two recovery-ordering defects (one a regression from the #17 preflight hoist) plus one display-only residual. All verified via control-flow analysis. - Finding 3 (download.ts, regression): the #17 hoist put the ownership preflight above sweepStaging, so a preflight-refused job (unowned/foreign finalDir) threw before the only dead-private-staging-tree reap ran, leaking crashed multi-GB staging indefinitely. Split sweepStaging into reapDeadStagingTrees() (process-wide, pid-gated dead-`<slug>@<sha>.<pid>` reap, run BEFORE the preflight so a refused job still frees its tree) and recoverBackup(slug, finalDir) (slug-scoped backup restore/reap, run AFTER the preflight so a foreign finalDir link is already refused and never followed). - Finding 1 (download.ts): the backup restore branch renamed any backup back onto an absent finalDir; a foreign-symlink backup (from a prior overwrite crash) would be restored after the only ownership check and then followed by skip-detection. Restore now requires the backup itself be an owned real directory (no-follow lstat + our marker), and the no-follow ownership preflight is re-run after recovery, before skip-detection. - Finding 2 (models.ts + docs, document-and-accept): walkDirStats traverses lexical paths, so a concurrent ancestor/TOCTOU symlink swap during the walk can redirect sizing. Its output is display-only (the Models table + the delete-confirmation "(X GB)" hint) and never drives a destructive decision (deletion uses the path-safe name, not the size), so the worst case is a wrong size number under adversarial mutation of the user's own store. A robust fix needs descriptor-relative traversal node:fs does not expose; documented as an accepted residual in code and docs/dashboard.md. Gate: typecheck 0; dashboard 202/202 (×2); lint 0. Dashboard-only — native and api.ts unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Import ChatRole from @mlx-node/lm instead of redefining it in @mlx-node/trl, establishing a single source of truth.
Note
Low Risk
Type-only change that centralizes a shared enum-like union; risk is limited to potential compile-time incompatibilities if downstream code relied on the old local definition.
Overview
packages/trlno longer defines its ownChatRoleunion type; it now imports and re-exportsChatRolefrom@mlx-node/lmso consumers use a single shared type.All
ChatMessage/completion typing intrlcontinues to referenceChatRole, but the source of the type is centralized tolmto avoid drift between packages.Written by Cursor Bugbot for commit bf50bf6. This will update automatically on new commits. Configure here.
Summary by CodeRabbit