Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Follows official SDK PR #300. Multiple concurrent sessions calling listModels() trigger rate limiting. Cache results after first successful call.

Implementation

In-memory instance cache (protected ?array $modelsCache)

  • Considered Laravel Cache with atomic locks, but PHP's single-threaded execution model doesn't require it
  • Matches official SDK pattern (Node.js/Python/Go/.NET all use instance-level caching)
  • Avoids service container complexity in package context

Cache lifecycle

  • Populated on first listModels() call
  • Cleared on stop()
  • Returns defensive copies via ModelInfo::fromArray($model->toArray()) to prevent external mutation

Changes

  • Client.php: Add $modelsCache property, modify listModels() to check/populate cache, clear in stop()
  • ClientTest.php: E2E test validates cache behavior and reconnection clears cache
  • TestCase.php: Register CacheServiceProvider for test infrastructure
  • docs/jp/models.md: Document caching behavior
// First call fetches from backend
$models1 = $client->listModels();

// Subsequent calls return from cache (different instance, same content)
$models2 = $client->listModels(); // No API call

// Cache cleared on disconnect
$client->stop();
$client->start();
$models3 = $client->listModels(); // Fresh API call
Original prompt

github/copilot-sdk#300 公式SDKのアップデートに追従。listModelsのキャッシュだけどLaravelのキャッシュ機能には標準でアトミックロックがあるのでそれを使った方がいいかも。

Custom agent used: laravel-sdk-sync
Use this agent when the user wants to update the Laravel Copilot SDK to follow official GitHub Copilot CLI SDK changes.

Trigger phrases include:

  • 'update the SDK to match the official version'
  • 'sync the Laravel SDK with the latest official release'
  • 'what changed in the official SDK and how do we update?'
  • 'implement the breaking changes from the official SDK'
    ... see config here

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 31, 2026 01:27
Co-authored-by: kawax <1502086+kawax@users.noreply.github.com>
Co-authored-by: kawax <1502086+kawax@users.noreply.github.com>
Copilot AI changed the title [WIP] Update official SDK and optimize listModels caching Cache listModels to prevent rate limiting under concurrency Jan 31, 2026
Copilot AI requested a review from kawax January 31, 2026 01:29
@kawax kawax marked this pull request as ready for review January 31, 2026 01:32
@kawax kawax merged commit e1169fb into main Jan 31, 2026
5 checks passed
@kawax kawax deleted the copilot/update-official-sdk branch January 31, 2026 01:32
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