Skip to content

tower: scope overview invalidation to forge-visible events, so the TTLs govern spend #1650

Open

Description

@waleedkadous

Context

#1646 fixed the runaway that exhausted the GitHub GraphQL budget, and set positive TTLs of
180 s (open PR/issue lists) and 600 s (the two 24 h search windows) to bound forge spend.

Those TTLs do not govern spend as completely as they look, because
POST /api/overview/refresh bypasses them by design — a refresh means "fetch now" — and
that route is fired automatically, not by a human:

  • commands/porch/index.ts — after every mutating porch command
  • apps/vscode/src/review-queue/overview-nudge.ts — every review-queue mutation
  • agent-farm/commands/cleanup.ts

In a workspace with a dozen builders running porch, the invalidation rate governed spend
rather than the TTLs. #1646 shipped a 60 s debounce on invalidation-driven refreshes,
which puts a ceiling back on (~4× idle for the busiest workspace) but is a cap on the
symptom.

The actual problem

Almost none of those invalidations can have changed the forge lists. A porch phase
transition moves builder state — which is filesystem-derived and refreshes on every 2.5 s
poll regardless of any cache. The forge-backed lists change only when a PR is opened or
merged, or an issue is closed.

So the overview cache is being told "your GitHub data is stale" by events that cannot have
made it stale.

What to build

Scope the invalidation to what actually changed.

  • The refresh route takes a scope — e.g. POST /api/overview/refresh?scope=forge|local.
  • porch sends forge only for the commands that touch a PR or issue (porch done --pr N,
    --merged N, issue closure); everything else sends local, which invalidates nothing
    forge-backed.
  • VSCode's review-queue nudge and cleanup are audited the same way.
  • local refreshes skip the debounce (they cost nothing); forge refreshes keep it.
  • A test asserting a phase-transition refresh spends no forge commands.

Touches porch's Tower client, the route contract, TowerClient.refreshOverview(), and
OverviewCache.invalidate().

Rejected alternative

Make invalidate() simply stop clearing the forge caches. Correct in effect and a
one-line change, but it silently removes a behaviour people rely on: #388 added
refresh-forces-refetch so a dashboard user pressing Refresh gets fresh GitHub data, and a
genuine PR merge would then take up to 180 s to appear with no way to hurry it. Scoping
keeps the fast path for events that warrant it and drops it only for events that do not,
which is the distinction that was missing rather than the behaviour itself.

Acceptance

Follow-up to #1645, architect decision 2026-09-08. See also #1647 (collapse the four
per-workspace calls into one GraphQL query) and #1648 (human-only early escape from a
rate-limit suspension).

Activity

  1. added
    area/tower
    on Sep 8, 2026
  2. added a commit that references this issue on Sep 8, 2026
  3. waleedkadous commented on Sep 8, 2026

    @waleedkadous
    ContributorAuthor

    Additional scope, found in #1646's round-9 review (codex).

    OverviewCache.invalidate() is global across workspaces, not just global across concepts.
    It clears the cached entries for every workspace, so one workspace's automated refresh
    forces a refetch in every watched workspace — each of which then spends four forge
    commands on its next poll.

    That multiplies the cost of every honoured invalidation by the number of watched workspaces:

    1 honoured invalidation x 13 watched workspaces x 4 concepts = 52 calls
    x 60 honoured invalidations/h (the debounce ceiling)          = 3,120 calls/h
    

    The 60 s debounce in #1646 bounds the rate of invalidations, not their fan-out. Scoping
    therefore has to be two-dimensional, and this issue should cover both:

    1. Which events invalidate (the original scope of this issue) — a porch phase transition
      cannot have changed any forge list.
    2. Which workspace an invalidation applies to — a porch command in workspace A cannot have
      changed workspace B's GitHub data.

    For (2), the refresh route would carry the originating workspace (?workspace=), the SDK's
    refreshOverview() would pass it, and invalidate(workspaceRoot?) would drop only that
    workspace's entries — falling back to the current global behaviour when no workspace is given,
    so nothing regresses for callers that do not send one.

    #1646 deliberately did not add that plumbing: with no caller sending the parameter it would
    have been unreachable code, which is the exact class of thing that PR's review kept catching.

  4. waleedkadous commented on Sep 8, 2026

    @waleedkadous
    ContributorAuthor

    Correction: #1646 was superseded, not merged

    This issue's body says PR #1646 shipped part of the fix. It did not — #1646 was closed
    unmerged on 2026-09-08 and the core is being rebuilt on a fresh branch (architect decision;
    ten rounds of fix-on-fix, and one commit whose message described changes it did not contain).

    So the behaviour this issue builds on does not exist yet. Read the body as describing the
    design that #1645's rebuild will land, not the current state of main.

    The specific invariants are captured as one-line testable statements in the rebuild's pitfall
    list (/tmp/bugfix-1645-pitfalls.md, attached to the #1645 lane), including the ones this
    issue depends on. Sequence this work after the rebuild lands.

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

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions