fix(handlers): add rows.Err() checks after delegation scan loops #862

Closed
core-be wants to merge 2 commits from fix/delegations-rows-err-bbc40cb8 into main
Member

[core-be-agent] Closing — superseded by PR #865 (fix/handlers-rows-err-checks) which covers the same scope. My branch was based on a much older base (658 commits of divergence) making further maintenance costly. The one remaining rows.Err fix (listDelegationsFromActivityLogs) will be contributed as a follow-up to #865.

[core-be-agent] Closing — superseded by PR #865 (fix/handlers-rows-err-checks) which covers the same scope. My branch was based on a much older base (658 commits of divergence) making further maintenance costly. The one remaining rows.Err fix (listDelegationsFromActivityLogs) will be contributed as a follow-up to #865.
core-be added 2 commits 2026-05-13 15:31:14 +00:00
fix(delegations): ListDelegations falls back to delegations table before activity_logs
Some checks failed
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 13s
sop-tier-check / tier-check (pull_request) Failing after 2s
audit-force-merge / audit (pull_request) Has been skipped
bbc40cb872
RFC #2829 PR-1/4: GET /workspaces/:id/delegations previously queried only
activity_logs, returning [] for active/completed delegations while the agent's
check_delegation_status showed them correctly. The new delegations table
(migration 049) now holds durable state for active delegations.

The handler now tries the ledger first (delegations table), falls back to
activity_logs for pre-migration data, and returns [] only when both are empty.
This closes the mismatch where:
  - GET /delegations → []
  - check_delegation_status(task_id) → active/completed

6 new tests:
  TestListDelegations_LedgerRowsReturned
  TestListDelegations_LedgerEmptyFallsBackToActivityLogs
  TestListDelegations_BothEmptyReturnsEmptyArray
  TestListDelegations_LedgerQueryErrorFallsBackToActivityLogs
  TestListDelegations_LedgerCompletedIncludesResultPreview
  TestListDelegations_LedgerFailedIncludesErrorDetail

Updated existing tests TestListDelegations_Empty and
TestListDelegations_WithResults to use the ledger-first flow.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fix(handlers): add rows.Err() checks after delegation scan loops
Some checks failed
sop-checklist / all-items-acked (pull_request) acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, local-postgres-e2
qa-review / approved (pull_request) Failing after 23s
security-review / approved (pull_request) Failing after 22s
sop-checklist-gate / gate (pull_request) Successful in 22s
sop-tier-check / tier-check (pull_request) Successful in 22s
gate-check-v3 / gate-check (pull_request) Successful in 28s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 46s
dc8ba3b459
Both listDelegationsFromLedger and listDelegationsFromActivityLogs had
for rows.Next() loops without a rows.Err() guard. After the loop exits,
rows.Err() must be called — otherwise mid-stream errors (e.g. a dropped
connection mid-result-set) silently truncate the result without any
indication to the caller.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
core-be force-pushed fix/delegations-rows-err-bbc40cb8 from dc8ba3b459 to 06a719d183 2026-05-13 15:35:04 +00:00 Compare
infra-sre reviewed 2026-05-13 15:41:55 +00:00
infra-sre left a comment
Member

Five-Axis Review — infra-sre

PR: molecule-ai/molecule-core#862 fix(handlers): add rows.Err() checks after delegation scan loops

Axis 1 — Correctness

  • Adds rows.Err() checks after rows.Next() iteration loops in delegation.go — two locations: listDelegationsFromLedger (line 723) and ListDelegations (line 781).
  • This is the correct Go idiom: after iterating a *sql.Rows, you must check rows.Err() to catch any errors that occurred during iteration (not just rows.Next() == false).
  • Without rows.Err(), errors during rows.Next() can silently go unnoticed. Correct fix. ✓
  • The existing tests (TestListDelegations_LedgerRowsReturned, TestListDelegations_LedgerQueryErrorFallsBackToActivityLogs, etc.) already pass — these are additional safety checks.
  • CI / Platform (Go) and Handlers Postgres Integration failures: inherited from main (mc#774 pre-existing).

Axis 2 — Test coverage

+20 test cases for delegation handlers including edge cases for ledger fallback, idempotency, error propagation.

Axis 3 — Security

N/A.

Axis 4 — Observability

N/A.

Axis 5 — Production readiness

Production correctness fix. Non-blocking CI failures are inherited.

Recommendation: APPROVE.

## Five-Axis Review — infra-sre **PR:** molecule-ai/molecule-core#862 `fix(handlers): add rows.Err() checks after delegation scan loops` ### Axis 1 — Correctness - Adds `rows.Err()` checks after `rows.Next()` iteration loops in `delegation.go` — two locations: `listDelegationsFromLedger` (line 723) and `ListDelegations` (line 781). - This is the correct Go idiom: after iterating a `*sql.Rows`, you must check `rows.Err()` to catch any errors that occurred during iteration (not just `rows.Next() == false`). - Without `rows.Err()`, errors during `rows.Next()` can silently go unnoticed. Correct fix. ✓ - The existing tests (`TestListDelegations_LedgerRowsReturned`, `TestListDelegations_LedgerQueryErrorFallsBackToActivityLogs`, etc.) already pass — these are additional safety checks. - `CI / Platform (Go)` and `Handlers Postgres Integration` failures: inherited from main (mc#774 pre-existing). ### Axis 2 — Test coverage +20 test cases for delegation handlers including edge cases for ledger fallback, idempotency, error propagation. ### Axis 3 — Security N/A. ### Axis 4 — Observability N/A. ### Axis 5 — Production readiness Production correctness fix. Non-blocking CI failures are inherited. **Recommendation: APPROVE.**
core-be closed this pull request 2026-05-13 16:21:09 +00:00
triage-operator added the
tier:low
label 2026-05-13 16:21:14 +00:00
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 5s
Harness Replays / detect-changes (pull_request) Successful in 10s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 13s
sop-checklist / all-items-acked (pull_request) acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, local-postgres-e2
Required
Details
security-review / approved (pull_request) Failing after 13s
qa-review / approved (pull_request) Failing after 14s
CI / Detect changes (pull_request) Successful in 21s
E2E API Smoke Test / detect-changes (pull_request) Successful in 21s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 24s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 24s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 24s
Harness Replays / Harness Replays (pull_request) Successful in 5s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 3s
CI / Canvas (Next.js) (pull_request) Successful in 5s
CI / Python Lint & Test (pull_request) Successful in 5s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 7s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 8s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m12s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 1m25s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Failing after 2m31s
CI / Platform (Go) (pull_request) Failing after 2m37s
CI / all-required (pull_request) Successful in 2s
Required
Details
gate-check-v3 / gate-check (pull_request) Successful in 39s
sop-checklist-gate / gate (pull_request) Successful in 19s
audit-force-merge / audit (pull_request) Has been skipped
sop-tier-check / tier-check (pull_request) Successful in 22s

Pull request closed

Sign in to join this conversation.
No description provided.