Skip to content

feat(platform): old payout path drain check (D5 step 0) - #129

Merged
agency-builder merged 1 commit into
stagingfrom
feature/d5-drain-check
Nov 26, 2026
Merged

agency-builder merged 1 commit into
stagingfrom
feature/d5-drain-check

Conversation

@agency-builder

Copy link
Copy Markdown
Collaborator

A site-admin page, /platform/old-payouts, listing every Organization with anything on the old direct payout path: its payout route, old agent, unsettled old payouts (anything not paid, refused or proven never sent: held, processing, unknown, sending, needs review), old owner actions in flight, and a live old permission (noted, not blocking). 'Drained' only when nothing blocks. Reads the old tables directly, so it outlives the code D5 removes.

@multi-review multi-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inline findings for 54bfead; see the summary comment for the rest.

Comment on lines +49 to +51
const inFlight = intents.filter(
(i) => i.organizationId === organizationId && IN_FLIGHT_INTENT.has(i.status),
).length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 Medium · correctness: Stale old-path intents (>7 days) count as 'in flight' forever, so the check can never report drained

The check counts every payout_intents row whose status is QUEUED, PROCESSING or PENDING_APPROVAL, however old it is. The old service only treats an intent as submitted for 7 days: submittedIntents filters on createdAt > now - INTENT_FOLLOW_UP_MS (7 days). Both the maintain() sweep and the AGENT_PENDING guard use that function.

After 7 days the old code stops polling an intent, so its status is never updated again. Concrete scenario: an owner's issue_grant intent returns PROCESSING. The sweep fails (Agent API errors are only logged) or stays PROCESSING for a week, and the row stays PROCESSING permanently. On this page that Organization then shows "1 owner action is still in flight on the old path" and drained stays false. The app has no way to clear this blocker, even though the old path itself already considers the intent abandoned. That can stall D5 indefinitely or push operators to ignore the check.

Suggested fix: Also select payoutIntents.createdAt and apply the same 7-day window as submittedIntents, so only intents the old path still follows count. If older ones should still be visible, report them separately as a non-blocking note.

@multi-review

multi-review Bot commented Nov 26, 2026

Copy link
Copy Markdown

Multi Review · 54bfead

This PR adds an admin-only, read-only endpoint and a /platform/old-payouts page. Together they report whether anything still depends on the old direct payout path, using the payout_agents, agent_payouts, payout_intents and platform_agents tables. The risk is low because nothing is written, but the in-flight intent count doesn't use the same 7-day window as the old service. Stale intents can then block "drained" permanently.

1 issue(s) (1 commented inline)

What was checked (8 areas)
  • createOldPayoutPath: its wiring in initializeServices and its single caller, the admin-only oldPayoutPath handler, which runs once per page load/refetch
  • the settled() predicate compared with payoutRetryable/noUnsettledPayout and AGENT_PAYOUT_STATUSES in schema.ts
  • IN_FLIGHT_INTENT compared with SUBMITTED_INTENT/PENDING_INTENT and submittedIntents' 7-day window in payouts/service.ts (maintain sweep, create_agent pending check)
  • how payout_intents status is written (generateIntent insert, settleIntent, submitIntent)
  • organizationName lookup via organizationDirectory.get, including when the directory is unconfigured, and the .catch fallback
  • platform route default ('legacy') when there is no platform_agents row; PAYOUT_ROUTES
  • contract output schema compared with the service return shape and the UI rendering
  • UI query options, route tree registration, platform index link, UI and integration tests

Findings

  • 🟠 Medium api/src/services/platform/old-payout-path.ts:49 Stale old-path intents (>7 days) count as 'in flight' forever, so the check can never report drained (commented inline)

Comment @multi-review to re-review new commits, or @multi-review full for a full review.

@agency-builder
agency-builder merged commit fe77ebe into staging Nov 26, 2026
6 checks passed
@agency-builder
agency-builder deleted the feature/d5-drain-check branch November 26, 2026 18:21
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.

2 participants