Skip to content

Conversation

Elbehery
Copy link
Contributor

@Elbehery Elbehery commented Jul 31, 2025

What does this PR do?

This PR removes init() from LlamaStackAsLibrary

Currently client.initialize() had to be invoked by user.
To improve dev experience and to avoid runtime errors, this PR init LlamaStackAsLibrary implicitly upon using the client.
It prevents also multiple init of the same client, while maintaining backward ccompatibility.

This PR does the following

  • Automatic Initialization: Constructor calls initialize_impl() automatically.
  • Client is fully initialized after init completes.
  • Prevents consecutive initialization after the client has been successfully initialized.
  • initialize() method still exists but is now a no-op.

fixes #2946

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 31, 2025
@Elbehery
Copy link
Contributor Author

cc @mattf @nathan-weinberg

@nathan-weinberg
Copy link
Contributor

Code overall is looking good to me, not sure why those unit tests are failing?

@Elbehery
Copy link
Contributor Author

Code overall is looking good to me, not sure why those unit tests are failing?

i tried to fix them but seems unrelated to my changes 🤔

@ashwinb
Copy link
Contributor

ashwinb commented Jul 31, 2025

I forgot why I had added a separate initialize() method. There was a very important reason but I guess I forgot to document. This needs to be really tested in a notebook environment also btw, while I try to remember ...

Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

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

please remove all extraneous changes

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from 3eec93f to ea66d34 Compare August 1, 2025 10:05
@mattf
Copy link
Collaborator

mattf commented Aug 11, 2025

I forgot why I had added a separate initialize() method. There was a very important reason but I guess I forgot to document. This needs to be really tested in a notebook environment also btw, while I try to remember ...

@ashwinb probably __init__ can't be async

@ashwinb
Copy link
Contributor

ashwinb commented Aug 13, 2025

I forgot why I had added a separate initialize() method. There was a very important reason but I guess I forgot to document. This needs to be really tested in a notebook environment also btw, while I try to remember ...

@ashwinb probably init can't be async

Yeah. But I didn't know about loop.run_until_complete at that time also :)

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from ea66d34 to 74817a7 Compare August 13, 2025 16:52
@Elbehery Elbehery requested a review from slekkala1 as a code owner August 13, 2025 16:52
@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch 6 times, most recently from 3334941 to 692843f Compare August 14, 2025 12:52
@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from 269c854 to af21f69 Compare August 17, 2025 15:25
Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

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

why did you remove skip_logger_removal from the sync client and add it to the async client?

@Elbehery
Copy link
Contributor Author

why did you remove skip_logger_removal from the sync client and add it to the async client?

thanks for your review 🙏🏽

so i received this review #2979 (comment), which actually makes sense imo :)

please let me know if you have other thoughts

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch 4 times, most recently from 0ec41e9 to 78f7be7 Compare August 18, 2025 22:32
@Elbehery
Copy link
Contributor Author

Hi @ashwinb

Any more required changes here ?

If not, I would appreciate it very much if we merge this PR.

I have already 4 open PRs, and I can not pick up more work till I merge them :)

thanks in advance :)

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from 78f7be7 to a39ca14 Compare August 19, 2025 02:42
@Elbehery
Copy link
Contributor Author

rebased 👍🏽

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch 4 times, most recently from 07c04cf to a1c4f17 Compare August 20, 2025 12:43
Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

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

downgrading my review to a comment. looks like @ashwinb has this handled.

@mattf mattf self-requested a review August 20, 2025 15:39
@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch 2 times, most recently from 681182d to a8436ee Compare August 20, 2025 21:16
@Elbehery
Copy link
Contributor Author

rebased 👍🏽

cc @ashwinb

@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from a8436ee to 3e3a380 Compare August 20, 2025 22:06
@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from 3e3a380 to 5bc261f Compare August 21, 2025 18:29
Currently client.initialize() had to be invoked by user.
To improve dev experience and to avoid runtime errors, this PR init LlamaStackAsLibrary implicitly upon using the client.
It prevents also multiple init of the same client, while maintaining backward ccompatibility.

Signed-off-by: Mustafa Elbehery <[email protected]>
…r removing initialize method

  The recent refactor (3778a4c) introduced automatic initialization for
  LlamaStackAsLibraryClient but the unit tests were expecting manual initalization and _is_initialized.
  This caused test failure.

  Changes:
  - Update test assertions to check route_impls is not None instead of _is_initialized
  - Add proper mocking in tests to avoid external provider dependencies
  - Maintain test coverage for automatic initialization behavior
  - Ensure backward compatibility testing for deprecated initialize() method

Signed-off-by: Mustafa Elbehery <[email protected]>
@Elbehery Elbehery force-pushed the 20250731_remove_init_LlamaStackAsLibrary branch from 5bc261f to 2ebdfce Compare August 21, 2025 22:51
@ashwinb ashwinb merged commit 1790fc0 into llamastack:main Aug 21, 2025
22 checks passed
@Elbehery Elbehery deleted the 20250731_remove_init_LlamaStackAsLibrary branch August 21, 2025 23:03
franciscojavierarceo pushed a commit to franciscojavierarceo/llama-stack that referenced this pull request Aug 22, 2025
…#2979)

# What does this PR do?
<!-- Provide a short summary of what this PR does and why. Link to
relevant issues if applicable. -->
This PR removes `init()` from `LlamaStackAsLibrary` 

Currently client.initialize() had to be invoked by user.
To improve dev experience and to avoid runtime errors, this PR init
LlamaStackAsLibrary implicitly upon using the client.
It prevents also multiple init of the same client, while maintaining
backward ccompatibility.

This PR does the following 

- Automatic Initialization: Constructor calls initialize_impl()
automatically.
-  Client is fully initialized after __init__ completes.
- Prevents consecutive initialization after the client has been
successfully initialized.
-  initialize() method still exists but is now a no-op.

<!-- If resolving an issue, uncomment and update the line below -->
<!-- Closes #[issue-number] -->
fixes llamastack#2946

---------

Signed-off-by: Mustafa Elbehery <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove initialize() Method from LlamaStackAsLibrary
5 participants