Skip to content

fix(deployment): reduce auto top-up escrow deposit sizing from 48h to 24h - #3562

Draft
baktun14 wants to merge 1 commit into
mainfrom
fix/deployment-auto-topup-24h-deposit-sizing
Draft

fix(deployment): reduce auto top-up escrow deposit sizing from 48h to 24h#3562
baktun14 wants to merge 1 commit into
mainfrom
fix/deployment-auto-topup-24h-deposit-sizing

Conversation

@baktun14

@baktun14 baktun14 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Why

The hourly auto top-up adds a flat AUTO_TOP_UP_AMOUNT_IN_H (48h) worth of a deployment's cost on top of whatever it already holds, and it triggers while the deployment can still hold up to 24h of runway. Expensive deployments therefore hold up to ~72h of cost, and a single funding event moves 48h of burn at once: a $5/h deployment pulls $240 per deposit and holds up to ~$360 in escrow. That lump drains the Available balance in one shot, chains consecutive auto-reload card charges for anything burning more than ~$2/h against the $100 default reload amount, and widens the insufficient-balance window for new deployment creation (CON-512).

Halving the flat amount to 24h halves each draw and the average locked escrow without shortening the buffer against a broken top-up job: time to first customer impact is set by the separate 24h look-ahead trigger (AUTO_TOP_UP_LOOK_AHEAD_WINDOW_IN_H), not by the deposit size. First closures after a dead cron still start ~24h in; only the tail of the fleet drains sooner (~48h instead of ~72h).

Related to CON-791: to-target sizing remains the proper fix. A flat 24h add at the 24h trigger is roughly equivalent to CON-791's 48h target in steady state, so this value should be revisited when that lands.

What

  • Lower the AUTO_TOP_UP_AMOUNT_IN_H zod default from 48 to 24. This sizes the hourly escrow top-up, the initial funding at lease start, and the estimatedTopUpAmount value shown in the UI.
  • Deposits become roughly daily per deployment instead of every ~2 days; messages stay batched into one tx per owner, so master-wallet fee spend for this job roughly doubles.
  • Still env-overridable: setting AUTO_TOP_UP_AMOUNT_IN_H=48 is an instant rollback with no deploy.

Summary by CodeRabbit

  • Configuration
    • Reduced the default automatic top-up interval from 48 hours to 24 hours.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48b835f1-ed69-4062-ba2e-96c3c9db46ee

📥 Commits

Reviewing files that changed from the base of the PR and between a17f152 and 4459f76.

📒 Files selected for processing (1)
  • apps/api/src/deployment/config/env.config.ts

📝 Walkthrough

Walkthrough

Changes

Auto top-up configuration

Layer / File(s) Summary
Update auto top-up default
apps/api/src/deployment/config/env.config.ts
The default AUTO_TOP_UP_AMOUNT_IN_H value changes from 48 to 24.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested reviewers: devalpatel67

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deployment-auto-topup-24h-deposit-sizing

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/api/src/deployment/config/env.config.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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

@claude claude 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.

LGTM — a single-line config default change (48 → 24), well-justified in the PR description and still env-overridable for instant rollback.

Extended reasoning...

Overview

The entire diff is a one-line change to apps/api/src/deployment/config/env.config.ts, lowering the zod default for AUTO_TOP_UP_AMOUNT_IN_H from 48 to 24. This value flows into the auto top-up job's escrow deposit sizing, the initial lease-start funding, and the estimatedTopUpAmount displayed in the UI — all downstream consumers just read the config value, no logic changes.

Security risks

None. No auth, crypto, or permission-sensitive code is touched. This only changes a numeric default that governs how much escrow is deposited per top-up cycle.

Level of scrutiny

Low. This is a tuning/config change with a clear, well-reasoned rationale in the PR description (reduces lump-sum draws and shortens the insufficient-balance window per CON-512) and an explicit rollback path via env override. I checked draining-deployment.service.spec.ts, which hardcodes AUTO_TOP_UP_AMOUNT_IN_H: 48 in its test env, so existing tests are unaffected by the default change.

Other factors

Grepped for other usages of AUTO_TOP_UP_AMOUNT_IN_H and confirmed there are only two consumers (the service and its spec), both already accounted for. No other file in the repo hardcodes the old 48h default.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.42%. Comparing base (a17f152) to head (4459f76).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3562      +/-   ##
==========================================
- Coverage   75.27%   74.42%   -0.86%     
==========================================
  Files        1163     1073      -90     
  Lines       30165    27816    -2349     
  Branches     7504     7044     -460     
==========================================
- Hits        22708    20702    -2006     
+ Misses       6585     6273     -312     
+ Partials      872      841      -31     
Flag Coverage Δ *Carryforward flag
api 88.64% <ø> (+0.03%) ⬆️
deploy-web 65.00% <ø> (ø) Carriedforward from a17f152
log-collector ?
notifications 93.84% <ø> (ø) Carriedforward from a17f152
provider-console 81.38% <ø> (ø) Carriedforward from a17f152
provider-inventory ?
provider-proxy 88.17% <ø> (ø) Carriedforward from a17f152
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
apps/api/src/deployment/config/env.config.ts 100.00% <ø> (ø)

... and 91 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@baktun14 baktun14 closed this Aug 6, 2026
@baktun14 baktun14 reopened this Aug 6, 2026
@baktun14
baktun14 marked this pull request as draft August 6, 2026 05:53

@claude claude 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.

LGTM — trivial config default change with a clearly reasoned rationale and instant env-var rollback.

What was reviewed: confirmed the only change is the zod default (48→24) for AUTO_TOP_UP_AMOUNT_IN_H; checked its three consumers (hourly top-up sizing, lease-start funding, UI estimate) all read from config rather than hardcoding the old value; verified the existing unit test pins its own value (48) via mock config, so it isn't silently invalidated by the default change.

Extended reasoning...

Overview

Single-line change in apps/api/src/deployment/config/env.config.ts: the zod default for AUTO_TOP_UP_AMOUNT_IN_H drops from 48 to 24. This value drives escrow top-up sizing (hourly job, lease-start funding, and the UI's estimated top-up display), all of which read it from the shared config rather than hardcoding it, so no other code needed to change.

Security risks

None. This is a numeric tuning parameter for escrow deposit sizing, not an auth/permissions/crypto path. Worst case of a wrong value is over/under-funding escrow, not a security exposure.

Level of scrutiny

Low. This is a pure config/default value change with no control-flow modification, still overridable via env var for instant rollback, and the PR description gives a well-reasoned quantitative justification (halves deposit size and average locked escrow without shortening the safety buffer, since that's governed by the separate look-ahead window). CI (lint/tests/coverage) is green and the one existing spec that cares about this constant pins its own value explicitly, so it's unaffected by the default change.

Other factors

No CODEOWNER-sensitive paths touched, no outstanding review comments to address, and CodeRabbit found nothing actionable. This is exactly the kind of small, well-justified, mechanical change suited for approval without further human review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant