Skip to content

fix(tasks): fail tasks with a lapsed lease in tasks/list - #345

Open
mcollina wants to merge 1 commit into
mainfrom
fix/330-tasks-list-lapsed-lease
Open

mcollina wants to merge 1 commit into
mainfrom
fix/330-tasks-list-lapsed-lease

Conversation

@mcollina

Copy link
Copy Markdown
Member

Summary

tasks/list reported a task whose owning instance had died as working. Only tasks/get and tasks/result ran the owner-lost check, so the list disagreed with them until one of those was called.

Fix

handleTasksList now runs failIfOwnerLost on each task in the page, at most 8 at a time. Terminal tasks and tasks with no lease return straight away with no store round trip, so only non-terminal leased tasks cost a failExpiredLease call. A task deleted during the check is dropped from the page.

Why the handler and not store.list

  • failIfOwnerLost also calls taskWaiters.notify(), which wakes tasks/result callers on this instance. The store has no access to the waiters.
  • tasks/get and tasks/result already reap in the handler through the store's failExpiredLease compare-and-set, using the store clock (the Redis server clock for Redis). Doing the same here keeps one code path for every backend, including custom TaskStore implementations, and leaves the TaskStore contract unchanged.
  • The diff stays out of the store files, which open PR fix(tasks): don't share one retention allowance across anonymous callers (#320) #326 also touches.

Tests

  • Memory (test/tasks.test.ts) and Redis (test/redis-task-integration.test.ts): with auth on and taskLeaseMs short, start a task that never finishes, mock renewLease so it stops renewing (a simulated crash), wait for the lease to lapse, then call tasks/list. The task comes back failed with the owner-lost message and no leaseExpiresAt. Both tests failed before the fix.
  • npm run lint, npm run typecheck and the full npm run test all pass (768/768).

Fixes #330

🤖 Generated with Claude Code

https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9

tasks/list returned tasks whose owning instance had died as `working`;
only tasks/get and tasks/result ran the owner-lost check. Run the same
failIfOwnerLost check on every entry of the page, with bounded
concurrency, so a lapsed lease is reported (and recorded) as `failed`
consistently across all three methods.

Fixes #330

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9

This branch has not been deployed

No deployments
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.

tasks/list reports tasks with a lapsed lease as working

1 participant