Skip to content

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

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

fix: throw an error instead of ignoring it when uploading batches#207
gasperzgonec wants to merge 9 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 thread src/multithreading/worker-adapter/worker-adapter.ts
Comment thread src/http/axios-client-internal.ts Outdated
@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
Comment thread src/multithreading/spawn/spawn.ts
Comment thread src/multithreading/worker-adapter/worker-adapter.ts
Comment thread src/multithreading/worker-adapter/worker-adapter.ts Outdated
Comment thread src/multithreading/worker-adapter/worker-adapter.ts
Comment thread src/multithreading/worker-adapter/worker-adapter.ts Outdated
Comment thread src/repo/repo.ts
Comment thread src/tests/upload-failure/slow-env.setup.ts Outdated
Comment thread src/types/workers.ts Outdated
Comment thread src/types/workers.ts Outdated
@github-actions

Copy link
Copy Markdown

⚠️ Heads-up: This repository will be blocked from any work other than patching.

File jest.config.cjs is not allowed to be modified in this patch.
The following vulnerability issues are past SLA:

Note that there is significant latency in updating this list. Please reach out on #antifragile if you are in a hurry or have an emergency.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ Heads-up: This repository will be blocked from any work other than patching.

File jest.config.cjs is not allowed to be modified in this patch.
The following vulnerability issues are past SLA:

Note that there is significant latency in updating this list. Please reach out on #antifragile if you are in a hurry or have an emergency.

Comment thread src/multithreading/spawn/spawn.ts Outdated
const isSdkLog = message.payload?.isSdkLog ?? true;
this.logger.logFn(stringifiedArgs, level, isSdkLog);
if (typeof this.logger?.logFn === 'function') {
this.logger.logFn(stringifiedArgs, level, isSdkLog);

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.

Hmm, why was this needed? Isn't logFn always a function?

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.

I got some errors and added this to get rid of those. It's probably related to the fixture tests. Removing this.

console.log(
`Uploading all repos before emitting event with event type: ${newEventType}.`
);
const canEmit = await this.beforeEmit(newEventType);

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.

canEmit calls the beforeEmit function (confusing)? And if it returns false what happens?

@gasperzgonec gasperzgonec Jul 10, 2026

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.

Renamed to a local prepared boolean and documented the return contract on beforeEmit's docstring. beforeEmit no longer emits anything itself; see the answer below, it's simpler now.

parentPort?.postMessage(WorkerMessageSubject.WorkerMessageExit);
this.hasWorkerEmitted = true;
const payload = this.buildEmitPayload(newEventType, data);
const sent = await this.sendToPlatform(newEventType, payload);

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.

Naming is a bit strange here IMO, can we find better name for sendToPlatform? And again, if it fails we just return, is that correct?

Maybe we could move the actual emit function here, so we have beforeEmit, actual emit logic and afterEmit in this exposed method.

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.

Removed sendToPlatform/emitToPlatform entirely. The actual emit() call (from control-protocol.ts) is now inlined directly in the public emit() method, right after beforeEmit/buildEmitPayload, with its own try/catch for the WorkerMessageEmitted/WorkerMessageExit outcome — matching what you did in v2 (beforeEmit → build payload → actual emit → afterEmit, all in one method).

} catch (error) {
console.error('Error while uploading repos', error);
for (const repo of this.repos) {
this.artifacts = [...this.artifacts, ...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.

What is the point of this on error? We extend the artifacts array with repo.uploadedArtifacts? Can you explain?

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.

When uploadAllRepos() throws partway through (e.g. repo 3 of 5 fails), repos 1-2 already had their artifacts merged into this.artifacts by the loop inside uploadAllRepos, but the loop aborts on the failing repo. This second loop re-scans every repo's uploadedArtifacts and merges them via the artifacts setter (which dedupes by object identity, so already-added ones aren't duplicated), guaranteeing every successfully-uploaded artifact is reported in the error emit instead of becoming an orphan in storage.

const { eventType: errorEventType } = getTimeoutErrorEventType(
this.event.payload.event_type
);
await this.emitUploadFailure(errorEventType, error);

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.

Just curious if we need separate function for this.

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.

Removed, now it's inlined, as it was only used in one place.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

⚠️ Heads-up: This repository will be blocked from any work other than patching.

File jest.config.cjs is not allowed to be modified in this patch.
The following vulnerability issues are past SLA:

Note that there is significant latency in updating this list. Please reach out on #antifragile if you are in a hurry or have an emergency.

- Revert defensive logFn guard in spawn.ts (unrelated to this fix, logFn
  is always a function on the real Logger).
- Rename canEmit to prepared and document beforeEmit's return contract.
- Collapse sendToPlatform/afterEmit into a single emitToPlatform method,
  matching the beforeEmit/buildEmitPayload/afterEmit shape used in v2.
- Inline emitUploadFailure into beforeEmit's catch block since it had a
  single call site.
- Run eslint --fix to clean up pre-existing formatting violations.
@github-actions

Copy link
Copy Markdown

⚠️ Heads-up: This repository will be blocked from any work other than patching.

File jest.config.cjs is not allowed to be modified in this patch.
The following vulnerability issues are past SLA:

Note that there is significant latency in updating this list. Please reach out on #antifragile if you are in a hurry or have an emergency.

Matches v2's adapter shape (beforeEmit/buildEmitPayload/afterEmit, no
separate sendToPlatform/emitToPlatform helper) per review feedback.
beforeEmit no longer swallows the repo-upload failure itself; emit()
catches it, collects partial artifacts, and picks the error event type
before sending, so there's a single call site for the actual platform
emit and its WorkerMessageEmitted/WorkerMessageExit outcome handling.
@github-actions

Copy link
Copy Markdown

⚠️ Heads-up: This repository will be blocked from any work other than patching.

File jest.config.cjs is not allowed to be modified in this patch.
The following vulnerability issues are past SLA:

Note that there is significant latency in updating this list. Please reach out on #antifragile if you are in a hurry or have an emergency.

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