[PR #390] [MERGED] Add degraded-mode regeneration for daily workflows and regeneration endpoint #696

Closed
opened 2026-03-13 21:04:16 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/390
Author: @AJaySi
Created: 3/6/2026
Status: Merged
Merged: 3/8/2026
Merged by: @AJaySi

Base: mainHead: codex/implement-regeneration-criteria-for-plans


📝 Commits (1)

  • 4621107 Add degraded-mode workflow regeneration criteria and endpoint

📊 Changes

2 files changed (+235 additions, -33 deletions)

View changed files

📝 backend/api/today_workflow.py (+88 -2)
📝 backend/services/today_workflow_service.py (+147 -31)

📄 Description

Motivation

  • Ensure plans created in degraded/fallback mode are re-evaluated once better context (onboarding) is available or when fallback quality is low.
  • Preserve user decisions across regenerations so user-chosen task statuses are not lost when plans are re-generated.
  • Provide an explicit, idempotent API to trigger regeneration with basic rate limiting to avoid abuse.

Description

  • Extend plan metadata by emitting generation_mode, quality_score, generated_with_agents and onboarding snapshot fields (onboarding_completed, onboarding_completed_at) inside plan_json from generation paths (agent_committee, llm, fallback).
  • Add stable task hashing _compute_task_hash(title, description) and implement regeneration logic regenerate_daily_workflow_plan that reuses the same DailyWorkflowPlan row (or creates it) and maps unchanged task hashes to preserve status, decided_at, and completion_notes during replacement.
  • Update get_or_create_daily_workflow_plan to auto-regenerate when the existing plan metadata indicates generation_mode == "fallback" with quality_score < FALLBACK_REGENERATION_QUALITY_THRESHOLD or when the plan predates onboarding completion and onboarding is now complete.
  • Add POST /api/today-workflow/regenerate endpoint which is idempotent in effect, returns the regenerated plan/tasks, and enforces a simple in-memory per-user sliding-window rate limit (3 requests per 60 seconds); also surfaced generation_mode, quality_score, and generated_with_agents in the today-workflow plan payload.

Testing

  • Verified Python syntax with python -m py_compile backend/services/today_workflow_service.py backend/api/today_workflow.py which succeeded.
  • Ran unit tests PYTHONPATH=backend pytest -q backend/test/test_today_workflow_service.py and they passed (2 passed).

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/390 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/8/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/implement-regeneration-criteria-for-plans` --- ### 📝 Commits (1) - [`4621107`](https://github.com/AJaySi/ALwrity/commit/4621107988962d6ae8bb14bd517771b0164dc99c) Add degraded-mode workflow regeneration criteria and endpoint ### 📊 Changes **2 files changed** (+235 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/today_workflow.py` (+88 -2) 📝 `backend/services/today_workflow_service.py` (+147 -31) </details> ### 📄 Description ### Motivation - Ensure plans created in degraded/fallback mode are re-evaluated once better context (onboarding) is available or when fallback quality is low. - Preserve user decisions across regenerations so user-chosen task statuses are not lost when plans are re-generated. - Provide an explicit, idempotent API to trigger regeneration with basic rate limiting to avoid abuse. ### Description - Extend plan metadata by emitting `generation_mode`, `quality_score`, `generated_with_agents` and onboarding snapshot fields (`onboarding_completed`, `onboarding_completed_at`) inside `plan_json` from generation paths (`agent_committee`, `llm`, `fallback`). - Add stable task hashing `_compute_task_hash(title, description)` and implement regeneration logic `regenerate_daily_workflow_plan` that reuses the same `DailyWorkflowPlan` row (or creates it) and maps unchanged task hashes to preserve `status`, `decided_at`, and `completion_notes` during replacement. - Update `get_or_create_daily_workflow_plan` to auto-regenerate when the existing plan metadata indicates `generation_mode == "fallback"` with `quality_score < FALLBACK_REGENERATION_QUALITY_THRESHOLD` or when the plan predates onboarding completion and onboarding is now complete. - Add `POST /api/today-workflow/regenerate` endpoint which is idempotent in effect, returns the regenerated plan/tasks, and enforces a simple in-memory per-user sliding-window rate limit (`3` requests per `60` seconds); also surfaced `generation_mode`, `quality_score`, and `generated_with_agents` in the today-workflow `plan` payload. ### Testing - Verified Python syntax with `python -m py_compile backend/services/today_workflow_service.py backend/api/today_workflow.py` which succeeded. - Ran unit tests `PYTHONPATH=backend pytest -q backend/test/test_today_workflow_service.py` and they passed (`2 passed`). ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69aaf8d2d71083289294fd248098aba9) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:04:16 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#696
No description provided.