Skip to content

fix(monitor): match storage not-found errors returned over the wire - #1474

Open
Robbie Cronin (robert-cronin) wants to merge 1 commit into
orka-agents:mainfrom
robert-cronin:fix-monitor-wire-not-found
Open

Robbie Cronin (robert-cronin) wants to merge 1 commit into
orka-agents:mainfrom
robert-cronin:fix-monitor-wire-not-found

Conversation

@robert-cronin

@robert-cronin Robbie Cronin (robert-cronin) commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The repository monitor recognizes a missing storage record with errorsIsStoreNotFound, which compared the error by identity: err == store.ErrNotFound. The embedded SQLite store returns the bare sentinel, so this works there. A storage backend reached over the storage wire returns the decoded error remoteError{sentinel: storagev1.ErrNotFound} (pkg/storage/v1/wire/errors.go). Its text is "not found" and errors.Is matches it, but the identity check doesn't.

The first place this shows is a monitor run on a dataset that has no item yet for an open pull request. This happens on a fresh dataset, and after the storage binding changes to a dataset that lacks an earlier review's records. processPullRequestInventoryRun calls GetMonitorItem for the first selected pull request, treats its not-found as a real error, and fails the whole run with [run_failed] not found. Nothing is reviewed, no readiness status is posted, and the controller logs nothing. Every later run fails the same way until the item exists, which never happens, because the failing read is what would create it.

  • internal/controller/repositorymonitor_controller.go: errorsIsStoreNotFound uses errors.Is(err, store.ErrNotFound), so it matches the bare sentinel, wrapped sentinels and wire-decoded errors. A failed run now also logs the error, the run ID and the failure state; until now run_failed was recorded only as a monitor event and the status condition.
  • internal/controller/repositorymonitor_workflow.go: recordRepositoryMonitorGitHubMutation treated a create error as an already-existing record only when its text contained "constraint", which is SQLite wording. It now uses the storage contract's typed store.ErrConflict, which every backend must return for a duplicate create (storagetest already requires it). Other errors still fail the call.

Other sites checked (no change needed)

  • All 11 callers of errorsIsStoreNotFound (repositorymonitor_inventory.go, repositorymonitor_issue_inventory.go, repositorymonitor_repair.go ×8, and the delete path in repositorymonitor_controller.go) read or delete a single record and mean "the record is absent". errors.Is gives every one of them its intended meaning.
  • A repository-wide search for ==/!= against a storage sentinel finds only acp_storage_hold.go, inside an Is(target error) bool method, where comparing the target by identity is the correct contract.

Tests

  • TestErrorsIsStoreNotFoundMatchesWrappedSentinel: the bare sentinel, a %w-wrapped sentinel and a not-found decoded by the real storage wire (wiretest) all match; a conflict, an unrelated "not found" string and nil do not. With the identity check restored, the wrapped and wire-decoded cases fail.
  • TestRepositoryMonitorFirstRunSelectsPullRequestWhenItemMissingOverStorageWire: the run's monitor-item read returns the wire-decoded not-found; the run must succeed, select the pull request and create its review Task. With the identity check restored, the run fails with [run_failed] storagefault: state.v1 GetMonitorItem: not found.
  • TestRepositoryMonitorMutationDuplicateCreateUsesConflictContract: a typed conflict without driver wording is accepted as an existing record; a non-conflict error containing "constraint" is returned.

Verification

  • go test ./internal/controller/ -run 'TestErrorsIsStoreNotFound|TestRepositoryMonitorFirstRunSelectsPullRequestWhenItemMissingOverStorageWire|TestRepositoryMonitorMutationDuplicateCreate' -race: passes. The wider -run 'RepositoryMonitor' -race run passes except TestRepositoryMonitorEvidenceSanitizerStaysFast, a wall-clock budget test for the CI-evidence sanitizer that this change does not touch; it passes without -race.
  • make lint-fix and full-tree golangci-lint run (root and pkg/storage): 0 issues. make lint-comments: passes.
  • $autoreview (claude, branch, P1): clean, no accepted findings.

Summary by CodeRabbit

  • Bug Fixes
    • Repository monitor runs can now continue selecting and reviewing pull requests when an item is missing.
    • Duplicate GitHub mutations are handled as conflicts, while other creation errors are surfaced instead of being incorrectly ignored.
    • Failed monitor runs now include clearer diagnostic details in their logs, making failures easier to investigate.

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 07:18
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The controller now matches wrapped and storage-wire-decoded store.ErrNotFound errors, logs failed monitor runs with identifying fields, and suppresses GitHub mutation creation errors only when they match store.ErrConflict. Added tests cover these error contracts and first-run reconciliation.

Changes: Repository monitor error handling

Layer / File(s) Summary
Not-found matching and reconciliation
internal/controller/repositorymonitor_controller.go, internal/controller/repositorymonitor_wire_not_found_test.go
The controller recognizes wrapped store.ErrNotFound errors and logs failed runs with the error, monitor name, run ID, and failure state. Tests cover decoded not-found errors from the storage wire and first-run pull-request reconciliation.
Mutation conflict handling
internal/controller/repositorymonitor_workflow.go, internal/controller/repositorymonitor_mutation_conflict_test.go
Mutation creation errors are ignored only when they match store.ErrConflict. Tests verify that other errors are returned.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 512 describes the need for clear failure rules for remote storage. This PR tests handling of decoded not-found errors over the storage wire and classifies mutation conflicts by sentinel.
Merge Risk: Minimal · up to c458f

The repository monitor now recognizes missing-record errors returned from remote storage, so a first run can select a pull request and create its review Task. Duplicate creates are suppressed only when they carry the typed conflict error, and failed runs are logged with their identifiers. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: repository-monitor handling of storage not-found errors returned over the wire. The objectives state the change uses errors.Is so wrapped and wire-decoded not-found er…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: repository-monitor handling of storage not-found errors returned over the wire. The objectives state the change uses errors.Is so wrapped and wire-decoded not-found errors are recognized. The summary also covers the related ErrConflict change and failure logging, which the title does not mention but does not need to. The title is a single concise sentence in conventional-commit form.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2bec7401-7bdc-4c72-b974-40fc66bafdea
Commits

Reviewing files that changed from the base of the PR and between c8c807f and c458f1c.

Files selected for processing: 4

  • internal/controller/repositorymonitor_controller.go
  • internal/controller/repositorymonitor_mutation_conflict_test.go
  • internal/controller/repositorymonitor_wire_not_found_test.go
  • internal/controller/repositorymonitor_workflow.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the repository monitor error-handling changes.

No open issues 🎉

What changed in this PR

Fixes repository monitor error handling for remote storage backends, allowing runs to proceed when pull requests have no existing monitor records.

Changes:

  • Uses errors.Is for not-found and duplicate-create conflict detection.
  • Adds structured logging for failed monitor runs.
  • Adds regression tests for wire-decoded errors and typed conflicts.
File Description
internal/​controller/​repositorymonitor_workflow.go Detects duplicate mutations using typed conflicts.
internal/​controller/​repositorymonitor_wire_not_found_test.go Tests not-found matching and first-run review creation.
internal/​controller/​repositorymonitor_mutation_conflict_test.go Tests conflict handling without driver-specific wording.
internal/​controller/​repositorymonitor_controller.go Fixes not-found detection and logs run failures.

Review effort: Balanced

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-02T08:03:45.044267Z
We couldn’t complete this review. Comment @codex review to try again.
c458f1c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants