lastlight-core 0.23.7 → 0.23.8
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/deploy/k8s/harness-deployment.yaml +1 -0
- package/dist/admin/routes.js +30 -23
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/tail.js +3 -1
- package/dist/admin/tail.js.map +1 -1
- package/dist/config/config.js +15 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.js +6 -4
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/github-webhook.js +9 -8
- package/dist/connectors/github-webhook.js.map +1 -1
- package/dist/connectors/index.js +5 -3
- package/dist/connectors/index.js.map +1 -1
- package/dist/connectors/messaging/base.js +7 -1
- package/dist/connectors/messaging/base.js.map +1 -1
- package/dist/connectors/messaging/delivery.d.ts +0 -4
- package/dist/connectors/messaging/delivery.js +5 -3
- package/dist/connectors/messaging/delivery.js.map +1 -1
- package/dist/connectors/messaging/session-manager.js +3 -1
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/slack/connector.js +24 -15
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/fanout.js +14 -4
- package/dist/cron/fanout.js.map +1 -1
- package/dist/cron/jobs.js +6 -2
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-crons.js +7 -2
- package/dist/cron/repo-crons.js.map +1 -1
- package/dist/cron/sandbox-sweep.js +3 -1
- package/dist/cron/sandbox-sweep.js.map +1 -1
- package/dist/cron/scheduler.js +11 -9
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/agent-executor.js +20 -16
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/chat/chat-runner.js +9 -3
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/chat/chat.js +12 -5
- package/dist/engine/chat/chat.js.map +1 -1
- package/dist/engine/chat/message-batcher.js +3 -1
- package/dist/engine/chat/message-batcher.js.map +1 -1
- package/dist/engine/dispatcher.js +35 -26
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/event-shim.js +3 -2
- package/dist/engine/event-shim.js.map +1 -1
- package/dist/engine/executors/orchestrator.js +5 -5
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.js +16 -14
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/fix-harvest.js +3 -2
- package/dist/engine/fix-harvest.js.map +1 -1
- package/dist/engine/github/git-auth.js +12 -7
- package/dist/engine/github/git-auth.js.map +1 -1
- package/dist/engine/github/github-app-client.js +14 -5
- package/dist/engine/github/github-app-client.js.map +1 -1
- package/dist/engine/pr-escalation.js +42 -22
- package/dist/engine/pr-escalation.js.map +1 -1
- package/dist/engine/pr-state.js +4 -2
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-check.js +21 -16
- package/dist/engine/review-check.js.map +1 -1
- package/dist/engine/router.js +38 -15
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/screen/classifier.js +7 -6
- package/dist/engine/screen/classifier.js.map +1 -1
- package/dist/engine/screen/screen.js +3 -2
- package/dist/engine/screen/screen.js.map +1 -1
- package/dist/index.js +152 -91
- package/dist/index.js.map +1 -1
- package/dist/logging/logger.d.ts +7 -0
- package/dist/logging/logger.js +55 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/notify/notifier.js +5 -6
- package/dist/notify/notifier.js.map +1 -1
- package/dist/sandbox/docker.js +7 -5
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/index.js +65 -32
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/k8s/artifact-upload-route.js +3 -1
- package/dist/sandbox/k8s/artifact-upload-route.js.map +1 -1
- package/dist/sandbox/k8s/egress-ensurer.js +4 -3
- package/dist/sandbox/k8s/egress-ensurer.js.map +1 -1
- package/dist/sandbox/k8s/pod-lifecycle.js +4 -2
- package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -1
- package/dist/sandbox/k8s/reclaim.js +14 -5
- package/dist/sandbox/k8s/reclaim.js.map +1 -1
- package/dist/sandbox/k8s/sweep.js +3 -2
- package/dist/sandbox/k8s/sweep.js.map +1 -1
- package/dist/sandbox/reap.js +5 -4
- package/dist/sandbox/reap.js.map +1 -1
- package/dist/sandbox/sandbox.js +2 -1
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/sandbox/smol.js +12 -9
- package/dist/sandbox/smol.js.map +1 -1
- package/dist/state/workflow-run-store.js +3 -2
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/telemetry/index.js +7 -7
- package/dist/telemetry/index.js.map +1 -1
- package/dist/workflows/admission.js +6 -8
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/post-review.js +5 -3
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/pr-scope.js +8 -6
- package/dist/workflows/pr-scope.js.map +1 -1
- package/dist/workflows/resume.js +27 -28
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.js +9 -8
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.js +28 -16
- package/dist/workflows/simple.js.map +1 -1
- package/dist/worktree/manager.js +6 -4
- package/dist/worktree/manager.js.map +1 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ import { harvestFixMarkers } from "./engine/fix-harvest.js";
|
|
|
45
45
|
import { resumeOrphanedWorkflows, resumeSimpleRun } from "./workflows/resume.js";
|
|
46
46
|
import { createAdmissionController } from "./workflows/admission.js";
|
|
47
47
|
import { ProgressNotifier, GitHubTransport, SlackTransport, } from "./notify/index.js";
|
|
48
|
+
import { logger } from "./logging/logger.js";
|
|
48
49
|
/**
|
|
49
50
|
/**
|
|
50
51
|
* The `review.trigger` ROUTE this dispatch arrived on, off the context key the
|
|
@@ -65,9 +66,10 @@ function reviewRouteFromContext(context) {
|
|
|
65
66
|
* Docker's restart policy doesn't loop forever on a misconfigured container.
|
|
66
67
|
*/
|
|
67
68
|
function validateConfig(config) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const log = logger("startup");
|
|
70
|
+
const fatal = (msg, fields) => {
|
|
71
|
+
log.fatal(msg, fields);
|
|
72
|
+
log.fatal("Fix your .env and restart.");
|
|
71
73
|
process.exit(78); // EX_CONFIG — sysexits.h convention
|
|
72
74
|
};
|
|
73
75
|
if (config.githubApp) {
|
|
@@ -85,16 +87,17 @@ function validateConfig(config) {
|
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
catch (err) {
|
|
88
|
-
fatal(`Cannot read GITHUB_APP_PRIVATE_KEY_PATH ("${privateKeyPath}")
|
|
90
|
+
fatal(`Cannot read GITHUB_APP_PRIVATE_KEY_PATH ("${privateKeyPath}")`, { err });
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
if (!config.webhookSecret && config.githubApp) {
|
|
92
|
-
|
|
94
|
+
log.warn("WEBHOOK_SECRET is not set — webhook signature verification is disabled.");
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
async function main() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
const startupLog = logger("startup");
|
|
99
|
+
startupLog.info(`Last Light v${readPackageVersion() ?? "unknown"} — Agent SDK Harness`);
|
|
100
|
+
startupLog.info("====================================");
|
|
98
101
|
// Load and validate config + overlay assets before starting anything. These
|
|
99
102
|
// throw on a broken/empty overlay, a cron targeting a missing workflow, or a
|
|
100
103
|
// phase whose prompt/skill can't resolve — all unfixable by a restart, so we
|
|
@@ -107,24 +110,31 @@ async function main() {
|
|
|
107
110
|
overlayRoot: config.overlayDir,
|
|
108
111
|
disabled: config.disabled,
|
|
109
112
|
});
|
|
110
|
-
validateAssets(config.routes);
|
|
113
|
+
validateAssets(config.routes, logger("workflows"));
|
|
111
114
|
}
|
|
112
115
|
catch (err) {
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
startupLog.fatal(err.message, { err });
|
|
117
|
+
startupLog.fatal("Fix your config/overlay and restart.");
|
|
115
118
|
process.exit(78); // EX_CONFIG — sysexits.h convention
|
|
116
119
|
}
|
|
117
120
|
validateConfig(config);
|
|
118
121
|
const packageJson = JSON.parse(readFileSync(resolve("package.json"), "utf8"));
|
|
119
122
|
await initTelemetry(config.otel, { packageVersion: packageJson.version });
|
|
120
123
|
let telemetryShutdownStarted = false;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
const configLog = logger("config");
|
|
125
|
+
configLog.info(config.otel.enabled ? "otel enabled" : "otel disabled", config.otel.enabled
|
|
126
|
+
? {
|
|
127
|
+
service: config.otel.serviceName,
|
|
128
|
+
forwardToSandbox: config.otel.forwardToSandbox,
|
|
129
|
+
includeContent: config.otel.includeContent,
|
|
130
|
+
}
|
|
131
|
+
: undefined);
|
|
132
|
+
configLog.info("Port and model", { port: config.port, model: config.model });
|
|
125
133
|
const modelOverrides = Object.entries(config.models).filter(([k]) => k !== "default");
|
|
126
134
|
if (modelOverrides.length > 0) {
|
|
127
|
-
|
|
135
|
+
configLog.info("Model overrides", {
|
|
136
|
+
overrides: Object.fromEntries(modelOverrides),
|
|
137
|
+
});
|
|
128
138
|
}
|
|
129
139
|
// Clean up any sandbox containers left over from a previous run
|
|
130
140
|
cleanupOrphanedSandboxes();
|
|
@@ -132,9 +142,8 @@ async function main() {
|
|
|
132
142
|
for (const sub of ["sessions", "logs", "sandboxes"]) {
|
|
133
143
|
mkdirSync(resolve(config.stateDir, sub), { recursive: true });
|
|
134
144
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
console.log(`[config] Sandbox backend: ${config.sandbox}`);
|
|
145
|
+
configLog.info("State dirs", { stateDir: config.stateDir, sessionsDir: config.sessionsDir });
|
|
146
|
+
configLog.info("Sandbox backend", { backend: config.sandbox });
|
|
138
147
|
// Regenerate egress firewall configs (nginx ssl_preread + coredns) from
|
|
139
148
|
// the allowlist source of truth. Only meaningful for the docker backend;
|
|
140
149
|
// cheap enough to do unconditionally so a backend switch doesn't leave
|
|
@@ -143,7 +152,7 @@ async function main() {
|
|
|
143
152
|
// SNI allowlist no longer needs collector hosts — that hop happens on
|
|
144
153
|
// the collector's trusted outbound leg, not through the firewall.
|
|
145
154
|
const proxyDir = writeEgressFirewallConfigs(config.stateDir);
|
|
146
|
-
|
|
155
|
+
configLog.info("Egress firewall configs", { dir: proxyDir });
|
|
147
156
|
// Generate the in-network OTEL collector config (docker backend). Derived
|
|
148
157
|
// from the harness's OTEL_* backend env so the collector re-exports to the
|
|
149
158
|
// same backend the harness uses — with auth headers that stay host-side.
|
|
@@ -153,11 +162,14 @@ async function main() {
|
|
|
153
162
|
const collectorConfigPath = writeOtelCollectorConfig(config.stateDir, {
|
|
154
163
|
active: config.otel.enabled && config.otel.forwardToSandbox,
|
|
155
164
|
});
|
|
156
|
-
|
|
165
|
+
configLog.info("OTEL collector config", {
|
|
166
|
+
path: collectorConfigPath,
|
|
167
|
+
forwarding: config.otel.enabled && config.otel.forwardToSandbox ? "active" : "disabled",
|
|
168
|
+
});
|
|
157
169
|
// Initialize state database first — ChatRunner needs SessionManager
|
|
158
170
|
// (DB-backed) at construction time.
|
|
159
171
|
const db = new StateDb(config.dbPath);
|
|
160
|
-
|
|
172
|
+
configLog.info("Database", { path: config.dbPath });
|
|
161
173
|
// Session manager for messaging connectors (shared across Slack, Discord, etc.)
|
|
162
174
|
const sessionManager = new SessionManager(db.database);
|
|
163
175
|
// In-process chat runner backs the messaging chat skill. One pi-ai
|
|
@@ -191,11 +203,12 @@ async function main() {
|
|
|
191
203
|
? { tools: [readSkill.tool], execute: readSkill.execute }
|
|
192
204
|
: undefined,
|
|
193
205
|
}, sessionManager);
|
|
206
|
+
const chatLog = logger("chat");
|
|
194
207
|
if (chatSkills.skills.length > 0) {
|
|
195
|
-
|
|
208
|
+
chatLog.info("Loaded skills", { names: chatSkills.skills.map((s) => s.name) });
|
|
196
209
|
}
|
|
197
210
|
else {
|
|
198
|
-
|
|
211
|
+
chatLog.warn("No skills loaded — frontmatter missing or no matching SKILL.md found");
|
|
199
212
|
}
|
|
200
213
|
// Configure git with GitHub App credentials — agents can git clone/push natively.
|
|
201
214
|
// Non-fatal: the token is refreshed before each agent execution anyway, so a
|
|
@@ -210,7 +223,7 @@ async function main() {
|
|
|
210
223
|
});
|
|
211
224
|
}
|
|
212
225
|
catch (err) {
|
|
213
|
-
|
|
226
|
+
logger("git-auth").warn("Initial token mint failed (will retry per-execution)", { err });
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
229
|
// GitHub API client for harness-level operations (posting comments, fetching
|
|
@@ -238,13 +251,14 @@ async function main() {
|
|
|
238
251
|
// on failure we fall back to whatever `managedRepos` config provides. Runs
|
|
239
252
|
// before the HTTP listener opens, so the list is warm before the first event.
|
|
240
253
|
if (github && config.githubApp) {
|
|
254
|
+
const githubLog = logger("github");
|
|
241
255
|
try {
|
|
242
256
|
const repos = await github.listInstallationRepos();
|
|
243
257
|
setInstallationRepos(repos);
|
|
244
|
-
|
|
258
|
+
githubLog.info("Discovered installation repos", { count: repos.length });
|
|
245
259
|
}
|
|
246
260
|
catch (err) {
|
|
247
|
-
|
|
261
|
+
githubLog.warn("Installation repo discovery failed", { err });
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
264
|
// Late-bound: constructed after resumeOpts (below) because it closes over
|
|
@@ -261,6 +275,7 @@ async function main() {
|
|
|
261
275
|
* agent skills they're 1:1 with workflow names.
|
|
262
276
|
*/
|
|
263
277
|
const dispatchWorkflow = async (workflowName, context, onRunStart) => {
|
|
278
|
+
const log = logger("dispatch");
|
|
264
279
|
// Slack-initiated workflows (explore, /explore) carry a
|
|
265
280
|
// `slack:{team}:{channel}:{thread}` triggerId and don't require a
|
|
266
281
|
// managed `repo` — their postComment goes back to the Slack thread.
|
|
@@ -270,7 +285,7 @@ async function main() {
|
|
|
270
285
|
const repoStr = context.repo;
|
|
271
286
|
if (!repoStr && !slackTriggerId) {
|
|
272
287
|
const msg = `dispatchWorkflow(${workflowName}): missing 'repo' in context`;
|
|
273
|
-
|
|
288
|
+
log.error(msg, { workflowName });
|
|
274
289
|
return { success: false, error: msg };
|
|
275
290
|
}
|
|
276
291
|
const [owner, repo] = repoStr && repoStr.includes("/")
|
|
@@ -280,7 +295,7 @@ async function main() {
|
|
|
280
295
|
: ["", ""];
|
|
281
296
|
if (repoStr && (!owner || !repo)) {
|
|
282
297
|
const msg = `dispatchWorkflow(${workflowName}): invalid repo format '${repoStr}'`;
|
|
283
|
-
|
|
298
|
+
log.error(msg, { workflowName, repoStr });
|
|
284
299
|
return { success: false, error: msg };
|
|
285
300
|
}
|
|
286
301
|
// Choke-point managedRepos guard: every trigger path (webhook, router,
|
|
@@ -292,7 +307,7 @@ async function main() {
|
|
|
292
307
|
const unmanaged = unmanagedReposInContext(context);
|
|
293
308
|
if (unmanaged.length > 0) {
|
|
294
309
|
const msg = `dispatchWorkflow(${workflowName}): refusing unmanaged repo(s): ${unmanaged.join(", ")}`;
|
|
295
|
-
|
|
310
|
+
log.warn(msg, { workflowName, unmanaged });
|
|
296
311
|
return { success: false, error: msg };
|
|
297
312
|
}
|
|
298
313
|
// Per-repository config layer (issue #180). Resolved at the SAME choke
|
|
@@ -307,7 +322,7 @@ async function main() {
|
|
|
307
322
|
// The repo opting itself out via `disabled.workflows`. Same refusal shape
|
|
308
323
|
// as the unmanaged-repo guard, so every caller already handles it.
|
|
309
324
|
const msg = `dispatchWorkflow(${workflowName}): refusing repo-disabled workflow: ${refusal}`;
|
|
310
|
-
|
|
325
|
+
log.warn(msg, { workflowName, refusal });
|
|
311
326
|
return { success: false, error: msg };
|
|
312
327
|
}
|
|
313
328
|
// ── The PR state machine (09-state-machine.md → S3) ────────────────────
|
|
@@ -502,8 +517,12 @@ async function main() {
|
|
|
502
517
|
(PR_FIX_SHAPED_WORKFLOWS.has(workflowName) ||
|
|
503
518
|
PR_HEADREF_PREPOPULATE_WORKFLOWS.has(workflowName))) {
|
|
504
519
|
prePopulateBranch = prState.headRef;
|
|
505
|
-
|
|
506
|
-
|
|
520
|
+
log.info("Pre-populating workspace", {
|
|
521
|
+
workflowName,
|
|
522
|
+
repo: `${owner}/${repo}`,
|
|
523
|
+
branch: prePopulateBranch,
|
|
524
|
+
base: prState.baseRef || "?",
|
|
525
|
+
});
|
|
507
526
|
}
|
|
508
527
|
if (!prePopulateBranch && typeof ctxBranch === "string" && ctxBranch && PR_FIX_SHAPED_WORKFLOWS.has(workflowName)) {
|
|
509
528
|
prePopulateBranch = ctxBranch;
|
|
@@ -530,13 +549,18 @@ async function main() {
|
|
|
530
549
|
// head ref, so `origin/<base>` isn't present until the agent fetches it).
|
|
531
550
|
if (pr.base?.ref)
|
|
532
551
|
extra.baseBranch = pr.base.ref;
|
|
533
|
-
|
|
534
|
-
|
|
552
|
+
log.info("Pre-populating workspace", {
|
|
553
|
+
workflowName,
|
|
554
|
+
repo: `${owner}/${repo}`,
|
|
555
|
+
headRef: prePopulateBranch,
|
|
556
|
+
baseRef: pr.base?.ref ?? "?",
|
|
557
|
+
});
|
|
535
558
|
}
|
|
536
559
|
catch (err) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
560
|
+
log.warn("Could not resolve PR head ref; agent will need to clone via MCP", {
|
|
561
|
+
workflowName,
|
|
562
|
+
err,
|
|
563
|
+
});
|
|
540
564
|
}
|
|
541
565
|
}
|
|
542
566
|
// Base branch for scoping. PR-triggered runs set it from the PR's base ref
|
|
@@ -551,9 +575,11 @@ async function main() {
|
|
|
551
575
|
extra.baseBranch = await github.getDefaultBranch(owner, repo);
|
|
552
576
|
}
|
|
553
577
|
catch (err) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
578
|
+
log.warn("Could not resolve default branch; assuming main", {
|
|
579
|
+
workflowName,
|
|
580
|
+
repo: `${owner}/${repo}`,
|
|
581
|
+
err,
|
|
582
|
+
});
|
|
557
583
|
extra.baseBranch = "main";
|
|
558
584
|
}
|
|
559
585
|
}
|
|
@@ -620,13 +646,16 @@ async function main() {
|
|
|
620
646
|
// exclusively (avoids double-rendering the body).
|
|
621
647
|
request.issueBody = "";
|
|
622
648
|
if (screen.flagged) {
|
|
623
|
-
|
|
649
|
+
log.warn("Screener flagged combined issue context", {
|
|
650
|
+
repo: `${owner}/${repo}`,
|
|
651
|
+
issueNumber: request.issueNumber,
|
|
652
|
+
reason: screen.reason || "no reason",
|
|
653
|
+
});
|
|
624
654
|
}
|
|
625
655
|
}
|
|
626
656
|
}
|
|
627
657
|
catch (err) {
|
|
628
|
-
|
|
629
|
-
console.warn(`[dispatch] Failed to fetch/screen issue context: ${m}`);
|
|
658
|
+
log.warn("Failed to fetch/screen issue context", { err });
|
|
630
659
|
// Non-fatal — workflow proceeds with whatever context the envelope had.
|
|
631
660
|
}
|
|
632
661
|
}
|
|
@@ -636,8 +665,7 @@ async function main() {
|
|
|
636
665
|
await slackConnector.sendMessage(channelId, threadId, msg);
|
|
637
666
|
}
|
|
638
667
|
catch (err) {
|
|
639
|
-
|
|
640
|
-
console.warn(`[dispatch] Failed to post to Slack thread: ${m}`);
|
|
668
|
+
log.warn("Failed to post to Slack thread", { err });
|
|
641
669
|
}
|
|
642
670
|
}
|
|
643
671
|
: undefined;
|
|
@@ -715,8 +743,7 @@ async function main() {
|
|
|
715
743
|
notifier = new ProgressNotifier(transports);
|
|
716
744
|
}
|
|
717
745
|
catch (err) {
|
|
718
|
-
|
|
719
|
-
console.warn(`[dispatch] notifier setup failed: ${m}`);
|
|
746
|
+
log.warn("Notifier setup failed", { err });
|
|
720
747
|
}
|
|
721
748
|
}
|
|
722
749
|
: undefined;
|
|
@@ -732,13 +759,12 @@ async function main() {
|
|
|
732
759
|
return await github.postComment(owner, repo, issueNumber, msg);
|
|
733
760
|
}
|
|
734
761
|
catch (err) {
|
|
735
|
-
|
|
736
|
-
console.warn(`[dispatch] Failed to post comment: ${m}`);
|
|
762
|
+
log.warn("Failed to post comment", { err });
|
|
737
763
|
}
|
|
738
764
|
}
|
|
739
765
|
: undefined),
|
|
740
766
|
onPhaseStart: async (phase) => {
|
|
741
|
-
|
|
767
|
+
log.info("Phase start", { workflowName, phase });
|
|
742
768
|
// Refresh the Slack thinking indicator so long-running phases
|
|
743
769
|
// don't leave the thread looking dead. threadId doubles as both
|
|
744
770
|
// the message anchor and the thread root for DM threads.
|
|
@@ -747,7 +773,7 @@ async function main() {
|
|
|
747
773
|
}
|
|
748
774
|
},
|
|
749
775
|
onPhaseEnd: async (phase, result) => {
|
|
750
|
-
|
|
776
|
+
log.info("Phase end", { workflowName, phase, success: result.success });
|
|
751
777
|
// The marker harvest (09 → S1). This is the ONLY moment the two marker
|
|
752
778
|
// lines exist in memory — `{{phaseOutputs}}` is empty across a run
|
|
753
779
|
// boundary and the shared per-PR workspace is `reset --hard`-ed between
|
|
@@ -790,7 +816,7 @@ async function main() {
|
|
|
790
816
|
}, callbacks, db, config.models, config.approval, config.bootstrapLabel, config.variants, config.concurrency);
|
|
791
817
|
const summary = result.phases.map((p) => `${p.phase}=${p.success ? "ok" : "fail"}`).join(", ");
|
|
792
818
|
if (result.queued) {
|
|
793
|
-
|
|
819
|
+
log.info("Queued (concurrency cap reached)", { workflowName });
|
|
794
820
|
// A queued run never reaches `onRunStart` — `runSimpleWorkflow` returns
|
|
795
821
|
// the moment it writes the `queued` row — so bind the check here instead
|
|
796
822
|
// of leaving the run's only PR-visible artifact unowned. The row is
|
|
@@ -801,19 +827,19 @@ async function main() {
|
|
|
801
827
|
await bindReviewCheckForQueuedRun();
|
|
802
828
|
}
|
|
803
829
|
else if (result.paused) {
|
|
804
|
-
|
|
830
|
+
log.info("Paused", { workflowName, summary });
|
|
805
831
|
}
|
|
806
832
|
else if (result.success) {
|
|
807
|
-
|
|
833
|
+
log.info("Completed", { workflowName, summary });
|
|
808
834
|
}
|
|
809
835
|
else {
|
|
810
|
-
|
|
836
|
+
log.warn("Failed", { workflowName, summary });
|
|
811
837
|
}
|
|
812
838
|
return { success: result.success, paused: result.paused, queued: result.queued };
|
|
813
839
|
}
|
|
814
840
|
catch (err) {
|
|
815
841
|
const msg = err instanceof Error ? err.message : String(err);
|
|
816
|
-
|
|
842
|
+
log.error("Threw", { workflowName, err });
|
|
817
843
|
return { success: false, error: msg };
|
|
818
844
|
}
|
|
819
845
|
finally {
|
|
@@ -824,8 +850,7 @@ async function main() {
|
|
|
824
850
|
// retry.
|
|
825
851
|
if (!result?.backpressure) {
|
|
826
852
|
admissionController?.admitNext().catch((err) => {
|
|
827
|
-
|
|
828
|
-
console.warn(`[admission] admitNext error: ${msg}`);
|
|
853
|
+
logger("admission").warn("admitNext error", { err });
|
|
829
854
|
});
|
|
830
855
|
}
|
|
831
856
|
}
|
|
@@ -929,6 +954,7 @@ async function main() {
|
|
|
929
954
|
// `dispatchWorkflow`, which is defined earlier in this file. Named (not inline)
|
|
930
955
|
// so the admin `triggerCron` callback can reuse it to fire a cron on demand.
|
|
931
956
|
const cronRunner = async (workflowName, context) => {
|
|
957
|
+
const log = logger("cron");
|
|
932
958
|
let dispatched;
|
|
933
959
|
let failures;
|
|
934
960
|
// A cron whose context sets `discover: <key>` fans out one bounded single-PR
|
|
@@ -964,14 +990,27 @@ async function main() {
|
|
|
964
990
|
})).repos
|
|
965
991
|
: candidates;
|
|
966
992
|
if (repos.length !== candidates.length) {
|
|
967
|
-
|
|
993
|
+
log.info("Repo(s) participate in this cron", {
|
|
994
|
+
cronName,
|
|
995
|
+
participating: repos.length,
|
|
996
|
+
candidates: candidates.length,
|
|
997
|
+
});
|
|
968
998
|
}
|
|
969
999
|
// Every repo opted out (or a globally-off cron nobody opted into) — no
|
|
970
1000
|
// discovery calls, no dispatches, no failure. A cheap no-op tick.
|
|
1001
|
+
// The discoverer's `log` callback only carries per-repo/per-candidate
|
|
1002
|
+
// diagnostics (a skipped malformed repo, a failed listing/fetch) — one
|
|
1003
|
+
// of these can fire per managed repo on every tick, so it's `.debug`,
|
|
1004
|
+
// not `.info`. The once-per-tick summary below stays `.info`.
|
|
971
1005
|
const prs = github && repos.length
|
|
972
|
-
? await discoverer(repos, github, { log: (m) =>
|
|
1006
|
+
? await discoverer(repos, github, { log: (m) => log.debug(m) })
|
|
973
1007
|
: [];
|
|
974
|
-
|
|
1008
|
+
log.info("Discovered PRs", {
|
|
1009
|
+
workflowName,
|
|
1010
|
+
discoverKey,
|
|
1011
|
+
count: prs.length,
|
|
1012
|
+
repoCount: repos.length,
|
|
1013
|
+
});
|
|
975
1014
|
const contexts = prs.map((pr) => ({
|
|
976
1015
|
_triggerType: "cron",
|
|
977
1016
|
repo: pr.repo,
|
|
@@ -996,7 +1035,7 @@ async function main() {
|
|
|
996
1035
|
({ dispatched, failures } = await dispatchCronWorkflow(workflowName, context, dispatchWorkflow));
|
|
997
1036
|
}
|
|
998
1037
|
if (failures > 0) {
|
|
999
|
-
|
|
1038
|
+
log.warn("Dispatches failed", { workflowName, failures, dispatched });
|
|
1000
1039
|
}
|
|
1001
1040
|
};
|
|
1002
1041
|
const cron = new CronScheduler(db, cronRunner);
|
|
@@ -1039,6 +1078,7 @@ async function main() {
|
|
|
1039
1078
|
});
|
|
1040
1079
|
// Mount admin dashboard on the shared HTTP server (always available).
|
|
1041
1080
|
{
|
|
1081
|
+
const adminLog = logger("admin");
|
|
1042
1082
|
mountAdmin(app, db, {
|
|
1043
1083
|
cronScheduler: cron,
|
|
1044
1084
|
triggerCron: cronRunner,
|
|
@@ -1073,7 +1113,7 @@ async function main() {
|
|
|
1073
1113
|
githubAllowedOrg: process.env.GITHUB_ALLOWED_ORG,
|
|
1074
1114
|
resumeWorkflow: async (workflowRun, sender) => {
|
|
1075
1115
|
if (!github) {
|
|
1076
|
-
|
|
1116
|
+
adminLog.warn("Cannot resume workflow: GitHub App not configured", { runId: workflowRun.id });
|
|
1077
1117
|
return;
|
|
1078
1118
|
}
|
|
1079
1119
|
// Derive owner/repo for the resume dispatch. Prefer the triggerId
|
|
@@ -1091,11 +1131,16 @@ async function main() {
|
|
|
1091
1131
|
}
|
|
1092
1132
|
const issueNumber = workflowRun.issueNumber;
|
|
1093
1133
|
if (!owner || !repo || !issueNumber) {
|
|
1094
|
-
|
|
1134
|
+
adminLog.warn("Cannot resume workflow: missing owner/repo/issueNumber", { runId: workflowRun.id });
|
|
1095
1135
|
return;
|
|
1096
1136
|
}
|
|
1097
1137
|
db.runs.setRunning(workflowRun.id);
|
|
1098
|
-
|
|
1138
|
+
adminLog.info("Resuming after dashboard approval", {
|
|
1139
|
+
workflowName: workflowRun.workflowName,
|
|
1140
|
+
repo: `${owner}/${repo}`,
|
|
1141
|
+
issueNumber,
|
|
1142
|
+
sender,
|
|
1143
|
+
});
|
|
1099
1144
|
dispatchWorkflow(workflowRun.workflowName, {
|
|
1100
1145
|
repo: `${owner}/${repo}`,
|
|
1101
1146
|
issueNumber,
|
|
@@ -1103,7 +1148,7 @@ async function main() {
|
|
|
1103
1148
|
body: "",
|
|
1104
1149
|
sender,
|
|
1105
1150
|
_triggerType: "admin",
|
|
1106
|
-
}).catch((err) =>
|
|
1151
|
+
}).catch((err) => adminLog.error("Resume failed", { err }));
|
|
1107
1152
|
},
|
|
1108
1153
|
// Retry a FAILED or CANCELLED run, resuming from where it stopped with the
|
|
1109
1154
|
// same context. Unlike `resumeWorkflow` (approval-gate resume, which
|
|
@@ -1116,7 +1161,10 @@ async function main() {
|
|
|
1116
1161
|
// phases and starts clean.
|
|
1117
1162
|
retryWorkflow: async (workflowRun, sender) => {
|
|
1118
1163
|
if (workflowRun.status !== "failed" && workflowRun.status !== "cancelled") {
|
|
1119
|
-
|
|
1164
|
+
adminLog.warn("Cannot retry: not in a retryable status", {
|
|
1165
|
+
runId: workflowRun.id,
|
|
1166
|
+
status: workflowRun.status,
|
|
1167
|
+
});
|
|
1120
1168
|
return;
|
|
1121
1169
|
}
|
|
1122
1170
|
// Compare-and-set: flip failed/cancelled→running and clear the terminal
|
|
@@ -1124,17 +1172,24 @@ async function main() {
|
|
|
1124
1172
|
// dispatch.
|
|
1125
1173
|
const changed = db.runs.restartRun(workflowRun.id);
|
|
1126
1174
|
if (changed !== 1) {
|
|
1127
|
-
|
|
1175
|
+
adminLog.warn("Retry: run is no longer retryable (raced) — skipping dispatch", {
|
|
1176
|
+
runId: workflowRun.id,
|
|
1177
|
+
});
|
|
1128
1178
|
return;
|
|
1129
1179
|
}
|
|
1130
1180
|
const fresh = db.runs.getRun(workflowRun.id);
|
|
1131
1181
|
if (!fresh)
|
|
1132
1182
|
return;
|
|
1133
|
-
|
|
1134
|
-
|
|
1183
|
+
adminLog.info("Retrying", {
|
|
1184
|
+
workflowName: fresh.workflowName,
|
|
1185
|
+
runId: fresh.id,
|
|
1186
|
+
previousPhase: workflowRun.currentPhase,
|
|
1187
|
+
sender,
|
|
1188
|
+
});
|
|
1189
|
+
resumeSimpleRun(fresh, resumeOpts).catch((err) => adminLog.error("Retry failed", { runId: fresh.id, err }));
|
|
1135
1190
|
},
|
|
1136
1191
|
});
|
|
1137
|
-
|
|
1192
|
+
adminLog.info("Dashboard mounted at /admin");
|
|
1138
1193
|
}
|
|
1139
1194
|
// Protect API endpoints with auth when any login method is configured
|
|
1140
1195
|
// (password OR OAuth) — same gate as the dashboard, via the shared helper.
|
|
@@ -1148,9 +1203,10 @@ async function main() {
|
|
|
1148
1203
|
githubOAuthClientSecret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
|
|
1149
1204
|
githubAllowedOrg: process.env.GITHUB_ALLOWED_ORG,
|
|
1150
1205
|
});
|
|
1206
|
+
const apiLog = logger("api");
|
|
1151
1207
|
if (apiAuthEnabled) {
|
|
1152
1208
|
app.use("/api/*", authMiddleware(apiAuthEnabled, adminSecret));
|
|
1153
|
-
|
|
1209
|
+
apiLog.info("API endpoints protected with auth");
|
|
1154
1210
|
}
|
|
1155
1211
|
// API endpoint for CLI triggers
|
|
1156
1212
|
app.post("/api/run", async (c) => {
|
|
@@ -1170,7 +1226,7 @@ async function main() {
|
|
|
1170
1226
|
if (unmanaged.length > 0) {
|
|
1171
1227
|
return c.json({ error: `Repo not managed: ${unmanaged.join(", ")}` }, 403);
|
|
1172
1228
|
}
|
|
1173
|
-
|
|
1229
|
+
apiLog.info("CLI triggered", { workflowName });
|
|
1174
1230
|
// Run asynchronously — return immediately with a stable id the caller
|
|
1175
1231
|
// can correlate with workflow_runs in the dashboard.
|
|
1176
1232
|
const executionId = randomUUID();
|
|
@@ -1183,8 +1239,7 @@ async function main() {
|
|
|
1183
1239
|
...(apiActor ? { triggeredBy: apiActor } : {}),
|
|
1184
1240
|
_triggerType: "api",
|
|
1185
1241
|
}).catch((err) => {
|
|
1186
|
-
|
|
1187
|
-
console.error(`[api] workflow ${workflowName} failed: ${msg}`);
|
|
1242
|
+
apiLog.error("Workflow failed", { workflowName, err });
|
|
1188
1243
|
});
|
|
1189
1244
|
return c.json({ accepted: true, executionId, workflow: workflowName }, 202);
|
|
1190
1245
|
});
|
|
@@ -1198,7 +1253,7 @@ async function main() {
|
|
|
1198
1253
|
if (!isManagedRepo(`${owner}/${repo}`)) {
|
|
1199
1254
|
return c.json({ error: `Repo not managed: ${owner}/${repo}` }, 403);
|
|
1200
1255
|
}
|
|
1201
|
-
|
|
1256
|
+
apiLog.info("CLI build triggered", { repo: `${owner}/${repo}`, issueNumber });
|
|
1202
1257
|
// If labels weren't supplied, fetch them so the orchestrator can detect
|
|
1203
1258
|
// bootstrap tasks (lastlight:bootstrap label) and skip the BLOCKED gate.
|
|
1204
1259
|
let resolvedLabels = issueLabels;
|
|
@@ -1222,7 +1277,7 @@ async function main() {
|
|
|
1222
1277
|
...(actorFromContext(c) ? { triggeredBy: actorFromContext(c) } : {}),
|
|
1223
1278
|
_triggerType: "api",
|
|
1224
1279
|
}).catch((err) => {
|
|
1225
|
-
|
|
1280
|
+
apiLog.error("Build failed", { err });
|
|
1226
1281
|
});
|
|
1227
1282
|
return c.json({ accepted: true, owner, repo, issueNumber }, 202);
|
|
1228
1283
|
});
|
|
@@ -1305,20 +1360,25 @@ async function main() {
|
|
|
1305
1360
|
});
|
|
1306
1361
|
return c.json({ text: reply, thread: threadId ?? session.id, sessionId: session.id, outcome: outcome.kind });
|
|
1307
1362
|
});
|
|
1363
|
+
const eventLog = logger("event");
|
|
1308
1364
|
const handleEnvelope = async (envelope) => {
|
|
1309
|
-
|
|
1365
|
+
eventLog.info("Received", {
|
|
1366
|
+
source: envelope.source,
|
|
1367
|
+
type: envelope.type,
|
|
1368
|
+
sender: envelope.sender,
|
|
1369
|
+
repo: envelope.repo,
|
|
1370
|
+
});
|
|
1310
1371
|
try {
|
|
1311
1372
|
const outcome = await dispatch(envelope, dispatchDeps);
|
|
1312
1373
|
if (outcome.kind === "ignored") {
|
|
1313
|
-
|
|
1374
|
+
eventLog.info("Ignored", { reason: outcome.reason });
|
|
1314
1375
|
}
|
|
1315
1376
|
else if (outcome.kind === "skipped") {
|
|
1316
|
-
|
|
1377
|
+
eventLog.info("Skipped", { reason: outcome.reason });
|
|
1317
1378
|
}
|
|
1318
1379
|
}
|
|
1319
1380
|
catch (err) {
|
|
1320
|
-
|
|
1321
|
-
console.error(`[event] dispatch threw: ${msg}`);
|
|
1381
|
+
eventLog.error("Dispatch threw", { err });
|
|
1322
1382
|
}
|
|
1323
1383
|
};
|
|
1324
1384
|
// Batch bursty messaging input per session BEFORE routing: a rapid Slack
|
|
@@ -1352,11 +1412,11 @@ async function main() {
|
|
|
1352
1412
|
cron.register(job);
|
|
1353
1413
|
}
|
|
1354
1414
|
if (webhooksEnabled) {
|
|
1355
|
-
|
|
1415
|
+
logger("cron").info("Webhooks enabled — skipping issue/PR polling crons");
|
|
1356
1416
|
}
|
|
1357
1417
|
}
|
|
1358
1418
|
else {
|
|
1359
|
-
|
|
1419
|
+
logger("cron").info("No GitHub client — skipping all cron jobs (chat-only mode)");
|
|
1360
1420
|
}
|
|
1361
1421
|
// Sandbox-workspace reaping backstop (issue #106) — a DIRECT (non-sandboxed)
|
|
1362
1422
|
// job, registered regardless of `github` so it runs in chat-only mode too.
|
|
@@ -1394,15 +1454,16 @@ async function main() {
|
|
|
1394
1454
|
});
|
|
1395
1455
|
}
|
|
1396
1456
|
// Start everything
|
|
1457
|
+
const mainLog = logger("main");
|
|
1397
1458
|
await registry.startAll();
|
|
1398
|
-
|
|
1399
|
-
|
|
1459
|
+
mainLog.info("All connectors started");
|
|
1460
|
+
mainLog.info("Cron jobs registered");
|
|
1400
1461
|
// Open the shared HTTP listener. All routes (admin, /api/*, /health,
|
|
1401
1462
|
// /webhooks/github, /webhooks/slack) are registered synchronously above, so
|
|
1402
1463
|
// the port is ready the moment it opens. Always boots — chat-only, PAT, and
|
|
1403
1464
|
// full GitHub App modes alike.
|
|
1404
1465
|
const server = serve({ fetch: app.fetch, port: config.port, hostname: "0.0.0.0" });
|
|
1405
|
-
|
|
1466
|
+
logger("http").info("Listening", { port: config.port });
|
|
1406
1467
|
// Chat runs in-process via pi-ai — no long-lived server to boot.
|
|
1407
1468
|
// Boot-time recovery: any workflow_runs left in 'running' state from a
|
|
1408
1469
|
// previous harness lifetime have already had their sandbox containers
|
|
@@ -1410,15 +1471,15 @@ async function main() {
|
|
|
1410
1471
|
// failed and re-dispatch each run so the runner can pick up after the last
|
|
1411
1472
|
// completed phase. Skips 'paused' runs — those intentionally wait for a
|
|
1412
1473
|
// human approval and are resumed via the dashboard / GitHub comment flow.
|
|
1413
|
-
resumeOrphanedWorkflows(resumeOpts).catch((err) =>
|
|
1474
|
+
resumeOrphanedWorkflows(resumeOpts).catch((err) => mainLog.error("Resume sweep failed", { err }));
|
|
1414
1475
|
// Start the periodic admission sweeper. Also admits any queued runs that
|
|
1415
1476
|
// were persisted before the harness restarted (e.g. a queued run survived
|
|
1416
1477
|
// a crash; the sweeper picks it up on the first tick).
|
|
1417
1478
|
admissionController.start();
|
|
1418
|
-
|
|
1479
|
+
mainLog.info("Ready to receive events");
|
|
1419
1480
|
// Graceful shutdown
|
|
1420
1481
|
const shutdown = async () => {
|
|
1421
|
-
|
|
1482
|
+
mainLog.info("Shutting down");
|
|
1422
1483
|
cron.stopAll();
|
|
1423
1484
|
admissionController.stop();
|
|
1424
1485
|
await registry.stopAll();
|
|
@@ -1436,7 +1497,7 @@ async function main() {
|
|
|
1436
1497
|
process.on("SIGTERM", shutdown);
|
|
1437
1498
|
}
|
|
1438
1499
|
main().catch((err) => {
|
|
1439
|
-
|
|
1500
|
+
logger("main").fatal("Fatal error", { err });
|
|
1440
1501
|
// Exit 78 (EX_CONFIG) to signal Docker restart policy that looping won't help.
|
|
1441
1502
|
// Common causes: bad PEM, wrong App ID, missing env vars.
|
|
1442
1503
|
const msg = err?.message || "";
|