Skip to content

fix(roadmap): remove cached issues when a repository becomes private #7298

Done

Description

@dan-petty

Problem Description

After #7292, the shared tier takes the issue records of a public repository only. But when a public repository becomes private, the records that the tier already holds stay until their TTL ends, at most 24 hours after their last write (DEFAULT_BRAIN_ISSUE_TTL_SECONDS). No process reads them after its public answer ends (at most 30 minutes), and a webhook delivery stops at once, because the delivery carries repository.private.

The listing snapshot has a bound for this case: its shared copy stays at most 1 hour after the change (openspec/specs/project-brain/shared-cache/spec.md, requirement of the visibility answer, owner decision of 2026-11-21). A round removes the snapshot when its visibility read gives private. The issue cache has no such removal, because its records are one key for each issue (valkey:roadmap:v1:issue:<owner>/<name>:<number>) and the issue cache runs no scan of keys. The cache tier itself has scan and unlink since #7320 (src/devops_cli/valkey/cache.py:183 and :196).

Reach of the data: the records were public when a process wrote them, and a reader needs the password of the cache in namespace devops. So this is a break of the 1-hour bound, with no known path for an outside reader.

Reproduction Steps

  1. With the valkey_server fake, write 2 issue records of a repository whose visibility read gives public.
  2. Change the visibility read to private, move the clock 30 minutes, and read one issue.
  3. Read the keys of the fake: the 2 records are still there.

Expected vs Actual Behavior

  • Expected: at most 1 hour after a repository becomes private, the shared tier holds no issue record of it, unless the process sends SWEEP_USER.
  • Actual: the records stay for at most 24 hours after their last write.

Proposed Fix

When the visibility check gives private for a process that does not send SWEEP_USER, the issue cache removes the keys of that repository: a SCAN with MATCH valkey:roadmap:v1:issue:<owner>/<name>:* and a bounded COUNT, then UNLINK, in the form of the snapshot removal. The scan has a bound of time and of keys, fails soft, and counts its result. The pattern of o/n matches no key of o/nn, because the : ends the repository part.

Acceptance Criteria

  • Test first: after a private answer, the fake holds no issue key of that repository and still holds the keys of another repository whose name starts with the same characters. The test fails on the base.
  • A test: a process that sends SWEEP_USER removes nothing.
  • A test: with the tier down, the removal sends no command and raises no error.
  • The spec states the 1-hour bound for the issue records.

Environment Diagnostics

devops-cli after the merge of the pull request of #7292.

Dependencies

Related: #6611 (the bound of the snapshot), #6589, #4624.

Source

Source: #4624

Alternatives check of 2026-11-26: none.
Tool: none found.
Reason: Searches found no open tool that evicts a repository's cached issue records when its visibility turns private; this is application logic in devops-cli, run against the Valkey keyspace it already writes.

Lacks:

  • No tool drops issue keys on a private visibility answer
  • No per-repository scan of the issue key space
  • No removal bound shorter than the 24-hour TTL
  • No sweep that spares keys of similarly named repositories

Proposed design

Problem statement

After #7292 the shared tier holds the issue records of a public repository only. When a public repository becomes private, the records that the tier already holds stay until their TTL, at most 24 hours after their last write. The listing snapshot removes its shared copy at the first private answer, and the issue cache has no such removal. This breaks the 1-hour bound of the spec for the issue records.

Acceptance criteria

Requirement: A private answer removes the issue keys of the repository

When the visibility check gives private for a process that sends no sweep ACL user, the issue cache SHALL remove each key valkey:roadmap:v1:issue:<owner>/<name>:<number> of that repository.

Scenario: A repository that became private

  • WHEN A store writes the issue keys of dan-petty/devops-cli and of dan-petty/devops-cli-2 on the valkey_server fake, and a store of a new process with no ACL user reads an issue of dan-petty/devops-cli while the visibility read gives isPrivate: true
  • THEN The fake holds no key with the prefix valkey:roadmap:v1:issue:dan-petty/devops-cli:. It keeps each key with the prefix valkey:roadmap:v1:issue:dan-petty/devops-cli-2:. devops_cli_brain_writes_total{store="issue",result="removed"} rises by one.

Requirement: The sweep user keeps the issue keys

A process that sends the sweep ACL user SHALL NOT remove the issue keys of a private repository.

Scenario: A private repository under the sweep user

  • WHEN A store writes the issue keys of a repository on the valkey_server fake, and a store of a new process that sends the sweep user reads an issue while the visibility read gives isPrivate: true
  • THEN The fake keeps each issue key of the repository, and devops_cli_brain_writes_total{store="issue",result="removed"} does not rise.

Requirement: A failed tier fails the removal soft

A removal whose SCAN or UNLINK command fails SHALL raise no error to the caller, SHALL send no further command, and SHALL count the failure.

Scenario: The tier stops before the removal

  • WHEN A store of a new process with no ACL user reads an issue of a repository whose visibility read gives isPrivate: true, and the valkey_server fake has connected = False before the removal
  • THEN The read returns no entry and no error reaches the caller. The fake receives no UNLINK. devops_cli_valkey_cache_errors_total{op="scan",error="connection"} rises by one.

Requirement: The spec states the 1-hour bound of the issue records

The project-brain/shared-cache spec SHALL state that the shared tier holds no issue record of a repository later than 1 hour after the repository becomes private, unless the process sends sweep.

Scenario: The spec delta validates

  • WHEN openspec validate --strict runs on the change folder of this issue
  • THEN The command reports no error for the change, and the spec delta of project-brain/shared-cache holds the requirement of the 1-hour bound for the issue records.

Existing Tool Considered

The alternatives check of 2026-11-26 in the issue body gives the verdict none: it found no open tool or library that evicts a repository's cached issue records when its visibility turns private, and the block lists what such a tool lacks. The change builds the removal itself on the SCAN and UNLINK commands that the cache tier already holds (src/devops_cli/valkey/cache.py:183 and :196), in the form of the snapshot removal. Written cost of the own code: about 40,000 tokens to build, keep and fix the removal and its tests, and about 3 hours of elapsed time.

Key questions

  • Where does the removal of a repository's issue keys run?: In src/devops_cli/roadmap/stores/brain_issues.py, at the visibility answer that the issue cache reads. The store removes the keys one time for each private answer, when the process sends no sweep ACL user, and then returns no entry. (best practice) [sources: src/devops_cli/roadmap/stores/brain_issues.py:103, src/devops_cli/roadmap/stores/visibility.py:56, src/devops_cli/roadmap/stores/listing_shared.py, openspec/specs/project-brain/shared-cache/spec.md]
    • Chosen: Remove at the private visibility answer of the issue store. The store already reads this answer, and the snapshot store removes its shared copy at the same point. The process sends no command for a private repository.
    • Rejected: Remove in the webhook route from repository.private. The route holds no visibility answer, and a change of visibility sends no issues delivery that the route handles.
    • Rejected: Remove in a scheduled sweep over the issue key space. No process holds the set of repositories, and the tier holds no reverse index, so a sweep would scan the whole keyspace each round.
  • Does the removal use SCAN with MATCH, or an index key for each repository?: SCAN with MATCH valkey:roadmap:v1:issue:<owner>/<name>:* and a bounded COUNT, then UNLINK, through the scan and unlink methods of the cache tier. (best practice) [sources: src/devops_cli/valkey/cache.py:183, src/devops_cli/valkey/cache.py:196, src/devops_cli/roadmap/brain_index.py:189]
    • Chosen: SCAN MATCH then UNLINK. The tier has scan and unlink, the brain index already scans this way, and no new key needs a write on each issue write.
    • Rejected: An index set for each repository. It adds a write to each issue write, a second structure to keep and a new failure path, and the tier holds no such index today.
    • Rejected: A KEYS command. KEYS blocks the server on the whole keyspace, and the tier does not expose it.
  • Which bound does the scan take?: SCAN with COUNT 500 in each call, repeated within a budget of 5 s and 10,000 keys for one removal. A removal that passes the budget stops, sends no further command, and counts the error. A key that the removal missed still ends at its 24-hour TTL. (best practice) [sources: src/devops_cli/valkey/cache.py:183, openspec/specs/project-brain/shared-cache/spec.md]
    • Chosen: A cursor loop with COUNT 500 and a budget of 5 s and 10,000 keys. Each call stays short, and the budget keeps a slow tier from holding the read of the issue.
    • Rejected: One SCAN call with no loop. A repository with many issues needs more than one cursor step.
    • Rejected: A removal with no bound. A slow or a large keyspace would hold the read of the issue, and the spec bounds each Valkey operation.
  • Which counter records a removal?: devops_cli_brain_writes_total{store="issue",result="removed"}, one time for each removal round that removed at least one key. (best practice) [sources: openspec/specs/project-brain/shared-cache/spec.md, src/devops_cli/roadmap/stores/brain_issues.py]
    • Chosen: A removed result on the existing write counter. The snapshot store counts its removal as removed on the same counter, and the label values stay in the fixed set of the source.
    • Rejected: Reuse the result private. A reader cannot tell a removal from a refused write.
    • Rejected: A new counter. It adds a second counter for one store, and the spec names four counters.
  • Does the removal meet the 1-hour bound of the spec?: Yes. A process keeps a public answer for 30 min, so it reads the visibility again at most 30 min after the change and removes at that read. The shared tier holds no issue record of the repository later than 1 hour after the change. [sources: openspec/specs/project-brain/shared-cache/spec.md, src/devops_cli/config/defaults.py:774, src/devops_cli/roadmap/stores/visibility.py]
  • Does the MATCH pattern stay inside the keys of one repository?: Yes. The pattern ends with the literal : after the casefolded RepoRef.key, and a key of dan-petty/devops-cli-2 holds -2: where the pattern holds :. ADR 0022 records that * spans : in a Valkey pattern, so the trailing * matches only the number part of a key of the same repository. [sources: openspec/specs/project-brain/shared-cache/spec.md, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:39, src/devops_cli/github/repo_ref.py]
  • How does a test prove that the spec holds the 1-hour bound?: openspec validate --strict validates the change folder and its spec delta. The requirement text of the delta carries the bound, and a test that reads the Markdown asserts no value of the document. (best practice) [sources: openspec/config.yaml, openspec/specs/project-brain/shared-cache/spec.md]
    • Chosen: openspec validate --strict on the change folder. OpenSpec is the spec layer, and the validator checks the delta that holds the requirement.
    • Rejected: A test that reads the spec Markdown. A test asserts no value of a document, and the validator already checks the delta.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 26, 2026
  2. added
    priority/p2-medium
    on Nov 26, 2026
  3. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (8)

    Tools considered:

    Searches run:

    • open source cache invalidation when GitHub repository becomes private webhook, results: 5
    • Valkey delete keys by pattern SCAN MATCH UNLINK bulk, results: 5
    • valkey SCAN command documentation cursor COUNT MATCH, results: 5
    • redis-py scan_iter delete keys pattern, results: 5
    • valkey.io commands SCAN, results: 5
    • redis key eviction by prefix pattern unlink production safe, results: 5
    • Valkey keyspace notifications library python cache invalidation, results: 5
    • GitHub App webhook repository privacy change purge cached data service, results: 5

    Sources:

  4. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Design check, 2026-11-26

    Body, 1 correction: the sentence "the cache tier has no scan of keys" was true before #7320. The tier now has scan (src/devops_cli/valkey/cache.py:183) and unlink (src/devops_cli/valkey/cache.py:196). The brain index uses scan (src/devops_cli/roadmap/brain_index.py:189).

    Premise: it is true. src/devops_cli/roadmap/stores/brain_issues.py has no scan and no removal of the keys of one repository.

    Service blocks: no error found. This item has no refine block yet.

    Dependencies: #7292 is closed (#7297). No open item blocks this item.

    Related: the comment of 2026-11-26 on #4687 gives the same case for the brain index.

  5. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  6. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  9. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 17:56 UTC

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/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions