Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

Per SRD/BRD data retention policy, CLOSED reservation requests must be deleted after 6 months. This implements automated cleanup via daily Azure Functions timer trigger.

Changes

Cellix Framework Extension

  • Added registerAzureFunctionTimerHandler() to support timer triggers alongside HTTP handlers
  • Modified handler registration to dispatch based on handler type (http | timer)

Domain & Persistence

  • Added ReservationRequest.requestDelete() with canDeleteRequest permission (system passport only)
  • Added ReservationRequestReadRepository.getExpiredClosed() query: state='Closed' AND updatedAt < (now - 182.5 days)
  • Date arithmetic uses milliseconds to avoid month boundary edge cases

Application Service

  • Created deleteExpiredReservationRequests() with OpenTelemetry tracing
  • Batch processes expired requests with per-item error isolation
  • Metrics: reservation_requests.expired.count, reservation_requests.deleted.count

Timer Trigger

  • Registered daily cleanup job (2 AM UTC, NCRONTAB: 0 0 2 * * *)
  • Uses system passport via forRequest() without auth header
// Example: Timer handler registration in apps/api/src/index.ts
.registerAzureFunctionTimerHandler(
  'cleanup-expired-reservation-requests',
  { schedule: '0 0 2 * * *', runOnStartup: false },
  cleanupExpiredReservationRequestsHandlerCreator,
)

Testing

  • Unit tests for deletion service (mocked data sources, error handling, edge cases)
  • BDD scenario for getExpiredClosed() repository query
  • Comprehensive documentation in apps/docs/docs/data-retention-reservation-requests.md

Notes

Follows same pattern as issue #199 (Listing deletion). System passport grants deletion permission for automated cleanup only.

Original prompt

This section details on the original issue you should resolve

<issue_title>Reservation Request - Expired Deletion</issue_title>
<issue_description>## Background
Reservation Requests that have reached the expired state (completed and archived for 6 months) must be deleted from the operational database (Azure Cosmos DB, MongoDB API) per the system's data retention policy. This ensures compliance with storage limits and keeps the database clean of stale records.

Task Description

  • Implement logic to automatically delete Reservation Requests from the operational database once they are marked as expired and the 6-month archival window has elapsed.
  • Ensure this process runs on a schedule or is triggered reliably to avoid retention policy violations.
  • Log deletion events for observability and auditing (OpenTelemetry/Azure Monitor integration).
  • Confirm that all related data (messages, notifications, etc.) are also cleaned up if required by retention rules.
  • Update documentation to clarify data retention behavior for Reservation Requests.

Acceptance Criteria

  • Reservation Requests in the expired state are deleted after 6 months.
  • Deletion is observable via logs and metrics.
  • No residual data remains in the database for deleted requests.
  • Documentation is updated to reflect retention and deletion logic.

References

<agent_instructions>Use the design and decisions discussed in issue #199 (#199) as context for this task. Ensure the solution follows those guidelines.
</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 6, 2026 17:03
- Extended Cellix framework to support Azure Functions Timer triggers
- Added getExpiredClosed() method to read repository for finding CLOSED requests older than 6 months
- Added requestDelete() domain method with canDeleteRequest permission
- Created deleteExpiredReservationRequests application service with OpenTelemetry tracing
- Registered daily timer trigger (2 AM UTC) for automated cleanup
- Per SRD data retention policy: CLOSED reservation requests deleted after 6 months

Co-authored-by: dani-vaibhav <182140623+dani-vaibhav@users.noreply.github.com>
- Added unit tests for deleteExpiredReservationRequests application service
- Added BDD test scenario for getExpiredClosed repository method
- Tests verify 6-month expiration logic and batch deletion flow
- Tests include error handling and edge cases

Co-authored-by: dani-vaibhav <182140623+dani-vaibhav@users.noreply.github.com>
);

When('I call getExpiredClosed', async () => {
modelsContext = {
Comment on lines +536 to +537
'user-1',
'listing-1',
Copilot AI and others added 2 commits January 6, 2026 17:09
- Created comprehensive documentation for timer trigger feature
- Documented architecture, configuration, and observability
- Added troubleshooting guide and references
- Included code examples and monitoring queries

Co-authored-by: dani-vaibhav <182140623+dani-vaibhav@users.noreply.github.com>
- Fix date arithmetic in getExpiredClosed() to use milliseconds instead of setMonth()
- Add comment explaining system passport behavior in timer handler
- Update schedule comment to clarify NCRONTAB format
- Improve JSDoc example to show system passport usage

Co-authored-by: dani-vaibhav <182140623+dani-vaibhav@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement automatic deletion of expired reservation requests Implement automated deletion of expired reservation requests per data retention policy Jan 6, 2026
Copilot AI requested a review from dani-vaibhav January 6, 2026 17:14
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.

Reservation Request - Expired Deletion

2 participants