Refactor task storage/lifecycle: add TaskLifecycleService, list/helpers, and update ExampleExecutor#70
Merged
Conversation
#71) ### Motivation - Provide a consistent server-side task id strategy for incoming messages that lack `message.taskId` and make generation pluggable. - Replace ad-hoc id construction in examples with a reusable lifecycle path to centralize validation and id resolution. ### Description - Introduce `TaskLifecycleService::TaskIdGenerator` interface and two implementations: `UuidV7TaskIdGenerator` (default) and `SequentialTaskIdGenerator` for deterministic testing, and wire a constructor accepting a generator (`TaskLifecycleService(TaskStore*, std::shared_ptr<TaskIdGenerator>)`). - Add `TaskLifecycleService::ResolveTaskIdForSendRequest` to validate message/task semantics and to delegate generation when `message.taskId` is absent. - Implement a UUIDv7-style generator that returns ids prefixed with `task-` and a test-only sequential generator that produces `task-test-N` ids. - Update `ExampleExecutor` to use `lifecycle_.ResolveTaskIdForSendRequest(...)` for `SendMessage` and `SendStreamingMessage` flows and inject the `SequentialTaskIdGenerator` in the example to keep deterministic behavior. - Add documentation section `Task ID generation` to `book/src/server/overview.md` describing default behavior and how to supply custom generators. - Add unit tests and CMake registration for `task_id_generator_test` covering UUIDv7 format/uniqueness, sequential generator determinism, generator error propagation, preserving explicit task ids, and validation of context/terminal state handling. ### Testing - Added and ran `task_id_generator_test` which verifies `UuidV7TaskIdGenerator`, `SequentialTaskIdGenerator`, and `ResolveTaskIdForSendRequest` behaviors, and it passed. - Ran existing `examples_support_test` which was updated to reflect the new deterministic example ids, and it passed. - All discovered unit tests (including the new tests registered in `tests/CMakeLists.txt`) were executed and succeeded. ------ [Codex Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a142702e4648333b2981039b6015b39)
Owner
Author
|
Need to run clang-tidy with --enable-check-profile and check what's causing the slowness |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Listrequests and ensure consistent artifact/history projection behavior across APIs.Description
TaskLifecycleServicewithCreateOrUpdateTask,TransitionTaskStatus, andAppendHistorythat wrapTaskStoreoperations and enforce lifecycle rules like terminal-state guarding viaTaskLifecycleService::TransitionTaskStatus.ParseListPageToken,ValidateListPageOffset,ApplyHistoryRetention,ApplyArtifactProjection, andTimestampDescTaskOrdering::Sort, and integrated them intoInMemoryTaskStore::Listto apply page token validation, artifact projection, and history retention when building responses.tasks_map inExampleExecutorwithserver::InMemoryTaskStore store_andserver::TaskLifecycleService lifecycle_, and updated handlers (SendMessage,SendStreamingMessage,GetTask,ListTasks,CancelTask) to usestore_/lifecycle_APIs andserver::ApplyHistoryRetentionfor history trimming.lifecycle_.CreateOrUpdateTask,lifecycle_.AppendHistory, andlifecycle_.TransitionTaskStatusto ensure consistent behavior and error handling.Testing
ServerTaskUtilitiesTest.ValidatesPageTokensAndOffsets,ServerTaskUtilitiesTest.LifecycleServiceEnforcesTerminalStateGuard,ServerTaskUtilitiesTest.AppliesHistoryAndArtifactProjectionHelpers, andServerTaskUtilitiesTest.OrdersTasksByTimestampWithNanosTiebreaker, and all assertions passed.InMemoryTaskStorecoverage and history append/listing tests were exercised and succeeded under the updated code paths.Codex Task