Skip to content

feat(core): consider choices and undefindable.#526

Merged
samchon merged 4 commits intomainfrom
fix/choices
Jan 30, 2026
Merged

feat(core): consider choices and undefindable.#526
samchon merged 4 commits intomainfrom
fix/choices

Conversation

@samchon
Copy link
Member

@samchon samchon commented Jan 30, 2026

image

This pull request introduces several updates to improve the handling of potentially undefined or missing choices arrays in the core orchestration and utility modules. The changes enhance robustness by ensuring that code does not fail when choices is undefined, and also add a new test for validation error stringification.

Robustness improvements for handling choices:

  • Updated all loops and array operations in call.ts, cancel.ts, and select.ts to use (completion.choices ?? []), preventing errors when choices is undefined. [1] [2] [3] [4] [5]
  • Changed checks and assignments to use optional chaining and default values for choices, ensuring safe access and correct behavior when choices may be absent. [1] [2] [3] [4] [5] [6] [7]

Utility function enhancements:

  • Modified ChatGptCompletionMessageUtil.ts and ChatGptCompletionStreamingUtil.ts to use choices ?? [] and optional chaining in array operations, improving error handling and consistency. [1] [2] [3]

Testing improvements:

  • Added a new test file test_validation_error_stringify.ts to verify the stringification of validation errors using JsonUtil.stringifyValidateFailure.

Copilot AI review requested due to automatic review settings January 30, 2026 03:21
@samchon samchon added the enhancement New feature or request label Jan 30, 2026
@samchon samchon added this to WrtnLabs Jan 30, 2026
Copy link
Member Author

@samchon samchon left a comment

Choose a reason for hiding this comment

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

Special issue by OpenRouter.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 30, 2026

Open in StackBlitz

@agentica/benchmark

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/benchmark@526

@agentica/chat

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/chat@526

agentica

npm i https://pkg.pr.new/wrtnlabs/agentica@526

@agentica/core

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/core@526

create-agentica

npm i https://pkg.pr.new/wrtnlabs/agentica/create-agentica@526

@agentica/rpc

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/rpc@526

@agentica/vector-selector

npm i https://pkg.pr.new/wrtnlabs/agentica/@agentica/vector-selector@526

commit: ae0d0b6

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the robustness of the agentica core library by adding defensive handling for potentially undefined choices arrays in ChatCompletion and ChatCompletionChunk objects. It also adds a test for validation error stringification.

Changes:

  • Added defensive ?? [] checks and optional chaining when accessing choices arrays across orchestration and utility modules
  • Introduced explicit boolean coercion with !! operator for choices?.every() calls in streaming code paths
  • Added a new test file for validation error stringification

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/src/features/test_validation_error_stringify.ts New test file for JsonUtil.stringifyValidateFailure functionality
packages/core/src/utils/ChatGptCompletionStreamingUtil.ts Added defensive ?? [] when accessing choices in flatMap and registerContext calls
packages/core/src/utils/ChatGptCompletionMessageUtil.ts Added defensive ?? [] for origin.choices and optional chaining for result.choices iteration
packages/core/src/orchestrate/select.ts Added defensive checks for choices with ?? [] in loops and optional chaining in array access
packages/core/src/orchestrate/initialize.ts Changed to optional chaining for choices array access
packages/core/src/orchestrate/describe.ts Changed to optional chaining for choices array access
packages/core/src/orchestrate/cancel.ts Added defensive ?? [] when iterating over choices
packages/core/src/orchestrate/call.ts Added defensive checks, explicit boolean type annotations, and optional chaining for choices access

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

samchon and others added 2 commits January 30, 2026 12:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@samchon samchon merged commit cde8484 into main Jan 30, 2026
10 of 11 checks passed
@samchon samchon deleted the fix/choices branch January 30, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants