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>