hook: refactor to avoid write status to disk#12
Merged
gaius-qi merged 1 commit intomodelpack:mainfrom Nov 25, 2025
Merged
Conversation
Collaborator
Author
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the model pull progress tracking to improve performance by avoiding disk writes for each layer. The introduction of HookManager to cache progress in memory is a good approach. The code is cleaner and the concerns are better separated.
I've found a few issues:
- A critical bug in
deleteModelthat will cause a memory leak due to incorrectstatusPathcalculation when deleting a hook fromHookManager. - A high-severity regression where the functionality to detect and log long-running layer pulls (
checkLongPulling) has been removed. - A medium-severity issue with some dead code in
StatusManager.Getdue to an incorrectnilcheck.
I've provided detailed comments and suggestions for each of these points. Once these are addressed, the PR should be in great shape.
cbdeb93 to
0a63e33
Compare
The hook currently executes during each layer pull, updating progress info to the status file, which is a disk write operation that may impact model pull concurrency on lower-performance disks. This PR refactors the hook implementation to avoid writing per-layer progress to the disk-based status file, instead keeping it cached in memory, users can still get the model pull progress via the API as before. Signed-off-by: imeoer <[email protected]>
0a63e33 to
a937c62
Compare
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.
The hook currently executes during each layer pull, updating progress info to the status file, which is a disk write operation that may impact model pull concurrency on lower-performance disks.
This PR refactors the hook implementation to avoid writing per-layer progress to the disk-based status file, instead keeping it cached in memory, users can still get the model pull progress via the API as before.
This pull request refactors how progress tracking for model pulls is handled, moving responsibility from the
servicepackage to a newstatus.Hookand introducing a centralizedHookManagerfor managing pull progress state. The changes simplify the codebase, improve separation of concerns, and ensure more consistent and thread-safe access to pull progress. The most important changes are grouped below.Refactoring and Code Organization
Hookimplementation frompkg/service/puller.goto a new filepkg/status/hook.go, and replaced all references toservice.Hookwithstatus.Hookthroughout the codebase. This includes updating thePullerinterface, constructors, and related usages. [1] [2] [3] [4] [5] [6]HookManager. [1] [2] [3]Progress Tracking and Status Management
HookManagerinpkg/status/hook.goand added it toStatusManagerinpkg/status/status.gofor centralized management of pull progress hooks, including methods to set, get, and delete hooks by key (typically the path to the status file). [1] [2] [3]StatusManager.Get()is called, it fetches the latest progress from theHookManagerand attaches it to the returned status. [1] [2]Worker and Model Pull Logic
status.HookandHookManagerfor progress tracking; progress is no longer passed around manually but is managed centrally. Also, progress is no longer set directly during status updates, but is attached automatically when status is retrieved. [1] [2]HookManager, preventing stale progress data.These changes improve modularity, thread safety, and maintainability of the codebase, especially around model pull progress tracking.