From 70dd264a621853e8e86e568e61d613839ff9b0b6 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 25 Mar 2026 23:55:28 +0400 Subject: [PATCH 1/2] refactor(Request): update ID generation logic and visibility --- src/Worker/Transport/Command/Client/Request.php | 11 +++-------- tests/Fixtures/CommandResetter.php | 13 ++++++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Worker/Transport/Command/Client/Request.php b/src/Worker/Transport/Command/Client/Request.php index d39819961..942034d96 100644 --- a/src/Worker/Transport/Command/Client/Request.php +++ b/src/Worker/Transport/Command/Client/Request.php @@ -63,14 +63,9 @@ public function getFailure(): ?\Throwable return $this->failure; } - private function getNextID(): int + protected function getNextID(): int { - $next = ++static::$lastID; - - if ($next >= \PHP_INT_MAX) { - $next = static::$lastID = 1; - } - - return $next; + static::$lastID = (static::$lastID + 1) % 1_000_000; + return \time() * 1_000_000 + static::$lastID; } } diff --git a/tests/Fixtures/CommandResetter.php b/tests/Fixtures/CommandResetter.php index afb13f529..2778acddc 100644 --- a/tests/Fixtures/CommandResetter.php +++ b/tests/Fixtures/CommandResetter.php @@ -15,8 +15,19 @@ class CommandResetter extends Request { - public static function reset() + public static function reset(): void { self::$lastID = 9000; } + + protected function getNextID(): int + { + $next = ++static::$lastID; + + if ($next >= \PHP_INT_MAX) { + $next = static::$lastID = 1; + } + + return $next; + } } From 85829801e3eefc5dfd36c1af1a0346eb6f62147b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 26 Mar 2026 00:13:25 +0400 Subject: [PATCH 2/2] refactor(Request): Just use microtime for start id --- src/Worker/Transport/Command/Client/Request.php | 15 +++++++++++---- tests/Fixtures/CommandResetter.php | 11 ----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Worker/Transport/Command/Client/Request.php b/src/Worker/Transport/Command/Client/Request.php index 942034d96..8da82a2f1 100644 --- a/src/Worker/Transport/Command/Client/Request.php +++ b/src/Worker/Transport/Command/Client/Request.php @@ -18,6 +18,8 @@ use Temporal\Worker\Transport\Command\Common\RequestTrait; use Temporal\Worker\Transport\Command\RequestInterface; +\define(['REQUEST_START_ID'][0], (int) (\microtime(true) * 1_000_000.0)); + /** * Carries request to perform host action with payloads and failure as context. Can be cancelled if allows * @@ -27,7 +29,7 @@ class Request implements RequestInterface { use RequestTrait; - protected static int $lastID = 9000; + protected static int $lastID = REQUEST_START_ID; protected int $id; protected ValuesInterface $payloads; protected HeaderInterface $header; @@ -63,9 +65,14 @@ public function getFailure(): ?\Throwable return $this->failure; } - protected function getNextID(): int + private function getNextID(): int { - static::$lastID = (static::$lastID + 1) % 1_000_000; - return \time() * 1_000_000 + static::$lastID; + ++static::$lastID; + + if (static::$lastID === \PHP_INT_MAX) { + static::$lastID = 1; + } + + return static::$lastID; } } diff --git a/tests/Fixtures/CommandResetter.php b/tests/Fixtures/CommandResetter.php index 2778acddc..244ae0ff2 100644 --- a/tests/Fixtures/CommandResetter.php +++ b/tests/Fixtures/CommandResetter.php @@ -19,15 +19,4 @@ public static function reset(): void { self::$lastID = 9000; } - - protected function getNextID(): int - { - $next = ++static::$lastID; - - if ($next >= \PHP_INT_MAX) { - $next = static::$lastID = 1; - } - - return $next; - } }