mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-31 06:42:06 +00:00
fix: address critical issues in PR #75 agent scheduling feature
This commit fixes several issues identified in the agent scheduling feature from PR #75: Frontend Fixes: - Add day boundary handling in timeUtils.ts for timezone conversions - Add utcToLocalWithDayShift/localToUTCWithDayShift functions - Add shiftDaysForward/shiftDaysBackward helpers for bitfield adjustment - Update ScheduleModal to correctly adjust days_of_week when crossing day boundaries during UTC conversion (fixes schedules running on wrong days for users in extreme timezones like UTC+9) Backend Fixes: - Add MAX_SCHEDULES_PER_PROJECT (50) limit to prevent resource exhaustion - Wire up crash recovery callback in scheduler_service._start_agent() - Convert schedules.py endpoints to use context manager for DB sessions - Fix race condition in override creation with atomic delete-then-create - Replace deprecated datetime.utcnow with datetime.now(timezone.utc) - Add DB-level CHECK constraints for Schedule model fields Files Modified: - api/database.py: Add _utc_now helper, CheckConstraint imports, constraints - progress.py: Replace deprecated datetime.utcnow - server/routers/schedules.py: Add context manager, schedule limits - server/services/assistant_database.py: Replace deprecated datetime.utcnow - server/services/scheduler_service.py: Wire crash recovery, fix race condition - ui/src/components/ScheduleModal.tsx: Use day shift functions - ui/src/lib/timeUtils.ts: Add day boundary handling functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,9 @@ import {
|
||||
useToggleSchedule,
|
||||
} from '../hooks/useSchedules'
|
||||
import {
|
||||
utcToLocal,
|
||||
localToUTC,
|
||||
utcToLocalWithDayShift,
|
||||
localToUTCWithDayShift,
|
||||
adjustDaysForDayShift,
|
||||
formatDuration,
|
||||
DAYS,
|
||||
isDayActive,
|
||||
@@ -109,10 +110,18 @@ export function ScheduleModal({ projectName, isOpen, onClose }: ScheduleModalPro
|
||||
return
|
||||
}
|
||||
|
||||
// Convert local time to UTC
|
||||
// Convert local time to UTC and get day shift
|
||||
const { time: utcTime, dayShift } = localToUTCWithDayShift(newSchedule.start_time)
|
||||
|
||||
// Adjust days_of_week based on day shift
|
||||
// If UTC is on the next day (dayShift = 1), shift days forward
|
||||
// If UTC is on the previous day (dayShift = -1), shift days backward
|
||||
const adjustedDays = adjustDaysForDayShift(newSchedule.days_of_week, dayShift)
|
||||
|
||||
const scheduleToCreate = {
|
||||
...newSchedule,
|
||||
start_time: localToUTC(newSchedule.start_time),
|
||||
start_time: utcTime,
|
||||
days_of_week: adjustedDays,
|
||||
}
|
||||
|
||||
await createSchedule.mutateAsync(scheduleToCreate)
|
||||
@@ -203,8 +212,12 @@ export function ScheduleModal({ projectName, isOpen, onClose }: ScheduleModalPro
|
||||
{!isLoading && schedules.length > 0 && (
|
||||
<div className="space-y-3 mb-6 max-h-[300px] overflow-y-auto">
|
||||
{schedules.map((schedule) => {
|
||||
const localTime = utcToLocal(schedule.start_time)
|
||||
// Convert UTC time to local and get day shift for display
|
||||
const { time: localTime, dayShift } = utcToLocalWithDayShift(schedule.start_time)
|
||||
const duration = formatDuration(schedule.duration_minutes)
|
||||
// Adjust displayed days: if local is next day (dayShift=1), shift forward
|
||||
// if local is prev day (dayShift=-1), shift backward
|
||||
const displayDays = adjustDaysForDayShift(schedule.days_of_week, dayShift)
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -223,7 +236,7 @@ export function ScheduleModal({ projectName, isOpen, onClose }: ScheduleModalPro
|
||||
{/* Days */}
|
||||
<div className="flex gap-1 mb-2">
|
||||
{DAYS.map((day) => {
|
||||
const isActive = isDayActive(schedule.days_of_week, day.bit)
|
||||
const isActive = isDayActive(displayDays, day.bit)
|
||||
return (
|
||||
<span
|
||||
key={day.label}
|
||||
|
||||
Reference in New Issue
Block a user