Better observability to EMMA#2122
Conversation
📝 WalkthroughWalkthroughAdds richer download state and timing metadata, moves snapshot generation to a derived, polling-driven model, threads a refresh handler through snapshot table components, enriches per-row status UI with progress/stage/retry logic, and introduces a retry component that invokes a retry API endpoint. Changes
Sequence DiagramsequenceDiagram
participant CS as CreateSnapshots
participant Row as CreateSnapshotTableRow
participant API as Distribution API
participant Toast as Toast Service
CS->>API: loadTokenPoolDownloads(allowlistId)
API-->>CS: downloads (status, stage, progress, timestamps)
CS->>Row: pass snapshot + download + refreshDownloads
Row->>Row: render status, stage, progress, issues
alt download.retryable
Row->>API: POST /token-pool-downloads/token-pool/{tokenPoolId}/retry
API-->>Toast: success
Toast-->>Row: show "Snapshot retry started"
Row->>CS: call refreshDownloads()
CS->>API: reload downloads
else active/pending
CS->>CS: continue polling (dynamic delay)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/distribution-plan-tool/create-snapshots/CreateSnapshots.tsx`:
- Around line 124-159: Add a hasRan flag to each snapshot in the snapshots map
(derive it from tokenPoolDownload.hasRan or compute from
tokenPoolDownload.status) and then change the activeSnapshots selection so it
does NOT treat every download === null snapshot as active; instead only include
snapshots where download === null (no job yet) OR where a download exists and it
hasRan === true and the download is not stalled/PENDING/CLAIMED; exclude
snapshots whose download exists but is stale/hasn't run. Update the
CreateSnapshots snapshot construction (the snapshots constant, tokenPoolDownload
variable) and the activeSnapshots filter to use the new hasRan property.
- Around line 271-279: The Run analysis button is hidden because
showRunAnalysisBtn is gated by allSnapshotsCompleted; change the visibility to
depend only on haveUnRunOperations so users can start jobs when there are un-run
operations. In the DistributionPlanNextStepBtn props, set
showRunAnalysisBtn={haveUnRunOperations} (keep
disableNextBtn={!allSnapshotsCompleted} so Next remains disabled until snapshots
complete) and keep existing
setStep/DistributionPlanToolStep.CREATE_CUSTOM_SNAPSHOT behavior unchanged.
In
`@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsx`:
- Around line 83-117: The switch over download.stage in CreateSnapshotTableRow
currently has no default, so unknown/new EMMA stage values render nothing;
update the switch (the code handling download.stage /
DistributionPlanTokenPoolDownloadStage) to include a default/fallback case that
returns a clear label (for example "Unknown stage" or "Unknown stage:
{download.stage}") so the UI always shows a meaningful string for unrecognized
stages; ensure you add the default case at the end of the switch (or a final
return after the switch) so it covers any future enum values.
In
`@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx`:
- Around line 38-46: The Retry button in CreateSnapshotTableRowRetry (the button
that calls onRetry and uses the loading prop) is icon-only and lacks an
accessible name; add an aria-label (e.g., aria-label="Retry snapshot") to the
button and include aria-busy={loading} so assistive tech knows when the retry is
in flight; keep existing title if desired but ensure the button element with
onRetry and loading props includes both aria-label and aria-busy attributes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ad029cdf-94cb-4ded-9a5b-9c1d7b37487f
📒 Files selected for processing (7)
components/allowlist-tool/allowlist-tool.types.tscomponents/distribution-plan-tool/common/DistributionPlanNextStepBtn.tsxcomponents/distribution-plan-tool/create-snapshots/CreateSnapshots.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTable.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableBody.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
d43a886 to
31ad6e7
Compare
|
There was a problem hiding this comment.
♻️ Duplicate comments (3)
components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsx (1)
84-118:⚠️ Potential issue | 🟡 MinorAdd a default case to handle unknown download stages.
The switch statement doesn't have a default case. If the API returns a new stage value not yet in the enum, the function returns
undefined, causing the UI to display nothing for the stage. This was flagged in a previous review and remains unaddressed.🛡️ Proposed fix
case DistributionPlanTokenPoolDownloadStage.FAILED: return "Snapshot failed"; + default: + return typeof download.stage === "string" + ? `Unknown stage (${download.stage})` + : "Processing"; } };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsx` around lines 84 - 118, The switch over download.stage in CreateSnapshotTableRow (in CreateSnapshotTableRow.tsx) lacks a default branch, so add a default case to the switch(download.stage) that returns a clear fallback string (e.g., "Unknown stage" or `Unknown stage: ${download.stage}`) and optionally call a logger/warn (e.g., console.warn or your app logger) with the unexpected value so the UI never renders undefined and new/unknown enum values are visible for debugging; update the default case rather than changing the existing specific cases.components/distribution-plan-tool/create-snapshots/CreateSnapshots.tsx (2)
190-197:⚠️ Potential issue | 🟠 MajorFast-polling triggers for snapshots that haven't been run yet.
The
activeSnapshotsfilter includes snapshots where!snapshot.download, which encompasses jobs that haven't been triggered at all (before "Run analysis" is clicked). This causes unnecessary 2-second polling before any work has started and for stalled jobs. Consider excluding snapshots that haven't run or are stale.⚙️ Proposed fix
const activeSnapshots = snapshots.filter((snapshot) => { - const rawStatus = snapshot.download?.rawStatus ?? null; - return ( - !snapshot.download || - rawStatus === DistributionPlanTokenPoolDownloadStatus.PENDING || - rawStatus === DistributionPlanTokenPoolDownloadStatus.CLAIMED - ); + // Only poll for snapshots that have a download in progress (not stale) + if (!snapshot.download) { + return false; + } + if (snapshot.download.stale) { + return false; + } + return [ + DistributionPlanTokenPoolDownloadStatus.PENDING, + DistributionPlanTokenPoolDownloadStatus.CLAIMED, + ].includes(snapshot.download.rawStatus); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/distribution-plan-tool/create-snapshots/CreateSnapshots.tsx` around lines 190 - 197, The filter for activeSnapshots currently includes !snapshot.download which causes polling of snapshots that were never started; update the activeSnapshots filter so it only considers snapshots with a download and with rawStatus === DistributionPlanTokenPoolDownloadStatus.PENDING || rawStatus === DistributionPlanTokenPoolDownloadStatus.CLAIMED (i.e., remove the !snapshot.download branch), and optionally add a staleness guard using snapshot.download?.createdAt or snapshot.download?.updatedAt compared against a STALE_THRESHOLD_MS constant to skip downloads older than the threshold; update the logic around the activeSnapshots constant to reference snapshot.download before checking rawStatus.
270-279:⚠️ Potential issue | 🔴 CriticalUser gets stuck when there are un-run snapshot operations.
The logic gates
showRunAnalysisBtnonallSnapshotsCompleted && haveUnRunOperations. However, when operations haven't run yet,allSnapshotsCompletedisfalse(no completed downloads), so the "Run analysis" button is hidden. Meanwhile, the "Next" button is shown but disabled. The user cannot proceed.🐛 Proposed fix
<DistributionPlanNextStepBtn - showRunAnalysisBtn={allSnapshotsCompleted && haveUnRunOperations} + showRunAnalysisBtn={haveUnRunOperations} onNextStep={() => setStep(DistributionPlanToolStep.CREATE_CUSTOM_SNAPSHOT) } loading={false} - showNextBtn={haveSnapshots} + showNextBtn={haveSnapshots && !haveUnRunOperations} showSkipBtn={false} disableNextBtn={!allSnapshotsCompleted} />🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/distribution-plan-tool/create-snapshots/CreateSnapshots.tsx` around lines 270 - 279, The "Run analysis" button is hidden because showRunAnalysisBtn is gated by allSnapshotsCompleted; change showRunAnalysisBtn to depend only on haveUnRunOperations (showRunAnalysisBtn={haveUnRunOperations}) so the button is visible whenever there are un-run snapshot operations, and adjust the Next button disable logic to prevent the user progressing while un-run ops exist by setting disableNextBtn to include haveUnRunOperations (for example disableNextBtn={haveUnRunOperations || !allSnapshotsCompleted}); update the props on the DistributionPlanNextStepBtn component accordingly.
🧹 Nitpick comments (1)
components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx (1)
22-37: Consider handling API failure with user feedback.When
successisfalse, the user receives no indication that the retry failed. Consider adding an error toast to inform users.💡 Proposed fix
if (success) { setToasts({ messages: ["Snapshot retry started"], type: "success", }); await refreshDownloads(); + } else { + setToasts({ + messages: ["Snapshot retry failed"], + type: "error", + }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx` around lines 22 - 37, The onRetry handler currently only shows success toasts and leaves users uninformed on failure; update onRetry (the async function that calls distributionPlanApiPost) to handle both non-success responses and thrown errors by showing an error toast via setToasts (e.g., messages: ["Snapshot retry failed"] or include error.message), and ensure setLoading(false) runs in all cases (use try/catch/finally around the distributionPlanApiPost call and await refreshDownloads only on success).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@components/distribution-plan-tool/create-snapshots/CreateSnapshots.tsx`:
- Around line 190-197: The filter for activeSnapshots currently includes
!snapshot.download which causes polling of snapshots that were never started;
update the activeSnapshots filter so it only considers snapshots with a download
and with rawStatus === DistributionPlanTokenPoolDownloadStatus.PENDING ||
rawStatus === DistributionPlanTokenPoolDownloadStatus.CLAIMED (i.e., remove the
!snapshot.download branch), and optionally add a staleness guard using
snapshot.download?.createdAt or snapshot.download?.updatedAt compared against a
STALE_THRESHOLD_MS constant to skip downloads older than the threshold; update
the logic around the activeSnapshots constant to reference snapshot.download
before checking rawStatus.
- Around line 270-279: The "Run analysis" button is hidden because
showRunAnalysisBtn is gated by allSnapshotsCompleted; change showRunAnalysisBtn
to depend only on haveUnRunOperations (showRunAnalysisBtn={haveUnRunOperations})
so the button is visible whenever there are un-run snapshot operations, and
adjust the Next button disable logic to prevent the user progressing while
un-run ops exist by setting disableNextBtn to include haveUnRunOperations (for
example disableNextBtn={haveUnRunOperations || !allSnapshotsCompleted}); update
the props on the DistributionPlanNextStepBtn component accordingly.
In
`@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsx`:
- Around line 84-118: The switch over download.stage in CreateSnapshotTableRow
(in CreateSnapshotTableRow.tsx) lacks a default branch, so add a default case to
the switch(download.stage) that returns a clear fallback string (e.g., "Unknown
stage" or `Unknown stage: ${download.stage}`) and optionally call a logger/warn
(e.g., console.warn or your app logger) with the unexpected value so the UI
never renders undefined and new/unknown enum values are visible for debugging;
update the default case rather than changing the existing specific cases.
---
Nitpick comments:
In
`@components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx`:
- Around line 22-37: The onRetry handler currently only shows success toasts and
leaves users uninformed on failure; update onRetry (the async function that
calls distributionPlanApiPost) to handle both non-success responses and thrown
errors by showing an error toast via setToasts (e.g., messages: ["Snapshot retry
failed"] or include error.message), and ensure setLoading(false) runs in all
cases (use try/catch/finally around the distributionPlanApiPost call and await
refreshDownloads only on success).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a44a741f-2089-4fd5-9be6-ef4b8e22b132
📒 Files selected for processing (7)
components/allowlist-tool/allowlist-tool.types.tscomponents/distribution-plan-tool/common/DistributionPlanNextStepBtn.tsxcomponents/distribution-plan-tool/create-snapshots/CreateSnapshots.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTable.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableBody.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRow.tsxcomponents/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowRetry.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableBody.tsx



Summary by CodeRabbit
New Features
Improvements