Skip to content

feat(marketplace): sell/cancel Standard RIs on AWS Marketplace (closes #292)#808

Open
cristim wants to merge 7 commits into
feat/multicloud-web-frontendfrom
fix/292-wave4
Open

feat(marketplace): sell/cancel Standard RIs on AWS Marketplace (closes #292)#808
cristim wants to merge 7 commits into
feat/multicloud-web-frontendfrom
fix/292-wave4

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented May 28, 2026

Summary

  • Migration 000060: adds offering_class, listing_id, listing_state columns to purchase_history
  • Backend: POST /api/purchases/{id}/marketplace-list and POST /api/purchases/{id}/marketplace-cancel routes with sell-any/sell-own RBAC (mirroring the cancel/retry/approve family); sell-own added to DefaultUserPermissions; default price schedule is 95% of residual value (upfront + monthly * remaining months); EC2 API: CreateReservedInstancesListing, DescribeReservedInstancesListings, CancelReservedInstancesListing
  • Frontend: "Sell on Marketplace" button on completed Standard RI rows; "Cancel listing" button when listing_state == "active"; confirm-dialog + API call + toast + reload click handlers; all API types exported from api/index.ts

Test plan

  • Run go test ./... - all 4966 tests pass across 38 packages
  • Run npm test in frontend/ - all 2142 frontend tests pass
  • Frontend build: npm run build - compiles with no TS errors
  • Smoke-test: create a Standard RI execution row with offering_class=standard and verify "Sell on Marketplace" button appears; click it and confirm the API call is dispatched
  • Verify the "Cancel listing" button appears when listing_state=active and cancels correctly
  • Verify Convertible RI rows and non-completed rows do NOT show the Sell button
  • Verify sell-own users can only sell RIs in their allowed accounts; sell-any users can sell any

Closes #292

Summary by CodeRabbit

  • New Features
    • Users can now list "Standard" AWS Reserved Instances on the Marketplace directly from purchase history
    • Added ability to cancel active marketplace listings
    • Support for custom pricing when creating marketplace listings
    • New role-based authorization controls for marketplace selling operations
    • Marketplace listing status is now tracked and displayed in purchase history

Review Change Stack

cristim added 2 commits May 28, 2026 19:59
…end (closes #292)

Add sell-on-Marketplace support for Standard Reserved Instances:

- migration 000060: add offering_class, listing_id, listing_state to purchase_history
- auth: sell-any and sell-own actions; sell-own added to DefaultUserPermissions
- config: extend PurchaseHistoryRecord, StoreInterface with GetPurchaseHistoryByPurchaseID + UpdatePurchaseHistoryListing
- ec2 client: CreateReservedInstancesListing, DescribeReservedInstancesListings, CancelReservedInstancesListing
- api: handler_marketplace.go with marketplaceList/Cancel, authorizeSessionSell (sell-any/sell-own RBAC), default price schedule (95% of residual value)
- router: POST /api/purchases/{id}/marketplace-list + /marketplace-cancel routes
- all tests updated for the new interface methods and permission count
…tend (closes #292)

Add Sell on Marketplace / Cancel listing buttons to purchase history rows:

- types.ts: extend HistoryPurchase with offering_class, listing_id, listing_state
- api/purchases.ts: createMarketplaceListing + cancelMarketplaceListing; re-export from api/index.ts
- history.ts: canSellOnMarketplace / canCancelMarketplaceListing predicates; renderActionCell renders Sell/Cancel buttons for Standard RI completed rows; wireRowActionHandlers wires confirm-dialog + API + toast + reload for both buttons
@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/low Minor harm urgency/this-quarter Within the quarter impact/few Limited audience effort/m Days type/feat New capability labels May 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes and 25 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50671a58-e003-40d9-94e1-21d12e740d0c

📥 Commits

Reviewing files that changed from the base of the PR and between 8bab8ca and 03ab7f5.

📒 Files selected for processing (7)
  • frontend/src/history.ts
  • frontend/src/permissions.generated.ts
  • internal/api/handler_marketplace.go
  • internal/database/postgres/migrations/000060_purchase_history_marketplace_listing.down.sql
  • internal/database/postgres/migrations/000060_purchase_history_marketplace_listing.up.sql
  • providers/aws/services/ec2/client.go
  • providers/aws/services/ec2/client_test.go
📝 Walkthrough

Walkthrough

This PR implements AWS RI Marketplace listing and cancellation for Standard Reserved Instances. It adds authorization (sell-own/sell-any permissions), database schema for listing metadata, EC2 API client bindings, backend handlers with RBAC and price scheduling, API routes, frontend TypeScript wrappers, and History table UI actions.

Changes

AWS RI Marketplace Listing Implementation

Layer / File(s) Summary
Authorization Model and Permissions
internal/auth/types.go, internal/auth/types_test.go, internal/auth/service_test.go, internal/auth/service_group_test.go
Adds ActionSellOwn and ActionSellAny permission constants; grants standard users sell-own:purchases via DefaultUserPermissions(); updates all auth service tests (11→12 permissions) to reflect the new permission set.
Data Models and Database Schema
internal/config/types.go, frontend/src/types.ts, internal/database/postgres/migrations/000060_*
Extends PurchaseHistoryRecord with OfferingClass, ListingID, ListingState fields; migration 000060 adds three nullable columns to purchase_history table; frontend HistoryPurchase type adds optional listing metadata fields.
Database Access Layer
internal/config/interfaces.go, internal/config/store_postgres.go, internal/config/store_postgres_pgxmock_test.go
Adds StoreInterface methods GetPurchaseHistoryByPurchaseID and UpdatePurchaseHistoryListing; PostgresStore implements both with proper nullable-string handling; updates all purchase-history read paths to scan new columns; pgxmock fixtures synchronized to match updated schema.
AWS EC2 Marketplace API Client
providers/aws/services/ec2/client.go
Extends EC2API interface with three marketplace listing operations; adds request/response types (MarketplaceListingRequest, MarketplacePriceTier, MarketplaceListingResult); implements CreateMarketplaceListing, DescribeMarketplaceListing, CancelMarketplaceListing Client methods with price-schedule transformation and error handling.
Handler Injection and EC2 Factory
internal/api/handler.go, internal/api/handler_marketplace.go (lines 1–45)
Adds optional marketplaceEC2Factory DI field to Handler; defines marketplaceEC2Client interface and buildMarketplaceEC2Client factory.
Marketplace Handlers and RBAC
internal/api/handler_marketplace.go (lines 47–311)
Implements marketplaceList and marketplaceCancel Lambda handlers with purchase validation, Standard-only enforcement, RBAC via authorizeSessionSell (checks permissions, delegates account checks) and authorizeAllowedAccount (validates session's allowed accounts); adds resolveMarketplacePriceSchedule for default/explicit price tiers; EC2 calls with logged-but-non-fatal DB persistence.
API Route Registration
internal/api/router.go
Registers POST /api/purchases/{id}/marketplace-list and POST /api/purchases/{id}/marketplace-cancel with AuthUser middleware; adds Router handler wrappers.
Frontend API Wrappers
frontend/src/api/purchases.ts, frontend/src/api/index.ts
Exports createMarketplaceListing (POST with optional price_schedule) and cancelMarketplaceListing (POST); adds MarketplacePriceTier and MarketplaceListResult types; updates barrel re-exports.
History Table UI and Handlers
frontend/src/history.ts
Adds eligibility helpers canSellOnMarketplace (standard class, no active listing, authenticated user) and canCancelMarketplaceListing (active listing state); extends sameRowActions() to include marketplace buttons in concurrent-disabling set; extends renderActionCell() to show "Sell on Marketplace" or "Cancel listing" buttons for completed Standard RIs; adds wireRowActionHandlers() wiring for click handlers with confirm dialogs, action disabling, API calls, toast notifications, and history reload.
Mock Store Methods (Test Support)
internal/analytics/collector_test.go, internal/api/mocks_test.go, internal/mocks/stores.go, internal/purchase/mocks_test.go, internal/scheduler/scheduler_test.go, internal/server/test_helpers_test.go
Adds GetPurchaseHistoryByPurchaseID and UpdatePurchaseHistoryListing mock methods to MockConfigStore across all test packages using testify mock pattern with consistent nil-handling and error returns.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • LeanerCloud/CUDly#299: Both PRs modify frontend/src/history.ts row action UI/handler wiring, with this PR adding marketplace sell/cancel buttons and the retrieved PR adding approve-any/own buttons, intersecting at the same action-cell rendering and click-handler layers.

Suggested labels

impact/many, effort/l

Poem

🐰 A marketplace unfolds for Reserved Instances,
Standard RIs can now list their final distances!
With RBAC guards and permission gates,
The sell-own and sell-any seal the fates—
Price schedules dance, listings take flight,
A recovery path when exchanges aren't right! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(marketplace): sell/cancel Standard RIs on AWS Marketplace (closes #292)' is fully related to the main changes: it describes the primary feature added (selling and canceling Standard Reserved Instances on AWS Marketplace) and references the closing issue.
Linked Issues check ✅ Passed The PR implements all major coding requirements from issue #292: history UI affordance for Standard RIs, backend CreateReservedInstancesListing/DescribeReservedInstancesListings/CancelReservedInstancesListing APIs, RBAC sell-any/sell-own permissions, database schema updates, EC2 client methods, and frontend integration with confirm dialogs and API calls.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the marketplace listing/cancellation feature: database migrations, backend API handlers and EC2 client extensions, RBAC additions, frontend UI and API calls, and supporting type definitions. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/292-wave4

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 28, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/history.ts (1)

610-624: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't let retry-lineage markup suppress marketplace actions.

Line 610 returns as soon as lineage exists, so a completed Standard RI with retry_attempt_n > 0 never reaches Lines 617-623. That hides Sell/Cancel for successful retry descendants, even though they're still eligible completed purchases.

Suggested direction
-  if (lineage.length > 0) {
-    return lineage.join(' ');
-  }
-
-  // Completed Standard RI rows: offer Sell on Marketplace (issue `#292`).
-  // The button is placed here (after lineage links) so it does not
-  // interfere with the Retry / Approve / Cancel affordances above.
-  if (p.purchase_id) {
-    if (canCancelMarketplaceListing(p)) {
-      return `<button type="button" class="btn-link history-marketplace-cancel-btn" data-marketplace-cancel-id="${escapeHtml(p.purchase_id)}">Cancel listing ${escapeHtml(p.listing_id || '')}</button>`;
-    }
-    if (canSellOnMarketplace(p)) {
-      return `<button type="button" class="btn-link history-marketplace-sell-btn" data-marketplace-sell-id="${escapeHtml(p.purchase_id)}">Sell on Marketplace</button>`;
-    }
-  }
+  const trailingActions: string[] = [];
+  if (p.purchase_id) {
+    if (canCancelMarketplaceListing(p)) {
+      trailingActions.push(
+        `<button type="button" class="btn-link history-marketplace-cancel-btn" data-marketplace-cancel-id="${escapeHtml(p.purchase_id)}">Cancel listing ${escapeHtml(p.listing_id || '')}</button>`,
+      );
+    } else if (canSellOnMarketplace(p)) {
+      trailingActions.push(
+        `<button type="button" class="btn-link history-marketplace-sell-btn" data-marketplace-sell-id="${escapeHtml(p.purchase_id)}">Sell on Marketplace</button>`,
+      );
+    }
+  }
+
+  if (lineage.length > 0 || trailingActions.length > 0) {
+    return [...lineage, ...trailingActions].join(' ');
+  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/history.ts` around lines 610 - 624, The early return when
lineage.length > 0 prevents the marketplace buttons from being rendered for
completed retry descendants; update the logic in the function handling the
history row so that when lineage exists you append (or merge) the marketplace
button markup instead of returning immediately — locate the lineage handling and
the marketplace block using lineage, p.purchase_id, canCancelMarketplaceListing,
canSellOnMarketplace and escapeHtml; either move the marketplace block above the
return or build a combined string (lineage.join(' ') + marketplaceMarkup) so
Sell on Marketplace / Cancel listing buttons are included for eligible
purchases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/history.ts`:
- Around line 914-943: The flow skips the required pricing modal: after the
initial confirmDialog in the '.history-marketplace-sell-btn' click handler, open
the RI pricing/pricing-schedule modal (e.g., call a new or existing
showMarketplacePricingModal / showPricingModal function) to display the RI
summary, default per-month price schedule and 12% fee breakdown and allow the
user to adjust/select schedule types (use the schedule types exposed by
frontend/src/api/purchases.ts via api.getPricingSchedules or similar). Only if
the user confirms the pricing modal proceed to call
api.createMarketplaceListing(id); preserve the existing UI state handling
(disable/enable sameRowActions(btn) and call loadHistory() on success) and
handle errors exactly as existing catch blocks do.
- Around line 474-496: canSellOnMarketplace currently omits the required
remaining-term check; update the function (canSellOnMarketplace(p:
HistoryPurchase)) to return false unless the purchase has at least one month
remaining before maturity by inspecting the appropriate remaining-term field on
p (e.g., p.remaining_term, p.remaining_months, or p.termRemaining depending on
the model) and parsing/coercing string values to numbers if needed; add this
gate alongside the existing status/offering_class/listing_state checks so
matured Standard RIs (remaining < 1) do not show the Sell button.

In `@internal/api/handler_marketplace.go`:
- Line 147: The code currently maps every AWS marketplace error to HTTP 502 via
NewClientError("AWS marketplace listing failed: "+err.Error()) which incorrectly
classifies client-side validation/precondition failures; update the handlers in
internal/api/handler_marketplace.go to inspect the returned AWS error (check for
awserr.Error or smithy.APIError / error with Code() and/or HTTPStatusCode()
methods) and map its actual HTTP-level or SDK error code to an appropriate
status (e.g., 4xx for validation/precondition/auth errors, 409 for conflict, 404
for not found, 401/403 for auth/perm, otherwise 502 for server-side), then call
NewClientError with that mapped status and the error message; apply the same
change to the other occurrence that currently returns 502 so client-correctable
errors are propagated with the correct 4xx status.
- Around line 151-156: When UpdatePurchaseHistoryListing(...) fails after AWS
listing creation (the block using purchaseID, result.ListingID, result.State),
do not silently return success; instead treat it as an error: attempt a
compensating rollback of the created listing (call the appropriate marketplace
delete/cleanup method for result.ListingID), log both the DB error and the
rollback outcome, and return an internal error to the API caller; apply the same
change for the other occurrence referenced (the block around lines 207-209) so
DB persistence failures never yield a successful response while external state
exists.
- Around line 117-118: The default listing price uses row.Term as the remaining
months, which overprices older reservations; instead compute remainingMonths as
the actual remaining term (e.g., row.RemainingTerm or row.Term - row.UsedMonths,
or derive from start/end dates and now) and pass that into
resolveMarketplacePriceSchedule when body.PriceSchedule is empty; update the
code around the schedule assignment (the call to resolveMarketplacePriceSchedule
and the local variable schedule) to use this computed remainingMonths and apply
the same fix to the other occurrence referenced (lines ~299-310).

In
`@internal/database/postgres/migrations/000060_purchase_history_marketplace_listing.up.sql`:
- Around line 15-18: The migration for table purchase_history adds
offering_class, listing_id, and listing_state but omits required marketplace
columns needed for lifecycle persistence; update the ALTER TABLE statement in
the migration to also ADD COLUMN IF NOT EXISTS listed_at TIMESTAMP WITH TIME
ZONE, listing_price_schedule JSONB (or appropriate type),
listing_proceeds_received NUMERIC (or appropriate money type), and
listing_fee_paid NUMERIC so the poller/sale path (references: table
purchase_history and columns offering_class, listing_id, listing_state) can
persist listing timestamps, price schedules, proceeds, and fees; ensure
nullability and default behavior match existing schema conventions.

In `@providers/aws/services/ec2/client.go`:
- Around line 970-979: Ensure the code never returns an empty ListingID: when
building MarketplaceListingResult (using variables listingID and
listing.ReservedInstancesListingId and listing.Status) validate that
aws.ToString(listing.ReservedInstancesListingId) yields a non-empty string and,
if empty, return a clear error instead of MarketplaceListingResult{ListingID:
"", ...}; apply the same validation & error-return logic in the other similar
blocks (the code paths referenced around the other two snippets) so downstream
handlers never persist an empty ListingID.

---

Outside diff comments:
In `@frontend/src/history.ts`:
- Around line 610-624: The early return when lineage.length > 0 prevents the
marketplace buttons from being rendered for completed retry descendants; update
the logic in the function handling the history row so that when lineage exists
you append (or merge) the marketplace button markup instead of returning
immediately — locate the lineage handling and the marketplace block using
lineage, p.purchase_id, canCancelMarketplaceListing, canSellOnMarketplace and
escapeHtml; either move the marketplace block above the return or build a
combined string (lineage.join(' ') + marketplaceMarkup) so Sell on Marketplace /
Cancel listing buttons are included for eligible purchases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b216fad4-4a77-4b3b-be24-d77f8f3b76d4

📥 Commits

Reviewing files that changed from the base of the PR and between 4956d66 and 8bab8ca.

📒 Files selected for processing (24)
  • frontend/src/api/index.ts
  • frontend/src/api/purchases.ts
  • frontend/src/history.ts
  • frontend/src/types.ts
  • internal/analytics/collector_test.go
  • internal/api/handler.go
  • internal/api/handler_marketplace.go
  • internal/api/mocks_test.go
  • internal/api/router.go
  • internal/auth/service_group_test.go
  • internal/auth/service_test.go
  • internal/auth/types.go
  • internal/auth/types_test.go
  • internal/config/interfaces.go
  • internal/config/store_postgres.go
  • internal/config/store_postgres_pgxmock_test.go
  • internal/config/types.go
  • internal/database/postgres/migrations/000060_purchase_history_marketplace_listing.down.sql
  • internal/database/postgres/migrations/000060_purchase_history_marketplace_listing.up.sql
  • internal/mocks/stores.go
  • internal/purchase/mocks_test.go
  • internal/scheduler/scheduler_test.go
  • internal/server/test_helpers_test.go
  • providers/aws/services/ec2/client.go

Comment thread frontend/src/history.ts
Comment thread frontend/src/history.ts Outdated
Comment thread internal/api/handler_marketplace.go Outdated
Comment thread internal/api/handler_marketplace.go Outdated
Comment thread internal/api/handler_marketplace.go
Comment thread providers/aws/services/ec2/client.go
cristim added 4 commits May 30, 2026 19:06
- canSellOnMarketplace: gate on remaining term >= 1 month computed from
  purchase timestamp + total term; matured Standard RIs no longer show Sell
- sell click handler: open pricing/schedule modal before calling
  createMarketplaceListing so users see RI summary, default list price, and
  12% fee breakdown before confirming
- lineage actions cell: build trailingActions[] first then combine with
  lineage[] so Sell/Cancel buttons render on retry-descendant rows
- Compute actual remaining months from purchase timestamp and total term
  via computeRemainingMonths; removes overpricing of older RIs in the
  default price schedule (was using full contract term)
- Map AWS errors via mapAWSMarketplaceError: inspect smithy.APIError code
  and fault; client-fault errors return 4xx instead of blanket 502
- On DB failure after successful listing creation, attempt compensating
  rollback via CancelMarketplaceListing to prevent AWS/DB desync; return
  internal error rather than false success to the caller
- Same DB-failure fix for cancel handler: return error on UpdatePurchaseHistoryListing
  failure so the caller knows the state is out of sync
Add listed_at, listing_price_schedule, listing_proceeds_received, and
listing_fee_paid columns for marketplace settlement tracking. All nullable,
consistent with existing offering_class/listing_id/listing_state nullability.
Down migration updated to drop the new columns.
…isting

Return an error when AWS returns a listing with an empty
ReservedInstancesListingId rather than propagating a blank ID that would
silently make rollback and describe calls fail.
@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Repair the stalled marketplace sell/cancel work:

- Add the three missing marketplace methods to MockEC2Client so the
  ec2 package compiles against the extended EC2API interface
  (CreateReservedInstancesListing, DescribeReservedInstancesListings,
  CancelReservedInstancesListing).
- Extract validateMarketplaceListRequest from marketplaceList to bring
  its cyclomatic complexity back under the gocyclo threshold.
- Regenerate frontend/src/permissions.generated.ts to include the new
  sell-own:purchases permission (pre-commit codegen check).
- Harden Describe/Cancel marketplace paths to fall back to the
  caller-supplied listing ID when AWS omits ReservedInstancesListingId,
  so downstream persistence never stores an empty ID (CR finding).
@cristim
Copy link
Copy Markdown
Member Author

cristim commented Jun 1, 2026

Fixed the compile/type issues (missing MockEC2Client methods for the extended EC2API interface), addressed the 7 CR findings (6 were already in prior commits and verified against HEAD; the Describe/Cancel empty-listing-ID fallback is now applied), and resolved the pre-commit failures (gocyclo on marketplaceList via extracting validateMarketplaceListRequest, and the stale permissions.generated.ts codegen) in 03ab7f5. @coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

@cristim Thanks for the detailed summary of the fixes in 03ab7f574! Triggering a fresh incremental review now to cover the updated commit.

(ᴗ˳ᴗ)

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented Jun 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented Jun 1, 2026

All 8 CodeRabbit findings from the 2026-05-28 review are resolved in commits a3cfc89 to 03ab7f5. Verification summary:

frontend/src/history.ts

  • Remaining-term gate: canSellOnMarketplace computes elapsed months from purchase timestamp and returns false when fewer than 1 month remains (line 498-504).
  • Lineage + marketplace composability: trailing actions are built before the lineage join, so retry descendants with eligible listings still get Sell/Cancel buttons (line 624-635).
  • Pricing modal: sell handler builds a DOM-based modal showing RI summary, remaining term, list price (5% below residual value), 12% fee, and estimated net proceeds before calling api.createMarketplaceListing (lines 938-985).

internal/api/handler_marketplace.go

  • Remaining-months accuracy: computeRemainingMonths(row.Timestamp, row.Term) is used instead of raw row.Term so default price schedules reflect actual residual value.
  • AWS error mapping: mapAWSMarketplaceError inspects smithy.APIError fault + known client-fault codes and returns 4xx for client errors, 502 for AWS-side failures.
  • DB failure on listing create: compensating CancelMarketplaceListing rollback attempted; both DB error and rollback outcome are logged; internal error returned to caller instead of success.

internal/database/postgres/migrations/000060_...

  • Added listed_at TIMESTAMPTZ, listing_price_schedule JSONB, listing_proceeds_received NUMERIC, listing_fee_paid NUMERIC to the ALTER TABLE.

providers/aws/services/ec2/client.go

  • CreateReservedInstancesListing: errors on empty listing ID.
  • DescribeMarketplaceListing / CancelMarketplaceListing: falls back to caller-supplied ID when AWS omits it in the response.

Tests: go build ./... clean, go test ./internal/api/... 1355 passed, go test in ec2 submodule 39 passed, frontend Jest 179 passed.

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

@cristim Thanks for the thorough verification summary — every finding is clearly mapped to the exact lines and commit range. The compensating rollback on DB failure, the AWS error mapping via mapAWSMarketplaceError, the remaining-months accuracy fix, and the extra migration columns all look well-considered. Triggering a fresh incremental review now.

(ᴗ˳ᴗ)

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented Jun 1, 2026

All 7 CR findings from the 2026-05-28 review (plus the outside-diff lineage composability note) are resolved and confirmed in the 2026-06-01T19:33 incremental review. No new findings were raised in that review pass. Verification summary:

7 inline threads - all confirmed LGTM by CR at 2026-06-01T19:33:

  • Thread 3319800619 (canSellOnMarketplace remaining-term gate): confirmed at 3336658526. Code at history.ts:498-504 computes elapsedMonths from purchase timestamp and returns false when remainingMonths < 1.
  • Thread 3319800649 (pricing modal for sell flow): confirmed at 3336658686. Sell handler builds a dl summary with RI ID, region, resource type, remaining term, default list price (residual value x 0.95), 12% AWS fee, and estimated net proceeds before calling createMarketplaceListing.
  • Thread 3319800653 (default listing price uses full-term cost): confirmed at 3336658817. computeRemainingMonths(row.Timestamp, row.Term) used in both marketplaceList and marketplaceCancel handlers.
  • Thread 3319800660 (AWS marketplace errors mapped to 502): confirmed LGTM at 3336659205. mapAWSMarketplaceError uses smithy.APIError.ErrorFault() == smithy.FaultClient as primary classifier, plus a deny-list of known client-fault codes.
  • Thread 3319800663 (success returned after failed DB persistence): confirmed at 3336659846. Compensating CancelMarketplaceListing call on UpdatePurchaseHistoryListing failure; both error paths return an internal error.
  • Thread 3319800664 (missing settlement columns in migration): confirmed at 3336660174. Migration 000060 now adds all 7 columns: offering_class, listing_id, listing_state, listed_at, listing_price_schedule, listing_proceeds_received, listing_fee_paid.
  • Thread 3319800673 (empty listing IDs returned from ec2 client): confirmed at 3335986569 and 3336658526. Create path errors on empty ID; Describe/Cancel paths fall back to caller-supplied listingID.

Outside-diff finding (lineage composability - history.ts:610-624): already fixed in the same commit range. trailingActions array is built before lineage join at history.ts:624-635 so retry descendants with eligible listings get Sell/Cancel buttons.

Build and tests pass: go build ./... clean, go test ./internal/api/... 1355 passed, go test ./providers/aws/services/ec2/... 39 passed.

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

@cristim Thanks for the meticulous resolution log — every thread is mapped to a specific commit reference and line range, making it easy to verify. All 7 findings plus the outside-diff composability note are clearly closed out, and the clean build + test results across all three suites look solid. Triggering a fresh incremental review now.

(ᴗ˳ᴗ)

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/few Limited audience priority/p2 Backlog-worthy severity/low Minor harm triaged Item has been triaged type/feat New capability urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant