Skip to content

Overcharge by one event when the budget is exhausted #1187

Open

Description

@vdusek

When a charge exceeds the remaining maxTotalChargeUsd budget, ChargingManager.charge() caps the count with min() (source), and the push-data limits do the same for dataset items (compute_push_data_limit, PPE dataset mixin). The platform never sees a charge over the budget, so an Actor that ignores the returned ChargeResult keeps running and doing unpaid work until it times out.

The JS SDK charges one event over the budget in that case, so the platform detects the overspend and terminates the run, unless the run is already strictly over budget (charge(), calculatePushDataLimit()). This came from apify/apify-sdk-js#574, which fixed apify/apify-sdk-js#572.

Acceptance criteria

  • charge() charges max_chargeable + 1 events when count exceeds the remaining budget and the total charged amount is not already over the limit.
  • push_data() and the default-dataset PPE path let one item through when the budget cannot cover a single item, under the same condition; a partially covered push is still capped to what the budget allows.
  • Unit tests updated, including the local PPE mode.

Implementation notes

  • ChargingManager.charge() (_charging.py#L344-L353): when count > max_chargeable and calculate_total_charged_amount() <= max_total_charge_usd, charge max_chargeable + 1; when the run is already strictly over budget, charge 0. Port the condition from JS charge() as is.
  • compute_push_data_limit() (#L467-L484) and DatasetClientPpeMixin._compute_limit_for_push() (_ppe_dataset_mixin.py#L12-L18): follow JS calculatePushDataLimit(), letting one item through only when the budget can't cover a single one.
  • ChargeResult.event_charge_limit_reached must still report True after the extra event.
  • Update the capped-count assertions in tests/unit/actor/test_actor_charge.py and tests/unit/actor/test_charging_manager.py, and add cases for the "already over budget" branch and the local (off-platform) mode.

✍️ Drafted by Claude Code

Activity

  1. added
    enhancementNew feature or request.
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Oct 16, 2026
  2. self-assigned this
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions