Skip to content

Refactor task storage/lifecycle: add TaskLifecycleService, list/helpers, and update ExampleExecutor#70

Merged
MisterVVP merged 7 commits into
mainfrom
dev-add-sdk-service-layer-around-taskstore
May 25, 2026
Merged

Refactor task storage/lifecycle: add TaskLifecycleService, list/helpers, and update ExampleExecutor#70
MisterVVP merged 7 commits into
mainfrom
dev-add-sdk-service-layer-around-taskstore

Conversation

@MisterVVP
Copy link
Copy Markdown
Owner

Motivation

  • Centralize task lifecycle operations and listing utilities to remove duplicated in-memory task map logic and to standardize status transitions and history/artifact handling.
  • Provide robust page token parsing and offset validation for List requests and ensure consistent artifact/history projection behavior across APIs.

Description

  • Added TaskLifecycleService with CreateOrUpdateTask, TransitionTaskStatus, and AppendHistory that wrap TaskStore operations and enforce lifecycle rules like terminal-state guarding via TaskLifecycleService::TransitionTaskStatus.
  • Extracted list and projection utilities: ParseListPageToken, ValidateListPageOffset, ApplyHistoryRetention, ApplyArtifactProjection, and TimestampDescTaskOrdering::Sort, and integrated them into InMemoryTaskStore::List to apply page token validation, artifact projection, and history retention when building responses.
  • Replaced local tasks_ map in ExampleExecutor with server::InMemoryTaskStore store_ and server::TaskLifecycleService lifecycle_, and updated handlers (SendMessage, SendStreamingMessage, GetTask, ListTasks, CancelTask) to use store_/lifecycle_ APIs and server::ApplyHistoryRetention for history trimming.
  • Adjusted history append and task upsert flows to use lifecycle_.CreateOrUpdateTask, lifecycle_.AppendHistory, and lifecycle_.TransitionTaskStatus to ensure consistent behavior and error handling.

Testing

  • Ran unit tests including ServerTaskUtilitiesTest.ValidatesPageTokensAndOffsets, ServerTaskUtilitiesTest.LifecycleServiceEnforcesTerminalStateGuard, ServerTaskUtilitiesTest.AppliesHistoryAndArtifactProjectionHelpers, and ServerTaskUtilitiesTest.OrdersTasksByTimestampWithNanosTiebreaker, and all assertions passed.
  • Existing InMemoryTaskStore coverage and history append/listing tests were exercised and succeeded under the updated code paths.

Codex Task

MisterVVP added 6 commits May 25, 2026 09:21
#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)
@MisterVVP
Copy link
Copy Markdown
Owner Author

Need to run clang-tidy with --enable-check-profile and check what's causing the slowness

@MisterVVP MisterVVP merged commit 252b0d8 into main May 25, 2026
14 checks passed
@MisterVVP MisterVVP deleted the dev-add-sdk-service-layer-around-taskstore branch May 25, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant