Skip to content

Refactor Loop class to use a LoopTools singleton for tool management for Octane compatibility #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

fsmonter
Copy link
Contributor

@fsmonter fsmonter commented Jun 11, 2025

Fixes #26

There is an Octane compatibility issue where registered tools don't persist between request cycles due to scoped instance recreation of the Loop class.

The proposed fix is storing the tools in a singleton LoopTools. Another option is making the Loop class a singleton but keep in mind the instance would be shared between users in Octane.

Current Behavior

// In LoopServiceProvider
$this->app->scoped(Loop::class, function ($app) {
    $loop = new Loop;
    $loop->setup();
    return $loop;
});
// In user's AppServiceProvider::boot()
Loop::toolkit(Kirschbaum\Loop\Filament\FilamentToolkit::make());

The Issue

  1. Octane flushes scoped instances on every request lifecycle
  2. Toolkits are registered in boot() which only run once when worker starts
  3. Subsequent requests get fresh Loop instances without any registered toolkits
  4. Users must implement a workaround in their applications

Current Application Workaround

// Users must add this to their AppServiceProvider::register()
$this->app->resolving('loop', function ($loop, $app) {
    $loop->toolkit(new MyToolkit());
});

@fsmonter fsmonter force-pushed the fix/octane-registrations branch from 4eaf290 to 0adcaa1 Compare June 12, 2025 17:15
@fsmonter fsmonter force-pushed the fix/octane-registrations branch from 0adcaa1 to 0be3ff2 Compare June 12, 2025 17:18
@fsmonter fsmonter marked this pull request as ready for review June 12, 2025 17:26
@fsmonter fsmonter requested a review from luisdalmolin June 12, 2025 17:26
@fsmonter fsmonter changed the title Implement tool registration persistence in application container for Octane compatibility Refactor Loop class to use a LoopTools singleton for tool management for Octane compatibility Jun 12, 2025
@luisdalmolin luisdalmolin merged commit fc41f18 into main Jun 17, 2025
11 checks passed
@luisdalmolin luisdalmolin deleted the fix/octane-registrations branch June 17, 2025 20:21
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.

Unable to get SSE transport working with Claude Code
2 participants