{"record":{"id":"74f25ee3146881c6","repo":"alibaba/open-code-review","slug":"finalize-run-manifest-w","errorCode":null,"errorMessage":"finalize run manifest: %w","messagePattern":"finalize run manifest: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/agent.go","lineNumber":1250,"sourceCode":"// manifest on the session for persistence and CLI consumption. Nil-safe. A\n// construction (validation) failure leaves the stored manifest nil — session_end\n// then persists in legacy form — and is returned as a delivery error so the CLI\n// cannot report a manifest-enabled review as successful without a valid snapshot.\n// Elapsed is measured from the session start so both outlets report the same duration.\nfunc (a *Agent) finalizeManifest() error {\n\tb := a.session.Manifest()\n\tif b == nil {\n\t\treturn nil\n\t}\n\t// Freeze the input/repository identity from this run's captured resolution and\n\t// current selected set before the manifest closes. Done here (not in New) so\n\t// the git-resolved endpoints and the post-filter source artifact are both\n\t// available, and so every terminal path records the same identity.\n\ta.applyInputIdentity(b)\n\tm, err := b.Finalize(time.Since(a.session.StartTime))\n\tif err != nil {\n\t\ta.recordWarning(\"manifest_error\", \"\", err.Error())\n\t\treturn fmt.Errorf(\"finalize run manifest: %w\", err)\n\t}\n\ta.session.SetFinalManifest(&m)\n\treturn nil\n}\n\nfunc resumedFromSession(resume *session.ResumeState) string {\n\tif resume == nil {\n\t\treturn \"\"\n\t}\n\treturn resume.SessionID\n}\n\n// buildMainTaskMessages renders the MAIN_TASK messages for one review round.\n// planResult is \"\" for round 2+ (stripped via stripEmptyPlanBlock).\n// confirmed is \"\" on round 1 (stripped via stripEmptyConfirmedBlock).\nfunc (a *Agent) buildMainTaskMessages(rule, changeFiles, diffs, planResult, confirmed string) []llm.Message {\n\trawMsgs := a.args.Template.MainTask.Messages\n\tmessages := make([]llm.Message, 0, len(rawMsgs))","sourceCodeStart":1232,"sourceCodeEnd":1268,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/agent/agent.go#L1232-L1268","documentation":"finalizeManifest closes the session's coverage builder and records an immutable run manifest. If builder.Finalize() fails (a construction/validation failure of the manifest), the agent records a manifest_error warning and returns this wrapped error so a manifest-enabled review can never be reported successful without a valid snapshot. The stored manifest stays nil and session_end persists in legacy form.","triggerScenarios":"Any terminal path of Agent.Run() where the manifest builder validation fails during Finalize — e.g. selected coverage items inconsistent with the sealed state, identity fields missing, or a RegisterSelected/SealSelected invariant violated upstream.","commonSituations":"Corrupted or partially-written session state being resumed; a bug or version mismatch producing coverage items that fail manifest validation (e.g. duplicate or unknown item keys after filtering deleted files).","solutions":["Read the wrapped cause (also recorded as a manifest_error warning in run output).","If resuming, start a fresh review instead of resuming the inconsistent session state.","Clear stale session state for this repo/session and re-run.","If reproducible on a clean run, it indicates an internal invariant bug — report with the manifest_error message and ocr version."],"exampleFix":"// before\nocr review --resume <stale-session-id>\n// -> finalize run manifest: selected item X not sealed\n// after\nrm -rf ~/.local/state/ocr/sessions/<stale-session-id>\nocr review  # fresh run","handlingStrategy":"validation","validationCode":"// ensure session state comes from a compatible version before resuming\nif sessionVersionOnDisk != currentVersion { startFreshRun() }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid resuming sessions written by a different ocr version; start fresh after upgrades.","Never hand-edit session state files.","Check the manifest_error warning line in output for the precise validation cause.","Report reproducible failures on clean runs as bugs with the wrapped cause."],"tags":["manifest","session","validation","go"],"backgroundTag":"manifest-validation-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}