Skip to content

[Spec 1647] tower-collapse-the-four-per-wo - #2004

Draft
waleedkadous wants to merge 70 commits into
mainfrom
builder/spir-1647
Draft

waleedkadous wants to merge 70 commits into
mainfrom
builder/spir-1647

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A new forge concept, overview-bundle, returns all four forge-backed sections of Tower's overview (open PRs, open issues, issues closed and PRs merged in the last 24 h) from one invocation. On GitHub its script sends one gh api graphql request and pages inside the same invocation up to today's caps (PRs 30, issues 200, searches 1,000). OverviewCache uses it per workspace when configuration allows and otherwise makes the four existing calls, unchanged. A failed bundle is never retried as four calls.

Refs #1647. The close keyword is left out on purpose: the architect asked to handle closing #1647 and its deliberate copy #1995 themselves. Swap in Closes #1647 if the merge should close it.

Per watched workspace, per idle hour, on GitHub:

today bundled
forge concept invocations 52 20
gh processes (more than 100 open issues / 100 or fewer) 52 / 52 40 / 20
HTTP requests (more than 100 open issues) 72 40
GraphQL points (more than 100 open issues) 112 100

Live on this repository: one refresh is one invocation and 2 gh processes, costing 5 points where the four calls cost 7.

Changes

  • Concept and script. overview-bundle is in KNOWN_CONCEPTS, and OverviewBundleResult in forge-contracts.ts documents the input (CODEV_SINCE_DATE) and four required keys, each an array or null. scripts/forge/github/overview-bundle.sh:
    • fixed query texts, with every dynamic value passed as a GraphQL variable;
    • -F only where gh must expand {owner}/{repo}, cursors through -f;
    • search-path-only GraphQL errors null that section and exit 0; everything else fails the whole bundle with gh's status and stderr;
    • every gh runs in the background with wait, so the dispatcher's timeout kills it promptly, and temp files are cleaned up by a trap.
  • Mode, projection and doctor. resolveOverviewPlan() in forge.ts picks the mode from configuration alone. The bundle is used when it resolves to a command and either the project overrides it, or no constituent is overridden or disabled. gitlab, gitea, linear and jira disable it; for the two hybrids that is a correctness requirement. The new src/lib/overview-budget.ts owns the overview TTLs, the debounce and projectHourlyForgeCalls(). codev doctor lists the concept and prints an overview line with the mode, reason and projected calls/hour, e.g. bundled — 20 forge calls/h idle, 60 under constant invalidation.
  • Cache. OverviewCache holds one bundle entry per workspace at the 180 s list TTL, through the unchanged tower: overview cache burns the user's entire GitHub GraphQL quota (3 gh calls × N workspaces every 30s, failures uncached) — every gh command on the machine then fails #1645 cachedFetch, so single-flight, debounced invalidation, the negative cache and suspension all carry over. The bundle is split back into the four section outcomes getOverview already reads, so /api/overview is unchanged. Its 24 h lists now refresh every 180 s instead of 600 s.
  • Docs. forge.md gains a Tower Overview section and a GitLab override sketch. arch.md and both forge SKILL.md files describe the concept, and the stale "18 concepts" counts are corrected to 21.

Behaviour changes adopters can see (all approved at the spec gate):

  • A repository with issues disabled now shows an empty backlog with forgeStatus: ok, instead of "could not fetch issues".
  • Any whole-bundle failure blanks all four sections for that workspace until the failure window passes. Today the 24 h lists survive a list failure on their own 600 s entries.

PR-review hardening (43573c0):

  • A rate limit reported only in the GraphQL body is now named on stderr, so the rate limiter suspends the budget.
  • The last issue page and search page 10 no longer fail on a "next page" without a cursor.
  • The fake gh releases its lock if killed (since replaced; see below).

PR-review round 2 (7864b9a, ea435ef):

  • The script tests now run on native Windows (gated on jq, not on the platform).
  • Fixed a Windows-only bug those tests found. jq.exe writes CRLF, so with both searches failed, closed\r matched no section and a search-local failure became a whole-bundle failure. Classification now goes by jq -e exit status, and cursors are read with -j. A CRLF jq shim pins it on POSIX.
  • resolveOverviewPlan() no longer reads every concept script on each poll: the new source-only resolver does no file I/O.
  • A test holds the script's rate-limit ERE equal to the limiter's regex.

After review round 3: the PR's Linux CI (acd756a). The Unit Tests check (ubuntu) had failed on every push since this PR opened. I had been citing local macOS runs as "the full suite"; that is corrected below.

  • A real Linux bug in the timeout path. Debian and Ubuntu's dash carries patch 0004, which disables the "exec the last command of sh -c" optimization. Node's exec timeout therefore SIGTERMed only the outer dash: overview-bundle.sh's traps never ran, gh outlived the limit and the temp directory stayed. Reproduced on macOS by building dash 0.5.12 with that one patch. POSIX execShellString/execShellStringSync (platform/posix/command-launch.ts) now run a bare absolute path to an existing .sh as exec '<path>', the POSIX counterpart of Windows' existing bare-script case. Every other shell string is passed through unchanged. Pinned by a mocked string-form test, spec-1647-posix-script-exec.test.ts (a script path with a space and a quote; on timeout, the script's TERM trap runs and its child dies), and exit status 143 asserted in the script timeout test. All three new tests fail with the fix disabled.
  • A harness flake, with its cause found. The end-to-end tests lost one fake gh call in about a third of Linux runs, a different call each time. The runner image had moved to ubuntu-26.04, whose uutils mkdir (rust-coreutils 0.8 to 0.10, fixed upstream in 0.11) reports success when it loses a race to create the same directory. The fake used mkdir for exclusion, first as a lock and then as a numbered claim. An invocation log in the failure message showed two pids both claiming n=1. The fake now claims call.N by creating it under noclobber (O_EXCL, done by the shell itself), and a regression test puts an always-succeeding mkdir first on PATH. Two diagnostics stay: a guard gh after the fake on PATH, which keeps a real gh from ever running in these tests, and CODEV_DEBUG in the e2e file. No shipped script uses mkdir for exclusion.

Adjacent fixes in this PR:

  • mergedPRCache was typed ForgePR[] although recently-merged returns MergedPrItem[]. It is retyped, and a merged PR without a url now links nothing; the JSON payload is unchanged.
  • forge.md's codev doctor sample used a format doctor no longer prints. It is replaced with real current output.

Testing

  • Linux CI (ubuntu-26.04), the PR's own Tests workflow: green on b455181 (45970788650), all 6 jobs, with the Unit Tests job passing 8 of 8 attempts. Unit Tests: 466 files passed, 14 skipped; 10,144 tests passed, 125 skipped. Until acd756a that check failed on every push. From acd756a to b455181 it failed about 1 run in 3 (the mkdir flake).
  • Local packages/codev suite (macOS) on b455181: 466 files passed, 14 skipped; 10,153 tests passed, 116 skipped.
  • New tests:
    • spec-1647-overview-bundle-script.test.ts: parity with the four sibling scripts on a state recorded from real GitHub, process counts and paging, argument guards, classification, hostile strings, timeout.
    • spec-1647-overview-plan.test.ts: mode resolution, the projection, doctor text.
    • spec-1647-fetch-overview-bundle.test.ts: limits, contract checks, the 24 h filter.
    • spec-1647-overview-bundle-cache.test.ts and spec-1647-overview-bundle-gh.test.ts: cache semantics, rate limit, timeout, mode selection, end-to-end OverviewData parity between the two modes.
  • Re-pinned only where the call count is under test: the tower: overview cache burns the user's entire GitHub GraphQL quota (3 gh calls × N workspaces every 30s, failures uncached) — every gh command on the machine then fails #1645 harness, which keeps a four-call twin. overview.test.ts and overview-rate-limit.test.ts pin four-call mode in one block each, as the kept four-call variant.
  • Each phase broke its own guards on purpose (trap without kill, rate-limit check, bot prefix, 24 h filter, null-section text, debounce constant). Each break turned exactly the expected tests red.
  • Live check against this repository with real gh, in both modes: same pendingPRs, backlog and recentlyClosed, same key sets. Both search sections equal their sibling concepts' results.
  • Windows (Git Bash), full suites on acd756a (this PR touches POSIX platform code): 45962329341, all jobs green. Its codev unit tests: 465 files passed, 15 skipped; 9,826 tests passed, 442 skipped. That includes the 5 cache end-to-end tests with the new fake gh numbering and 36 script tests; spec-1647-posix-script-exec.test.ts is POSIX-only and skips by design.
  • Windows (Git Bash), targeted on b455181 (the fake's new claim): 45970799116, 110 passed, 16 skipped, including the 5 end-to-end tests and the new numbering test.
  • Windows (Git Bash), earlier targeted run: 45956770907 on ea435ef, -f filter=spec-1647. All 5 cache end-to-end tests (real OverviewCache → dispatcher → Git Bash → script) and 36 script tests passed; 14 skipped by design. The skipped ones are the direct /bin/sh runs, the hostile cursor (its route file name is illegal on NTFS), the signal-based timeout kill, and the CRLF shim, which Windows covers with the real jq.exe. Correction: the two earlier runs ran none of these tests (45952952774 was green, and 45954554101's unit-test job ended without finishing), because both files were gated off win32 until the second PR review caught it. The first real run then found the CRLF bug below.
  • Not done yet, at verify: a browser check of the Work view on the architect's install (it needs a Tower restart, which needs the owner's permission).

Consultation: two lanes (codex, claude) for the spec, the plan and each of the four phases. All four implementation phases came back APPROVE. Dispositions are in the review doc.

Spec

codev/specs/1647-tower-collapse-the-four-per-wo.md

Review

codev/reviews/1647-tower-collapse-the-four-per-wo.md

…script

Register the overview-bundle forge concept with its OverviewBundleResult
contract, disable it in the gitlab, gitea, linear and jira presets, and
count it as an issue concept for id-kind detection.

The GitHub script returns open PRs, open issues and both 24 h search
windows from one gh api graphql request, paging only on overflow up to
the sibling concepts' caps. Search-local GraphQL errors null their
section; everything else fails the whole bundle with gh's status and
stderr. gh runs in the background so the timeout's SIGTERM reaches the
trap, and jq only ever reads staged files through redirection.

Parity is proven against the four sibling scripts on a state recorded
from real gh (grafana/grafana), with constructed team/bot reviewer and
null-author cases.
# Conflicts:
#	packages/codev/src/agent-farm/servers/overview.ts
…ce-only plan resolution; pin the rate-limit pattern
@waleedkadous
waleedkadous marked this pull request as draft November 27, 2026 07:29
…t signals the script

Debian and Ubuntu build dash without the exec-last-command optimization for
sh -c (Debian patch 0004), so Node's exec timeout killed only the outer shell:
overview-bundle.sh's traps never ran, gh outlived the limit and the temp
directory stayed. Linux CI's Unit Tests check failed on this on every push.

Also number the fake gh's calls by atomic mkdir claims instead of a locked
count file, which lost a call under load on Linux CI.
The e2e tests still lose a call intermittently on Linux CI with mkdir
numbering, so the counter was not the cause. A guard gh next on PATH records
any call that falls through the fake (and keeps a real gh from running), and
CODEV_DEBUG plus the cache's status in the assertion message capture what the
lost call did.
…kdir

The Linux runner is now ubuntu-26.04, whose uutils mkdir (rust-coreutils
0.8-0.10; fixed upstream in 0.11) reports success when it loses a race to
create the same directory. The fake gh used mkdir for exclusion, so two
concurrent calls could claim one number and a call went missing in about a
third of CI runs. The invocation log showed two pids both claiming n=1.

Claim by creating call.N under noclobber, which the shell opens with
O_EXCL. A regression test puts an always-succeeding mkdir first on PATH.
The temporary invocation log is removed.
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.

1 participant