Skip to content

org discovery is re-fetched per filter: one listing per script, and a race window between them #292

Open

Description

@aitrawog

What is true now

lib-org.sh fetches the org listing once per FILTER, not once per process: discover_repos, discover_excludes and discover_membership each call discover_all as their own command substitution. A bash command substitution runs in a subshell, so a memo held in a variable cannot survive from one filter to the next — which is why each re-fetches.

Each read is paged and count-checked (#290), so no single read can understate the org. What the multiplicity costs is narrower than correctness, but it is real:

  • A race window: a repo created between the targets read and the excludes read is in NEITHER set. Nothing reads the two together, so nothing notices.
  • Two or three paged listings per script run against an org of 486 repos — org-ruleset.sh issues three (discover_repos, discover_excludes, discover_membership), reconcile-tag-on-merge-callers.sh two.
  • Independent failure: the second read can fail after the first succeeded. org-ruleset.sh aborts at that call site, and its coverage now exists (FORCE_SECOND_DISCOVERY_FAIL), so this is handled — but it is handled rather than prevented.

What would fix it

One read per SCRIPT, with the filters as pure stdin transforms:

rows="$(discover_all)" || exit 1                     # once
targets="$(printf '%s\n' "$rows" | discovery_targets)"
excludes="$(printf '%s\n' "$rows" | discovery_excludes)"

That removes the race and the extra listings, and it collapses the second-read failure path — which is the reason it is its OWN change: six scripts call these helpers (org-ruleset.sh, reconcile-tag-on-merge-callers.sh, both retire-per-repo-*, strip-config-version.sh, governance-reconcile.sh), and each has its own coverage that has to move with it. Doing it inside the paging fix would have mixed two mechanisms in one gate.

Agent: containerd-crabbox-program · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud

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

    category:governancetype:chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions