A code snapshot management method and device and related equipment
Patent Information
- Application Number
- CN202511887632.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2045-12-15
AI Technical Summary
然而,Git存在显著缺陷:缺乏语义理解、依赖手动触发且回滚操作简单
[0011] This application provides a code snapshot management method, apparatus, and related equipment. The method involves monitoring code file change events; acquiring multiple evaluation dimensions corresponding to the change events and fusing these dimensions to obtain a semantic importance score for each change event; when the semantic importance score exceeds a preset threshold, performing semantic analysis on the code in the changed file to obtain its semantic information; the changed file being the modified code file; and generating and storing a code snapshot based on the semantic information. This code snapshot management method employs an automatic triggering mechanism based on semantic importance assessment for code change evaluation, replacing traditional manual or timed triggering methods. Intelligent decision-making regarding snapshot generation, through natural language semantic matching, transforms problem localization from manual retrieval to semantic retrieval, significantly shortening the analysis cycle and eliminating the uncertainty of manual judgment. The system continuously records key change states, and the stored code snapshots effectively reduce storage usage while ensuring complete reconstruction of any historical snapshot.
Smart Images

Figure CN121704892B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a code snapshot management method, apparatus and related equipment. Background Technology
[0002] In modern software development, version control systems are indispensable tools, primarily used to track and manage the history of code changes.
[0003] Among existing technologies, commonly used tools in the industry include Git, which is currently the most widely used version control system. It employs a content-addressable file storage method, recording code snapshots through developers manually executing commit commands. Git uses a textual difference (Diff) algorithm to compare differences between versions. However, Git has significant drawbacks: a lack of semantic understanding, reliance on manual triggering, and simplistic rollback operations. Another related technology is automatic backup systems, such as Apple Time Machine. It automatically triggers incremental backups at fixed time intervals (e.g., hourly). Its drawbacks include unintelligible backup content, a rigid triggering mechanism, and coarse-grained recovery.
[0004] Existing systems all use passive triggering methods (manual or timed), which prevents them from making intelligent decisions.
[0005] Therefore, how to provide a code snapshot management method that enables intelligent and automatic snapshot triggering has become an important problem that the industry urgently needs to solve. Summary of the Invention
[0006] In view of this, embodiments of this application provide a code snapshot management method, apparatus, and related equipment to at least partially solve the above-mentioned problems.
[0007] In a first aspect, embodiments of this application provide a code snapshot management method, including: Listen for changes to code files; Obtain multiple evaluation dimension information corresponding to the change event, and fuse the multiple evaluation dimension information to obtain the semantic importance score of the change event; When the semantic importance score is greater than a preset score threshold, semantic analysis is performed on the code in the modified file to obtain the code semantic information of the modified file; the modified file is the modified code file. Based on the code semantic information, a code snapshot is generated and stored.
[0008] Secondly, based on the code snapshot management method described in the first aspect of this application, embodiments of this application also provide a code snapshot management device, including: The listener module is used to listen for changes to code files; The evaluation module is used to obtain multiple evaluation dimension information corresponding to the change event, and to fuse the multiple evaluation dimension information to obtain the semantic importance score of the change event. The analysis module is used to perform semantic analysis on the code in the modified file when the semantic importance score is greater than a preset score threshold, and to obtain the code semantic information of the modified file; the modified file is the modified code file. The storage module is used to generate a code snapshot based on the code semantic information and to store the code snapshot.
[0009] Thirdly, embodiments of this application also provide a computer storage medium storing computer-executable instructions, wherein when the computer-executable instructions are executed, any one of the code snapshot management methods described in the first aspect of embodiments of this application is executed.
[0010] Fourthly, embodiments of this application also provide an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; The memory is used to store at least one executable instruction that causes the processor to execute any of the code snapshot management methods described in the first aspect of the embodiments of this application.
[0011] This application provides a code snapshot management method, apparatus, and related equipment. The method involves monitoring code file change events; acquiring multiple evaluation dimensions corresponding to the change events and fusing these dimensions to obtain a semantic importance score for each change event; when the semantic importance score exceeds a preset threshold, performing semantic analysis on the code in the changed file to obtain its semantic information; the changed file being the modified code file; and generating and storing a code snapshot based on the semantic information. This code snapshot management method employs an automatic triggering mechanism based on semantic importance assessment for code change evaluation, replacing traditional manual or timed triggering methods. Intelligent decision-making regarding snapshot generation, through natural language semantic matching, transforms problem localization from manual retrieval to semantic retrieval, significantly shortening the analysis cycle and eliminating the uncertainty of manual judgment. The system continuously records key change states, and the stored code snapshots effectively reduce storage usage while ensuring complete reconstruction of any historical snapshot. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings.
[0013] Figure 1 A schematic diagram illustrating the workflow of a code snapshot management method provided in this application embodiment; Figure 2 A schematic diagram illustrating the workflow of another code snapshot management method provided in this application embodiment; Figure 3 An exemplary workflow diagram of a code snapshot management method provided in this application embodiment; Figure 4 A schematic diagram of the structure of a code snapshot management device provided in an embodiment of this application; Figure 5 A schematic diagram of another code snapshot management device provided in this application embodiment; Figure 6 This application provides a schematic diagram of the overall structure of a code snapshot management system (device) according to an embodiment of the present application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0014] To enable those skilled in the art to better understand the technical solutions in the embodiments of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art should fall within the protection scope of the embodiments of this application.
[0015] It should be understood that the steps described in the method embodiments of this application may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this application is not limited in this respect.
[0016] This application provides a code snapshot management method, such as... Figure 1 As shown, Figure 1 This illustration shows a flowchart of a code snapshot management method provided in an embodiment of this application, including: Step S101: Listen for change events to code files. A change event refers to any change to the code corresponding to any functional module of the system, including but not limited to creating new code, modifying or deleting existing code, etc. This embodiment of the application determines change events by listening for them, serving as a preliminary basis for deciding whether to initiate the generation of a code snapshot. This effectively ensures the integrity of the generated code snapshot history, enabling the complete reconstruction of previous code based on stored historical code snapshots.
[0017] Step S102: Obtain multiple evaluation dimension information corresponding to the change event, and fuse the multiple evaluation dimension information to obtain the semantic importance score of the corresponding change event. This embodiment of the application limits the evaluation of the semantic importance of the monitored change event to the code from multiple evaluation dimensions, as a basis for further determining whether to generate a code snapshot. This method of generating a semantic importance score by fusing multiple evaluation dimension information, and using this as the basis for determining whether to generate a code snapshot, no longer relies on a simple single-dimensional basis such as "how many lines of code were modified." Therefore, the meaning of generating a code snapshot using the method described in this embodiment transcends simple file metadata or text changes, and quantifies the semantic importance of the score, making the method more intuitive and controllable.
[0018] Specifically, in an optional implementation of this application embodiment, the multiple evaluation dimensions include at least two of the following: the impact scope analysis result of the change event, the complexity change analysis result, the architecture impact detection result, the test coverage change evaluation result, and the security risk identification result. Correspondingly, fusing the multiple evaluation dimensions to obtain the semantic importance score corresponding to the change event includes: performing a weighted calculation on the multiple evaluation dimensions to obtain the semantic importance score corresponding to the change event. In this application embodiment, the process of obtaining the impact scope analysis result includes using a dependency graph pre-built or updated in real time by a semantic analysis engine to check the changed file (e.g., api.py), traversing the dependency graph, and calculating how many other files (e.g., web_controller.py, mobile_app_service.py) directly or indirectly depend on the changed file corresponding to the change event. The more affected files, the higher the determined impact scope analysis result score. The complexity change analysis result is determined by comparing the cyclomatic complexity or other structural complexity indicators of the code before and after the change. For example, if a code change event causes the cyclomatic complexity of a function to surge from 10 to 50, this will be considered a high-risk change, and the score of the identified complexity change analysis result will be significantly increased. Architectural impact detection results refer to the system (relying on the semantic analysis engine) identifying the project's architectural pattern (such as "model-view-controller") and checking whether the change violates architectural rules (e.g., the view layer directly calls the database layer) or modifies core design patterns (such as singleton or factory). Change events that violate architectural rules receive a high score for architectural impact detection. Test coverage change assessment results evaluate whether the changed lines of code are covered by existing unit tests. If a large amount of uncovered code is added or modified, leading to a decrease in overall test coverage, the test coverage change assessment result for this change event is considered to have a high score. Security risk identification results refer to the detection of dangerous code patterns, such as SQL injection, hard-coded keys, or the use of known vulnerable libraries. If these situations are confirmed, the security risk identification result of the code change event is considered to have a high score. The system then iterates through the stored historical snapshot data, calculating a weighted sum of the aforementioned multiple dimensions for each snapshot to obtain a comprehensive importance score of 0-100 as the semantic importance score for that snapshot. For example, the semantic importance score can be set as: Semantic Importance Score = (Impact Scope Analysis Result * 0.3) + (Complexity Change Analysis Result * 0.2) + (Architecture Impact Detection Result * 0.3) + (Test Coverage Change Assessment Result * 0.1) + (Security Risk Identification Result * 0.1). Of course, this embodiment is merely an illustrative example illustrating the process of "weighting and calculating multiple evaluation dimensions to obtain the semantic importance score corresponding to the change event."In practical applications, the specific evaluation dimensions and corresponding weight parameters used can be configured according to the project type (e.g., security risk weights can be increased for security-sensitive projects). This application embodiment does not impose any limitations on this. This embodiment obtains the final semantic importance score in a more flexible and controllable manner, and more accurately and reasonably reflects the semantic importance of change events, thus providing a more reliable basis for the subsequent generation and management of code snapshots.
[0019] Optionally, in one implementation of this application embodiment, before fusing the multiple evaluation dimension information to obtain the semantic importance score corresponding to the change event, the method further includes: extracting the changed file and the changed code structure features, and determining at least two results from the impact scope analysis result, complexity change analysis result, architecture impact detection result, test coverage change evaluation result, and security risk identification result corresponding to the modification event based on the code structure features. In the actual application scenario of this application embodiment, code structure features refer to the attributes that describe the internal organization and relationships of the code extracted from the source code through static analysis techniques (such as AST parsers). These structural features include, but are not limited to, abstract syntax tree structure (AST), function / class / import list, structural complexity, etc., which are the basic components of code semantic metadata and can describe the static organization and complexity of the code in a standardized way. In this embodiment, the code structure features are extracted first to generate non-textual, semantically meaningful indicator data, which is used as input parameters for multi-dimensional semantic evaluation. This makes the process of obtaining multi-dimensional semantic evaluation results easier to implement and more reliable. For example, without a pre-obtained Abstract Syntax Tree (AST) structure, it is impossible to obtain complexity change analysis results or identify architectural pattern analysis dependencies to obtain architectural impact detection results. If it is only text, it is also difficult to know which function has been modified, by how much its nesting depth has increased, or whether a new design pattern violation has been introduced. This would cause this step in the embodiments of this application to degenerate into a coarse evaluation relying on simple changes in the number of lines or files, failing to achieve an automatic snapshot-triggered generation process based on semantic importance assessment.
[0020] Step S103: When the semantic importance score is greater than a preset score threshold, perform semantic analysis on the code in the changed file to obtain the code semantic information of the changed file, where the changed file is the modified code file. In this embodiment, a preset score threshold is introduced as a condition for triggering a code snapshot. Subsequent steps are only performed when the semantic importance score of the changed code is greater than this preset score threshold. For example, if the semantic importance score is 60 > the preset score threshold of 50, the snapshot trigger used by the system to generate the code snapshot issues a snapshot generation instruction and calls the semantic analysis engine for further processing. If the score is lower than the threshold (e.g., 30 < 50), the code change is considered unimportant (e.g., modifying code comments), and monitoring continues. This ensures that subsequent triggering decisions such as snapshot generation and storage match the project's historical patterns. Furthermore, it significantly improves the accuracy and automation of snapshot triggering, reduces redundant snapshots, and effectively ensures that high-risk critical change events and other project states can be recorded promptly and accurately.
[0021] In one optional implementation of this application embodiment, the preset scoring threshold is an adaptive threshold. Specifically, the adaptive threshold is determined by: calculating an initial threshold based on the statistical distribution characteristics of the historical snapshot importance scoring sequence; monitoring the snapshot triggering frequency; dynamically adjusting the initial threshold according to the triggering frequency; and using the adjusted initial threshold as the preset scoring threshold. This embodiment sets a dynamic adaptive threshold as the preset scoring threshold, ensuring that the triggering decision matches the project's historical patterns. This ensures that the scoring threshold is self-learning and requires no manual configuration, solving the problem of universality in threshold setting and overcoming the limitations of the method described in this embodiment caused by using a fixed threshold, thus achieving adaptive learning for project-specific code change patterns.
[0022] Specifically, in an optional implementation of this application embodiment, the monitoring snapshot triggering frequency and the dynamic adjustment of the initial threshold based on the triggering frequency include: statistically analyzing the statistical distribution characteristics of the comprehensive importance score sequence of historical snapshots, wherein the statistical distribution characteristics include at least one of the mean and variance of historical scores; and dynamically adjusting the adaptive threshold based on the statistical distribution characteristics and feedback from the actual snapshot triggering frequency to achieve adaptive learning of project-specific code change patterns. This application embodiment here defines the continuous statistical analysis of the statistical distribution characteristics (e.g., mean score, standard deviation, or high percentile) of the comprehensive importance score sequence of historical snapshots. This historical sequence reflects the inherent importance pattern of project code changes. Then, based on the above statistical distribution characteristics, dynamic adjustments are made in conjunction with feedback from the actual snapshot triggering frequency. For example, if the algorithm frequently triggers many low-scoring snapshots (redundancy) during a high-frequency iteration period, the current threshold is deemed too sensitive, and the initial threshold is automatically increased to reduce the generation of redundant snapshots. Conversely, if changes with high importance scores are missed during a critical change period, the system can lower the initial threshold to reduce sensitivity (or adjust the weight of the scoring algorithm). This enables adaptive learning of project-specific code change patterns, eliminating the need for complex manual threshold configuration and achieving truly out-of-the-box technical effectiveness. Furthermore, by dynamically matching the project's actual change rhythm, the system can more accurately and intelligently identify key code changes, effectively avoiding omissions that may be caused by manual submissions, significantly reducing the generation of redundant snapshots, and improving storage utilization and reliability.
[0023] Optionally, in one embodiment of this application, the step of performing semantic analysis on the code in the modified file to obtain the code semantic information of the modified file includes: performing semantic analysis on the code in the modified file to obtain the modified code text and semantic metadata, wherein the semantic metadata includes at least an Abstract Syntax Tree (AST), a dependency graph, quality metrics, and a multidimensional normalized semantic vector. Correspondingly, generating a code snapshot and storing the code snapshot based on the code semantic information includes: encoding the modified code text and the semantic metadata into a semantically enhanced snapshot with a unified data structure to form a code snapshot to be stored, wherein the semantically enhanced snapshot includes at least: the modified code text, the abstract syntax tree, the dependency graph, quality metrics, and a multidimensional normalized semantic vector; determining whether the content of the code snapshot to be stored is a baseline snapshot of the previous version of the code, wherein the baseline snapshot is a data structure that fully stores all semantically enhanced snapshots; if the determination result is a non-baseline snapshot, then recording and storing the change information of the code snapshot to be stored relative to the previous version of the code, wherein the change information includes the binary differential data of the modified file (Binary... The binary difference data is used to reconstruct the code text, and the incremental update data of the semantic vector is used to reconstruct the aggregate semantic vector of the current version. Upon detecting a change event, other code files within the current project scope besides the changed file are identified as code files whose code text has not been changed. For code files whose code text has not been changed, their hash reference information relative to the baseline snapshot or the previous version's code snapshot is stored to link to the corresponding baseline snapshot.
[0024] In this embodiment, the abstract syntax tree (AST) is a tree-like representation of the abstract syntactic structure of the source code. It ignores unstructured information (such as parentheses and semicolons) in the source code, retaining only the skeleton structure (such as function definitions, class definitions, and call relationships). It can be used to extract the structured features of the code, such as function lists, class lists, and cyclomatic complexity, and is the foundation for semantic analysis. A dependency graph is a directed graph used to represent the dependencies between code units (such as files, modules, and classes). For example, if file A imports file B, there is an edge from A to B. In the method described in this embodiment, it can be used to assess the impact scope of changes and to obtain the impact scope analysis results when performing partial module rollbacks. Quality metrics are important indicators used to quantify the health, maintainability, complexity, and potential risks of code. Specific metrics may include cyclomatic complexity, which measures the complexity of code logic and assesses the readability and maintainability of the code. Furthermore, it may also include test coverage information represented by the aforementioned test coverage change assessment structure, reflecting the proportion of code executed by test cases and used to assess the probability of potential risks introduced by changes. It may also include the aforementioned security risk identification result score and the architectural integrity score of the architectural impact detection result; the former assesses the risk level of potential security vulnerabilities or dangerous code patterns in the code, while the latter assesses the degree to which the code conforms to pre-defined architectural patterns or design rules. These quality metrics transform the static analysis results of the code into quantifiable values, forming the basis for enabling the generated code snapshot to have self-assessment capabilities. The semantic metadata encoding and modified code text are edited into a unified data structure, resulting in a semantically enhanced snapshot to be stored. This semantically enhanced snapshot, composed of code text and complete semantic metadata, includes at least the modified code text, abstract syntax tree structure, dependency graph, quality metrics, and multidimensional normalized semantic vectors. Based on this semantically enhanced snapshot, the substantial changes in the code can be easily determined through equivalent reconstruction using the included AST and semantic vector recognition functions. This contrasts with traditional systems that only generate and store snapshots based on text differences, such as systems that only store code text (Git) or file metadata (Time Machine), which cannot distinguish semantically equivalent changes or understand the code structure. A baseline snapshot (K-Base) refers to the first snapshot that completely stores all files and semantic data. It serves as the basic anchor point for rollback, ensuring that all data from that point onward is complete. A previous version code snapshot is the snapshot immediately preceding the current snapshot in the time series; it may be a baseline snapshot or an incremental snapshot.By storing hash reference information relative to the baseline snapshot or the previous version of the code snapshot, when it is determined that a previous snapshot needs to be referenced for rollback, the hash value in the previous version of the code snapshot is used. This simplifies the creation process of incremental snapshots. When it is determined that a baseline snapshot needs to be referenced for rollback, the hash value of the file in the most recent baseline snapshot can be used to reduce the length of the rollback chain and improve the speed of code rollback recovery in certain code rollback recovery scenarios. In addition, in this embodiment of the application, when it is determined whether the content of the code snapshot to be stored is the baseline snapshot of the previous version of the code, if so, it is stored using an incremental update method of binary difference and semantic vector. Binary difference is used to efficiently compress and store the modified code text by calculating the difference between two binary files. This method goes beyond simple text difference, enabling the system implementing this method to accurately identify functionally equivalent refactoring, structural adjustment and other semantically preserved optimizations, improving the intelligence of code review and subsequent use of stored snapshots for rollback decisions. The "binary differential + semantic vector increment + hash reference" approach avoids the repeated storage of unchanged files and semantic data. While ensuring that snapshots can be fully reconstructed to achieve semantic integrity, it saves storage space to the greatest extent, thereby reducing storage costs (on average, it can reduce storage costs by about 80%).
[0025] Further, in an optional implementation of this application embodiment, the process of obtaining the multidimensional normalized semantic vector specifically involves: using a pre-trained language model to obtain the text semantic vector of the modified code text; and extracting the structured feature vector of the modified code text based on the abstract syntax tree structure in the semantic metadata, wherein the structured feature vector includes at least a complexity index and a pattern recognition result; fusing the text semantic vector with the structured feature vector and normalizing the result to generate the multidimensional normalized semantic vector. This is crucial for achieving semantic understanding. In this application embodiment, a pre-trained language model (such as CodeBERT or a domain-specific model) is first used to read the modified code text and generate a text semantic vector (e.g., 768-dimensional) representing the code. Then, structured features (such as complexity and dependency count) obtained from AST, dependency analysis, etc., are also converted into structured feature vectors. Finally, the "text semantic vector" and the "structured feature vector" are fused (e.g., concatenated and normalized) to generate a final, high-dimensional normalized semantic vector. This semantic vector (e.g., 773-dimensional) comprehensively represents the meaning and structure of the code. This design, which fuses textual semantic vectors with structured feature vectors and then normalizes them to generate multidimensional normalized semantic vectors, is crucial to this solution. Traditional textual semantic vectors relying solely on CodeBERT struggle to distinguish between functionally equivalent reconstructions with significant differences in structural quality. However, by fusing structured features in this embodiment, the calculation of semantic similarity can simultaneously quantify functional similarity and structural integrity, ensuring that semantically equivalent code is close in distance in the vector space. This supports the accuracy of code quality assessment during subsequent intelligent rollback decisions using code snapshots, thereby improving the accuracy of code rollback operations.
[0026] Step S104: Generate a code snapshot based on the code semantic information and store the code snapshot. By storing the code semantic information and the corresponding code snapshot together, users can quickly query and retrieve information based on the code semantic information, improving the efficiency of users using stored historical code snapshots for code rollback or to meet other code needs.
[0027] Optionally, in one optional implementation of the embodiments of this application, such as Figure 2 As shown, Figure 2This is a schematic diagram of the workflow of another code snapshot management method provided in this application embodiment. The other code snapshot management method further includes step S105: when a rollback request containing a natural language description is received, the semantic information similarity between the rollback request and the stored code snapshot is calculated; based on the similarity calculation result, a code rollback recommendation list is generated to determine a target rollback snapshot from the code rollback recommendation list, and a corresponding intelligent rollback operation is performed according to the target rollback snapshot; wherein, the intelligent rollback operation is used to perform a semantic comparison between the current code version and the target rollback snapshot, and then determine the code rollback strategy to be executed based on the comparison result. This application embodiment here limits the use of semantic comparison to intelligently and efficiently determine which changes should be retained (such as recent effective improvements) and which should be rolled back (problem changes), and safely handles the rollback of some functional modules. Meanwhile, this embodiment of the application effectively breaks through the dependence on the standardization of user-submitted information through this cross-modal semantic association mechanism. Even if the submitted information is not standard, the system can understand the semantic content of the problem description and directly map it to the semantic features of the code state, thereby achieving accurate matching from natural language to code snapshot for intelligent code rollback, effectively improving the convenience of rollback operation and achieving accurate rollback.
[0028] Further, in an optional implementation of this application embodiment, when a rollback request containing a natural language description is received, the semantic information similarity between the rollback request and the stored code snapshot is calculated; based on the similarity calculation result, a code rollback recommendation list is generated to determine the target rollback snapshot from the code rollback recommendation list, and a corresponding intelligent rollback operation is performed according to the target rollback snapshot. Specifically, this includes: using natural language processing technology (NLP technology) to convert the natural language problem description contained in the rollback request into a problem semantic vector; obtaining the aggregate semantic vector of each historical snapshot in the stored historical snapshot set and the semantic relevance score, file overlap information, and time decay factor information of the problem semantic vector; and determining the rollback risk of different historical snapshots based on the number of changes, test coverage differences, and code quality differences of the historical snapshots; calculating the final recommendation score based on one of the semantic relevance score, file overlap information, and time decay factor information, and a weighted combination with the rollback risk; and generating a top N recommended snapshot list as the code rollback recommendation list based on the final recommendation score, and outputting corresponding recommendation reasons for the user to choose from. This embodiment of the application exemplarily illustrates the implementation process of the above steps: For example, when a user inputs a problem description in natural language form, such as "After yesterday afternoon's update, the payment interface completely crashed and kept timing out," the system's problem analyzer (functional module) uses a natural language semantic encoding model to convert the text into a high-dimensional problem semantic vector, that is, converting the aforementioned input text "payment interface crashed...timeout" into a problem semantic vector. Keyword extraction: Extracting keywords such as "payment interface" and "timeout," and identifying related code modules or files, such as "PaymentService.java" or " / api / payment / ," etc. The rollback recommender then traverses the stored historical snapshot collection. Since each historical snapshot stores an aggregate semantic vector (corresponding to the overall semantic representation of the codebase under that snapshot), by traversing the historical code snapshots and calculating a comprehensive recommendation score for each snapshot, this process includes the following steps: Semantic relevance score: Calculate the cosine similarity between the semantic vector of the question and the semantic vector of the code snapshot. The higher the similarity, the better, if the semantic vector of a snapshot shows significant changes in the code related to "payment" and "network requests". File overlap: Detects whether the files changed in the code snapshot contain the identified related files (such as PaymentService.java); Time decay factor: If the user mentions the key time point "yesterday afternoon", code snapshots related to that time period will be given priority. Rollback Risk Assessment: Assess the risk of rolling back to this code snapshot. If the quality metrics of this code snapshot (such as test coverage change assessment results and security risk identification results) are significantly lower than the current version, or the scale of the change (number of lines of code) is huge, then the rollback risk is considered high. Finally, the system performs weighted fusion processing based on one or more of the above scores. For example, the recommendation score is set as (semantic relevance score * 0.7) - (rollback risk assessment * 0.3), generating the top N (e.g., Top-3) recommendation snapshots and providing the reasons for the recommendations (e.g., "Recommended snapshot A: yesterday at 15:30, highly relevant, modified PaymentService.java, but quality slightly decreased").
[0029] This embodiment establishes a cross-modal semantic mapping between natural language problem descriptions and code snapshot states, enabling the identification of semantically related snapshots that do not perfectly match keywords, thus achieving intelligent recommendations. This better realizes cross-modal semantic association from natural language to code states, significantly shortening problem localization time. The system can automatically understand the meaning of the problem and quickly filter out the most relevant candidate points from a massive amount of stored historical code snapshots, eliminating the need for developers to check each historical version for testing. This greatly reduces the time spent on manual trial and error, improves maintenance efficiency, and the implementation method not only considers semantic relevance but also introduces risk assessment (code quality, coverage, change scale). This avoids recommending a rollback to a high-risk version with extremely poor code quality or involving a large number of file changes just to fix a small bug, ensuring that the final rollback strategy is both relevant and safe. In other words, semantic matching solves the problem of "finding," time and overlap solve the problem of "accurate finding," and risk assessment solves the problem of "safe rollback," ultimately achieving intelligent and highly available code rollback recommendations.
[0030] Optionally, before obtaining at least one of the semantic relevance score, file overlap information, and time decay factor information of the aggregated semantic vector of each historical snapshot in the stored historical snapshot set and the semantic vector of the question, the method further includes: encoding the code text of each historical snapshot using a pre-trained language model to generate text semantic vectors for each snapshot; analyzing the code structure features based on an abstract syntax tree to extract structured feature vectors of the code text of each historical snapshot; fusing and normalizing the text semantic vectors and structured feature vectors of each historical snapshot to generate the aggregated semantic vector, which is used to represent the overall semantic features of each historical snapshot. In this embodiment, this step clarifies that the aggregated semantic vector is formed by fusing file-level semantic vectors using a fusion algorithm (e.g., weighted combination). This vector represents the overall semantics of the codebase and is a necessary foundation for efficiently achieving fast cross-modal similarity matching. Optionally, in one implementation of this application embodiment, performing a semantic comparison between the current code version and the target rollback snapshot, and then determining the code rollback strategy to be executed based on the comparison results, includes: performing a semantic structure comparison of the code files between the target rollback snapshot and the current version, analyzing changes in code complexity, test coverage, and security scores; and determining the rollback strategy for each file of the current version based on the semantic structure comparison results, wherein the rollback strategy includes: a) When the result of semantic structure comparison determines that the code complexity increases more than a preset complexity threshold, or the test coverage decreases more than a preset coverage threshold, or the security score decreases more than a preset security threshold, it is judged as code quality degradation, and a complete rollback strategy is determined. b) When it is determined from the results of semantic structure comparison that a change in the interface definition has caused a compatibility conflict, an intelligent merging strategy is adopted; c) When it is determined from the results of semantic structure comparison that there are semantic improvements in the current version and no interface conflicts, the strategy of retaining the current code version shall be adopted.
[0031] In this embodiment, the steps described above limit the rollback decision-making process from simple textual manipulation to a semantic and quality-based judgment level by introducing an intelligent merger and semantic structure comparison. Then, semantic structure comparison is used as a prerequisite: after determining the target historical snapshot and current version that need to be rolled back, the system first initiates semantic structure comparison. This is used to analyze changes in non-textual dimensions such as code complexity, test coverage, and security scores between target files. Based on the comparison results, intelligent merge judgment logic is applied to each changed file or changed block, deciding to adopt one of three strategies: Full Rollback: If semantic comparison results show a significant degradation in code quality, such as a significant increase in code complexity, a significant decrease in test coverage, or a drop in security score, the system determines that this is an issue change and should perform a full rollback to eliminate its negative impact. For example, if it is determined that code complexity > 50%, test coverage decrease > 20%, and security score decrease > 0.1%, then a safe rollback strategy is recommended.
[0032] Intelligent Merge: If a change involves critical interface definitions and causes compatibility conflicts, a simple rollback (which may break compatibility) or simple retention (which cannot solve the problem) is not feasible. In this case, the system recommends and executes an intelligent merge strategy to attempt to resolve the conflicts and retain non-problematic improvements. For example, if it is determined that changes to function signatures and class inheritance relationships involve critical interface definitions, and the modified code does not have compatibility conflicts, then an intelligent merge rollback strategy should be executed. Retain Current: If the current version shows a valid improvement in semantic structure relative to the target snapshot (e.g., improved test coverage or performance optimization) and does not involve issues requiring rollback, it is recommended to retain the version of code with the current changes.
[0033] Finally, based on the intelligent judgment result, the corresponding rollback, retention, or complex merge operation is determined. This achieves precise decision-making and risk control during the rollback phase, significantly improving the rollback success rate and reducing risk. The steps described above effectively overcome the coarse-grained replacement defects of traditional version control. Through semantic comparison, the system can distinguish between problematic changes that need to be eliminated and effective improvements that should be retained, significantly reducing the risk of introducing new compatibility errors during rollback operations. It also achieves semantic-level code understanding and enables the method described in this embodiment to support fine-grained change control. Developers no longer need to manually determine which changes are good and which are bad. Through automated analysis and intelligent judgment, the system provides users with the optimal rollback solution, ensuring the fine-grained and reliable nature of the rollback operation.
[0034] Optionally, in one implementation of this application embodiment, the method further includes: when a user selects to partially roll back a specified module, identifying downstream dependent files affected by the rollback strategy of the specified module based on the dependency graph; detecting the compatibility between the interface usage of the downstream dependent files and the interface definition of the specified module in the target rollback snapshot, and determining compatibility issues; generating code suggestions to repair the downstream files based on the compatibility issues and providing feedback to the user; after the user confirms the repair suggestions, only performing a rollback operation on the corresponding code of the specified module, while retaining the improved state of other code. This step in this application embodiment defines a secure partial module rollback method, aiming to solve the problem that traditional version control systems (VCS) can only perform full rollbacks or coarse file replacements, and cannot cope with the need to restore only specific functional modules to historical versions under complex architectures. The implementation logic of this method is based on a deep analysis of the code dependency graph, and its core is to achieve security assurance for partial rollback: when the user determines the specific module list to be rolled back (i.e., a set of functional components in the code library, such as a microservice or a library) and the target historical snapshot, the system first determines the range of physical files included in the list. Next, dependency impact analysis is performed: Traditional partial rollbacks may disrupt existing calls to that interface by downstream modules due to the rollback of upstream module interfaces, potentially leading to catastrophic consequences. The method described in this implementation utilizes a dependency graph to quickly and accurately identify all downstream files that depend on the specific functional module performing the rollback operation. These downstream files are marked as potentially affected areas; even if their code content itself is not rolled back, their calling logic may be incompatible with historical versions. Therefore, this solution avoids immediate rollback operations, instead performing static semantic analysis on all affected downstream files, comparing the rolled-back module interface definition with the current interface usage of the downstream files. Key technical features to be detected may include incompatible changes to function signatures, public methods, or return value types. If incompatibility issues are detected, a rollback plan containing a list of compatibility issues and suggested fixes is generated. For example, if the rollback results in a reduction of function parameters, the system will prompt the developer or automatically generate code to modify function calls in downstream files to adapt to historical interfaces. The system only performs a rollback operation after user confirmation or acceptance of the suggested fix, and only the code of the primarily specified modules is rolled back, ensuring that other modules (including retained improvements and irrelevant modules) remain in the latest stable state. This approach achieves fine-grained local rollback, which is particularly suitable for microservice and plug-in architecture projects. It also avoids the unnecessary impact of a full project rollback on other functional modules, ensuring that effective improvements in other modules are preserved while resolving local issues. Furthermore, by pre-detecting interface compatibility issues and providing fix suggestions, it avoids introducing new runtime errors as traditional local rollbacks do, improving the success rate of rollbacks and the stability of the system after rollback.
[0035] Specifically, in one optional implementation of this application embodiment, detecting the compatibility between the interface usage of the downstream file and the interface definition of the corresponding specified module in the target rollback snapshot, and determining compatibility issues, includes: identifying downstream dependent files affected by the rollback strategy executed by the specified module based on the dependency graph; performing fine-grained interface checks on each affected downstream file, with check dimensions including at least: consistency of function signatures, inheritance relationships of public methods of the class, and compatibility of return value types; and generating a compatibility analysis report containing repair suggestions if incompatibility is found. In the actual application scenario of this application embodiment, when the system attempts to roll back a module (such as PaymentService) to an older version (target snapshot), while keeping other modules that depend on it (such as OrderService) in the current new version, it must ensure that the old version of PaymentService can be correctly called by the new version of OrderService. Therefore, at least a multi-dimensional interface check regarding the consistency of function signatures, inheritance relationships of public methods of the class, and compatibility of return value types is required. The function signature typically includes a function name and a parameter list. The elements of the parameter list include the number of parameters, the type of parameters, and the order of parameters. The consistency check of the function signature refers to confirming whether the rolled-back old function can accept the parameters passed by the current code. For example, if the current version of the code calls a function and passes 3 parameters, but the rolled-back old version of the function only accepts 2 parameters, or the parameter types are different, then the system will directly throw an error (such as MethodNotFoundException or TypeError) after the rollback. The function compatibility check is only passed if the function names are exactly the same, the number of parameters matches (unless default parameters are supported), and the parameter types are compatible (i.e., the types accepted by the old function must cover the types currently called). The inheritance relationship of public methods refers to the contractual relationship between a subclass and a superclass in object-oriented programming (OOP). Especially when the rollback involves changes to the superclass, it is necessary to ensure that the subclass (which may have been modified in the current version) can still legally inherit or call the superclass's methods. In performing a partial rollback operation, if the superclass file is rolled back but the subclass file is retained, it is necessary to prevent situations where the subclass attempts to call methods that have been deleted from the superclass or where the subclass overrides a method in violation of the superclass definition. Return value type compatibility refers to whether the data type returned by the function meets the caller's expectations. Callers typically assume that the return value has a specific structure, fields, or type.In the implementation of this solution, if the current version of the code expects a function to return a complex object (such as UserObject), but the rolled-back old version only returns a simple string (such as UserId), then the current code will crash when attempting to access object properties (such as UserObject.name). Therefore, the return type must be the same, or a subclass of the type expected by the caller (covariance). If the returned type is an object / dictionary, the data structure returned by the old version must contain all the key fields used by the current code. Furthermore, it must also comply with the non-null constraint; that is, if the current code does not handle null, but the old version returns null, it is considered potentially incompatible. This multi-dimensional compatibility detection step in this embodiment of the application makes this step not just a simple text comparison, but a logical check that delves into the code syntax and semantic level (AST analysis), which is also the core technical advantage that distinguishes this solution from traditional Git diff. This allows for the generation of highly effective warnings and remedial suggestions for developers to better prevent rollbacks from compromising system stability.
[0036] Furthermore, in one implementation of this application embodiment, the method further includes: for a detected change event, instead of immediately determining whether to generate a corresponding code snapshot or other processing operations based on the change event, it is first written into a "change buffer." Only when the change events stored in the buffer meet preset conditions or a time interval is met is it automatically triggered, extracting all changes from the buffer and initiating subsequent steps. If the change events in the buffer do not meet the preset conditions or the semantic importance score of the extracted change events is not greater than a preset score threshold, the change events in the buffer are cleared, and monitoring continues. This application embodiment here, by setting such a change buffer, can both meet the integrity requirements of storing code snapshots and reduce the system hardware and software resources occupied during the implementation of this solution to a certain extent. The preset conditions can be set regarding the size of the storage space occupied by the stored change events, or can be set according to other needs of system developers or users to meet different user scenario needs, thereby further improving the flexibility of the method described in this embodiment. This application embodiment exemplarily describes the usage process of the above-mentioned change buffer, such as... Figure 3 As shown, Figure 3This is an exemplary workflow diagram of a code snapshot management method provided in an embodiment of this application. Before obtaining multiple evaluation dimension information corresponding to the change event and fusing the multiple evaluation dimension information to obtain the semantic importance score of the corresponding change event, the monitored change event is first written into the change buffer. Then, it is determined whether the stored change event meets the preset conditions or the time interval. When it is determined that it meets the preset conditions or the time interval, the semantic importance score of the corresponding change event is obtained. Then, it is determined whether the semantic importance score is greater than the preset score threshold. When it is determined that the semantic importance score is greater than the preset score threshold, a code snapshot of the corresponding change event is generated and saved. Otherwise, the monitoring of change events continues and the change buffer is cleared.
[0037] Furthermore, the method also includes performing runtime tests and functional integrity checks on the rolled-back code after executing the intelligent rollback, generating a rollback report based on the test results and check results, and generating corresponding rollback feedback. The rollback feedback includes at least one of the following feedback information: the number of rolled-back files, the number of retained improvements, and the test pass rate, so that users can adjust the parameters of the rollback operation based on the rollback report or rollback feedback, thereby further improving the accuracy and flexibility of the rollback.
[0038] The methods described in this solution possess strong engineering implementation capabilities and application value. For example, in a CI / CD (Continuous Integration / Continuous Deployment) pipeline, the system implementing the methods described in this embodiment can act as an intelligent access control system, monitoring and automatically capturing high-risk merge points in real time during the code integration phase. This enables real-time snapshot management in the CI / CD process, allowing for the assessment of change importance and snapshot generation before each build. If a build fails, it automatically recommends rollback points. In a microservice architecture, the aforementioned partial module rollback technology allows developers to safely roll back historical versions of individual microservice modules. Simultaneously, the dependency graph automatically detects the impact on compatibility with other microservice interfaces, ensuring the overall stability of the distributed system. Semantic-level code understanding and intelligent rollback recommendations help developers quickly locate and fix ambiguous issues in legacy code, reducing maintenance costs.
[0039] Furthermore, traditional version control systems, such as Git, rely on pure textual difference algorithms for version comparison and incremental storage. This mechanism only identifies changes in line numbers and characters, failing to understand the semantics of the code. Any functionally equivalent code refactoring (e.g., function renaming, variable scope adjustment) can easily be identified by Git as a large number of text line changes, resulting in a noisy version history and an inability to determine whether the changes are optimizations or functional modifications. In contrast, our enhanced snapshot data structure achieves semantic-level representation and storage by uniformly encapsulating code text and rich semantic metadata. This data structure, unlike traditional Diff, cannot determine the essence of code evolution. By storing ASTs and semantic vectors, the system gains structure awareness and deep semantic understanding capabilities, accurately identifying functionally equivalent refactorings or semantically preserved optimizations. This means that during version comparison, the system can filter out a large amount of textual noise that does not affect functionality, truly focusing on substantial changes in code functionality or quality, providing high-precision feature support for subsequent intelligent decision-making. Moreover, traditional incremental storage is based solely on textual differences. This solution employs a dual incremental storage strategy that combines binary differential (for code text) with incremental updates of semantic vectors (for semantic data). This approach of semantic incremental compression and reference reuse not only ensures the semantic integrity of any historical snapshot but also significantly saves storage space, making it highly suitable for large-scale, long-term version tracking scenarios.
[0040] Compared to intelligent rollback strategies, the methods described in this embodiment are significantly superior to traditional Git revert or reset operations in terms of both technical complexity and effectiveness. Traditional Git rollbacks are essentially simple and crude text or file replacements, resulting in relatively coarse problem localization. Developers need to manually search for issue snapshots one by one, either manually or through vague commit messages, leading to time-consuming localization. These rollback operations do not consider code semantics; during rollback, they simply erase all content (including effective improvements) in all versions after the issue snapshot, lacking checks on dependencies and interface compatibility, which can easily cause other dependent modules to crash. The method in this embodiment, by introducing semantic association and semantic comparison, overcomes the reliance on keywords, achieving cross-modal semantic matching, significantly shortening problem localization time, and automatically recommending the most relevant historical snapshots, transforming problem localization from manual retrieval to second-level intelligent recommendation. Furthermore, Git cannot distinguish between good and bad changes, nor can it perform safe partial rollbacks. This method, however, uses semantic structure comparison to clearly define the judgment criteria: if a change leads to a significant increase in complexity, a decrease in coverage, or a reduction in security score (quality degradation), a full rollback is performed. If valid improvements exist and there are no conflicts, the current version is retained, increasing the rollback success rate and reducing risk. This ensures that valuable optimizations and improvements are preserved to the greatest extent possible while eliminating problematic code, achieving precise rollback. Furthermore, this method supports module-level rollback, further reducing the scope of change impact.
[0041] This application provides a code snapshot management method. It involves monitoring code file change events; acquiring multiple evaluation dimensions corresponding to the change events; fusing these dimensions to obtain a semantic importance score for each change event; performing semantic analysis on the code in the changed file when the semantic importance score exceeds a preset threshold to obtain the code semantic information of the changed file; the changed file being the modified code file; and generating and storing a code snapshot based on the semantic information. This code snapshot management method employs an automatic triggering mechanism based on semantic importance assessment for code change evaluation, replacing traditional manual or timed triggering methods. Intelligent decision-making on whether to generate a snapshot, through natural language semantic matching, transforms problem localization from manual retrieval to semantic retrieval, significantly shortening the analysis cycle and eliminating the uncertainty of manual judgment. The system continuously records key change states, ensuring that the stored code snapshots can be fully reconstructed from any historical snapshot while effectively reducing storage consumption.
[0042] Based on the code snapshot management method provided in the above embodiments of this application, this application also provides a corresponding code snapshot management device, such as... Figure 4 As shown, Figure 4 This is a schematic diagram of the structure of a code snapshot management device 20 provided in an embodiment of this application. The code snapshot management device 20 includes: Listener module 201 is used to listen for change events to code files; The evaluation module 202 is used to obtain multiple evaluation dimension information corresponding to the change event, and to fuse the multiple evaluation dimension information to obtain a semantic importance score corresponding to the change event; Analysis module 203 is used to perform semantic analysis on the code in the modified file when the semantic importance score is greater than a preset score threshold, and obtain the code semantic information of the modified file; the modified file is the modified code file; The storage module 204 is used to generate a code snapshot based on the code semantic information and to store the code snapshot.
[0043] Optionally, in one implementation of the embodiments of this application, such as Figure 5 As shown, Figure 5 This is a schematic diagram of another code snapshot management device 21 provided in an embodiment of this application. The device 21 further includes a rollback module 205. The rollback module 205 is used to calculate the semantic information similarity between the rollback request and the stored code snapshot when a rollback request containing a natural language description is received; generate a code rollback recommendation list based on the similarity calculation result, determine the target rollback snapshot from the code rollback recommendation list, and perform a corresponding intelligent rollback operation based on the target rollback snapshot; wherein, the intelligent rollback operation is used to perform a semantic comparison between the current code version and the target rollback snapshot, and then determine the code rollback strategy to be executed based on the comparison result.
[0044] Optionally, in one implementation of this application embodiment, the evaluation dimension information includes at least two of the following: the impact scope analysis result of the change event, the complexity change analysis result, the architecture impact detection result, the test coverage change evaluation result, and the security risk identification result; correspondingly, the process by which the rollback module 205 integrates the multiple evaluation dimension information to obtain the semantic importance score corresponding to the change event specifically involves performing a weighted calculation on the multiple evaluation dimension information to obtain the semantic importance score corresponding to the change event.
[0045] Optionally, in one implementation of this application embodiment, the analysis module 203 is further configured to: perform semantic analysis on the code in the modified file to obtain the modified code text and semantic metadata, wherein the semantic metadata includes at least an abstract syntax tree structure, a dependency graph, quality indicators, and a multidimensional normalized semantic vector; correspondingly, the storage module 204 is further configured to: encode the modified code text and the semantic metadata into a semantically enhanced snapshot with a unified data structure to form a code snapshot to be stored, wherein the semantically enhanced snapshot includes at least: the modified code text, the abstract syntax tree structure, the dependency graph, the quality indicators, and the multidimensional normalized semantic vector; determine whether the content of the code snapshot to be stored is a baseline snapshot of the previous version of the code (the first snapshot is the baseline version), wherein the baseline snapshot is a complete storage of all semantic metadata. Enhance the data structure of the snapshot; if the judgment result is a non-baseline snapshot, record and store the change information of the code snapshot to be stored relative to the previous version of the code. The change information includes binary difference data of the changed file and incremental update data of the multidimensional normalized semantic vector (including the structural difference of the AST). The binary difference data is used to reconstruct the code text, and the incremental update data of the semantic vector is used to reconstruct the aggregate semantic vector of the current version. Based on the monitored change event, determine that other code files within the current project scope, excluding the changed file, are code files that have not undergone code text changes. For files that have not undergone code text changes, store their hash reference information relative to the baseline snapshot or the code snapshot of the previous version of the code, so as to link to the corresponding baseline snapshot through the hash reference information.
[0046] Optionally, in one implementation of this application embodiment, the process of obtaining the multidimensional normalized semantic vector includes: using a pre-trained language model to obtain the text semantic vector of the modified code text; and extracting the structured feature vector of the modified code text based on the abstract syntax tree structure in the semantic metadata, wherein the structured feature vector includes at least a complexity index and a pattern recognition result; fusing the text semantic vector with the structured feature vector and performing normalization processing to generate the multidimensional normalized semantic vector.
[0047] Optionally, in one implementation of this application embodiment, the rollback module 205 is further configured to: use natural language processing technology to convert the natural language problem description contained in the rollback request into a problem semantic vector; obtain at least one of the following information from the stored historical snapshot set: the aggregate semantic vector of each historical snapshot and the problem semantic vector: semantic relevance score, file overlap information, and time decay factor information; and determine the rollback risk of different historical snapshots based on the number of changes, test coverage differences, and code quality differences of the historical snapshots; calculate a final recommendation score based on at least one of the semantic relevance score, file overlap information, and time decay factor information, and a weighted combination of the rollback risk; and generate a list of the top N recommended snapshots as the code rollback recommendation list based on the final recommendation score, and output the corresponding recommendation reasons for the user to choose from.
[0048] Optionally, in one implementation of this application embodiment, the rollback module 205 is further configured to, before acquiring at least one of the following information from the aggregate semantic vector of each historical snapshot in the stored historical snapshot set and the semantic relevance score, file overlap information, and time decay factor information of the problem semantic vector, encode the code text of each historical snapshot using a pre-trained language model to generate text semantic vectors for each snapshot; and analyze the code structure features based on an abstract syntax tree to extract the structured feature vectors of the code text of each historical snapshot; and fuse and normalize the text semantic vectors and structured feature vectors of each historical snapshot to generate the aggregate semantic vector, which is used to characterize the overall semantic features of each historical snapshot.
[0049] Optionally, in one implementation of this application embodiment, the rollback module 205 is further configured to: Perform semantic structure comparison of code files between the target rollback snapshot and the current version to analyze changes in code complexity, test coverage, and security score; Based on the results of semantic structure comparison, a rollback strategy is determined for each file, and the rollback strategy includes: When the results of semantic structure comparison determine that the code complexity increases more than a preset complexity threshold, or the test coverage decreases significantly more than a preset coverage threshold, or the security score decreases more than a preset security threshold, it is judged that the code quality has degraded, and a complete rollback strategy is adopted. When it is determined from the results of semantic structure comparison that a change in the interface definition has caused a compatibility conflict, an intelligent merging strategy is adopted. When the semantic structure comparison determines that there are semantic improvements in the current version and no interface conflicts, the strategy of retaining the current code version is adopted.
[0050] Optionally, in one implementation of this application embodiment, the rollback module 205 is further configured to: when a user selects to partially roll back a specified module, identify downstream files affected by the rollback strategy of the specified module based on the dependency graph; detect the compatibility between the interface usage of the downstream files and the interface definition of the specified module in the target rollback snapshot, and determine compatibility issues; based on the compatibility issues, generate code suggestions to repair the downstream files and provide feedback to the user; after the user confirms the repair suggestions, only perform the rollback operation on the corresponding code of the specified module, while retaining the improvement status of other code.
[0051] Optionally, in one implementation of this application embodiment, the rollback module 205 is further configured to: perform one or more of the following checks on the interface of the downstream file and the interface of the specified module in the target rollback snapshot, based on the abstract syntax tree structure and dependency graph: function signature check, method parameter check, inheritance chain check, and return value type check.
[0052] Furthermore, in one implementation of this application embodiment, the device 20 further includes a buffer module (attached). Figure 1 (Not shown in / 2) This buffer module, upon receiving a detected change event, does not immediately determine whether to generate a corresponding code snapshot or perform other processing operations based on the change event. Instead, it first writes the changes into a "change buffer." Only when the change events stored in this buffer meet preset conditions or a timed interval are met is the change automatically triggered, retrieving all changes from the buffer and initiating subsequent steps. This approach satisfies the integrity requirements of stored code snapshots while also reducing the system hardware and software resources required during implementation. The preset conditions can be set regarding the storage space occupied by the stored change events, or they can be set according to other needs of system developers or users to meet different user scenarios. This further improves the flexibility of the method described in this embodiment.
[0053] Optionally, in one implementation of this application embodiment, the device 20 further includes an adaptive module (not shown in the figures), which is used to configure the preset scoring threshold as an adaptive threshold. Specifically, the process of configuring the pre-review scoring threshold by the adaptive module is as follows: calculating an initial threshold based on the statistical distribution characteristics of the historical snapshot importance scoring sequence; monitoring the snapshot trigger frequency, dynamically adjusting the initial threshold according to the trigger frequency, and using the adjusted initial threshold as the preset scoring threshold. The process of monitoring the snapshot trigger frequency and dynamically adjusting the initial threshold according to the trigger frequency includes: statistically analyzing the statistical distribution characteristics of the comprehensive importance scoring sequence of historical snapshots, wherein the statistical distribution characteristics include at least one of the mean and variance of historical scores; dynamically adjusting the adaptive threshold based on the statistical distribution characteristics and in conjunction with feedback from the actual snapshot trigger frequency, thereby achieving adaptive learning of project-specific code change patterns. This application embodiment here limits the continuous statistical analysis of the statistical distribution characteristics (e.g., mean score, standard deviation, or high percentile) of the comprehensive importance scoring sequence of historical snapshots.
[0054] This application embodiment exemplifies a code snapshot system to illustrate the code snapshot management device described in this embodiment. Specifically, as shown in Figure 6, Figure 6This application provides a schematic diagram of the overall structure of a code snapshot management system (device). The system is divided into four main functional units: a snapshot triggering unit, a semantic analysis unit, an intelligent rollback unit, and a snapshot storage unit. The triggering unit includes a listening module, a buffering module, an evaluation module, and an analysis module. The listening module listens for change events to code files. The buffering module writes the change events detected by the listening module into a "change buffer." When the change events stored in the buffer meet preset conditions or a predetermined time interval, the evaluation module executes instructions to obtain the semantic importance score of the corresponding change event. Specifically, by calling the semantic analysis unit, it determines the code semantic information (semantic data) representing the semantic data of the change event from multiple dimensions of semantic metadata, including abstract syntax tree structure (AST parsing), dependency analysis (dependency graph), pattern detection, and multidimensional normalized semantic vectors, and evaluates its importance. Then, the analysis module determines whether to trigger the command to generate a code snapshot based on the importance assessment results. If it is determined that a code snapshot needs to be generated, the code text corresponding to the change event, the hash reference information of the code snapshot relative to the previous version of the code, and the semantic metadata determined during semantic analysis, and may also include semantic data such as the design intent and incremental data (Delta) of the code corresponding to the change event, are all saved to the snapshot storage unit for storing historical snapshots. When code rollback is required, the intelligent rollback unit analyzes the user's rollback request, converts the natural language problem description into a problem semantic vector, and uses the problem semantic vector to calculate the semantic similarity between the rollback request and the code snapshots and other data stored in the snapshot storage unit. Based on the similarity calculation results, a code rollback recommendation (recommendation list) is generated. The target rollback snapshot is determined from the code rollback recommendation list, and the corresponding intelligent rollback operation is performed according to the target rollback snapshot. This system employs an automatic triggering mechanism based on semantic importance assessment for code change evaluation. It also uses an automatic snapshot triggering mechanism to intelligently decide whether to generate a snapshot. Through semantic analysis, problem localization is transformed from manual retrieval to semantic retrieval, significantly shortening the analysis cycle and eliminating the uncertainty of manual judgment. The system comprehensively and accurately demonstrates the entire lifecycle of code snapshot generation, storage, and code rollback support included in this solution. Each unit module has a clear function, a complete and controllable process, and continuously records the status of key changes. This ensures that stored code snapshots can be fully reconstructed from any historical snapshot while effectively reducing storage consumption. This application also provides a storage medium storing a computer program that, when executed by a processor, implements any of the code snapshot management methods described in the foregoing embodiment one of this application. Furthermore, embodiments of this application also provide an electronic device, such as... Figure 7As shown, Figure 7 This application provides a schematic diagram of the structure of an electronic device 30, which includes: One or more processors 301, communication interface 302, memory 303 and communication bus 304, the processors 301, memory 303 and communication interface 302 communicate with each other through communication bus 304; Memory 303 is used to store one or more programs; When the one or more programs are executed by the one or more processors 301, the one or more processors 401 implement any of the code snapshot management methods described in Embodiment 1 of this application.
[0055] This application has now described specific embodiments of the subject matter. In some cases, the actions described in the claims can be performed in a different order and still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing can be advantageous.
[0056] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system layer onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must also be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0057] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0058] The system layers, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0059] For ease of description, the above devices are described separately by function as various units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.
[0060] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0061] Those skilled in the art will understand that embodiments of this application can be provided as methods, system-level, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0062] This application can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific transactions or implement specific abstract data types. This application can also be practiced in distributed computing environments where transactions are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0063] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system-level embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0064] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A code snapshot management method, characterized in that, include: Listen for changes to code files; Obtain multiple evaluation dimension information corresponding to the change event, and fuse the multiple evaluation dimension information to obtain the semantic importance score of the change event; When the semantic importance score is greater than a preset score threshold, semantic analysis is performed on the code in the modified file to obtain the code semantic information of the modified file; The modified file is the revised code file; Based on the code semantic information, generate a code snapshot and store the code snapshot; The method further includes: when a rollback request containing a natural language description is received, calculating the semantic similarity between the rollback request and the stored code snapshot; generating a code rollback recommendation list based on the similarity calculation result, determining a target rollback snapshot from the code rollback recommendation list, and performing a corresponding intelligent rollback operation based on the target rollback snapshot; wherein, the intelligent rollback operation is used to perform a semantic comparison between the current code version and the target rollback snapshot, and determine the code rollback strategy to be executed based on the comparison result; The step of performing semantic analysis on the code in the modified file to obtain the code semantic information of the modified file includes: performing semantic analysis on the code in the modified file to obtain the modified code text and semantic metadata; the semantic metadata includes at least: an abstract syntax tree structure, a dependency graph, quality indicators, and a multidimensional normalized semantic vector; the step of generating a code snapshot based on the code semantic information and storing the code snapshot includes: encoding the modified code text and the semantic metadata into a semantically enhanced snapshot with a unified data structure to form a code snapshot to be stored; the semantically enhanced snapshot includes at least: the modified code text, the abstract syntax tree structure, the dependency graph, the quality indicators, and the multidimensional normalized semantic vector; determining whether the content of the code snapshot to be stored is a baseline snapshot of the previous version of the code, the baseline... The snapshot is a data structure that fully stores all semantically enhanced snapshots. If the determination result is a non-baseline snapshot, the change information of the code snapshot to be stored relative to the previous version of the code is recorded and stored. The change information includes the binary differential data of the changed file and the incremental update data of the multidimensional normalized semantic vector. The binary differential data is used to reconstruct the code text, and the incremental update data of the semantic vector is used to reconstruct the aggregate semantic vector of the current version. Based on the detected change event, other code files within the current project scope, excluding the changed file, are identified as code files that have not undergone code text changes. For the code files that have not undergone code text changes, their hash reference information relative to the baseline snapshot or the code snapshot of the previous version of the code is stored so as to link to the corresponding baseline snapshot through the hash reference information.
2. The code snapshot management method according to claim 1, characterized in that, The multiple evaluation dimensions include at least two of the following: The results of the impact scope analysis, complexity change analysis, architecture impact detection, test coverage change assessment, and security risk identification of the change event are as follows: The process of fusing information from multiple evaluation dimensions to obtain a semantic importance score for the corresponding change event includes: The semantic importance score corresponding to the change event is obtained by weighting the information of the multiple evaluation dimensions.
3. The code snapshot management method according to claim 1, characterized in that, The process of obtaining the multidimensional normalized semantic vector includes: Using a pre-trained language model, the text semantic vector of the modified code text is obtained; and based on the abstract syntax tree structure in the semantic metadata, the structured feature vector of the modified code text is extracted, wherein the structured feature vector includes at least a complexity index and a pattern recognition result. The text semantic vector is fused with the structured feature vector and then normalized to generate the multidimensional normalized semantic vector.
4. The code snapshot management method according to claim 1, characterized in that, When a rollback request containing a natural language description is received, the semantic similarity between the rollback request and the stored code snapshot is calculated; based on the similarity calculation result, a code rollback recommendation list is generated to determine the target rollback snapshot from the code rollback recommendation list, and a corresponding intelligent rollback operation is performed according to the target rollback snapshot, including: Using natural language processing techniques, the natural language problem description contained in the rollback request is converted into a problem semantic vector; Obtain the semantic relevance score, file overlap information, and time decay factor information of the aggregated semantic vector of each historical snapshot in the stored historical snapshot set and the problem semantic vector; and determine the rollback risk of different historical snapshots based on the number of changes, test coverage differences, and code quality differences of the historical snapshots. The final recommendation score is calculated based on a weighted combination of the semantic relevance score, file overlap information, time decay factor information, and rollback risk. Based on the final recommendation score, a list of the top N recommended snapshots is generated as the code rollback recommendation list, and the corresponding recommendation reasons are output for the user to choose from.
5. The code snapshot management method according to claim 4, characterized in that, Before acquiring the semantic relevance score, file overlap information, and time decay factor information of the aggregated semantic vector of each historical snapshot in the stored historical snapshot set and the question semantic vector, the method further includes: The code text of each historical snapshot is encoded using a pre-trained language model to generate text semantic vectors for each snapshot; and the code structure features are analyzed based on an abstract syntax tree to extract the structured feature vectors of the code text corresponding to each historical snapshot. The text semantic vectors of each historical snapshot are fused and normalized with their structural feature vectors to generate the aggregate semantic vector, which is used to represent the overall semantic features of each historical snapshot.
6. The code snapshot management method according to claim 1, characterized in that, The step of performing a semantic comparison between the current code version and the target rollback snapshot, and determining the code rollback strategy to be executed based on the comparison results, includes: A semantic structure comparison is performed on the code files between the target rollback snapshot and the current version to analyze changes in code complexity, test coverage, and security score. Based on the results of semantic structure comparison, a rollback strategy is determined for each code file in the current version. The rollback strategy includes: When the results of semantic structure comparison determine that the code complexity increases more than a preset complexity threshold, or the test coverage decreases more than a preset coverage threshold, or the security score decreases more than a preset security threshold, it is judged as code quality degradation, and a complete rollback strategy is determined. When it is determined from the results of semantic structure comparison that a change in the interface definition has caused a compatibility conflict, an intelligent merging strategy is adopted. When the semantic structure comparison determines that there are semantic improvements in the current version and no interface conflicts, the strategy of retaining the current code version is adopted.
7. The code snapshot management method according to claim 6, characterized in that, The method further includes: When a user selects to partially roll back a specified module, the downstream files that depend on the specified module are identified based on the dependency graph. The compatibility between the interface usage of the downstream file and the interface definition of the corresponding specified module in the target rollback snapshot is checked to identify compatibility issues; Based on the aforementioned compatibility issues, code suggestions for fixing the downstream files are generated and fed back to the user; After the user confirms the repair suggestion, a rollback operation is performed on the corresponding code of the specified module, while preserving the improved state of other code.
8. The code snapshot management method according to claim 7, characterized in that, The compatibility between the interface usage for detecting the downstream file and the interface definition of the corresponding specified module in the target rollback snapshot includes: Identify downstream dependent files affected by the rollback strategy executed by the specified module based on the dependency graph; Perform fine-grained interface checks on each affected downstream dependency file, including at least the following dimensions: consistency of function signatures, inheritance relationships of public methods in the class, and compatibility of return value types. If incompatibility is found, a compatibility analysis report containing repair recommendations will be generated.
9. The code snapshot management method according to claim 1, characterized in that, The method further includes configuring the preset scoring threshold as an adaptive threshold; The adaptive threshold is determined by calculating an initial threshold based on the statistical distribution characteristics of the historical snapshot importance score sequence. Monitor the snapshot trigger frequency, dynamically adjust the initial threshold according to the trigger frequency, and use the adjusted initial threshold as the preset scoring threshold.
10. A code snapshot management device, characterized in that, include: The listener module is used to listen for changes to code files; An evaluation module is used to obtain multiple evaluation dimension information corresponding to the change event, and to fuse the multiple evaluation dimension information to obtain a semantic importance score for the change event. The analysis module is used to perform semantic analysis on the code in the modified file when the semantic importance score is greater than a preset score threshold, so as to obtain the code semantic information of the modified file. The modified file is the revised code file; A storage module is used to generate a code snapshot based on the code semantic information and to store the code snapshot; It also includes a rollback module, which, when a rollback request containing a natural language description is received, calculates the semantic similarity between the rollback request and the stored code snapshot; generates a code rollback recommendation list based on the similarity calculation result, determines a target rollback snapshot from the code rollback recommendation list, and performs a corresponding intelligent rollback operation based on the target rollback snapshot; wherein, the intelligent rollback operation is used to perform a semantic comparison between the current code version and the target rollback snapshot, and determines the code rollback strategy to be executed based on the comparison result; The analysis module is further configured to: perform semantic analysis on the code in the modified file to obtain the modified code text and semantic metadata; the semantic metadata includes at least: an abstract syntax tree structure, a dependency graph, quality indicators, and a multidimensional normalized semantic vector; the step of generating a code snapshot and storing the code snapshot based on the code semantic information includes: encoding the modified code text and the semantic metadata into a semantically enhanced snapshot with a unified data structure to form a code snapshot to be stored; the semantically enhanced snapshot includes at least: the modified code text, the abstract syntax tree structure, the dependency graph, the quality indicators, and the multidimensional normalized semantic vector; and determining whether the content of the code snapshot to be stored is a baseline snapshot of the previous version of the code, wherein the baseline snapshot is a complete storage of all semantically enhanced snapshots. The data structure is as follows: If the judgment result is a non-baseline snapshot, the change information of the code snapshot to be stored relative to the previous version of the code is recorded and stored. The change information includes the binary difference data of the changed file and the incremental update data of the multidimensional normalized semantic vector. The binary difference data is used to reconstruct the code text, and the incremental update data of the semantic vector is used to reconstruct the aggregate semantic vector of the current version. Based on the detected change event, other code files in the current project scope besides the changed file are identified as code files that have not undergone code text changes. For the code files that have not undergone code text changes, their hash reference information relative to the baseline snapshot or the code snapshot of the previous version of the code is stored so as to link to the corresponding baseline snapshot through the hash reference information.
11. A computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions, which, when executed, perform the code snapshot management method as described in any one of claims 1-9.
Citation Information
Patent Citations
Model training method and device, code submission annotation generation method and device and electronic equipment
CN116737228A
Intelligent code change recognition system, method and device based on large language model and medium
CN120596354A