alibaba/open-code-review · error

finalize run manifest: %w

Error message

finalize run manifest: %w

What it means

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.

Source

Thrown at internal/agent/agent.go:1250

// manifest on the session for persistence and CLI consumption. Nil-safe. A
// construction (validation) failure leaves the stored manifest nil — session_end
// then persists in legacy form — and is returned as a delivery error so the CLI
// cannot report a manifest-enabled review as successful without a valid snapshot.
// Elapsed is measured from the session start so both outlets report the same duration.
func (a *Agent) finalizeManifest() error {
	b := a.session.Manifest()
	if b == nil {
		return nil
	}
	// Freeze the input/repository identity from this run's captured resolution and
	// current selected set before the manifest closes. Done here (not in New) so
	// the git-resolved endpoints and the post-filter source artifact are both
	// available, and so every terminal path records the same identity.
	a.applyInputIdentity(b)
	m, err := b.Finalize(time.Since(a.session.StartTime))
	if err != nil {
		a.recordWarning("manifest_error", "", err.Error())
		return fmt.Errorf("finalize run manifest: %w", err)
	}
	a.session.SetFinalManifest(&m)
	return nil
}

func resumedFromSession(resume *session.ResumeState) string {
	if resume == nil {
		return ""
	}
	return resume.SessionID
}

// buildMainTaskMessages renders the MAIN_TASK messages for one review round.
// planResult is "" for round 2+ (stripped via stripEmptyPlanBlock).
// confirmed is "" on round 1 (stripped via stripEmptyConfirmedBlock).
func (a *Agent) buildMainTaskMessages(rule, changeFiles, diffs, planResult, confirmed string) []llm.Message {
	rawMsgs := a.args.Template.MainTask.Messages
	messages := make([]llm.Message, 0, len(rawMsgs))

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Read the wrapped cause (also recorded as a manifest_error warning in run output).
  2. If resuming, start a fresh review instead of resuming the inconsistent session state.
  3. Clear stale session state for this repo/session and re-run.
  4. If reproducible on a clean run, it indicates an internal invariant bug — report with the manifest_error message and ocr version.

Example fix

// before
ocr review --resume <stale-session-id>
// -> finalize run manifest: selected item X not sealed
// after
rm -rf ~/.local/state/ocr/sessions/<stale-session-id>
ocr review  # fresh run
Defensive patterns

Strategy: validation

Validate before calling

// ensure session state comes from a compatible version before resuming
if sessionVersionOnDisk != currentVersion { startFreshRun() }

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/74f25ee3146881c6. Report an issue: GitHub.