Repository navigation
Conversation
After a reboot, migration or restart the platform seeds the new container with the `APIFY_CHARGED_ACTOR_EVENT_COUNTS` recorded when the run started, so the charging manager began from zero charged events and allowed a fresh `maxTotalChargeUsd` budget. The charging manager now keeps its charged event counts in a Crawlee `RecoverableState` stored in the default key-value store under `__ACTOR_CHARGING_STATE`. It is written on every `PERSIST_STATE` event, which `Actor.reboot()` and a migration dispatch before the container stops, and once more on exit. A pay-per-event run on the platform reads it at start and takes the persisted count of each event where it is higher than the env var's. Local runs keep their counts in memory only. The per-event totals are derived from the counts and the prices instead of being stored. Same fix as apify/apify-sdk-python#1222. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_017ocuAKQTqReMDTjXCUTnKP
|
✅ The link checker did not find any broken links. See more at https://github.com/apify/apify-sdk-js/actions/runs/42202593178#summary-127841278079 |
The charging manager owns the persistence of its charged event counts and writes them with direct storage access, so a `PERSIST_STATE` dispatched inside a request handler's storage transaction, as `Actor.reboot()` does when called from a handler, reaches the store instead of being buffered into a transaction that never commits. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_017ocuAKQTqReMDTjXCUTnKP
The counts are serialized when a write starts, so a periodic write still in flight when a reboot persists could land after the reboot's write and leave older counts in the store. Each write now waits for the previous one. The persist listener is a private field, as the Actor's own are. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_017ocuAKQTqReMDTjXCUTnKP
|
See more at https://github.com/apify/apify-sdk-js/actions/runs/42216909708#summary-127889098677 |
Pijukatel
marked this pull request as ready for review
November 6, 2026 12:32
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After a reboot, migration or restart, the platform seeds the new container with the charged event counts recorded when the run started, so the charging manager began from a fresh
maxTotalChargeUsdbudget. The SDK now carries its own counts across in the default key-value store.__ACTOR_CHARGING_STATE, written on everyPERSIST_STATEevent, whichActor.reboot()and a migration dispatch before the container stops, and once more on exit. The write uses direct storage access, so a reboot from inside a request handler, where a storage transaction is open, still reaches the store.Parity with the Python SDK fix in apify/apify-sdk-python#1222, which fixes apify/apify-sdk-python#1209.