lastlight-core 0.32.1 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/default.yaml +81 -0
- package/dist/admin/board-cache.d.ts +81 -0
- package/dist/admin/board-cache.js +301 -0
- package/dist/admin/board-cache.js.map +1 -0
- package/dist/admin/board-stream.d.ts +47 -0
- package/dist/admin/board-stream.js +45 -0
- package/dist/admin/board-stream.js.map +1 -0
- package/dist/admin/board.d.ts +264 -0
- package/dist/admin/board.js +376 -0
- package/dist/admin/board.js.map +1 -0
- package/dist/admin/routes.js +943 -13
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +88 -0
- package/dist/config/config.js +163 -0
- package/dist/config/config.js.map +1 -1
- package/dist/connectors/github-webhook.d.ts +16 -0
- package/dist/connectors/github-webhook.js +104 -8
- package/dist/connectors/github-webhook.js.map +1 -1
- package/dist/connectors/types.d.ts +9 -2
- package/dist/cron/issue-discovery.d.ts +120 -0
- package/dist/cron/issue-discovery.js +127 -0
- package/dist/cron/issue-discovery.js.map +1 -0
- package/dist/cron/runner.d.ts +25 -1
- package/dist/cron/runner.js +53 -10
- package/dist/cron/runner.js.map +1 -1
- package/dist/engine/build-decisions.d.ts +91 -0
- package/dist/engine/build-decisions.js +295 -0
- package/dist/engine/build-decisions.js.map +1 -0
- package/dist/engine/build-gate.d.ts +78 -0
- package/dist/engine/build-gate.js +355 -0
- package/dist/engine/build-gate.js.map +1 -0
- package/dist/engine/executors/shared.d.ts +1 -0
- package/dist/engine/executors/shared.js +13 -2
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/github/github-app-client.js +25 -1
- package/dist/engine/github/github-app-client.js.map +1 -1
- package/dist/engine/github/github.d.ts +195 -6
- package/dist/engine/github/github.js +331 -6
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +23 -0
- package/dist/engine/pr-decisions.js.map +1 -1
- package/dist/engine/router.js +108 -1
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/stage-advance.d.ts +92 -0
- package/dist/engine/stage-advance.js +129 -0
- package/dist/engine/stage-advance.js.map +1 -0
- package/dist/engine/stage-labels.d.ts +57 -0
- package/dist/engine/stage-labels.js +58 -0
- package/dist/engine/stage-labels.js.map +1 -0
- package/dist/engine/stage-observer.d.ts +79 -0
- package/dist/engine/stage-observer.js +221 -0
- package/dist/engine/stage-observer.js.map +1 -0
- package/dist/index.js +110 -2
- package/dist/index.js.map +1 -1
- package/dist/logging/phase-log.d.ts +6 -0
- package/dist/logging/phase-log.js +16 -0
- package/dist/logging/phase-log.js.map +1 -1
- package/dist/state/activity-store.d.ts +45 -1
- package/dist/state/activity-store.js +44 -0
- package/dist/state/activity-store.js.map +1 -1
- package/dist/state/execution-store.d.ts +48 -0
- package/dist/state/execution-store.js +112 -0
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/schema/pg.d.ts +2 -2
- package/dist/state/schema/sqlite.d.ts +2 -2
- package/dist/state/workflow-run-store.d.ts +51 -0
- package/dist/state/workflow-run-store.js +98 -0
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/simple.d.ts +40 -1
- package/dist/workflows/simple.js +113 -2
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +4 -4
- package/workflows/cron-autonomy.yaml +24 -0
- package/workflows/prompts/pr.md +18 -1
package/config/default.yaml
CHANGED
|
@@ -670,6 +670,81 @@ review:
|
|
|
670
670
|
# affected — an absent field is not a zero.
|
|
671
671
|
internalFloor: 0.15
|
|
672
672
|
|
|
673
|
+
# The software-factory pipeline (label-driven autonomy).
|
|
674
|
+
#
|
|
675
|
+
# An issue labelled `ready-for-agent` on a repo listed below dispatches a gated
|
|
676
|
+
# `build` run: the harness moves the label on, runs the workflow behind its
|
|
677
|
+
# human approval gates, and parks the result on a label a human reads.
|
|
678
|
+
#
|
|
679
|
+
# IT SHIPS INERT. `repos: []` means no issue label routes anywhere — the router
|
|
680
|
+
# reads this block on every `issue.labeled` event, and with no repo listed the
|
|
681
|
+
# label is not a pipeline stage at all, so the event is dropped where it
|
|
682
|
+
# arrives. A deployment that says nothing about `autonomy:` behaves exactly as
|
|
683
|
+
# it did before the block existed.
|
|
684
|
+
#
|
|
685
|
+
# OPERATOR-ONLY, deliberately — the same reasoning `review.analysis` carries
|
|
686
|
+
# above. Autonomy is SPEND on the operator's budget, and there is no "more
|
|
687
|
+
# conservative" direction for a repo to clamp it toward, so there is no
|
|
688
|
+
# repo-settable autonomy key and `repoConfig.allowKeys` must NOT gain one: a
|
|
689
|
+
# repo that could add itself here could spend the operator's money by committing
|
|
690
|
+
# a file. A repo opts OUT with the affordances it already owns — an explicit
|
|
691
|
+
# `disabled.workflows: [build]` in its `.lastlight/lastlight.yml` turns the
|
|
692
|
+
# pipeline off for the whole repo, and the hold label turns it off for one
|
|
693
|
+
# issue.
|
|
694
|
+
autonomy:
|
|
695
|
+
# Exact `owner/repo` names. NO GLOBS, by design: enabling an org by pattern is
|
|
696
|
+
# how a repo nobody reviewed acquires an agent — and a budget — the moment
|
|
697
|
+
# somebody creates it. Matching is exact string equality
|
|
698
|
+
# (`isAutonomousRepo()`); `owner/*` is a repo name that will never exist.
|
|
699
|
+
repos: []
|
|
700
|
+
# The stages a label can start. `build` is the one shipped stage.
|
|
701
|
+
stages:
|
|
702
|
+
build:
|
|
703
|
+
# The label a human — or the triage agent — applies to START the stage. A
|
|
704
|
+
# stage with no `enter` label can never fire, so config load DROPS one
|
|
705
|
+
# rather than keeping it: a stage that is present in the `/config` view
|
|
706
|
+
# and unreachable in fact is a silent trap.
|
|
707
|
+
enter: ready-for-agent
|
|
708
|
+
# What the harness advances the label to AT DISPATCH — before the run has
|
|
709
|
+
# started, not after it finishes. That ordering is the whole point: while
|
|
710
|
+
# `enter` is still on the issue, every backstop sweep and every re-
|
|
711
|
+
# delivered webhook sees a pipeline entry it is entitled to pick up, and
|
|
712
|
+
# dispatches the same build again. Moving the label first makes the issue
|
|
713
|
+
# its own lock.
|
|
714
|
+
running: agent-building
|
|
715
|
+
on_success: ready-for-human # terminal — a human reviews, and merges, the PR
|
|
716
|
+
on_failure: agent-blocked # terminal — the run stopped; a human reads why
|
|
717
|
+
workflow: build
|
|
718
|
+
# Human-in-the-loop approval gates, ON by default and merged ADD-ONLY onto
|
|
719
|
+
# the run's effective approval map: this block can turn a gate ON that the
|
|
720
|
+
# workflow left off, never off one the operator's `approval:` block asked
|
|
721
|
+
# for. The names are the gates `workflows/build.yaml` already declares.
|
|
722
|
+
gates:
|
|
723
|
+
post_architect: true
|
|
724
|
+
post_reviewer: true
|
|
725
|
+
# What becomes of the pull request the build opens:
|
|
726
|
+
# none the PR parks at `on_success` and a human merges it —
|
|
727
|
+
# the default, and the only value that ships on
|
|
728
|
+
# auto the build agent enables GitHub AUTO-MERGE, so CI and
|
|
729
|
+
# branch protection still gate the merge; the agent
|
|
730
|
+
# never presses the button itself
|
|
731
|
+
# auto-low-impact NOT IMPLEMENTED YET, and it is worth saying plainly:
|
|
732
|
+
# there is no impact signal for a FEATURE PR today
|
|
733
|
+
# (`dependencies.autoMergeMaxImpact` scores dependency
|
|
734
|
+
# bumps and nothing else). The value is accepted and
|
|
735
|
+
# recorded, and behaves as `none` until one exists.
|
|
736
|
+
on_merge: none
|
|
737
|
+
# Bounds on the pipeline as a whole, enforced at the DISPATCH GATE — before a
|
|
738
|
+
# run starts, never mid-flight — and EVERY refusal is recorded, so "a quiet
|
|
739
|
+
# day" and "the budget said no" are distinguishable after the fact. They bound
|
|
740
|
+
# the one real failure mode: a label applied in bulk by a triage sweep, a
|
|
741
|
+
# re-import or another bot, turning into N concurrent agent runs.
|
|
742
|
+
budget:
|
|
743
|
+
maxConcurrentBuilds: 2 # across every repo, at any instant
|
|
744
|
+
maxBuildsPerRepoPerDay: 3 # per repo, rolling day
|
|
745
|
+
dailyUsd: 25 # deployment-wide model spend per day
|
|
746
|
+
repoDailyUsd: 10 # one repo's share of it
|
|
747
|
+
|
|
673
748
|
# Retry policy for every PR_FIX_SHAPED workflow — pr-fix and dependabot-ci-fix
|
|
674
749
|
# (issue #251). The loop diagnoses a CI failure before it retries, and these are
|
|
675
750
|
# the budgets that bound it.
|
|
@@ -746,6 +821,12 @@ routes:
|
|
|
746
821
|
issue_opened: issue-triage
|
|
747
822
|
issue_answer: answer
|
|
748
823
|
issue_reopened: issue-triage
|
|
824
|
+
# A pipeline STAGE label was applied to an issue (the software-factory
|
|
825
|
+
# flow). The router drops every label that is not a configured
|
|
826
|
+
# `autonomy.stages.*.enter`, so this is inert until `autonomy.repos` names
|
|
827
|
+
# a repo — and it is guard 1 of the four that replace the bot-sender filter
|
|
828
|
+
# we deliberately opened for `issues.labeled`.
|
|
829
|
+
issue_labeled: build
|
|
749
830
|
pr_opened: pr-review
|
|
750
831
|
pr_synchronize: pr-review
|
|
751
832
|
pr_reopened: pr-review
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The board's live-item cache — what stops a browser poll becoming a GitHub
|
|
3
|
+
* bill.
|
|
4
|
+
*
|
|
5
|
+
* Modelled on `src/config/repo-config.ts`: a module-level cache, a TTL, a
|
|
6
|
+
* `force` escape hatch, degrade-to-last-good, and a `resetBoardCacheForTests()`
|
|
7
|
+
* that matches the convention. What it adds over that one is the two properties
|
|
8
|
+
* a per-request dashboard read needs and a per-dispatch config read did not.
|
|
9
|
+
*
|
|
10
|
+
* **Single-flight per OWNER batch.** N dashboards refreshing at once cost ONE
|
|
11
|
+
* GraphQL document, because the second caller awaits the first's in-flight
|
|
12
|
+
* promise instead of starting its own. Keyed on the owner rather than the repo
|
|
13
|
+
* because `GitHubClient.listOpenBoardItems` batches by owner — that is where
|
|
14
|
+
* the installation token, and therefore the request, lives.
|
|
15
|
+
*
|
|
16
|
+
* **Stale-while-revalidate.** A cached answer is served IMMEDIATELY and the
|
|
17
|
+
* refresh runs behind the request. This is the property that matters most: a
|
|
18
|
+
* 20 s poll that blocked on GitHub would turn every slow GitHub minute into a
|
|
19
|
+
* stalled dashboard, and worse, would hold the refresh open long enough for the
|
|
20
|
+
* next poll to start another. Only a repo with NO last-good answer is waited
|
|
21
|
+
* on — there is nothing to serve for it. The same shape
|
|
22
|
+
* `TeamVisibilityResolver.visibleRepos` uses.
|
|
23
|
+
*
|
|
24
|
+
* **Per-owner exponential backoff.** GraphQL `search` is subject to GitHub's
|
|
25
|
+
* SECONDARY rate limits, which are not the documented point budget and carry no
|
|
26
|
+
* warning. A throttled owner is left alone for a growing window rather than
|
|
27
|
+
* retried on the next poll, which is how a rate-limited board stops making
|
|
28
|
+
* things worse for the harness's own work.
|
|
29
|
+
*
|
|
30
|
+
* The highest-value freshness lever is NOT a shorter TTL — it is
|
|
31
|
+
* {@link invalidateBoard}, which a later slice wires to the `issue.labeled`
|
|
32
|
+
* webhook so a human moving a card sees it move.
|
|
33
|
+
*/
|
|
34
|
+
import type { GitHubClient, BoardItem } from "../engine/github/github.js";
|
|
35
|
+
/**
|
|
36
|
+
* How long a repo's items are trusted. Two minutes, against a dashboard that
|
|
37
|
+
* polls at twenty seconds: the poll is then served from memory five times out
|
|
38
|
+
* of six, and the GitHub cost is a function of the TTL and the repo count
|
|
39
|
+
* alone — never of how many tabs are open.
|
|
40
|
+
*/
|
|
41
|
+
export declare const BOARD_TTL_MS = 120000;
|
|
42
|
+
/**
|
|
43
|
+
* Most often `?refresh=1` may actually force one repo. A refresh button held
|
|
44
|
+
* down, or a client that re-fetches on every render, must not be able to turn
|
|
45
|
+
* the TTL off.
|
|
46
|
+
*/
|
|
47
|
+
export declare const BOARD_FORCE_THROTTLE_MS = 10000;
|
|
48
|
+
export interface BoardItemsResult {
|
|
49
|
+
items: BoardItem[];
|
|
50
|
+
degraded: Array<{
|
|
51
|
+
repo: string;
|
|
52
|
+
error: string;
|
|
53
|
+
staleSince?: string;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
export interface BoardItemsOptions {
|
|
57
|
+
github: GitHubClient;
|
|
58
|
+
/** Bypass the TTL, subject to {@link BOARD_FORCE_THROTTLE_MS}. */
|
|
59
|
+
force?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Every open item across `repos` (qualified `owner/repo`), from cache where it
|
|
63
|
+
* is fresh and from GitHub where it is not.
|
|
64
|
+
*
|
|
65
|
+
* Never throws: a repo the fetch could not answer for contributes a `degraded`
|
|
66
|
+
* entry and whatever last-good items it has.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getBoardItems(repos: string[], opts: BoardItemsOptions): Promise<BoardItemsResult>;
|
|
69
|
+
/** The current cache revision — see {@link revision}. */
|
|
70
|
+
export declare function boardRevision(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Drop a repo's cached items (or every repo's, with no argument), so the next
|
|
73
|
+
* read goes to GitHub.
|
|
74
|
+
*
|
|
75
|
+
* Exported for the `issue.labeled` webhook: a human moving a card should see it
|
|
76
|
+
* move, and invalidating one repo is far cheaper than shortening the TTL for
|
|
77
|
+
* all of them.
|
|
78
|
+
*/
|
|
79
|
+
export declare function invalidateBoard(repo?: string): void;
|
|
80
|
+
/** Test-only: clear the cache, the in-flight map, the backoff state and the revision. */
|
|
81
|
+
export declare function resetBoardCacheForTests(): void;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The board's live-item cache — what stops a browser poll becoming a GitHub
|
|
3
|
+
* bill.
|
|
4
|
+
*
|
|
5
|
+
* Modelled on `src/config/repo-config.ts`: a module-level cache, a TTL, a
|
|
6
|
+
* `force` escape hatch, degrade-to-last-good, and a `resetBoardCacheForTests()`
|
|
7
|
+
* that matches the convention. What it adds over that one is the two properties
|
|
8
|
+
* a per-request dashboard read needs and a per-dispatch config read did not.
|
|
9
|
+
*
|
|
10
|
+
* **Single-flight per OWNER batch.** N dashboards refreshing at once cost ONE
|
|
11
|
+
* GraphQL document, because the second caller awaits the first's in-flight
|
|
12
|
+
* promise instead of starting its own. Keyed on the owner rather than the repo
|
|
13
|
+
* because `GitHubClient.listOpenBoardItems` batches by owner — that is where
|
|
14
|
+
* the installation token, and therefore the request, lives.
|
|
15
|
+
*
|
|
16
|
+
* **Stale-while-revalidate.** A cached answer is served IMMEDIATELY and the
|
|
17
|
+
* refresh runs behind the request. This is the property that matters most: a
|
|
18
|
+
* 20 s poll that blocked on GitHub would turn every slow GitHub minute into a
|
|
19
|
+
* stalled dashboard, and worse, would hold the refresh open long enough for the
|
|
20
|
+
* next poll to start another. Only a repo with NO last-good answer is waited
|
|
21
|
+
* on — there is nothing to serve for it. The same shape
|
|
22
|
+
* `TeamVisibilityResolver.visibleRepos` uses.
|
|
23
|
+
*
|
|
24
|
+
* **Per-owner exponential backoff.** GraphQL `search` is subject to GitHub's
|
|
25
|
+
* SECONDARY rate limits, which are not the documented point budget and carry no
|
|
26
|
+
* warning. A throttled owner is left alone for a growing window rather than
|
|
27
|
+
* retried on the next poll, which is how a rate-limited board stops making
|
|
28
|
+
* things worse for the harness's own work.
|
|
29
|
+
*
|
|
30
|
+
* The highest-value freshness lever is NOT a shorter TTL — it is
|
|
31
|
+
* {@link invalidateBoard}, which a later slice wires to the `issue.labeled`
|
|
32
|
+
* webhook so a human moving a card sees it move.
|
|
33
|
+
*/
|
|
34
|
+
import { logger } from "../logging/logger.js";
|
|
35
|
+
const log = logger("board");
|
|
36
|
+
/**
|
|
37
|
+
* How long a repo's items are trusted. Two minutes, against a dashboard that
|
|
38
|
+
* polls at twenty seconds: the poll is then served from memory five times out
|
|
39
|
+
* of six, and the GitHub cost is a function of the TTL and the repo count
|
|
40
|
+
* alone — never of how many tabs are open.
|
|
41
|
+
*/
|
|
42
|
+
export const BOARD_TTL_MS = 120_000;
|
|
43
|
+
/**
|
|
44
|
+
* Most often `?refresh=1` may actually force one repo. A refresh button held
|
|
45
|
+
* down, or a client that re-fetches on every render, must not be able to turn
|
|
46
|
+
* the TTL off.
|
|
47
|
+
*/
|
|
48
|
+
export const BOARD_FORCE_THROTTLE_MS = 10_000;
|
|
49
|
+
/**
|
|
50
|
+
* First backoff window after a throttle; doubles per consecutive failure.
|
|
51
|
+
*
|
|
52
|
+
* It starts ABOVE the TTL, deliberately. A backoff shorter than — or equal to —
|
|
53
|
+
* {@link BOARD_TTL_MS} can never bind: the read it would have refused is the
|
|
54
|
+
* read the cache was going to serve anyway, so the first poll past the TTL goes
|
|
55
|
+
* straight back to the throttled owner. Anything at or under the TTL here is a
|
|
56
|
+
* backoff that exists only in the code.
|
|
57
|
+
*/
|
|
58
|
+
const BACKOFF_BASE_MS = BOARD_TTL_MS * 2;
|
|
59
|
+
const BACKOFF_MAX_MS = 15 * 60_000;
|
|
60
|
+
const cache = new Map();
|
|
61
|
+
const inflight = new Map();
|
|
62
|
+
const backoff = new Map();
|
|
63
|
+
/**
|
|
64
|
+
* Every open item across `repos` (qualified `owner/repo`), from cache where it
|
|
65
|
+
* is fresh and from GitHub where it is not.
|
|
66
|
+
*
|
|
67
|
+
* Never throws: a repo the fetch could not answer for contributes a `degraded`
|
|
68
|
+
* entry and whatever last-good items it has.
|
|
69
|
+
*/
|
|
70
|
+
export async function getBoardItems(repos, opts) {
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
const wanted = [...new Set(repos.filter((r) => r.includes("/")))];
|
|
73
|
+
const byOwner = new Map();
|
|
74
|
+
for (const repo of wanted) {
|
|
75
|
+
const owner = repo.slice(0, repo.indexOf("/"));
|
|
76
|
+
const list = byOwner.get(owner) ?? [];
|
|
77
|
+
list.push(repo);
|
|
78
|
+
byOwner.set(owner, list);
|
|
79
|
+
}
|
|
80
|
+
const waits = [];
|
|
81
|
+
for (const [owner, ownerRepos] of byOwner) {
|
|
82
|
+
const stale = ownerRepos.filter((repo) => needsFetch(repo, now, opts.force === true));
|
|
83
|
+
if (stale.length === 0)
|
|
84
|
+
continue;
|
|
85
|
+
const blocked = backoff.get(owner);
|
|
86
|
+
if (blocked && now < blocked.until) {
|
|
87
|
+
log.debug("board fetch skipped — owner is backing off", {
|
|
88
|
+
owner,
|
|
89
|
+
untilMs: blocked.until - now,
|
|
90
|
+
});
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (opts.force)
|
|
94
|
+
for (const repo of stale)
|
|
95
|
+
markForced(repo, now);
|
|
96
|
+
const refresh = refreshOwner(owner, stale, opts.github);
|
|
97
|
+
// Wait ONLY for repos we have nothing at all to serve for. Everything else
|
|
98
|
+
// gets the cached answer now and the fresh one on the next poll.
|
|
99
|
+
if (stale.some((repo) => !cache.has(repo)))
|
|
100
|
+
waits.push(refresh);
|
|
101
|
+
}
|
|
102
|
+
if (waits.length > 0)
|
|
103
|
+
await Promise.all(waits);
|
|
104
|
+
const items = [];
|
|
105
|
+
const degraded = [];
|
|
106
|
+
for (const repo of wanted) {
|
|
107
|
+
const entry = cache.get(repo);
|
|
108
|
+
if (!entry) {
|
|
109
|
+
degraded.push({ repo, error: "No data for this repo yet." });
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
items.push(...entry.items);
|
|
113
|
+
if (entry.error) {
|
|
114
|
+
degraded.push({
|
|
115
|
+
repo,
|
|
116
|
+
error: entry.error,
|
|
117
|
+
staleSince: entry.staleSince ? new Date(entry.staleSince).toISOString() : undefined,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { items, degraded };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* How many times the cached GitHub answer has CHANGED.
|
|
125
|
+
*
|
|
126
|
+
* The board's SSE stream folds this into its signature so a dashboard can be
|
|
127
|
+
* told "refetch" without the server rendering a board per client per tick. It
|
|
128
|
+
* means the CONTENT changed — deliberately not "something was invalidated",
|
|
129
|
+
* which is a different and much noisier claim.
|
|
130
|
+
*
|
|
131
|
+
* That distinction is why {@link lastRendered} exists. `invalidateBoard`
|
|
132
|
+
* DELETES the entry, so a refresh afterwards has no cached copy left to compare
|
|
133
|
+
* against and would look like a change every time — and since every
|
|
134
|
+
* board-relevant webhook invalidates, that would push twice per delivery and
|
|
135
|
+
* wake every open tab for a label nothing on the board renders. Keeping the
|
|
136
|
+
* last rendered fingerprint outside the cache, so it survives invalidation, is
|
|
137
|
+
* what makes "push on change" true rather than aspirational.
|
|
138
|
+
*/
|
|
139
|
+
let revision = 0;
|
|
140
|
+
/**
|
|
141
|
+
* The last fingerprint each repo was seen to RENDER as, surviving cache
|
|
142
|
+
* invalidation. See {@link revision} for why it is not held on the entry.
|
|
143
|
+
*/
|
|
144
|
+
const lastRendered = new Map();
|
|
145
|
+
/** Record what a repo now renders as, moving {@link revision} only on a change. */
|
|
146
|
+
function noteRendered(repo, signature) {
|
|
147
|
+
if (lastRendered.get(repo) === signature)
|
|
148
|
+
return;
|
|
149
|
+
lastRendered.set(repo, signature);
|
|
150
|
+
revision++;
|
|
151
|
+
}
|
|
152
|
+
/** A repo whose read failed renders as its degraded self, whatever the message. */
|
|
153
|
+
const DEGRADED = "!degraded";
|
|
154
|
+
/** The current cache revision — see {@link revision}. */
|
|
155
|
+
export function boardRevision() {
|
|
156
|
+
return revision;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* What the board would RENDER for one repo, as a comparable string.
|
|
160
|
+
*
|
|
161
|
+
* Numbers and labels only: those are what decide which column a card sits in
|
|
162
|
+
* and what it shows. A title edit is not worth waking every dashboard for, and
|
|
163
|
+
* the next TTL read will carry it anyway.
|
|
164
|
+
*/
|
|
165
|
+
function fingerprint(items) {
|
|
166
|
+
return items
|
|
167
|
+
.map((item) => `${item.number}:${item.labels.map((l) => l.name).sort().join(",")}`)
|
|
168
|
+
.sort()
|
|
169
|
+
.join("|");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Drop a repo's cached items (or every repo's, with no argument), so the next
|
|
173
|
+
* read goes to GitHub.
|
|
174
|
+
*
|
|
175
|
+
* Exported for the `issue.labeled` webhook: a human moving a card should see it
|
|
176
|
+
* move, and invalidating one repo is far cheaper than shortening the TTL for
|
|
177
|
+
* all of them.
|
|
178
|
+
*/
|
|
179
|
+
export function invalidateBoard(repo) {
|
|
180
|
+
// Deliberately does NOT move the revision. Forgetting an answer is not a
|
|
181
|
+
// claim that the board changed — the next read is what discovers whether it
|
|
182
|
+
// did, and `noteRendered` signals then. The webhook hook fires for every
|
|
183
|
+
// board-relevant delivery on every managed repo, the vast majority of which
|
|
184
|
+
// change nothing any dashboard is rendering.
|
|
185
|
+
if (repo)
|
|
186
|
+
cache.delete(repo);
|
|
187
|
+
else
|
|
188
|
+
cache.clear();
|
|
189
|
+
}
|
|
190
|
+
/** Test-only: clear the cache, the in-flight map, the backoff state and the revision. */
|
|
191
|
+
export function resetBoardCacheForTests() {
|
|
192
|
+
cache.clear();
|
|
193
|
+
inflight.clear();
|
|
194
|
+
backoff.clear();
|
|
195
|
+
lastRendered.clear();
|
|
196
|
+
revision = 0;
|
|
197
|
+
}
|
|
198
|
+
/** Is this repo's entry missing, expired, or being legitimately forced? */
|
|
199
|
+
function needsFetch(repo, now, force) {
|
|
200
|
+
const entry = cache.get(repo);
|
|
201
|
+
if (!entry)
|
|
202
|
+
return true;
|
|
203
|
+
if (force && now - (entry.forcedAt ?? 0) >= BOARD_FORCE_THROTTLE_MS)
|
|
204
|
+
return true;
|
|
205
|
+
return now - entry.checkedAt >= BOARD_TTL_MS;
|
|
206
|
+
}
|
|
207
|
+
function markForced(repo, now) {
|
|
208
|
+
const entry = cache.get(repo);
|
|
209
|
+
if (entry)
|
|
210
|
+
entry.forcedAt = now;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* One GitHub round trip for one owner, shared by every concurrent caller.
|
|
214
|
+
*
|
|
215
|
+
* The promise is registered BEFORE the first await, so a second caller in the
|
|
216
|
+
* same tick finds it rather than starting a second document.
|
|
217
|
+
*/
|
|
218
|
+
function refreshOwner(owner, repos, github) {
|
|
219
|
+
const existing = inflight.get(owner);
|
|
220
|
+
if (existing)
|
|
221
|
+
return existing;
|
|
222
|
+
const run = (async () => {
|
|
223
|
+
const bare = repos.map((repo) => repo.slice(repo.indexOf("/") + 1));
|
|
224
|
+
try {
|
|
225
|
+
const results = await github.listOpenBoardItems(owner, bare);
|
|
226
|
+
const now = Date.now();
|
|
227
|
+
let throttled = false;
|
|
228
|
+
for (const repo of repos) {
|
|
229
|
+
const result = results.get(repo);
|
|
230
|
+
if (!result) {
|
|
231
|
+
noteFailure(repo, "GitHub returned nothing for this repo.", now);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (result.throttled)
|
|
235
|
+
throttled = true;
|
|
236
|
+
if (result.error && result.items.length === 0) {
|
|
237
|
+
noteFailure(repo, result.error, now);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const prior = cache.get(repo);
|
|
241
|
+
// A TTL refresh that returned the same board is the COMMON case, and
|
|
242
|
+
// it is not news. Compared against `lastRendered`, not against `prior`,
|
|
243
|
+
// because an invalidation just deleted the latter.
|
|
244
|
+
noteRendered(repo, fingerprint(result.items));
|
|
245
|
+
cache.set(repo, {
|
|
246
|
+
items: result.items,
|
|
247
|
+
checkedAt: now,
|
|
248
|
+
fetchedAt: now,
|
|
249
|
+
forcedAt: prior?.forcedAt,
|
|
250
|
+
...(result.error ? { error: result.error, staleSince: now } : {}),
|
|
251
|
+
...(result.fallback ? { fallback: true } : {}),
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (throttled)
|
|
255
|
+
noteThrottle(owner, now);
|
|
256
|
+
else
|
|
257
|
+
backoff.delete(owner);
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
// `listOpenBoardItems` is written not to throw, so reaching here means
|
|
261
|
+
// something outside it did — no installation for the owner, most likely.
|
|
262
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
263
|
+
const now = Date.now();
|
|
264
|
+
log.warn("board refresh failed", { owner, err });
|
|
265
|
+
for (const repo of repos)
|
|
266
|
+
noteFailure(repo, message, now);
|
|
267
|
+
noteThrottle(owner, now);
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
inflight.delete(owner);
|
|
271
|
+
}
|
|
272
|
+
})();
|
|
273
|
+
inflight.set(owner, run);
|
|
274
|
+
return run;
|
|
275
|
+
}
|
|
276
|
+
/** Keep the last good items, record why they stopped refreshing. */
|
|
277
|
+
function noteFailure(repo, error, now) {
|
|
278
|
+
const prior = cache.get(repo);
|
|
279
|
+
// Going degraded changes what the board renders (the `degraded` list), so it
|
|
280
|
+
// is news exactly once — not on every failed retry afterwards.
|
|
281
|
+
noteRendered(repo, DEGRADED);
|
|
282
|
+
cache.set(repo, {
|
|
283
|
+
items: prior?.items ?? [],
|
|
284
|
+
// The attempt counts against the TTL even though it failed — see `checkedAt`.
|
|
285
|
+
checkedAt: now,
|
|
286
|
+
// Deliberately NOT advanced: `fetchedAt` is when the items were true, and
|
|
287
|
+
// moving it on a failure would hide a stale board behind a fresh timestamp.
|
|
288
|
+
fetchedAt: prior?.fetchedAt ?? 0,
|
|
289
|
+
forcedAt: prior?.forcedAt,
|
|
290
|
+
error,
|
|
291
|
+
staleSince: prior?.staleSince ?? now,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function noteThrottle(owner, now) {
|
|
295
|
+
const prior = backoff.get(owner);
|
|
296
|
+
const failures = (prior?.failures ?? 0) + 1;
|
|
297
|
+
const wait = Math.min(BACKOFF_BASE_MS * 2 ** (failures - 1), BACKOFF_MAX_MS);
|
|
298
|
+
backoff.set(owner, { until: now + wait, failures });
|
|
299
|
+
log.warn("backing off board reads for an owner", { owner, failures, waitMs: wait });
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=board-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"board-cache.js","sourceRoot":"","sources":["../../src/admin/board-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,O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IGNAL — one revision string every dashboard watches.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately NOT the board itself, which is the one real design decision
|
|
5
|
+
* here. `GET /board` resolves its scope PER CALLER: `?repos=`, `?unstaged=`,
|
|
6
|
+
* and per-actor team visibility (issue #169). A stream that pushed the rendered
|
|
7
|
+
* board would therefore have to re-run that whole resolution for every
|
|
8
|
+
* connected client on every tick — and would have to carry repo names in the
|
|
9
|
+
* frame, which is a side channel around the very visibility boundary that
|
|
10
|
+
* resolution exists to hold. The session-list stream can afford its full
|
|
11
|
+
* payload because its work is a directory listing plus `docker ps`; three
|
|
12
|
+
* queries and a possibly-cold GitHub read are not comparable.
|
|
13
|
+
*
|
|
14
|
+
* So the frame says only THAT something changed. Each client then refetches at
|
|
15
|
+
* its own scope, through the same authorized route it already uses, and the
|
|
16
|
+
* expensive work happens only for tabs that are actually open. Keep it that
|
|
17
|
+
* way: the moment this frame grows a repo list it stops being safe to send to
|
|
18
|
+
* everyone.
|
|
19
|
+
*
|
|
20
|
+
* The tick is shared — one signature computation for the whole process,
|
|
21
|
+
* however many tabs are connected.
|
|
22
|
+
*/
|
|
23
|
+
import type { StateDb } from "../state/db.js";
|
|
24
|
+
/** How often the signature is recomputed. */
|
|
25
|
+
export declare const BOARD_TICK_MS = 3000;
|
|
26
|
+
/**
|
|
27
|
+
* A board can sit unchanged for hours, so a SILENT stream is its normal state —
|
|
28
|
+
* and an idle reverse proxy will close one. The heartbeat is what makes this
|
|
29
|
+
* endpoint different from the session stream it is otherwise modelled on, which
|
|
30
|
+
* changes often enough to keep itself alive.
|
|
31
|
+
*/
|
|
32
|
+
export declare const BOARD_HEARTBEAT_MS = 25000;
|
|
33
|
+
/** Note that a run reached a terminal state — see {@link runRevision}. */
|
|
34
|
+
export declare function noteBoardRunChange(): void;
|
|
35
|
+
/** Test-only: reset the run revision. */
|
|
36
|
+
export declare function resetBoardStreamForTests(): void;
|
|
37
|
+
/**
|
|
38
|
+
* What the board would show right now, as a comparable string.
|
|
39
|
+
*
|
|
40
|
+
* Three components: the cached GitHub answer's revision, the terminal-run
|
|
41
|
+
* counter, and the live shape of every ACTIVE run — the last because a run
|
|
42
|
+
* moving `queued → running`, or advancing a phase, changes a card without
|
|
43
|
+
* changing either counter.
|
|
44
|
+
*
|
|
45
|
+
* One query per tick for the whole process, on an indexed status filter.
|
|
46
|
+
*/
|
|
47
|
+
export declare function boardSignature(db: StateDb): Promise<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { boardRevision } from "./board-cache.js";
|
|
2
|
+
/** How often the signature is recomputed. */
|
|
3
|
+
export const BOARD_TICK_MS = 3000;
|
|
4
|
+
/**
|
|
5
|
+
* A board can sit unchanged for hours, so a SILENT stream is its normal state —
|
|
6
|
+
* and an idle reverse proxy will close one. The heartbeat is what makes this
|
|
7
|
+
* endpoint different from the session stream it is otherwise modelled on, which
|
|
8
|
+
* changes often enough to keep itself alive.
|
|
9
|
+
*/
|
|
10
|
+
export const BOARD_HEARTBEAT_MS = 25_000;
|
|
11
|
+
/**
|
|
12
|
+
* Run-side changes the cache knows nothing about.
|
|
13
|
+
*
|
|
14
|
+
* Bumped from a terminal-run observer at boot. The GitHub half of a card is
|
|
15
|
+
* cached and the run half is read live, so without this a run finishing would
|
|
16
|
+
* be invisible until something else moved.
|
|
17
|
+
*/
|
|
18
|
+
let runRevision = 0;
|
|
19
|
+
/** Note that a run reached a terminal state — see {@link runRevision}. */
|
|
20
|
+
export function noteBoardRunChange() {
|
|
21
|
+
runRevision++;
|
|
22
|
+
}
|
|
23
|
+
/** Test-only: reset the run revision. */
|
|
24
|
+
export function resetBoardStreamForTests() {
|
|
25
|
+
runRevision = 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What the board would show right now, as a comparable string.
|
|
29
|
+
*
|
|
30
|
+
* Three components: the cached GitHub answer's revision, the terminal-run
|
|
31
|
+
* counter, and the live shape of every ACTIVE run — the last because a run
|
|
32
|
+
* moving `queued → running`, or advancing a phase, changes a card without
|
|
33
|
+
* changing either counter.
|
|
34
|
+
*
|
|
35
|
+
* One query per tick for the whole process, on an indexed status filter.
|
|
36
|
+
*/
|
|
37
|
+
export async function boardSignature(db) {
|
|
38
|
+
const active = await db.runs.listActive();
|
|
39
|
+
const live = active
|
|
40
|
+
.map((run) => `${run.id}:${run.status}:${run.currentPhase ?? ""}`)
|
|
41
|
+
.sort()
|
|
42
|
+
.join("|");
|
|
43
|
+
return `${boardRevision()}:${runRevision}:${live}`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=board-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"board-stream.js","sourceRoot":"","sources":["../../src/admin/board-stream.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC;;;;;;GAMG;AACH,IAAI,WAAW,GAAG,CAAC,CAAC;AAEpB,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB;IAChC,WAAW,EAAE,CAAC;AAChB,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,wBAAwB;IACtC,WAAW,GAAG,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAW;IAC9C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,MAAM;SAChB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,EAAE,CAAC;SACjE,IAAI,EAAE;SACN,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,aAAa,EAAE,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;AACrD,CAAC"}
|