Skip to content

fix: throw an error instead of ignoring it when uploading batches#207

Open
gasperzgonec wants to merge 4 commits into
mainfrom
gasperz/ASCPT-28
Open

fix: throw an error instead of ignoring it when uploading batches#207
gasperzgonec wants to merge 4 commits into
mainfrom
gasperz/ASCPT-28

Conversation

@gasperzgonec

Copy link
Copy Markdown
Contributor

Description

Connected Issues

Checklist

  • Tests added/updated and ran with npm run test OR no tests needed.
  • Ran backwards compatibility tests with npm run test:backwards-compatibility.
  • Code formatted and checked with npm run lint.
  • Tested airdrop-template linked to this PR.
  • Documentation updated and provided a link to PR / new docs OR no docs needed.

@gasperzgonec gasperzgonec requested review from a team and radovanjorgic as code owners June 4, 2026 08:16
Comment thread src/repo/repo.ts
Comment on lines +115 to +117
const batch = this.items.slice(0, batchSize);
await this.upload(batch);
this.items.splice(0, batchSize);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This now first slices the items from the array, which doesn't remove them, uploads them, and if it fails, the items are still present in the array for processing in the next iteration.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, so in this case if upload fails it will throw an error which must be caught by developer if he wants and if not it will fail the sync, do I understand correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's correct.

Comment on lines +295 to +297
for (const repo of this.repos) {
this.artifacts.push(...repo.uploadedArtifacts);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was added, because until now, if we errored before now, the few artifacts that we uploaded, would have stayed without a parent, this sends them with the emit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on this?
What is the exact issue? Maybe give an example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is related to the S3 cleanup. I think that if we upload an artifact and we don't specify it in the event, to note that it was uploaded, it becomes an orphan and gets deleted after 30 days instead of when the sync is killed. Cleanup is deferred for the items that aren't reported.

Comment thread src/http/axios-client-internal.ts Outdated
Comment on lines +3 to +23
import { isMainThread, workerData } from 'node:worker_threads';

/** Production default; tests may lower via workerData.options.httpRetries or ADAAS_TEST_HTTP_RETRIES. */
function getHttpRetryCount(): number {
if (
!isMainThread &&
workerData?.options?.httpRetries !== undefined &&
workerData.options.httpRetries >= 0
) {
return workerData.options.httpRetries;
}

const fromEnv = process.env.ADAAS_TEST_HTTP_RETRIES;
if (fromEnv !== undefined) {
const parsed = parseInt(fromEnv, 10);
if (!isNaN(parsed) && parsed >= 0) {
return parsed;
}
}
return 5;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This helps us extract the HTTP retry values from the environment or worker options.

@radovanjorgic radovanjorgic changed the title fix: Throw an error instead of ignoring it when uploading batches fix: throw an error instead of ignoring it when uploading batches Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are these logger changes needed as part of this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They're not. I've removed them.

Comment on lines +295 to +297
for (const repo of this.repos) {
this.artifacts.push(...repo.uploadedArtifacts);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on this?
What is the exact issue? Maybe give an example?

/**
* Persists adapter state before emitting, except for stateless worker phases.
*/
private async postStateBeforeEmit(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is somehting I have done in v2 as well. I just structured it a bit differently: beforeEmit, buildEmityPayload and afterEmit. What if we go in that direction?

return true;
}

console.log(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is something I wanted to do as part of another task but I imagine it is not a big change, can you log the state object here as well and also a state size if it is easy to calculate?

So this log looks sth like this: "Saving state before emitting event with event type . Current state {}". But if you decide to do this please test it properly both locally and on lambda (that logger formats it correctly).

* Posts state (when required), emits to the platform, and notifies the parent
* worker that an event was emitted.
*/
private async emitToPlatform(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

emitToPlatform is a bit bad naming if you ask me. Can you check what was done in v2? I moved the emit function from control-protocol.ts to emit.ts and reused it in adapters, emit in adapters is still called emit, with some before, build and after methods.

Comment thread src/repo/repo.ts
Comment on lines +115 to +117
const batch = this.items.slice(0, batchSize);
await this.upload(batch);
this.items.splice(0, batchSize);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, so in this case if upload fails it will throw an error which must be caught by developer if he wants and if not it will fail the sync, do I understand correctly?

* Applied to the slow Jest project only. Reduces axios-retry attempts so spawn
* integration tests finish in seconds instead of minutes. Not used in production.
*/
process.env.ADAAS_TEST_HTTP_RETRIES = '2';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove this optimization of axios client retries from this PR. I don't think this is the way to do it and we are changing the public interfaces this way as well, let's design this properly.

Comment thread src/types/workers.ts Outdated
workerPathOverrides?: WorkerPathOverrides;
skipConfirmation?: boolean;
/** Test-only: limits axios-retry attempts inside worker threads (see axios-client-internal). */
httpRetries?: number;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As said above please remove related stuff (+ changes in axios client).

Comment thread src/types/workers.ts Outdated
options?: WorkerAdapterOptions;
resolve: (value: void | PromiseLike<void>) => void;
originalConsole?: Console;
logger?: Logger;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why was this added?

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