Skip to content

[WIP] Consolidate Cosmos DB retry logic into shared utility#88

Draft
roberthunterjr with Copilot wants to merge 1 commit into
mainfrom
copilot/ai-186-consolidate-cosmos-db-retry-logic
Draft

[WIP] Consolidate Cosmos DB retry logic into shared utility#88
roberthunterjr with Copilot wants to merge 1 commit into
mainfrom
copilot/ai-186-consolidate-cosmos-db-retry-logic

Conversation

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Issue: AI-186
Summary: AI-CLONE - Consolidate Cosmos DB retry logic into shared utility
Description: As of PR #53 (Conversation Capture), the codebase now has retry logic duplicated across four Cosmos DB store modules. This should be consolidated into a shared utility to improve maintainability and consistency.
Current State
Retry logic is now implemented in:

  • slack-users-store.js (existing implementation with executeWithRetry() wrapper)
  • feedback-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
  • interaction-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
  • conversation-capture-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
    Duplicated Code
  • Retryable error code detection (RETRYABLE_CODES, toNumericCode())
  • Exponential backoff calculation with jitter (getDelayMs())
  • Policy configuration (getRetryPolicy() with test/emulator/production variations)
  • Safe error formatting (formatCosmosError())
    Proposed Solution
    Extract shared retry utilities to cosmos-utils.js (which already exists with isEmulatorTarget()):
  • getRetryPolicy(connectionString, endpoint, isTest)
  • getDelayMs(policy, attempt)
  • toNumericCode(error)
  • formatCosmosError(error)
  • RETRYABLE_CODES and RECONNECT_CODES constants
    This consolidation would:
  • Eliminate ~150 lines of duplicated code
  • Ensure retry behavior is consistent across all stores
  • Simplify testing and maintenance
  • Make future retry enhancements (e.g., metrics/tracing) easier
    Acceptance Criteria
  • Retry utilities exported from cosmos-utils.js with comprehensive JSDoc
  • All four store modules refactored to use shared utilities
  • All existing tests pass
  • Unit tests added for cosmos-utils retry functions
    Related
    Follow-up to PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53 (Conversation Capture). Can be picked up after that merges.
    Labels: refactoring, technical-debt

Custom Fields:
Development: {}
Epic Link: AI-143
Rank: 1|i00l0v:
Sprint: Sprint 9 (future)

Parent Issue: AI-143
Parent Summary: R-MS5 MVP Agentic Workflow delivery of bug fixes
Parent Description: Goal: Establish agent-assisted software delivery on the Fiona repo by delivering one bug-fix workflow end-to-end — from a refined Jira ticket to a review-ready PR — with governance and no local compute. This validates the full pipeline before broadening to features, tech-debt, and Dependabot in Phase 1.
Approach: An implementation of Agentic Loop Engineering — governed reasoning loops where governance is the loop's base case. A hybrid architecture: versioned GitHub Actions own the Jira contract, readiness checks, and wall-clock governance; GitHub Copilot's hosted coding agent (steered by the automate-bug-fix skill) owns branch/tests/implementation/draft-PR.
h3. Effort (child stories)

  • AI-150 — PRD: agentic workflow, end-state vision + governance (prerequisite; GitHub PR PRD: Agentic Workflow #67)
  • AI-148 — TDD: MVP architecture + Phase 1 expansion (done, 69b6751)
  • AI-98 — HITL bug-fix implementation. Elements may still be reused when implementing this epic, but the MVP follows the TDD's hybrid Copilot approach at deliberately limited scope (TDD Decision D-5). AI-98's full Claude-on-Foundry + Durable Functions pipeline is beyond MVP scope; its governance/telemetry learnings feed Phase 1.
    h3. July 31 MVP scope
  • One supervised end-to-end run on a disposable ticket in the AI project
  • Bug scoped to apps/fiona-slack (the app whose CI supplies the reused pre-check suite)
  • Trigger: Jira Automation → GitHub repository_dispatch
    h3. Out of scope for MVP (Phase 1+)
  • Prompt-injection defense (FR-CROSS-13) and protected-file scoping (FR-CROSS-14)
  • Structured OpenTelemetry observability
  • Feature, tech-debt, and Dependabot workflows

You have been assigned to a work item "AI-CLONE - Consolidate Cosmos DB retry logic into shared utility". Analyze the details of the work item and get started.
Summary: AI-CLONE - Consolidate Cosmos DB retry logic into shared utility
Description: As of PR #53 (Conversation Capture), the codebase now has retry logic duplicated across four Cosmos DB store modules. This should be consolidated into a shared utility to improve maintainability and consistency.
Current State
Retry logic is now implemented in:

  • slack-users-store.js (existing implementation with executeWithRetry() wrapper)
  • feedback-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
  • interaction-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
  • conversation-capture-store.js (added in PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53)
    Duplicated Code
  • Retryable error code detection (RETRYABLE_CODES, toNumericCode())
  • Exponential backoff calculation with jitter (getDelayMs())
  • Policy configuration (getRetryPolicy() with test/emulator/production variations)
  • Safe error formatting (formatCosmosError())
    Proposed Solution
    Extract shared retry utilities to cosmos-utils.js (which already exists with isEmulatorTarget()):
  • getRetryPolicy(connectionString, endpoint, isTest)
  • getDelayMs(policy, attempt)
  • toNumericCode(error)
  • formatCosmosError(error)
  • RETRYABLE_CODES and RECONNECT_CODES constants
    This consolidation would:
  • Eliminate ~150 lines of duplicated code
  • Ensure retry behavior is consistent across all stores
  • Simplify testing and maintenance
  • Make future retry enhancements (e.g., metrics/tracing) easier
    Acceptance Criteria
  • Retry utilities exported from cosmos-utils.js with comprehensive JSDoc
  • All four store modules refactored to use shared utilities
  • All existing tests pass
  • Unit tests added for cosmos-utils retry functions
    Related
    Follow-up to PR [AI-129] Capture all conversations in Cosmos DB for evaluation #53 (Conversation Capture). Can be picked up after that merges.

User: You have been assigned to a work item "AI-CLONE - Consolidate Cosmos DB retry logic into shared utility". Analyze the details of the work item and get started.

Agent: I received your request and will let you know when the PR is ready.

Agent: checking if I have everything I need to get started.

User: Ed-Fi-Alliance-OSS/Fiona/

Branch naming

This task relates to issue AI-186. The branch name and pull request title MUST include AI-186 as a distinct token for traceability — this is required, not optional. The repository's branch-naming pattern is authoritative: the branch name must satisfy it in full, and you must never drop or rewrite a prefix the pattern requires — even when that prefix is given to you only as a pattern rather than spelled out here. Place AI-186 as early as the pattern permits: immediately after any required leading prefix, or as the first segment when the pattern requires none. Follow it with a short kebab-case description of the task. Do not use AI-186 as the entire branch name, do not prepend it with a leading hyphen, and do not place it at the end. Only if the pattern cannot admit AI-186 at all should you comply with the pattern and omit it.

Include a link to the original issue in the pull request description: https://edfi.atlassian.net/browse/AI-186

Copilot AI requested a review from roberthunterjr July 24, 2026 22:22
Copilot stopped work on behalf of roberthunterjr due to an error July 24, 2026 22:22
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.

2 participants