Skip to content

feat(roadmap): delete the data of a removed repository #4603

Open

Description

@dan-petty

Problem or Motivation

When a repository leaves service.repos, the roadmap Service only logs a warning. After the move to Valkey, its keys in valkey-roadmap (plan records, ledgers, schedules, read model, run records) and its clone folder stay with no owner. Each key must have a TTL or one owner that deletes it (a rule of the ADR of the move).

Proposed Solution & Architectural Design

  • The sweep owns the cleanup. When service.repos has not named a repository for 7 days, the sweep deletes its keys (the two SCAN MATCH patterns of RepoRef, then UNLINK) and its clone folder.
  • The 7-day wait keeps a configuration typo from deleting plan records (a loss costs tokens).
  • A gauge counts the repositories that wait. One log line names each cleanup.
  • Caches in valkey-devops expire by TTL and need no cleanup.

Target Subsystem

Workstation Caching & Valkey (roadmap sweep).

Existing Tool Considered

Valkey SCAN MATCH and UNLINK (open tool). Cost: about 150,000 tokens and 1.5 hours to build, about 3,000 tokens a month to keep, about 20,000 tokens to fix.

Acceptance Criteria

  • A repository that service.repos has not named for 7 days loses its valkey-roadmap keys and its clone folder; a test with a fake Valkey shows that the keys of other repositories stay.
  • A gauge counts the repositories that wait; one log line names each cleanup.
  • A repository that comes back within 7 days keeps its keys.

Dependencies

  • "feat(roadmap): name each repository's resources from one RepoRef".
  • "feat(roadmap): keep schedules, intake and ledgers in Valkey".
  • "feat(roadmap): run the reconcile sweep on a cluster schedule".

Source: #4517

