A review session management and comment delivery method for database code merge requests
Patent Information
- Application Number
- CN202610724308.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-25
- Publication Date
- 2026-08-18
AI Technical Summary
这导致以下缺陷:其一,同一合并请求的多轮追问引发重复拉取代码、重复构建上下文与重复全量分析,产生大量冗余开销与时延;其二,模型对同一份代码的多次分析结论不一致,损害审查可信度;其三,服务因升级、重启或异常中断时,正在进行的或已沉淀的会话信息均会丢失;其四,合并请求生命周期结束时缺乏对会话数据、互斥资源等的系统化清理,长期运行后存储空间与可观测性显著恶化
Smart Images

Figure CN122593832A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent code review technology, and in particular to a method for managing review sessions and submitting comments for database code merging requests. Background Technology
[0002] As foundational software, database management systems (DBMS) are experiencing a continuous increase in the complexity of their core and peripheral tools, demanding extremely high levels of code correctness and performance stability. Currently, the industry commonly employs a collaborative development model based on code hosting platforms (such as GitLab and Gitee). Before merging into the main branch, developers must create a merge request, which is then manually reviewed by qualified peers. To alleviate the pressure of manual review, an increasing number of teams are introducing automated intelligent review systems based on large language models at this stage. These systems use hosting platform event callbacks as triggers, submitting code differences along with their context to the model for analysis, and then writing the generated review conclusions back to the merge request page as line-level comments.
[0003] However, code hosting platforms impose strict protocol constraints on the acceptance of line-level comments: the file path and line number pointed to by the comment must fall precisely within the scope of differences (i.e., change blocks) of the current merge request, and there are also clear requirements regarding the "side" to which the line number belongs (new version side or old version side). Under these constraints, existing intelligent review solutions have significant shortcomings in both the "session management" and "comment submission" stages, which are interconnected.
[0004] In terms of session management, existing solutions generally adopt a stateless request-response processing model, where each external event triggers an independent and complete analysis process without retaining context memory. This leads to the following drawbacks: First, multiple rounds of questioning for the same merge request result in repeated code fetching, repeated context building, and repeated full analysis, generating significant redundant overhead and latency. Second, inconsistent analysis conclusions from multiple analyses of the same code by the model damage the credibility of audits. Third, ongoing or previously stored session information is lost when the service is upgraded, restarted, or interrupted abnormally. Fourth, the lack of systematic cleanup of session data and mutually exclusive resources at the end of the merge request's lifecycle leads to significant deterioration in storage space and observability after long-term operation.
[0005] Regarding comment submission, existing solutions also face long-standing unresolved challenges: when large language models reason about longer, more complex segments, their judgments on specific line numbers often become biased, leading to a large number of comment submission requests being rejected by the hosting platform, resulting in a lack of observability where "the model generates comments, but the user cannot see them." There is a lack of effective constraints on whether the comments generated by the model are truly based on the code content; the model often makes judgments based on superficial clues, leading to "fabrication" issues. Faced with occasional, small-scale line number misalignments, existing solutions either directly abandon the comments, resulting in the loss of review information, or force submissions, causing interface failures, lacking fault tolerance and correction capabilities. Furthermore, the lack of structured constraints on comment content leads the model to tend to output lengthy, free text lacking evidence for problem identification, reducing the reading efficiency of human reviewers.
[0006] The two types of problems mentioned above overlap, and even if the conversation context is well maintained, the generated comments may not be actually seen due to line number misalignment or lack of evidence; even if the comment submission process has a certain fault tolerance, the lack of cross-time memory of the conversation context will also make it difficult to maintain stable comment quality.
[0007] Chinese patent CN109918114A discloses a method for obtaining code comment information. It provides a method to extract "comments on code" from a list of comments on multiple code merging requests submitted to a protection branch and associate them with corresponding code content, thereby generating code comment information in batches. However, this solution only addresses the collection and presentation of comment information and does not address mechanisms such as session state management, cross-event context maintenance, service interruption recovery, accurate determination and correction of line numbers for line-level comments, credibility constraints on comment content based on actual reading trajectories, and structured output contracts during the intelligent review process. Therefore, it cannot address issues such as redundant overhead, inconsistent conclusions, comment delivery failures, and "fabrication" caused by stateless processing in intelligent review systems based on large language models.
[0008] Therefore, there is an urgent need to design a unified and systematic approach to session management and comment delivery across the entire review process in order to improve the reliability and observability of the intelligent review system in database code merging request scenarios. Summary of the Invention
[0009] In view of this, in order to overcome the shortcomings of the prior art, the present invention aims to provide a method for review session management and comment delivery for database code merging requests.
[0010] This invention provides a method for managing review sessions and submitting comments for database code merging requests, the method comprising:
[0011] Step S1: Build a root namespace for each merge request, maintain the main session and thread sessions under it, realize the on-demand derivation of the thread session from the main session through deep copy, persist the session state to local hierarchical storage and support index reconstruction when the service starts;
[0012] Step S2: Listen for the end event of the merge request, and after acquiring the mutual exclusion resource, perform session storage directory cleanup and memory index release;
[0013] Step S3: Construct a change block index based on the structured parsing of code differences, maintain the set of file paths read by the agent, and generate candidate comments by constraining the structured contract containing the problem evidence field;
[0014] Step S4: Perform three-state line number determination and correction on the candidate comments based on the changed block index, and submit after mandatory verification in combination with the read path set.
[0015] Optionally, in the review session management and comment delivery method for database code merging requests of the present invention, in step S1, the thread session is derived from the main session on demand through deep copy in the following manner: when the target thread session does not exist and the main session exists, the main session is directly deep copied to derive a new thread session; when the main session also does not exist, the main session is first created and a complete code difference understanding is completed, and then the thread session is derived based on the state of the main session, so that the thread session inherits the code understanding context, change block index and read path set of the main session.
[0016] Optionally, in the method for managing review sessions and submitting comments for database code merging requests of the present invention, in step S1, the session state is persisted to local hierarchical storage and index reconstruction is supported at service startup in the following manner:
[0017] The runtime state of each session is stored in a structured file in the default session directory of the local file system. The session directory path is organized hierarchically according to the root namespace and session identifier.
[0018] When the service starts, the recovery program first performs a first-level scan on the session root directory to identify all merge request namespaces and rebuild the merge request mutex resource index accordingly. Then, it performs a second-level scan on each namespace to identify all session identifiers and rebuild the session index accordingly.
[0019] During the index rebuild process, only the session's metadata entries are restored without immediately loading the session state. The session state is loaded from local storage on demand when its corresponding event is first triggered.
[0020] Optionally, in the method for managing review sessions and submitting comments for database code merging requests according to the present invention, step S2 includes:
[0021] When a merge request is received, either merge or close, the system attempts to acquire the requested mutex resource after a preset timeout.
[0022] Regardless of whether the acquisition is successful within the timeout period, a cleanup operation is forcibly performed, including removing the context data directory, removing all session persistence directories, removing session index entries in memory, and releasing mutex resources. This cleanup operation deliberately preserves the local code repository copy corresponding to the code hosting platform.
[0023] If the mutually exclusive resource cannot be acquired within the preset timeout, an alarm log will be recorded.
[0024] Optionally, in the review session management and comment delivery method for database code merging requests of the present invention, step S3 involves constructing a change block index based on structured parsing of code differences in the following manner: during the review task initiation phase, the difference content of the merging request is parsed according to a general difference format, and the old side starting line, old side line number, new side starting line, and new side line number of each change block are identified file by file; each change block is encapsulated as a change block object containing the file path and the endpoints of the old and new sides, and organized into a change block index using the file path as the key.
[0025] Optionally, in the review session management and comment delivery method for database code merging requests of the present invention, in step S3, the set of read file paths of the agent is maintained in the following manner: the session layer pre-sets code reading tools in the agent's toolset and maintains a set of read paths that records the history of tool calls. Each time the agent successfully reads a file, it adds the path of that file to the set of read paths.
[0026] Optionally, in the review session management and comment submission method for database code merging requests of the present invention, step S3, the generation of candidate comments is constrained by a structured contract containing a problem evidence field in the following manner: the comment submission action is modeled as a structured tool with strong type field constraints. The parameter structure of the tool includes at least the target file path, target line number, comment body, and a problem evidence field with a limited length. The problem evidence field forces the agent to explicitly provide the specific problem statement corresponding to the comment in each comment, and its length is constrained by a preset upper limit. When the candidate comment generated by the agent does not conform to the structured contract at the field level, or the problem evidence field is missing, or the problem evidence field exceeds the length limit, the candidate comment is rejected, and a structured error feedback is returned to the agent to request regeneration. At the same time, an upper limit is set on the number of retries for a single candidate comment. If the retry limit is exceeded, the generation attempt of the comment is terminated.
[0027] Optionally, in the review session management and comment delivery method for database code merging requests of the present invention, in step S4, the candidate comments are judged in a three-state line number manner according to the change block index as follows: the target file path and target line number declared in the candidate comment are extracted, and all change blocks corresponding to the file are searched in the change block index; if the target line number falls within the interval defined by the new side start line and end line of a change block, it is judged as a strict hit; if the target line number falls outside the interval but is within the adjacent interval defined by the preset context window size extended outward from the endpoint of the interval, it is judged as an adjacent hit, the context window size is specified by a configurable parameter, and the number of lines indicated by the parameter is extended outward from the new side endpoint of the change block in each judgment; if the target line number is outside the adjacent interval, it is judged as a complete out-of-bounds.
[0028] Optionally, in the method for review session management and comment submission for database code merging requests of the present invention, in step S4, a correction process is performed after the three-state line number determination in the following manner: when a candidate comment is determined to be a neighboring hit, a correction is performed based on the relative position of the target line number and the new side interval of the change block. If the target line number is less than the starting line of the new side, the target line number is corrected to the starting line of the new side; if the target line number is greater than the ending line of the new side, the target line number is corrected to the ending line of the new side. The corrected comment is reassembled, and a marker indicating that the line number has been corrected is carried in the comment's metadata. The corrected comment is then submitted to the code hosting platform.
[0029] Optionally, the review session management and comment submission method for database code merging requests of the present invention submits comments after mandatory verification of the read path set in the following manner: when an agent submits a candidate comment, it is mandatory that the target file path declared in the candidate comment must exist in the read path set; if the target file path is not included in the read path set, the candidate comment is rejected and a structured correction feedback containing the correction feedback is returned to the agent; the read path set is persisted as part of the session state and can be restored across restarts.
[0030] The method for managing review sessions and submitting comments for database code merging requests in this invention has the following beneficial technical effects:
[0031] 1. By using a hierarchical session model and a main session snapshot derivation mechanism, multiple review events under the same merge request can share the same code understanding context, reducing the number of repeated inference calls to a fraction of the original solution, and significantly reducing token consumption and interface call overhead.
[0032] 2. By combining external persistence of session state with a two-level scanning recovery mechanism, the session index can be quickly recovered and the context can be maintained after the service restarts. The startup latency is controlled within seconds at a scale of tens of thousands of sessions. At the same time, the linear growth of storage space is avoided through consistent resource reclamation throughout the lifecycle.
[0033] 3. In the comment delivery process, the complexity of line number determination is reduced from linear to logarithmic level based on the change block structured index. Combined with the three-state line number determination and context window correction mechanism, the end-to-end delivery success rate of line-level comments is increased to over 95%.
[0034] 4. By reading the trajectory and enforcing contracts with structured fields, we prevent fabricated comments from being made out of thin air at the engineering level, ensuring that each comment is accompanied by clear evidence of the problem, thereby achieving efficient, reliable, and observable intelligent review throughout the entire chain of database code merging and review. Attached Figure Description
[0035] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a flowchart illustrating the review session management and comment submission method for database code merging requests according to an exemplary embodiment 1 of the present invention;
[0037] Figure 2 A schematic diagram illustrating the thread session derivation process for the review session management and comment delivery method for database code merging requests according to an exemplary embodiment 1 of the present invention;
[0038] Figure 3 This is a schematic diagram illustrating the process of constraining the generation of candidate comments in the review session management and comment delivery method for database code merging requests according to an exemplary embodiment 1 of the present invention;
[0039] Figure 4 A flowchart illustrating the three-state line number determination process for the review session management and comment submission method for database code merging requests according to an exemplary embodiment 1 of the present invention;
[0040] Figure 5 A flowchart illustrating the correction process for the review session management and comment delivery method for database code merging requests according to an exemplary embodiment 1 of the present invention;
[0041] Figure 6 This is a flowchart illustrating the review session management and comment submission method for database code merging requests according to an exemplary embodiment 1 of the present invention, which incorporates mandatory verification of the read path set. Detailed Implementation
[0042] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0043] It should be noted that, in the absence of conflict, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0044] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.
[0045] Example 1
[0046] Figure 1 This is a flowchart illustrating the review session management and comment submission method for database code merging requests according to an exemplary embodiment 1 of the present invention, as follows: Figure 1 As shown, in this embodiment, the method of the present invention is implemented in the following manner:
[0047] Step S1: Build a root namespace for each merge request, maintain the main session and thread sessions under it, implement the on-demand derivation of the thread session from the main session through deep copy, persist the session state to local hierarchical storage and support index reconstruction when the service starts.
[0048] This embodiment constructs a unique root namespace identifier for each code merge request, which is formed by concatenating the code hosting address, project identifier, and internal number of the merge request in a preset format. Under this root namespace, a two-level session structure is introduced: the first level is the main session, which carries the initial analysis and understanding results of the overall code changes of the merge request; the second level is the thread session, which corresponds to a specific discussion thread in the merge request comment section, and its session identifier is composed of the root namespace plus the identifier of the discussion thread.
[0049] Figure 2 This is a flowchart illustrating the thread session derivation process of the review session management and comment delivery method for database code merging requests according to Exemplary Embodiment 1 of the present invention. Figure 2As shown in this embodiment, when a follow-up question event is received for a certain comment thread, the corresponding thread session is first searched in the session index; if the target thread session does not exist and the main session exists, the main session is directly deep copied to derive a new thread session; if the main session also does not exist, the main session is first created and a complete code difference understanding is completed, and then the thread session is derived based on the state of the main session, so that the thread session inherits the code understanding context, change block index and read path set of the main session.
[0050] In this embodiment, each thread session naturally inherits the existing code understanding context of the main session, eliminating the need for repeated code fetching and full analysis. This significantly reduces the number of repeated inferences and token consumption, while ensuring a consistent code understanding foundation across thread sessions under the same merge request, avoiding inconsistencies in conclusions caused by multiple independent analyses. By limiting the storage of session states to hierarchical structured files and performing a two-level scan to rebuild the index and restore only metadata during service startup, the audit service can quickly restore the index structure of all merge requests and sessions after a restart or abnormal interruption, without immediately loading a large number of session states. Startup time is controlled to an order of magnitude approximately linear with the total number of sessions, maintaining a startup latency of seconds even with tens of thousands of sessions, while ensuring the continuity of session context after restart.
[0051] As an optional example, in this embodiment, the session state is persisted to local hierarchical storage and index reconstruction is supported at service startup in the following manner: the runtime state of each session is stored in the form of a structured file in a preset session directory of the local file system, and the session directory path is organized hierarchically according to the root namespace and session identifier; when the service starts, the recovery program first performs a first-level scan on the session root directory to identify all merge request namespaces and rebuild the merge request mutual exclusion resource index accordingly, and then performs a second-level scan on each namespace to identify all session identifiers and rebuild the session index accordingly; during the index reconstruction process, only the session's metadata entries are restored and the session state is not loaded immediately. The session state is loaded from local storage as needed when its corresponding event is first triggered.
[0052] Step S2: Listen for the end event of the merge request, and perform session storage directory cleanup and memory index release after acquiring the mutual exclusion resource.
[0053] In this embodiment, when a merge request is received (either merge or close), an attempt is made to acquire the requested mutex resource within a preset timeout period. Regardless of whether the acquisition is successful within the timeout period, a cleanup operation is forcibly executed, including removing the context data directory, removing all session persistence directories, removing session index entries from memory, and releasing the mutex resource. This cleanup operation intentionally preserves a copy of the local code repository corresponding to the code hosting platform for reuse by other merge request review tasks, ensuring that all session data, context directories, and memory indexes are reliably reclaimed after the merge request ends, avoiding linear growth of storage space and reducing the overhead of repeatedly pulling code. If the mutex resource cannot be acquired within the preset timeout period, an alarm log is recorded, providing observability support for operation and maintenance troubleshooting.
[0054] Step S3: Construct a change block index based on code difference structured parsing, maintain the set of file paths read by the agent, and generate candidate comments by constraining the structured contract with the problem evidence field.
[0055] In this embodiment, a change block index is constructed based on structured parsing of code differences as follows: During the review task initiation phase, the difference content of the merge request is parsed according to a general difference format, and the old side starting line, old side line number, new side starting line, and new side line number of each change block are identified file by file; each change block is encapsulated as a change block object containing the file path and the endpoints of the old and new sides, and organized into a change block index using the file path as the key. This embodiment transforms the difference content of the merge request into structured, indexable baseline data. This index provides a unified query interface for subsequent line number determination, reducing the time complexity of line number determination for a single comment from O(total number of difference lines) to O(log number of change blocks), significantly improving the computational efficiency of comment verification.
[0056] For example, in the review task initiation phase of this embodiment, the difference content of this merge request is parsed according to the general difference format. The difference header is extracted file by file and the old side starting line number, old side line number, new side starting line number, and new side line number are identified by the syntax "@@-starting line, line number + starting line, line number @@". Each change block is encapsulated as a change block object containing key attributes such as file path and the endpoints of the old and new sides, and a change block index is organized with the file path as the key, which serves as a unified benchmark for subsequent line number determination.
[0057] In this embodiment, the set of read file paths for the agent is maintained as follows: The session layer pre-configures a code reading tool in the agent's toolset and maintains a set of read paths that records the tool's call history. Each time the agent successfully reads a file, it adds the file's path to this set of read paths. By pre-configuring a code reading tool in the toolset and maintaining a set of read paths, a hard constraint of "read before commenting" is established. The agent can only comment on files that have actually been read, thus preventing the creation of comments based on superficial clues from an engineering perspective, significantly improving the credibility and traceability of comments.
[0058] Figure 3 This is a schematic diagram illustrating the process of constraining the generation of candidate comments in the review session management and comment delivery method for database code merging requests according to an exemplary embodiment 1 of the present invention, as shown below. Figure 3 As shown, in this embodiment, candidate comments are generated using a structured contract constraint that includes a problem evidence field, in the following manner:
[0059] The comment submission action is modeled as a structured tool with strong type field constraints. The tool's parameter structure includes at least the target file path, target line number, comment body, and a limited-length question evidence field. This question evidence field mandates that the agent explicitly state the specific question corresponding to each comment, and its length is constrained by a preset upper limit. When a candidate comment generated by the agent does not conform to this structured contract at the field level, or the question evidence field is missing, or the question evidence field exceeds the length limit, the candidate comment is rejected, and a structured error feedback is returned to the agent requesting regeneration. A maximum number of retries is set for a single candidate comment; exceeding this limit terminates the comment generation attempt. This ensures that each comment includes clear and concise question-identification evidence, avoiding the model outputting lengthy and unsupported free text, improving the reading efficiency for human reviewers, and preventing invalid loops through the retry limit, thus guaranteeing overall throughput.
[0060] Step S4: Perform three-state line number determination and correction on the candidate comments based on the changed block index, and submit after mandatory verification in combination with the read path set.
[0061] In this embodiment, candidate comments generated by the agent are searched in the change block index according to their declared target file and target line number, mapped to three judgment states: strict hit (falling within the new side interval of the change block) is directly submitted; near hit (falling outside the new side interval but within a preset context window) enters the correction branch, correcting the target line number to the nearest endpoint of the new side interval of the change block according to preset rules; and complete out-of-bounds enters the rejection branch. The corrected comments are reassembled and marked with the source of correction before being submitted again. This embodiment provides a unified and quantifiable judgment standard for line number determination, expanding the original binary (hit / miss) judgment to a three-state one, reserving precise triggering conditions for subsequent correction processing, and avoiding the direct rejection of comments due to small-range line number offsets.
[0062] Figure 4 A flowchart illustrating the three-state line number determination process for the review session management and comment submission method for database code merging requests according to Exemplary Embodiment 1 of the present invention is shown below. Figure 4 As shown, in this embodiment, the candidate comment is subjected to a three-state line number determination based on the change block index in the following manner: the target file path and target line number declared in the candidate comment are extracted, and all change blocks corresponding to the file are searched in the change block index; if the target line number falls within the interval defined by the new side start line and end line of a change block, it is determined to be a strict hit; if the target line number falls outside the interval but is within the adjacent interval defined by the preset context window size extended outward from the endpoint of the interval, it is determined to be an adjacent hit. The context window size is specified by a configurable parameter, and is extended outward by the number of lines indicated by the parameter from the new side endpoint of the change block in each determination; if the target line number is outside the adjacent interval, it is determined to be a complete out-of-bounds hit.
[0063] Figure 5 A flowchart illustrating the correction process for the review session management and comment delivery method for database code merging requests according to Exemplary Embodiment 1 of the present invention is shown below. Figure 5 As shown, in this embodiment, the correction process is performed after the three-state line number determination in the following manner: when a candidate comment is determined to be a neighboring hit, the correction is performed according to the relative position of the target line number and the new side interval of the change block. If the target line number is less than the starting line of the new side, the target line number is corrected to the starting line of the new side. If the target line number is greater than the ending line of the new side, the target line number is corrected to the ending line of the new side. The corrected comment is reassembled, and the line number is marked as corrected in the comment's metadata. The corrected comment is then submitted to the code hosting platform.
[0064] This embodiment corrects the target line number to the new endpoint based on the relative position of the target line number and the new side interval when a neighboring hit occurs, and carries a correction mark. This allows comments that were originally rejected by the platform due to small-range line number offsets to be successfully submitted in a corrected form. In practical applications, this mechanism increases the end-to-end delivery success rate of line-level comments from approximately 60%-70% to over 95%, while the correction mark maintains the transparency of the review process, making it easy for human reviewers to identify.
[0065] Figure 6 This is a flowchart illustrating the review session management and comment delivery method for database code merging requests according to Exemplary Embodiment 1 of the present invention, which combines mandatory verification of the read path set. Figure 6 As shown, in this embodiment, submission is performed after mandatory verification using the read path set as follows: When an agent submits a candidate comment, it is mandatory that the target file path declared in the candidate comment must exist in the read path set; if the target file path is not included in the read path set, the candidate comment is rejected and a structured correction feedback containing the corrected path is returned to the agent; the read path set is persisted as part of the session state and can be recovered across restarts. This embodiment applies the "read before commenting" constraint throughout the entire session lifecycle. This constraint remains effective even in follow-up questioning and service restart scenarios, ensuring that the credibility of comments does not decrease due to context switching, and providing engineered quality assurance for intelligent review in high-reliability scenarios such as database kernels.
[0066] Example 2
[0067] Exemplary embodiment 2 of the present invention provides a method for managing review sessions and submitting comments for database code merging requests. This embodiment's method is implemented in a layered service architecture based on the Python language. This layered service architecture includes an event access layer, a scheduling layer, a session layer, an execution layer, and a submission verification layer. The event access layer exposes event callback interfaces based on the FastAPI framework, responsible for receiving merge request events and comment events from the code hosting platform; the scheduling layer implements asynchronous task consumption based on a thread pool model, maintaining a mutex resource object for each merge request; the session layer is responsible for session indexing, session derivation, state persistence, startup recovery, and maintenance of the read path set; the execution layer encapsulates a large language model and toolset based on an open-source intelligent agent framework; the submission verification layer is used for difference parsing and change block index construction, candidate comment verification, line number correction, and structured submission.
[0068] Specifically, the method of this embodiment is implemented in the following manner:
[0069] Step 1: Merge request namespaces and initialize mutual exclusion resources
[0070] When the event access layer receives an event involving a merge request for the first time, the scheduling layer generates a root namespace identifier in the format of "code hosting address: project identifier: merge request number" and creates a corresponding entry in the mutual exclusion resource index.
[0071] Step 2: Difference Analysis and Change Block Index Construction
[0072] The scheduling layer parses the differences in the merge request according to the unified diff format, builds a change block index, and then persists it to disk by the persistence layer.
[0073] Step 3: Session Lookup and Derivation
[0074] When an event involves merging a specific discussion thread in the comments section of a request, the session layer constructs the target session identifier according to the format "root namespace: discussion thread identifier" and performs lookup and derivation.
[0075] Step 4: Session State Persistence and Startup Recovery
[0076] Each session's entire runtime state during its lifecycle is stored in its dedicated directory as structured files. After the service process starts, the recovery program performs a two-level scan of the session root directory, rebuilding the namespace mutex resource index and the session index. The entire recovery process only rebuilds the index and does not actually load the session state.
[0077] Step 5: Agent Execution and Timeout Protection
[0078] When the review task is actually started, the execution layer constructs or restores the agent session instance based on the session information. To prevent individual sessions from occupying worker threads for a long time due to model anomalies, the execution layer starts a timer for each session, and automatically calls the session pause interface when the execution time exceeds a preset threshold (e.g., 12 minutes).
[0079] Step Six: Multi-Verification Pipeline for Candidate Comments
[0080] For each comment candidate generated by the agent, it sequentially performs field contract verification, read path verification, and tri-state line number determination. If any of these steps fail, structured feedback is generated and returned to the agent, requesting regeneration; the context window size is specified by configurable parameters (e.g., configured to 3 lines).
[0081] Step 7: Branching based on three-state determination
[0082] If the target line number is a strict hit, the assembly and submission are completed directly. If the target line number is a near hit, the relative position of the target line number and the new side interval of the changed block is corrected to the new side start line or new side end line before submission, and "line number has been corrected" is marked in the comment metadata. If the target line number is completely out of bounds, the submission is rejected and feedback is sent to the agent.
[0083] Step 8: Merge request lifecycle resource reclamation
[0084] When the event access layer receives a merge request to merge or close an event, it performs cleanup, intentionally preserving a local code repository copy corresponding to the code hosting platform during the cleanup process for reuse by other merge request review tasks.
[0085] Example 3
[0086] Exemplary Example 3 of the present invention provides a method for managing review sessions and submitting comments for database code merging requests. This embodiment further describes the method of the present invention in a specific database kernel development scenario.
[0087] In this scenario, a research and development team uses the method described in this embodiment to conduct intelligent review of merge requests for its database kernel repository. Researcher A creates a merge request for both the query optimizer and storage engine modules and triggers the first intelligent review via a comment section command. A root namespace is constructed for this merge request, and seven change blocks are parsed. One change block located in optimizer / plan_node.cpp has a new side start line of 142 and a new side end line of 158. The context window is configured with three rows, so the adjacent window expands to rows 139–161.
[0088] The session layer missed the main session, so a main session was created and the agent was started to analyze all code differences. The agent then produced two candidate comments: the first declared the target file as optimizer / plan_node.cpp, the target line number as 150, and the evidence for the problem as "this branch does not provide a rollback strategy when statistics are missing"; the second declared the target file as optimizer / cost_model.cpp, the target line number as 76, but there was no record of reading cost_model.cpp in the tool call history.
[0089] The first candidate passed the field contract, read path, and line number checks (150 strictly falls within the 142–158 range), and was submitted under the "Strict Hit" branch. The comment ultimately appeared below line 150 of the merge request. The second candidate failed the read path check, was rejected, and feedback was returned to the agent: "The target file cost_model.cpp has not been read; please read it before generating a comment." The agent then read the cost_model.cpp file and generated a new candidate comment, this time declaring the target line number as 80. In the change block index, a certain change block in the file had a new side start line of 82 and a new side end line of 95. Line 80 fell within the adjacent window range but was not strictly hit. Following the "Adjacent Hit" branch, the correction module corrected the target line number to 82 and marked it "Line Number Corrected," then submitted, successfully publishing it below line 82.
[0090] Developer B initiated a follow-up question under a review comment. The session layer did not hit the thread session but hit the existing main session, and derived a new thread session from the main session state. The new thread session naturally inherited the existing code understanding context, change block index and read path set of the main session. The agent can generate a response by performing incremental reasoning based only on the follow-up question content, and the end-to-end response latency is significantly reduced.
[0091] Subsequently, the service was restarted due to service node maintenance requirements. The recovery process automatically scanned the session root directory, reconstructed the namespace, mutex resource entries, and metadata entries for the main session and thread sessions corresponding to the merge request. When developers subsequently inquired again, the event was routed to the recovered thread session context, and the entire interaction was completely transparent to the developers. Finally, the merge request was merged into the main branch. After receiving the merge event, the event access layer cleaned up the context data directory, the main session and thread session directories, and removed relevant entries from the memory index, retaining only the local repository copy corresponding to the code hosting platform.
[0092] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0093] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for managing review sessions and submitting comments for database code merging requests, characterized in that, The method includes: Step S1: Build a root namespace for each merge request, maintain the main session and thread sessions under it, realize the on-demand derivation of the thread session from the main session through deep copy, persist the session state to local hierarchical storage and support index reconstruction when the service starts; Step S2: Listen for the end event of the merge request, and after acquiring the mutual exclusion resource, perform session storage directory cleanup and memory index release; Step S3: Construct a change block index based on the structured parsing of code differences, maintain the set of file paths read by the agent, and generate candidate comments by constraining the structured contract containing the problem evidence field; Step S4: Perform three-state line number determination and correction on the candidate comments based on the changed block index, and submit after mandatory verification in combination with the read path set.
2. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S1, the thread session is derived from the main session on demand through deep copy as follows: when the target thread session does not exist and the main session exists, the main session is directly deep copied to derive the new thread session; when the main session does not exist, the main session is created first and a complete code difference understanding is completed, and then the thread session is derived based on the state of the main session, so that the thread session inherits the code understanding context, change block index and read path set of the main session.
3. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S1, the session state is persisted to local hierarchical storage and index rebuilding is supported at service startup in the following manner: The runtime state of each session is stored in a structured file in the default session directory of the local file system. The session directory path is organized hierarchically according to the root namespace and session identifier. When the service starts, the recovery program first performs a first-level scan on the session root directory to identify all merge request namespaces and rebuild the merge request mutex resource index accordingly. Then, it performs a second-level scan on each namespace to identify all session identifiers and rebuild the session index accordingly. During the index rebuild process, only the session's metadata entries are restored without immediately loading the session state. The session state is loaded from local storage on demand when its corresponding event is first triggered.
4. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, Step S2 includes: When a merge request is received, either merge or close, the system attempts to acquire the requested mutex resource after a preset timeout. Regardless of whether the acquisition is successful within the timeout period, a cleanup operation is forcibly performed, including removing the context data directory, removing all session persistence directories, removing session index entries in memory, and releasing mutex resources. This cleanup operation deliberately preserves the local code repository copy corresponding to the code hosting platform. If the mutually exclusive resource cannot be acquired within the preset timeout, an alarm log will be recorded.
5. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S3, the change block index is constructed based on the structured parsing of code differences in the following manner: During the review task initiation phase, the difference content of the merge request is parsed according to the general difference format, and the old side starting line, old side line number, new side starting line, and new side line number of each change block are identified file by file; each change block is encapsulated as a change block object containing the file path and the endpoints of the old and new sides, and organized into a change block index with the file path as the key.
6. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S3, the set of read file paths of the agent is maintained in the following way: The session layer pre-configures code reading tools in the agent's toolset and maintains a set of read paths that records the history of tool calls. Each time the agent successfully reads a file, it adds the path of that file to the set of read paths.
7. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S3, the generation of candidate comments is constrained by a structured contract containing a problem evidence field as follows: The comment submission action is modeled as a structured tool with strong type field constraints. The parameter structure of this tool includes at least the target file path, target line number, comment body, and a problem evidence field with a limited length. This problem evidence field forces the agent to explicitly state the specific problem statement corresponding to each comment, and its length is constrained by a preset upper limit. When a candidate comment generated by the agent does not conform to the structured contract at the field level, or the problem evidence field is missing, or the problem evidence field exceeds the length limit, the candidate comment is rejected, and a structured error feedback is returned to the agent to request regeneration. At the same time, an upper limit is set on the number of retries for a single candidate comment. If the retry limit is exceeded, the generation attempt of the comment is terminated.
8. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, In step S4, the candidate comments are evaluated for three-state line number determination based on the change block index as follows: the target file path and target line number declared in the candidate comment are extracted, and all change blocks corresponding to the file are searched in the change block index; if the target line number falls within the interval defined by the new side start line and end line of a change block, it is determined to be a strict hit; if the target line number falls outside the interval but is within the adjacent interval defined by the preset context window size extended outward from the endpoint of the interval, it is determined to be an adjacent hit. The context window size is specified by a configurable parameter, and is extended outward by the number of lines indicated by the parameter from the new side endpoint of the change block in each determination; if the target line number is outside the adjacent interval, it is determined to be a complete out-of-bounds hit.
9. The method for managing review sessions and submitting comments for database code merging requests according to claim 8, characterized in that, In step S4, after the three-state line number determination, the correction process is performed as follows: when a candidate comment is determined to be a neighboring hit, the correction is performed according to the relative position of the target line number and the new side interval of the change block. If the target line number is less than the starting line of the new side, the target line number is corrected to the starting line of the new side. If the target line number is greater than the ending line of the new side, the target line number is corrected to the ending line of the new side. The corrected comment is reassembled, and the metadata of the comment carries a mark that the line number has been corrected. The corrected comment is then submitted to the code hosting platform.
10. The method for managing review sessions and submitting comments for database code merging requests according to claim 1, characterized in that, Submit the candidate comment after mandatory verification using the read path set as follows: When an agent submits a candidate comment, it is mandatory that the target file path declared in the candidate comment must exist in the read path set. If the target file path is not included in the read path set, the candidate comment is rejected and the agent is returned with the included structured correction feedback; the read path set is persisted as part of the session state and recovered across restarts.
Citation Information
Patent Citations
Code comment information acquisition method and device, computer equipment and storage medium
CN109918114A