[v2] Minor task-related refactors (#1758)

Co-authored-by: Luca Chang <lucalc@amazon.com>
Co-authored-by: Luca Chang <131398524+LucaButBoring@users.noreply.github.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
This commit is contained in:
Konstantin Konstantinov 2026-03-27 22:25:06 +02:00 • committed by GitHub
commit e86b1835cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 108 additions and 18 deletions

View file

@ -26,7 +26,7 @@ import type {
* @experimental
*/
export type CreateTaskServerContext = ServerContext & {
task: { store: RequestTaskStore; requestedTtl?: number | null };
task: { store: RequestTaskStore; requestedTtl?: number };
};
/**
@ -34,7 +34,7 @@ export type CreateTaskServerContext = ServerContext & {
* @experimental
*/
export type TaskServerContext = ServerContext & {
task: { id: string; store: RequestTaskStore; requestedTtl?: number | null };
task: { id: string; store: RequestTaskStore; requestedTtl?: number };
};
/**
@ -137,7 +137,7 @@ export interface TaskMessageQueue {
*/
export interface CreateTaskOptions {
/**
* Time in milliseconds to keep task results available after completion.
* Duration in milliseconds to retain task from creation.
* If `null`, the task has unlimited lifetime until manually cleaned up.
*/
ttl?: number | null;

View file

@ -151,7 +151,7 @@ export interface RequestTaskStore {
export type TaskContext = {
id?: string;
store: RequestTaskStore;
requestedTtl?: number | null;
requestedTtl?: number;
};
export type TaskManagerOptions = {

View file

@ -32,10 +32,9 @@ export const CursorSchema = z.string();
*/
export const TaskCreationParamsSchema = z.looseObject({
/**
* Time in milliseconds to keep task results available after completion.
* If `null`, the task has unlimited lifetime until manually cleaned up.
* Requested duration in milliseconds to retain task from creation.
*/
ttl: z.union([z.number(), z.null()]).optional(),
ttl: z.number().optional(),
/**
* Time in milliseconds to wait between task status requests.

View file

@ -488,17 +488,16 @@ describe('InMemoryTaskStore', () => {
expect(task).toBeNull();
});
it('should support null TTL for unlimited lifetime', async () => {
// Test that null TTL means unlimited lifetime
const taskParams: TaskCreationParams = {
ttl: null
};
it('should support omitted TTL for unlimited lifetime', async () => {
// Test that omitting TTL means unlimited lifetime (server returns null)
// Per spec: clients omit ttl to let server decide, server returns null for unlimited
const taskParams: TaskCreationParams = {};
const createdTask = await store.createTask(taskParams, 2222, {
method: 'tools/call',
params: {}
});
// The returned task should have null TTL
// The returned task should have null TTL (unlimited)
expect(createdTask.ttl).toBeNull();
// Task should not be cleaned up even after a long time