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

2 Commits

Author SHA1 Message Date
06a719d183 fix(handlers): add rows.Err() checks after delegation scan loops
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
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
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
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>
2026-05-13 15:34:57 +00:00
c830449f13 fix(delegations): ListDelegations falls back to delegations table before activity_logs
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>
2026-05-13 15:34:32 +00:00