Skip to content

fix(dashboard): read every DynamoDB page; fail closed on a failed page (#1421) - #1425

Merged
scttfrdmn merged 4 commits into
mainfrom
fix/1421-dashboard-watches-pagination
Oct 29, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
fix/1421-dashboard-watches-pagination

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1421

What

The dashboard read one DynamoDB page (at most 1 MB) per Query/Scan and showed it as the complete list. lambda/dashboard-api/paging.go adds queryAll, queryUpTo (bounded with a truncated signal), scanAll and scanFirst, modelled on lagotto#181's queryAll. Each follows LastEvaluatedKey to the end and returns an error, never a partial result, when any page fails.

Call sites fixed:

Endpoint / function Before After
GET /api/watches (handleListWatches) one Query page queryAll + per-item user_id == caller check (fail-closed, as handleGetWatch)
GET /api/watches/history (handleWatchHistory) one page, Limit 100, no signal newest 100 via queryUpTo across pages, "truncated": true when older matches exist, per-item ownership (MatchInfo.UserID, json:"-")
GET /api/cost-history one Query page queryAll + ownership check
GET /api/sweeps personal one Scan page, Limit 200 (counted BEFORE the user_id filter, so >200 sweeps in the table = arbitrary subset) scanAll + ownership check
GET /api/sweeps?team_id= team one Query page; a failure was logged and the personal list returned with success: true queryAll; failure is a 500 (CHANGELOG: Changed)
GET /teams (handleListMyTeams) one Query page queryAll + member_arn == caller
GET /teams/{id} members one page, Limit 500 queryAll + team_id check
DELETE /teams/{id} first 500 memberships deleted, then the team record (orphaning the rest) every page; a failed page deletes nothing
Slack token rotation workspace Scan (filtered) one page; scan error reported as "not found" scanFirst across pages; scan error is an error
dashboard-websocket-processor getActiveConnections one Scan page: connections past it missed broadcasts full pagination; takes dynamodb.ScanAPIClient

Left single-page with a justification comment: auth.go lookupCliIamArnByEmail, which uses only the first match, and a Query without a FilterExpression returns an empty page only when nothing matches.

Audited and already correct: cost-history-collector listAllUsers (paginates). dashboard-websocket makes no Query/Scan calls.

No IAM change: same actions on the same tables.

Gates (each watched failing against a compiling revert)

  • paging_test.go wire fake (pagedDynamo) serves 3 pages (the middle one empty, as filtered Scans often are) and can fail a page with a non-retryable error. For each handler: all items across 3 pages, a failed page is a 500 with no list, and a foreign or ownerless record on page 3 is not returned.
  • TestDashboardDynamoCallsArePaginated: an AST scan of the package's non-test sources. Any direct .Query(/.Scan( call must carry a // single-page: comment above it. The test fails if discovery finds no calls at all.
  • TestWatchHistoryBoundIsReportedAsTruncated: 121 matches give 100 and truncated; exactly 100 give 100 and no truncated.
  • websocket processor: connections_test.go, 3 pages read and a failed page is an error.

Reverts and the gates that failed:

  • helpers read only the first page: every reads-all / failing-page test failed
  • helpers break on page error (partial): every failing-page test failed
  • origin/main copy of each of cost_history.go, sweeps.go, teams.go, slack_oauth.go, auth.go: that file's handler tests and/or the AST gate failed
  • handleListWatches / handleWatchHistory back to a single client.Query: their tests + AST gate failed
  • each ownership check disabled (if false): the matching ownership test failed
  • Truncated forced false: truncated test failed
  • team-sweeps failure back to a log warning: the team test failed
  • processor: break after first page, or break on error: both tests failed

make check, make lint (0 issues, 10 modules) and semgrep scan --config=auto --error . all pass.

Deploy

After release, redeploy dashboard-api and dashboard-websocket-processor from the release tag, using each function's deploy.sh from a checkout of the tag. No IAM or table changes.

Note: the personal sweeps listing now scans the entire spawn-sweep-orchestration table on each request, where before it read one 200-item page. That is correct but costs O(table). The table has a user_id-created_at-index (scripts/setup-sweep-dynamodb.sh), so a Query on it would be cheaper. That needs an IAM grant on the index, so it is left as a follow-up.

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the fix/1421-dashboard-watches-pagination branch from cc38964 to 2b8f9f3 Compare October 29, 2026 19:21
@scttfrdmn
scttfrdmn merged commit 38c7f47 into main Oct 29, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1421-dashboard-watches-pagination branch October 29, 2026 19:46
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.

dashboard-api: /api/watches and /api/watches/history read one DynamoDB page (lagotto#181 fixed in lagotto's store, not here)

1 participant