PBI-50 F2-T1: claim-filter kind-based + lease_until persisten
Schema-sync vanaf Scrum4Me (PBI-50 F1): - PrStrategy.SPRINT_BATCH, ClaudeJobKind.SPRINT_IMPLEMENTATION - enum SprintTaskExecutionStatus, model SprintTaskExecution - ClaudeJob.lease_until + status_lease_until index - SprintRun.previous_run_id (self-relation) tryClaimJob in src/tools/wait-for-job.ts: - WHERE-clause refactor naar kind-based discriminatie. NULL-checks vervangen door expliciete `cj.kind IN (...)`. SPRINT_IMPLEMENTATION en TASK_IMPLEMENTATION vereisen beide actieve SprintRun (QUEUED/RUNNING). Idea-kinds blijven standalone claimable. - UPDATE op claim zet `lease_until = NOW() + INTERVAL '5 minutes'`. Tests: 19 wait-for-job tests groen. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7dbc9fe249
commit
de6bbd4edd
2 changed files with 118 additions and 62 deletions
|
|
@ -87,6 +87,7 @@ enum SprintRunStatus {
|
||||||
enum PrStrategy {
|
enum PrStrategy {
|
||||||
SPRINT
|
SPRINT
|
||||||
STORY
|
STORY
|
||||||
|
SPRINT_BATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
enum IdeaStatus {
|
enum IdeaStatus {
|
||||||
|
|
@ -105,6 +106,15 @@ enum ClaudeJobKind {
|
||||||
IDEA_GRILL
|
IDEA_GRILL
|
||||||
IDEA_MAKE_PLAN
|
IDEA_MAKE_PLAN
|
||||||
PLAN_CHAT
|
PLAN_CHAT
|
||||||
|
SPRINT_IMPLEMENTATION
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SprintTaskExecutionStatus {
|
||||||
|
PENDING
|
||||||
|
RUNNING
|
||||||
|
DONE
|
||||||
|
FAILED
|
||||||
|
SKIPPED
|
||||||
}
|
}
|
||||||
|
|
||||||
enum IdeaLogType {
|
enum IdeaLogType {
|
||||||
|
|
@ -299,24 +309,27 @@ model Sprint {
|
||||||
}
|
}
|
||||||
|
|
||||||
model SprintRun {
|
model SprintRun {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
sprint Sprint @relation(fields: [sprint_id], references: [id], onDelete: Cascade)
|
sprint Sprint @relation(fields: [sprint_id], references: [id], onDelete: Cascade)
|
||||||
sprint_id String
|
sprint_id String
|
||||||
started_by User @relation("SprintRunStartedBy", fields: [started_by_id], references: [id])
|
started_by User @relation("SprintRunStartedBy", fields: [started_by_id], references: [id])
|
||||||
started_by_id String
|
started_by_id String
|
||||||
status SprintRunStatus @default(QUEUED)
|
status SprintRunStatus @default(QUEUED)
|
||||||
pr_strategy PrStrategy
|
pr_strategy PrStrategy
|
||||||
branch String?
|
branch String?
|
||||||
pr_url String?
|
pr_url String?
|
||||||
started_at DateTime?
|
started_at DateTime?
|
||||||
finished_at DateTime?
|
finished_at DateTime?
|
||||||
failure_reason String?
|
failure_reason String?
|
||||||
failed_task Task? @relation("SprintRunFailedTask", fields: [failed_task_id], references: [id], onDelete: SetNull)
|
failed_task Task? @relation("SprintRunFailedTask", fields: [failed_task_id], references: [id], onDelete: SetNull)
|
||||||
failed_task_id String?
|
failed_task_id String?
|
||||||
pause_context Json?
|
pause_context Json?
|
||||||
created_at DateTime @default(now())
|
previous_run_id String? @unique
|
||||||
updated_at DateTime @updatedAt
|
previous_run SprintRun? @relation("SprintRunChain", fields: [previous_run_id], references: [id], onDelete: SetNull)
|
||||||
jobs ClaudeJob[]
|
next_run SprintRun? @relation("SprintRunChain")
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
jobs ClaudeJob[]
|
||||||
|
|
||||||
@@index([sprint_id, status])
|
@@index([sprint_id, status])
|
||||||
@@index([started_by_id, status])
|
@@index([started_by_id, status])
|
||||||
|
|
@ -324,32 +337,33 @@ model SprintRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
model Task {
|
model Task {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
story Story @relation(fields: [story_id], references: [id], onDelete: Cascade)
|
story Story @relation(fields: [story_id], references: [id], onDelete: Cascade)
|
||||||
story_id String
|
story_id String
|
||||||
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
|
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
|
||||||
product_id String
|
product_id String
|
||||||
sprint Sprint? @relation(fields: [sprint_id], references: [id])
|
sprint Sprint? @relation(fields: [sprint_id], references: [id])
|
||||||
sprint_id String?
|
sprint_id String?
|
||||||
code String @db.VarChar(30)
|
code String @db.VarChar(30)
|
||||||
title String
|
title String
|
||||||
description String?
|
description String?
|
||||||
implementation_plan String?
|
implementation_plan String?
|
||||||
priority Int
|
priority Int
|
||||||
sort_order Float
|
sort_order Float
|
||||||
status TaskStatus @default(TO_DO)
|
status TaskStatus @default(TO_DO)
|
||||||
verify_only Boolean @default(false)
|
verify_only Boolean @default(false)
|
||||||
verify_required VerifyRequired @default(ALIGNED_OR_PARTIAL)
|
verify_required VerifyRequired @default(ALIGNED_OR_PARTIAL)
|
||||||
// Override product.repo_url for branch/worktree/push purposes. Set when
|
// Override product.repo_url for branch/worktree/push purposes. Set when
|
||||||
// a task targets a different repo than its parent product (e.g. an
|
// a task targets a different repo than its parent product (e.g. an
|
||||||
// MCP-server task tracked under the main product's PBI). Falls back to
|
// MCP-server task tracked under the main product's PBI). Falls back to
|
||||||
// product.repo_url when null.
|
// product.repo_url when null.
|
||||||
repo_url String?
|
repo_url String?
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt
|
updated_at DateTime @updatedAt
|
||||||
claude_questions ClaudeQuestion[]
|
claude_questions ClaudeQuestion[]
|
||||||
claude_jobs ClaudeJob[]
|
claude_jobs ClaudeJob[]
|
||||||
sprint_run_failures SprintRun[] @relation("SprintRunFailedTask")
|
sprint_run_failures SprintRun[] @relation("SprintRunFailedTask")
|
||||||
|
sprint_task_executions SprintTaskExecution[]
|
||||||
|
|
||||||
@@unique([product_id, code])
|
@@unique([product_id, code])
|
||||||
@@index([story_id, priority, sort_order])
|
@@index([story_id, priority, sort_order])
|
||||||
|
|
@ -359,20 +373,20 @@ model Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
model ClaudeJob {
|
model ClaudeJob {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||||
user_id String
|
user_id String
|
||||||
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
|
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
|
||||||
product_id String
|
product_id String
|
||||||
task Task? @relation(fields: [task_id], references: [id], onDelete: Cascade)
|
task Task? @relation(fields: [task_id], references: [id], onDelete: Cascade)
|
||||||
task_id String?
|
task_id String?
|
||||||
idea Idea? @relation(fields: [idea_id], references: [id], onDelete: Cascade)
|
idea Idea? @relation(fields: [idea_id], references: [id], onDelete: Cascade)
|
||||||
idea_id String?
|
idea_id String?
|
||||||
sprint_run SprintRun? @relation(fields: [sprint_run_id], references: [id], onDelete: SetNull)
|
sprint_run SprintRun? @relation(fields: [sprint_run_id], references: [id], onDelete: SetNull)
|
||||||
sprint_run_id String?
|
sprint_run_id String?
|
||||||
kind ClaudeJobKind @default(TASK_IMPLEMENTATION)
|
kind ClaudeJobKind @default(TASK_IMPLEMENTATION)
|
||||||
status ClaudeJobStatus @default(QUEUED)
|
status ClaudeJobStatus @default(QUEUED)
|
||||||
claimed_by_token ApiToken? @relation(fields: [claimed_by_token_id], references: [id], onDelete: SetNull)
|
claimed_by_token ApiToken? @relation(fields: [claimed_by_token_id], references: [id], onDelete: SetNull)
|
||||||
claimed_by_token_id String?
|
claimed_by_token_id String?
|
||||||
claimed_at DateTime?
|
claimed_at DateTime?
|
||||||
started_at DateTime?
|
started_at DateTime?
|
||||||
|
|
@ -391,9 +405,11 @@ model ClaudeJob {
|
||||||
pr_url String?
|
pr_url String?
|
||||||
summary String?
|
summary String?
|
||||||
error String?
|
error String?
|
||||||
retry_count Int @default(0)
|
retry_count Int @default(0)
|
||||||
created_at DateTime @default(now())
|
lease_until DateTime?
|
||||||
updated_at DateTime @updatedAt
|
task_executions SprintTaskExecution[] @relation("SprintJobExecutions")
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
|
||||||
@@index([user_id, status])
|
@@index([user_id, status])
|
||||||
@@index([task_id, status])
|
@@index([task_id, status])
|
||||||
|
|
@ -401,9 +417,41 @@ model ClaudeJob {
|
||||||
@@index([sprint_run_id, status])
|
@@index([sprint_run_id, status])
|
||||||
@@index([status, claimed_at])
|
@@index([status, claimed_at])
|
||||||
@@index([status, finished_at])
|
@@index([status, finished_at])
|
||||||
|
@@index([status, lease_until])
|
||||||
@@map("claude_jobs")
|
@@map("claude_jobs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PBI-50: frozen scope-snapshot per SPRINT_IMPLEMENTATION-claim. Bij claim
|
||||||
|
// wordt voor elke TO_DO-task in scope één PENDING-record gemaakt met
|
||||||
|
// implementation_plan + verify_required gesnapshot. Worker en gate werken
|
||||||
|
// uitsluitend op deze rows; latere wijzigingen aan Task hebben geen
|
||||||
|
// invloed op de lopende batch.
|
||||||
|
model SprintTaskExecution {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
sprint_job ClaudeJob @relation("SprintJobExecutions", fields: [sprint_job_id], references: [id], onDelete: Cascade)
|
||||||
|
sprint_job_id String
|
||||||
|
task Task @relation(fields: [task_id], references: [id], onDelete: Cascade)
|
||||||
|
task_id String
|
||||||
|
order Int
|
||||||
|
plan_snapshot String @db.Text
|
||||||
|
verify_required_snapshot VerifyRequired
|
||||||
|
verify_only_snapshot Boolean @default(false)
|
||||||
|
base_sha String?
|
||||||
|
head_sha String?
|
||||||
|
status SprintTaskExecutionStatus @default(PENDING)
|
||||||
|
verify_result VerifyResult?
|
||||||
|
verify_summary String? @db.Text
|
||||||
|
skip_reason String? @db.Text
|
||||||
|
started_at DateTime?
|
||||||
|
finished_at DateTime?
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
|
||||||
|
@@unique([sprint_job_id, task_id])
|
||||||
|
@@index([sprint_job_id, order])
|
||||||
|
@@map("sprint_task_executions")
|
||||||
|
}
|
||||||
|
|
||||||
model ModelPrice {
|
model ModelPrice {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
model_id String @unique
|
model_id String @unique
|
||||||
|
|
|
||||||
|
|
@ -308,12 +308,15 @@ export async function tryClaimJob(
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
// Atomic claim in a single transaction — also captures plan_snapshot from task.
|
// Atomic claim in a single transaction — also captures plan_snapshot from task.
|
||||||
//
|
//
|
||||||
// Sprint-flow filter (PBI-46):
|
// PBI-50: claim-filter discrimineert via cj.kind:
|
||||||
// Idea-jobs (task_id IS NULL) blijven onafhankelijk claimable.
|
// - IDEA_GRILL/IDEA_MAKE_PLAN/PLAN_CHAT: standalone idea-jobs.
|
||||||
// Task-jobs zijn alleen claimable wanneer ze aan een actieve SprintRun
|
// - TASK_IMPLEMENTATION/SPRINT_IMPLEMENTATION: alleen via actieve SprintRun
|
||||||
// hangen (status QUEUED of RUNNING). Legacy task-jobs zonder sprint_run_id
|
// (status QUEUED of RUNNING). Legacy task-jobs zonder sprint_run_id en
|
||||||
// en jobs in PAUSED/FAILED/CANCELLED/DONE SprintRuns worden overgeslagen.
|
// jobs in PAUSED/FAILED/CANCELLED/DONE SprintRuns worden overgeslagen.
|
||||||
// Bij eerste claim van een nog QUEUED SprintRun → status RUNNING.
|
// Bij eerste claim van een nog QUEUED SprintRun → status RUNNING.
|
||||||
|
//
|
||||||
|
// PBI-50 lease: lease_until = NOW() + 5min op claim. resetStaleClaimedJobs
|
||||||
|
// reset bij verlopen lease.
|
||||||
const rows = await prisma.$transaction(async (tx) => {
|
const rows = await prisma.$transaction(async (tx) => {
|
||||||
const found = productId
|
const found = productId
|
||||||
? await tx.$queryRaw<
|
? await tx.$queryRaw<
|
||||||
|
|
@ -327,8 +330,10 @@ export async function tryClaimJob(
|
||||||
AND cj.product_id = ${productId}
|
AND cj.product_id = ${productId}
|
||||||
AND cj.status = 'QUEUED'
|
AND cj.status = 'QUEUED'
|
||||||
AND (
|
AND (
|
||||||
cj.task_id IS NULL
|
cj.kind IN ('IDEA_GRILL', 'IDEA_MAKE_PLAN', 'PLAN_CHAT')
|
||||||
OR (cj.sprint_run_id IS NOT NULL AND sr.status IN ('QUEUED', 'RUNNING'))
|
OR (cj.kind IN ('TASK_IMPLEMENTATION', 'SPRINT_IMPLEMENTATION')
|
||||||
|
AND cj.sprint_run_id IS NOT NULL
|
||||||
|
AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||||
)
|
)
|
||||||
ORDER BY cj.created_at ASC
|
ORDER BY cj.created_at ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|
@ -344,8 +349,10 @@ export async function tryClaimJob(
|
||||||
WHERE cj.user_id = ${userId}
|
WHERE cj.user_id = ${userId}
|
||||||
AND cj.status = 'QUEUED'
|
AND cj.status = 'QUEUED'
|
||||||
AND (
|
AND (
|
||||||
cj.task_id IS NULL
|
cj.kind IN ('IDEA_GRILL', 'IDEA_MAKE_PLAN', 'PLAN_CHAT')
|
||||||
OR (cj.sprint_run_id IS NOT NULL AND sr.status IN ('QUEUED', 'RUNNING'))
|
OR (cj.kind IN ('TASK_IMPLEMENTATION', 'SPRINT_IMPLEMENTATION')
|
||||||
|
AND cj.sprint_run_id IS NOT NULL
|
||||||
|
AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||||
)
|
)
|
||||||
ORDER BY cj.created_at ASC
|
ORDER BY cj.created_at ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|
@ -362,7 +369,8 @@ export async function tryClaimJob(
|
||||||
SET status = 'CLAIMED',
|
SET status = 'CLAIMED',
|
||||||
claimed_by_token_id = ${tokenId},
|
claimed_by_token_id = ${tokenId},
|
||||||
claimed_at = NOW(),
|
claimed_at = NOW(),
|
||||||
plan_snapshot = ${snapshot}
|
plan_snapshot = ${snapshot},
|
||||||
|
lease_until = NOW() + INTERVAL '5 minutes'
|
||||||
WHERE id = ${jobId}
|
WHERE id = ${jobId}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue