Skip to content

Commit 98f882a

Browse files
authored
Merge Agent 2A - Recurring Tasks Implementation pull request #25 from mjunaidca/recurring-tasks
feat: Agent 2A - Recurring Tasks Implementation
2 parents f621e02 + ea2c5f5 commit 98f882a

25 files changed

Lines changed: 3205 additions & 44 deletions

File tree

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
id: 0001
3+
title: Create implementation plan for Recurring Tasks feature
4+
stage: plan
5+
date: 2025-12-10
6+
surface: agent
7+
model: claude-sonnet-4-5-20250929
8+
feature: 013-recurring-tasks
9+
branch: main
10+
user: mjunaidca
11+
command: Create implementation plan for Recurring Tasks feature
12+
labels: ["planning", "recurring-tasks", "phase-v", "spec-driven"]
13+
links:
14+
spec: specs/013-recurring-tasks/spec.md
15+
ticket: null
16+
adr: null
17+
pr: null
18+
files:
19+
- specs/013-recurring-tasks/plan.md
20+
tests:
21+
- None (planning phase)
22+
---
23+
24+
## Prompt
25+
26+
Create implementation plan for Recurring Tasks feature.
27+
28+
## Context Files to Read
29+
1. Spec: specs/013-recurring-tasks/spec.md
30+
2. Constitution: .specify/memory/constitution.md
31+
3. PRD: specs/011-phase-v-features-planner/agent-2a-recurring-tasks-prd.md
32+
33+
## Current Codebase Structure
34+
- Backend: packages/api/src/taskflow_api/
35+
- models/task.py - Task SQLModel
36+
- schemas/task.py - Pydantic schemas (TaskCreate, TaskUpdate, TaskRead, TaskListItem)
37+
- routers/tasks.py - Task API endpoints including update_status
38+
- Frontend: web-dashboard/src/
39+
- types/index.ts - TypeScript types
40+
- app/projects/[id]/tasks/new/page.tsx - Task creation form
41+
42+
## Your Task
43+
Create a comprehensive implementation plan at specs/013-recurring-tasks/plan.md that includes:
44+
45+
1. **Summary**: Primary requirement + technical approach
46+
47+
2. **Technical Context**:
48+
- Language: Python 3.13 (backend), TypeScript (frontend)
49+
- Framework: FastAPI + SQLModel (backend), Next.js 16 (frontend)
50+
- Database: PostgreSQL via Neon (production), SQLite (tests)
51+
- Testing: pytest (backend)
52+
53+
3. **Constitution Check**: Verify against 5 Non-Negotiable Principles:
54+
- Audit: Every action auditable
55+
- Agent Parity: Same API for humans/agents
56+
- Recursive Tasks: N/A for this feature
57+
- Spec-Driven: Spec exists before code
58+
- Phase Continuity: Data model works through Phase V
59+
60+
4. **Implementation Phases**:
61+
62+
**Phase 1: Backend Model + Migration** (Priority: Highest)
63+
- Add 5 fields to Task model: is_recurring, recurrence_pattern, reminder_sent, max_occurrences, occurrences_created
64+
- Create Alembic migration
65+
- Test with pytest
66+
67+
**Phase 2: Schema Updates**
68+
- Update TaskCreate with is_recurring, recurrence_pattern, max_occurrences
69+
- Update TaskUpdate with same fields
70+
- Update TaskRead, TaskListItem with is_recurring indicator
71+
- Add validation (pattern required when recurring=true)
72+
73+
**Phase 3: Recurring Logic**
74+
- Add calculate_next_due() function
75+
- Add create_next_occurrence() async function
76+
- Modify update_status endpoint to trigger on completion
77+
- Create audit log entry for spawned tasks
78+
79+
**Phase 4: Frontend Updates**
80+
- Update TypeScript types (TaskCreate, TaskRead, TaskListItem)
81+
- Add RECURRENCE_PATTERNS constant
82+
- Add recurring toggle + pattern selector to task create form
83+
- Add recurring badge to task list
84+
- Add recurring indicator to task detail view
85+
86+
5. **File Changes Summary**:
87+
List all files to be modified/created with specific changes
88+
89+
6. **Test Strategy**:
90+
- Unit tests for calculate_next_due()
91+
- Integration test for complete recurring task flow
92+
- Edge case tests (max_occurrences, no due_date, etc.)
93+
94+
7. **Risk Assessment**:
95+
- Database migration on production
96+
- Backward compatibility with existing tasks
97+
98+
Write the complete plan to: specs/013-recurring-tasks/plan.md
99+
100+
## Response snapshot
101+
102+
Created comprehensive implementation plan at `specs/013-recurring-tasks/plan.md` with the following structure:
103+
104+
**Key Sections:**
105+
1. **Summary**: Auto-create next occurrence on task completion with time-based (1m-1h) and calendar-based (daily/weekly/monthly) patterns
106+
2. **Technical Context**: Python 3.13/FastAPI/SQLModel backend, TypeScript/Next.js 16 frontend, PostgreSQL database
107+
3. **Constitution Check**: ✅ All 5 principles verified (Audit, Agent Parity, Recursive N/A, Spec-Driven, Phase Continuity)
108+
4. **4 Implementation Phases** (45min total):
109+
- Phase 1: Backend Model + Migration (15min) - Add 5 fields, generate/apply Alembic migration
110+
- Phase 2: Schema Updates (10min) - Extend TaskCreate/Update/Read with validation
111+
- Phase 3: Recurring Logic (15min) - Implement calculate_next_due(), create_next_occurrence(), integrate into update_status
112+
- Phase 4: Frontend (15min) - Add recurring toggle, pattern selector, badges/indicators
113+
5. **File Changes**: 8 files, ~307 lines total
114+
6. **Test Strategy**: Unit tests (calculate_next_due), integration tests (completion flow, max_occurrences, audit), manual testing checklist
115+
7. **Risk Assessment**: 5 risks identified with mitigation (migration safety, backward compat, infinite loops, timezones, UI validation)
116+
117+
**Technical Highlights:**
118+
- New Task fields: `is_recurring`, `recurrence_pattern`, `reminder_sent`, `max_occurrences`, `occurrences_created`
119+
- Recurrence patterns: 1m, 5m, 10m, 15m, 30m, 1h, daily, weekly, monthly
120+
- Triggers only on `status=completed` (one-time event, no loops)
121+
- Inherits: title, description, assignee, priority, tags, project
122+
- Audit log links new task to source (`recurring_from` detail)
123+
- Backend validation: pattern required when recurring=true
124+
- Frontend: Checkbox + Select dropdown + optional max occurrences input
125+
126+
**Constitution Compliance:**
127+
- ✅ Audit: log_action() for new task with recurring_from reference
128+
- ✅ Agent Parity: Same /api/tasks/{id}/status endpoint for humans/agents
129+
- ⚠️ Recursive: N/A (new tasks are siblings, not subtasks)
130+
- ✅ Spec-Driven: Follows specs/013-recurring-tasks/spec.md
131+
- ✅ Phase Continuity: Additive fields with defaults, backward compatible
132+
133+
## Outcome
134+
135+
- ✅ Impact: Created production-ready implementation plan with 13 sections covering all aspects (model, schemas, logic, frontend, tests, risks)
136+
- 🧪 Tests: Test strategy includes unit tests (9 pattern calculations), integration tests (4 scenarios: basic flow, max_occurrences, no due_date, audit), manual checklist
137+
- 📁 Files: Plan document (1 created), identifies 8 files to modify (4 backend, 4 frontend), ~307 total lines
138+
- 🔁 Next prompts: (1) Implement Phase 1 (backend model + migration), (2) Implement Phase 2 (schemas), (3) Implement Phase 3 (recurring logic), (4) Implement Phase 4 (frontend)
139+
- 🧠 Reflection: Plan follows constitution's 5 principles, provides clear phase breakdown with time estimates, includes rollback strategies for migration risk, documents edge cases (no due_date → use completion time, monthly = 30 days not calendar month)
140+
141+
## Evaluation notes (flywheel)
142+
143+
- Failure modes observed: None - plan creation successful on first attempt
144+
- Graders run and results (PASS/FAIL): N/A (planning phase, no code execution)
145+
- Prompt variant (if applicable): Base prompt with structured sections (Context + Task breakdown)
146+
- Next experiment (smallest change to try): Begin Phase 1 implementation (backend model changes)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
id: "0002"
3+
title: "Implement Recurring Tasks with Chain Tracking"
4+
stage: green
5+
date: 2025-12-11
6+
surface: agent
7+
model: claude-opus-4-5
8+
feature: recurring-tasks
9+
branch: main
10+
user: agent
11+
command: "continue implementation"
12+
labels: ["recurring-tasks", "refactoring", "subtask-cloning"]
13+
links:
14+
spec: "specs/013-recurring-tasks/spec.md"
15+
ticket: null
16+
adr: null
17+
pr: null
18+
files:
19+
- packages/api/src/taskflow_api/models/task.py
20+
- packages/api/src/taskflow_api/schemas/task.py
21+
- packages/api/src/taskflow_api/routers/tasks.py
22+
- web-dashboard/src/types/index.ts
23+
- web-dashboard/src/app/projects/[id]/tasks/new/page.tsx
24+
- web-dashboard/src/app/tasks/[id]/page.tsx
25+
tests:
26+
- "uv run pytest -x (74 passed)"
27+
- "pnpm build (success)"
28+
---
29+
30+
# Prompt
31+
32+
Continue implementing the recurring tasks feature. During implementation, the original design was refined:
33+
34+
1. **Bug discovered**: The `occurrences_created` counter on each task would reset to 0 when spawning new tasks, breaking the `max_occurrences` limit check.
35+
36+
2. **User insight**: "If we implement Option 2 (recurring_root_id) then do we even need occurrences_created=0?" - Confirmed that with chain tracking, we can remove the counter entirely and use COUNT query.
37+
38+
3. **Design refinement**:
39+
- Removed: `occurrences_created` (counter), `reminder_sent` (not used yet)
40+
- Added: `recurring_root_id` (FK to task.id for chain tracking)
41+
- Spawn count derived via: `COUNT(*) WHERE recurring_root_id = root_id`
42+
43+
4. **Additional features requested**:
44+
- `clone_subtasks_on_recur`: When enabled, subtasks are recursively cloned to each new occurrence
45+
- `recurrence_trigger`: "on_complete" | "on_due_date" | "both" (only on_complete implemented, others marked "Coming Soon")
46+
47+
# Response
48+
49+
## Implementation Summary
50+
51+
### Field Design (Final)
52+
53+
| Field | Type | Description |
54+
|-------|------|-------------|
55+
| `is_recurring` | bool | Enables recurring behavior |
56+
| `recurrence_pattern` | str | Pattern: 1m-monthly |
57+
| `max_occurrences` | int | Spawn limit (NULL = unlimited) |
58+
| `recurring_root_id` | int | FK to root task (NULL = this IS the root) |
59+
| `recurrence_trigger` | str | "on_complete", "on_due_date", "both" |
60+
| `clone_subtasks_on_recur` | bool | Clone subtasks when spawning |
61+
62+
### Key Functions
63+
64+
1. `get_spawn_count(session, root_id)` - COUNT query for spawn limit check
65+
2. `clone_subtasks_recursive(session, source, new_parent, ...)` - Deep clone subtasks
66+
3. `create_next_occurrence(session, completed_task, ...)` - Spawn with chain tracking
67+
68+
### SQLAlchemy Fix
69+
70+
Added explicit `foreign_keys` to parent/subtasks relationships because Task now has TWO self-referential FKs:
71+
```python
72+
parent: "Task" = Relationship(
73+
back_populates="subtasks",
74+
sa_relationship_kwargs={
75+
"remote_side": "Task.id",
76+
"foreign_keys": "[Task.parent_task_id]",
77+
},
78+
)
79+
```
80+
81+
### Frontend Updates
82+
83+
- Task creation form: Clone subtasks checkbox, recurrence trigger dropdown with "Coming Soon" badges
84+
- Task detail: Shows clone_subtasks_on_recur and recurrence_trigger values
85+
86+
### Test Results
87+
88+
- Backend: 74 passed, 3 skipped
89+
- Frontend: Build successful
90+
91+
# Outcome
92+
93+
Feature complete with improved design. Chain tracking via `recurring_root_id` is cleaner and more reliable than counter-based tracking. Subtask cloning enables complex recurring workflows (e.g., weekly sprint with standard checklist).
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
id: 001
3+
title: Recurring Tasks Specification
4+
stage: spec
5+
date: 2025-12-10
6+
surface: agent
7+
model: claude-opus-4-5-20251101
8+
feature: recurring-tasks
9+
branch: recurring-tasks
10+
user: autonomous
11+
command: /sp.specify recurring-tasks
12+
labels: ["recurring-tasks", "phase-v", "specification", "sdd"]
13+
links:
14+
spec: specs/013-recurring-tasks/spec.md
15+
ticket: null
16+
adr: null
17+
pr: null
18+
files:
19+
- specs/013-recurring-tasks/spec.md
20+
- specs/013-recurring-tasks/checklists/requirements.md
21+
tests:
22+
- N/A (specification phase)
23+
---
24+
25+
## Prompt
26+
27+
/sp.specify recurring-tasks
28+
29+
Implement Recurring Tasks - tasks that auto-create their next occurrence when completed. Support minute-level recurrence (1m, 5m, etc.), daily, weekly, monthly patterns. Include max occurrences limit.
30+
31+
Context from PRD (specs/011-phase-v-features-planner/agent-2a-recurring-tasks-prd.md):
32+
- Add 3 fields to Task model (is_recurring, recurrence_pattern, reminder_sent)
33+
- Modify update_status to create next occurrence when completing recurring task
34+
- Add recurring toggle to task forms in frontend
35+
36+
User additions:
37+
- Support 1-minute recurrence intervals
38+
- Add duration/max occurrences feature
39+
40+
## Response snapshot
41+
42+
Created comprehensive specification at `specs/013-recurring-tasks/spec.md` covering:
43+
44+
1. **5 User Stories** (prioritized P1-P3):
45+
- P1: Complete recurring task creates next occurrence
46+
- P1: Create recurring task via form
47+
- P2: View recurring task indicator
48+
- P2: Edit task recurrence settings
49+
- P3: Max occurrences limit
50+
51+
2. **13 Functional Requirements** (FR-001 through FR-013):
52+
- Model fields: is_recurring, recurrence_pattern, reminder_sent, max_occurrences, occurrences_created
53+
- Supported patterns: 1m, 5m, 10m, 15m, 30m, 1h, daily, weekly, monthly
54+
- Auto-creation logic on completion
55+
- Audit log integration
56+
- Frontend UI requirements
57+
58+
3. **6 Success Criteria** with measurable outcomes:
59+
- SC-001: Next occurrence appears within 2 seconds
60+
- SC-002: Exactly one occurrence per completion (no duplicates)
61+
- SC-006: Max occurrences 100% accuracy
62+
63+
4. **Spec-architect validation**: 9.5/10 score, READY FOR PLANNING
64+
65+
## Outcome
66+
67+
- Impact: Comprehensive specification created for recurring tasks feature
68+
- Tests: N/A (specification phase - no code yet)
69+
- Files: 2 files created (spec.md, requirements.md checklist)
70+
- Next prompts: /sp.plan recurring-tasks
71+
- Reflection: Extended PRD with max_occurrences feature per user request. Spec-architect validated with formal verification (invariants, small scope testing).
72+
73+
## Evaluation notes (flywheel)
74+
75+
- Failure modes observed: None - spec passed all validation checks
76+
- Graders run and results (PASS/FAIL): spec-architect validation PASS (9.5/10)
77+
- Prompt variant (if applicable): Standard /sp.specify flow
78+
- Next experiment (smallest change to try): Could add p95 latency percentile to SC-001
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
id: 002
3+
title: Recurring Tasks Implementation Planning
4+
stage: plan
5+
date: 2025-12-10
6+
surface: agent
7+
model: claude-opus-4-5-20251101
8+
feature: recurring-tasks
9+
branch: recurring-tasks
10+
user: autonomous
11+
command: /sp.plan recurring-tasks
12+
labels: ["recurring-tasks", "phase-v", "planning", "sdd"]
13+
links:
14+
spec: specs/013-recurring-tasks/spec.md
15+
ticket: null
16+
adr: null
17+
pr: null
18+
files:
19+
- specs/013-recurring-tasks/plan.md
20+
tests:
21+
- N/A (planning phase)
22+
---
23+
24+
## Prompt
25+
26+
/sp.plan recurring-tasks
27+
28+
Create comprehensive implementation plan based on spec.md for recurring tasks feature.
29+
30+
## Response snapshot
31+
32+
Created detailed implementation plan at `specs/013-recurring-tasks/plan.md` (1245 lines) covering:
33+
34+
**4 Implementation Phases** (45 min total):
35+
1. Backend Model + Migration (15 min) - Add 5 fields to Task model
36+
2. Schema Updates (10 min) - Extend TaskCreate, TaskUpdate, TaskRead, TaskListItem
37+
3. Recurring Logic (15 min) - calculate_next_due, create_next_occurrence, update_status integration
38+
4. Frontend Updates (15 min) - Recurring toggle, pattern selector, badges
39+
40+
**Key Technical Decisions**:
41+
- timedelta-based calculations (no dateutil dependency)
42+
- Monthly = 30 days (simplified, not calendar month)
43+
- Fallback to daily for unknown patterns
44+
- Transaction pattern: caller owns commit (follows constitution)
45+
46+
**Constitution Compliance**: All 5 principles verified
47+
- Audit: log_action with recurring_from reference
48+
- Agent Parity: Same endpoint for humans/agents
49+
- Spec-Driven: Following spec.md
50+
- Phase Continuity: Additive fields, backward compatible
51+
52+
**File Changes Summary**: 8 files, ~307 lines
53+
**Test Strategy**: Unit tests for patterns + integration tests for workflow
54+
55+
## Outcome
56+
57+
- Impact: Complete implementation roadmap created
58+
- Tests: N/A (planning phase)
59+
- Files: 1 file created (plan.md)
60+
- Next prompts: /sp.tasks recurring-tasks
61+
- Reflection: Plan is production-ready with detailed code snippets for each phase
62+
63+
## Evaluation notes (flywheel)
64+
65+
- Failure modes observed: None
66+
- Graders run and results (PASS/FAIL): Constitution check PASS
67+
- Prompt variant (if applicable): Standard /sp.plan with general-purpose agent routing
68+
- Next experiment (smallest change to try): Could add time estimates per code block

0 commit comments

Comments
 (0)