Alternatives check of 2026-12-01: in-use.
The repository already uses this tool.
Tool: Valkey (https://github.com/valkey-io/valkey), BSD-3-Clause, last activity 2026-12-01, maintained.
Reason: Searches found Valkey, the store the issue already names. Valkey SCAN MATCH and UNLINK cover key discovery and key deletion, but the sweep logic around them stays project code. The clone folder, the 7-day wait, the gauge and the log line stay uncovered.

Covers:

  • Finds keys of one repository with SCAN MATCH
  • Deletes many keys without blocking with UNLINK
  • Keeps each key under a TTL or one owner

Lacks:

  • Deletes no clone folder on disk
  • Tracks no 7-day absence wait
  • Sets no gauge and writes no cleanup log line
  • Skips no repository that a unit of work holds

Proposed design

Problem statement

The sweep must delete the data of a repository that service.repos has not named for 7 days. The data includes the valkey-roadmap keys and the clone folder. ADR 0022 requires each key to have a TTL or one owner that deletes it. The 7-day wait prevents a configuration typo from deleting plan records.

Acceptance criteria

Requirement: Delete absent repository keys

The sweep SHALL delete each valkey-roadmap key that matches either RepoRef pattern of a repository that service.repos has not named for 7 days.

Scenario: Absent repository keys are unlinked

  • WHEN A fake Valkey holds keys that match both RepoRef patterns of an absent repository and keys of a named repository, and the waiting key of the absent repository is 7 days old.
  • THEN The sweep removes the absent repository's keys and keeps the named repository's keys.

Requirement: Delete the clone folder of an absent repository

The sweep SHALL delete the clone folder of a repository that service.repos has not named for 7 days.

Scenario: Clone folder is removed

  • WHEN The clone folder of an absent repository holds a file and its waiting key is 7 days old.
  • THEN The sweep removes the folder and the file.

Requirement: Keep the data of a named repository

The sweep SHALL delete no key and no clone folder of a repository that service.repos names.

Scenario: Named repository is untouched

  • WHEN A repository is in service.repos and the sweep runs.
  • THEN Its keys and its clone folder stay and it has no waiting key.

Requirement: Wait 7 days before cleanup

The sweep SHALL store the time of the first sweep that finds a repository absent and SHALL delete only after 7 days from that time.

Scenario: A short absence keeps the data

  • WHEN The sweep finds a repository absent and its waiting key holds a time 3 days ago.
  • THEN The sweep deletes no key, deletes no clone folder, and keeps the waiting key.

Requirement: Clear the wait when the repository returns

The sweep SHALL delete the waiting key of a repository that service.repos names again.

Scenario: Returning repository clears its waiting key

  • WHEN A repository has a waiting key and service.repos names it again.
  • THEN The sweep deletes the waiting key and keeps the repository's other keys.

Requirement: Gauge of repositories that wait

The sweep SHALL set a gauge to the number of repositories that have a waiting key.

Scenario: Gauge counts the waiting repositories

  • WHEN Two repositories have a waiting key and one repository has none.
  • THEN The cleanup gauge reads 2.

Requirement: One log line for each cleanup

The sweep SHALL write exactly one log line that names each repository that it cleans up.

Scenario: Cleanup writes one line

  • WHEN The sweep cleans up one repository.
  • THEN The log holds exactly one line that names the repository.

Requirement: Leave valkey-devops to its TTLs

The sweep SHALL delete no key in valkey-devops.

Scenario: A devops cache key survives a cleanup

  • WHEN valkey-devops holds a key of the absent repository and the sweep cleans up that repository.
  • THEN The key in valkey-devops stays.

Requirement: Keep data while a unit of work holds the repository

The sweep SHALL delete no key and no clone folder of a repository while a unit of work holds it.

Scenario: Held repository is skipped

  • WHEN A unit of work holds an absent repository and its waiting key is 7 days old.
  • THEN The sweep deletes no key, deletes no clone folder, and keeps the waiting key.

Existing Tool Considered

The alternatives check in the issue body records in-use for Valkey (valkey-io/valkey). The check lists what Valkey covers and lacks. The proposal uses Valkey SCAN MATCH and UNLINK through the existing redis-py client. The sweep code around those commands provides the parts that the check says Valkey lacks. The project builds that sweep code: about 150,000 tokens and 1.5 hours to build, about 3,000 tokens a month to keep, and about 20,000 tokens to fix.

Key questions

  • Which tool deletes the roadmap keys of a removed repository?: Valkey SCAN MATCH finds the keys of one repository and UNLINK deletes them through the redis-py client. The alternatives check in the issue body records the verdict in-use. (best practice) [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:124, src/devops_cli/valkey/client.py]
    • Chosen: Valkey SCAN MATCH then UNLINK. It is the open, maintained store in use. UNLINK frees the keys without blocking the server.
    • Rejected: Valkey KEYS then DEL. KEYS walks the whole keyspace and blocks the server.
    • Rejected: A TTL on each roadmap key only. A TTL cannot delete the clone folder. ADR 0022 gives one owner that deletes.
  • Which component owns the cleanup?: The reconcile sweep owns the cleanup. ADR 0022 gives the sweep the deletion of the keys and the clone folder. (best practice) [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:124, CONTEXT.md]
    • Chosen: The reconcile sweep. ADR 0022 names the sweep. The sweep already reads the configuration of each repository.
    • Rejected: A separate cleanup job. It adds a second schedule and a second owner for one rule that the ADR gives to the sweep.
  • How does the sweep know that a repository has been absent for 7 days?: The sweep writes one waiting key in valkey-roadmap for each repository that it finds absent. The value is the time of that sweep. The sweep deletes when the stored time is 7 days old. A repository that service.repos names again loses its waiting key. (best practice) [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:124, src/devops_cli/github/repo_ref.py:93]
    • Chosen: A waiting key with the time of the first absent sweep. The gauge needs a stored record. The record survives a restart of the Service.
    • Rejected: A count of sweeps in memory. A restart loses the count. More than one unit of work runs a sweep.
    • Rejected: A TTL on every roadmap key. It deletes a live repository's key on a long absence from the configuration. It cannot cover the clone folder.
  • Which key patterns hold the roadmap data of one repository?: RepoRef builds the two valkey-roadmap key patterns. The sweep uses both patterns and parses no owner/name itself. [sources: src/devops_cli/github/repo_ref.py:93, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:124, ARCHITECTURE.md:226]
  • Which path does the sweep delete for the clone folder?: The sweep deletes the folder from the data directory setting and RepoRef. It builds no path of its own. (best practice) [sources: src/devops_cli/github/repo_ref.py:93, src/devops_cli/config/settings.py]
    • Chosen: The path from the data directory setting and RepoRef. It names the folder of one repository. One rule names each path.
    • Rejected: A scan of the data directory for a matching folder. A wrong match deletes the clone folder of another repository.
  • What does the sweep do when a unit of work holds the repository that it cleans up?: The sweep deletes nothing and keeps the waiting key. The next sweep tries again. (best practice) [sources: CONTEXT.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Skip the repository while a unit of work holds it. A deleted clone folder stops the running job. The wait costs nothing.
    • Rejected: Delete the data at once. The running job loses its clone and its result.
  • Which issues must merge before this item?: The body's Dependencies section lists feat(roadmap): run the reconcile sweep on a cluster schedule #4574, feat(roadmap): name each repository's resources from one RepoRef #4533 and feat(roadmap): keep schedules, intake and ledgers in Valkey #4565. CONTEXT.md confirms feat(roadmap): run the reconcile sweep on a cluster schedule #4574 is the sweep on a cluster schedule. [sources: CONTEXT.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4574, #4533, #4565

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. Orphaned data accumulates but the service still runs; the 7-day grace period confirms it is not an urgent failure.
    • Value: Medium. Prevents unbounded growth of orphaned keys and clone folders that waste storage and tokens.
    • Effort: Medium. Requires SCAN MATCH patterns, UNLINK calls, folder deletion, a gauge, a log line, and a fake-Valkey test; the body estimates about 1.5 hours to build.
    • Related: feat(roadmap): run the roadmap jobs when they are due (devops roadmap run) #981, which asks for a different change. Both target the roadmap service sweep, but #981 schedules job execution while the candidate adds cleanup logic for removed repositories.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches found Valkey, the open, maintained data store the issue itself names, whose SCAN MATCH/UNLINK commands (and per-key TTLs) cover deleting a repository's roadmap keys by pattern. It does not cover the rest of the need: watching service.repos for 7 days, deleting the clone folder, the waiting gauge and cleanup log line, or the fake-Valkey test.

    The repository already uses this tool.

    Tool: valkey-io/valkey (https://github.com/valkey-io/valkey)

    • License: BSD-3-Clause
    • Last activity: 2026-11-12
    • Maintained: yes

    Covers:

    • SCAN MATCH finds the keys of one repository by pattern
    • UNLINK deletes the matched keys without blocking the server
    • Per-key TTL/expiry is available as the alternative owner rule

    Lacks:

    • No knowledge of service.repos or a 7-day grace period
    • Does not delete a repository's clone folder on the node
    • No gauge of repositories waiting for cleanup and no per-cleanup log line
    • No fake-Valkey test harness for the cleanup

    Tools considered:

    Searches run:

    • python library scan_iter delete keys matching pattern redis valkey, results: 5
    • Valkey SCAN MATCH UNLINK delete keys by pattern, results: 5
    • valkey.io SCAN command documentation, results: 5
    • redis-py scan_iter unlink documentation, results: 5
    • Valkey open source key-value store GitHub repository, results: 5
    • redis-py GitHub repository Python client, results: 5
    • Valkey UNLINK command, results: 5
    • cleanup orphaned redis keys cron job open source tool, results: 5
    • Valkey EXPIRE key TTL documentation, results: 5
    • open source tool to clean up data of decommissioned services redis keys and files, results: 5

    Sources:

    Checked on 2026-11-13. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 0410772 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  7. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/roadmapsource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions