@bridge_gpt/mcp-server 0.2.70 → 0.2.72
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/README.md +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +29 -4
- package/build/agent-notes.js +171 -95
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +12 -2
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +17 -5
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +776 -23
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +93 -13
- package/build/conductor/epic-implementer-cli.js +55 -2
- package/build/conductor/gate-discovery.js +659 -19
- package/build/conductor/gate-settings-review.js +751 -0
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +16 -11
- package/build/conductor/launch-plan.js +185 -0
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +25 -9
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +281 -14
- package/build/conductor/recovery-operations.js +78 -5
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +240 -56
- package/build/epic-ci-workflow-drift.js +71 -23
- package/build/epic-ci-workflow-install.js +83 -26
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +174 -13
- package/build/epic-implementer-bin.js +119 -44
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +274 -5
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +355 -36
- package/build/executor/likely-tests.js +100 -98
- package/build/executor/preflight.js +5 -0
- package/build/executor/process-containment.js +18 -0
- package/build/executor/prompt-spec.js +84 -15
- package/build/executor/reconcile-overlap-job.js +6 -1
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +188 -1
- package/build/executor/worker-database.js +299 -40
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +12 -1
- package/build/executor/worker-verification-guidance.js +64 -0
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +767 -310
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +416 -41
- package/build/install-bridge-conductor-setup.js +135 -32
- package/build/install-bridge-conductor.js +769 -353
- package/build/install-bridge.js +419 -124
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +22 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-execution-ledger.js +171 -10
- package/build/plane/plane-freshness.js +12 -9
- package/build/plane/preflight.js +19 -0
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +31 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +623 -0
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +26 -9
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +61 -80
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-artifacts.js +7 -0
- package/build/ticket-delivery-enrollment.js +80 -4
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER.md +43 -0
- package/docs/epic-implementer/getting-started.md +95 -14
- package/package.json +2 -2
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { sanitizeHarnessCoverage } from "./harness-coverage.js";
|
|
2
|
+
import { monotonicNow, elapsedMs } from "../conductor/precheck-timings.js";
|
|
1
3
|
/**
|
|
2
4
|
* Disposable worker database lifecycle (BAPI-1479).
|
|
3
5
|
*
|
|
@@ -22,8 +24,8 @@ import { constants as fsConstants } from "node:fs";
|
|
|
22
24
|
import { access, mkdir } from "node:fs/promises";
|
|
23
25
|
import path from "node:path";
|
|
24
26
|
import { parseAlembicRevisions, resolveRepositoryAlembicCommand } from "../plane/alembic-head.js";
|
|
25
|
-
import {
|
|
26
|
-
import { POSTGRES_IDENTIFIER_MAX_LENGTH, WORKER_DATABASE_HOST, WORKER_DATABASE_PORT, WORKER_DATABASE_PREFIX, WORKER_DATABASE_ROLE,
|
|
27
|
+
import { buildExecutorBaseWorkerEnv, hasWorkerEnvOption } from "./env.js";
|
|
28
|
+
import { POSTGRES_IDENTIFIER_MAX_LENGTH, WORKER_DATABASE_HOST, WORKER_DATABASE_PORT, WORKER_DATABASE_PREFIX, WORKER_DATABASE_ROLE, isValidWorkerDatabaseName, validateWorkerDatabaseName, } from "./worker-database-target.js";
|
|
27
29
|
/** Runbook section every worker-database diagnostic points the host operator to. */
|
|
28
30
|
export const WORKER_DATABASE_RUNBOOK_SECTION = "docs/claude/runbooks/local-db-safety.md#worker-databases";
|
|
29
31
|
export const WORKER_DATABASE_PROVISION_BUDGET_MS = 120_000;
|
|
@@ -63,6 +65,23 @@ const RANDOM_SUFFIX_PATTERN = /^[0-9a-f]{4,16}$/;
|
|
|
63
65
|
const ISO_TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
64
66
|
const SAFE_JOB_ID_FOR_LOG = /^[A-Za-z0-9_-]{1,64}$/;
|
|
65
67
|
const HEX_PATTERN = /^(?:[0-9a-f]{2})*$/;
|
|
68
|
+
const MIGRATION_CAUSES = new Set([
|
|
69
|
+
"multiple_heads",
|
|
70
|
+
"revision_missing",
|
|
71
|
+
"ssl_refused",
|
|
72
|
+
"connection_refused",
|
|
73
|
+
"permission_denied",
|
|
74
|
+
"timeout",
|
|
75
|
+
"other",
|
|
76
|
+
]);
|
|
77
|
+
/** True only for a member of the closed {@link WorkerDatabaseMigrationCause} vocabulary. */
|
|
78
|
+
export function isWorkerDatabaseMigrationCause(value) {
|
|
79
|
+
return typeof value === "string" && MIGRATION_CAUSES.has(value);
|
|
80
|
+
}
|
|
81
|
+
/** Only this many leading bytes of stderr are ever inspected for a cause. */
|
|
82
|
+
const MIGRATION_CAUSE_STDERR_BYTES = 4_096;
|
|
83
|
+
/** Per-step cap for one offline Alembic inspection command (inside the stage budget). */
|
|
84
|
+
export const WORKER_DATABASE_ALEMBIC_INSPECTION_STEP_TIMEOUT_MS = 5_000;
|
|
66
85
|
const UNAVAILABLE_CATEGORIES = new Set([
|
|
67
86
|
"client_missing",
|
|
68
87
|
"postgres_unavailable",
|
|
@@ -492,7 +511,106 @@ const LISTING_COLUMNS = "encode(convert_to(datname::text, 'UTF8'), 'hex'), " +
|
|
|
492
511
|
"encode(convert_to(coalesce(shobj_description(oid, 'pg_database'), ''), 'UTF8'), 'hex')";
|
|
493
512
|
const WORKER_LISTING_SQL = `SELECT ${LISTING_COLUMNS} FROM pg_database WHERE ${exactPrefixPredicate(WORKER_DATABASE_PREFIX)} ` +
|
|
494
513
|
`ORDER BY datname LIMIT ${MAX_LISTED_DATABASES}`;
|
|
495
|
-
|
|
514
|
+
/** Most owners one harness listing returns (one representative database each). */
|
|
515
|
+
const MAX_HARNESS_OWNERS = 5;
|
|
516
|
+
/** A PostgreSQL role name the doctor and launch plan may display: ASCII, no whitespace or control characters. */
|
|
517
|
+
const HARNESS_OWNER_ROLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_$-]{0,62}$/;
|
|
518
|
+
/** True only for a whole-string valid owner role name; nothing is trimmed into validity. */
|
|
519
|
+
export function isValidHarnessOwnerRole(value) {
|
|
520
|
+
return typeof value === "string" && HARNESS_OWNER_ROLE_PATTERN.test(value);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Harness databases with their owners. Totals are computed over the full set
|
|
524
|
+
* BEFORE the row limit: the exact database count, and the exact count of distinct
|
|
525
|
+
* VALID owners. The listing then ranks owners in byte order and returns one
|
|
526
|
+
* representative database per owner for the first five, so many databases owned
|
|
527
|
+
* by one role cannot hide another owner. Invalid owners are counted in the total
|
|
528
|
+
* only. Names and owners are hex-encoded so no separator or newline can split a
|
|
529
|
+
* row. At most five rows, far below the runner's capture limit.
|
|
530
|
+
*/
|
|
531
|
+
/** Explicit CI-owner declaration is the authority; syntax validation alone grants nothing. */
|
|
532
|
+
export const HARNESS_CI_OWNER_ENV = "BAPI_HARNESS_CI_OWNER_ROLE";
|
|
533
|
+
function harnessListingSql(ciOwner, activity = true) {
|
|
534
|
+
const ci = isValidHarnessOwnerRole(ciOwner)
|
|
535
|
+
? `pg_get_userbyid(datdba)::text = ${sqlLiteral(ciOwner)}` : "false";
|
|
536
|
+
const used = activity
|
|
537
|
+
? "EXISTS (SELECT 1 FROM pg_stat_activity a WHERE a.datid = pg_database.oid AND a.backend_type = 'client backend')"
|
|
538
|
+
: "false";
|
|
539
|
+
return `WITH h AS (SELECT datname::text AS n, pg_get_userbyid(datdba)::text AS o, ${used} AS in_use, ${ci} AS ci_owned FROM pg_database ` +
|
|
540
|
+
`WHERE ${exactPrefixPredicate(HARNESS_DATABASE_PREFIX)}), ` +
|
|
541
|
+
`v AS (SELECT n, o FROM h WHERE o ~ ${sqlLiteral(HARNESS_OWNER_ROLE_PATTERN.source)}), ` +
|
|
542
|
+
`t AS (SELECT (SELECT count(*) FROM h) AS total, (SELECT count(DISTINCT o) FROM v) AS owners, ` +
|
|
543
|
+
`(SELECT count(*) FROM h WHERE in_use) AS used, (SELECT count(*) FROM h WHERE ci_owned) AS ci, ` +
|
|
544
|
+
`(SELECT count(*) FROM h WHERE in_use OR ci_owned) AS covered), ` +
|
|
545
|
+
`r AS (SELECT n, o, row_number() OVER (PARTITION BY o ORDER BY n COLLATE "C") AS rn, ` +
|
|
546
|
+
`dense_rank() OVER (ORDER BY o COLLATE "C") AS orank FROM v), ` +
|
|
547
|
+
`x AS (SELECT n, o, orank FROM r WHERE rn = 1 AND orank <= ${MAX_HARNESS_OWNERS}) ` +
|
|
548
|
+
`SELECT t.total, t.owners, coalesce(encode(convert_to(x.n, 'UTF8'), 'hex'), ''), ` +
|
|
549
|
+
`coalesce(encode(convert_to(x.o, 'UTF8'), 'hex'), ''), t.used, t.ci, t.covered, t.total - t.covered FROM t LEFT JOIN x ON true ` +
|
|
550
|
+
`ORDER BY x.orank LIMIT ${MAX_HARNESS_OWNERS}`;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Parse the harness listing. Null on any malformed output: wrong field count, bad
|
|
554
|
+
* hex, a name outside the exact harness prefix, inconsistent totals, or an unsafe
|
|
555
|
+
* integer. Empty output is a successful count of zero. An owner that fails the role
|
|
556
|
+
* rule is dropped here too (defense in depth) and never returned.
|
|
557
|
+
*/
|
|
558
|
+
export function parseHarnessListing(stdout) {
|
|
559
|
+
const lines = stdout.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0);
|
|
560
|
+
if (lines.length === 0)
|
|
561
|
+
return { count: 0, owners: [], ownerCount: 0 };
|
|
562
|
+
if (lines.length > MAX_HARNESS_OWNERS)
|
|
563
|
+
return null;
|
|
564
|
+
let total;
|
|
565
|
+
let ownerTotal;
|
|
566
|
+
const owners = new Set();
|
|
567
|
+
let coverage;
|
|
568
|
+
for (const line of lines) {
|
|
569
|
+
const fields = line.split("|");
|
|
570
|
+
if (fields.length !== 8)
|
|
571
|
+
return null;
|
|
572
|
+
const [totalText, ownersText, nameHex, ownerHex] = fields;
|
|
573
|
+
if (!/^\d{1,15}$/.test(totalText) || !/^\d{1,15}$/.test(ownersText))
|
|
574
|
+
return null;
|
|
575
|
+
const lineTotal = Number(totalText);
|
|
576
|
+
const lineOwners = Number(ownersText);
|
|
577
|
+
if (!Number.isSafeInteger(lineTotal) || !Number.isSafeInteger(lineOwners))
|
|
578
|
+
return null;
|
|
579
|
+
if (total !== undefined && (total !== lineTotal || ownerTotal !== lineOwners))
|
|
580
|
+
return null;
|
|
581
|
+
const counts = fields.slice(4);
|
|
582
|
+
if (counts.some((n) => !/^\d{1,15}$/.test(n)))
|
|
583
|
+
return null;
|
|
584
|
+
const [inUse, ciOwned, covered, uncovered] = counts.map(Number);
|
|
585
|
+
const parsed = sanitizeHarnessCoverage({ total: lineTotal, activity: "known", inUse, ciOwned, covered, uncovered });
|
|
586
|
+
if (!parsed || (coverage && JSON.stringify(coverage) !== JSON.stringify(parsed)))
|
|
587
|
+
return null;
|
|
588
|
+
coverage = parsed;
|
|
589
|
+
total = lineTotal;
|
|
590
|
+
ownerTotal = lineOwners;
|
|
591
|
+
if (!HEX_PATTERN.test(nameHex) || !HEX_PATTERN.test(ownerHex))
|
|
592
|
+
return null;
|
|
593
|
+
if (nameHex.length === 0 && ownerHex.length === 0)
|
|
594
|
+
continue;
|
|
595
|
+
if (nameHex.length === 0 || ownerHex.length === 0)
|
|
596
|
+
return null;
|
|
597
|
+
const name = Buffer.from(nameHex, "hex").toString("utf8");
|
|
598
|
+
if (!name.startsWith(HARNESS_DATABASE_PREFIX))
|
|
599
|
+
return null;
|
|
600
|
+
const owner = Buffer.from(ownerHex, "hex").toString("utf8");
|
|
601
|
+
if (Buffer.from(name, "utf8").toString("hex") !== nameHex ||
|
|
602
|
+
Buffer.from(owner, "utf8").toString("hex") !== ownerHex)
|
|
603
|
+
return null;
|
|
604
|
+
if (isValidHarnessOwnerRole(owner))
|
|
605
|
+
owners.add(owner);
|
|
606
|
+
}
|
|
607
|
+
if (total === undefined || ownerTotal === undefined)
|
|
608
|
+
return null;
|
|
609
|
+
if (ownerTotal > total || owners.size > ownerTotal)
|
|
610
|
+
return null;
|
|
611
|
+
const sorted = [...owners].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)).slice(0, MAX_HARNESS_OWNERS);
|
|
612
|
+
return { count: total, owners: sorted, ownerCount: ownerTotal, coverage };
|
|
613
|
+
}
|
|
496
614
|
function singleDatabaseListingSql(name) {
|
|
497
615
|
return `SELECT ${LISTING_COLUMNS} FROM pg_database WHERE datname = ${sqlLiteral(validateWorkerDatabaseName(name))}`;
|
|
498
616
|
}
|
|
@@ -587,13 +705,42 @@ async function guardedDropWorkerDatabase(name, deps, budgetMs, signal) {
|
|
|
587
705
|
function alembicFailureCategory(ctx, r) {
|
|
588
706
|
return interruption(ctx, r) ?? (r.timedOut ? "timeout" : "migration_failed");
|
|
589
707
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
708
|
+
/**
|
|
709
|
+
* Classify a failed Alembic subprocess into the closed cause vocabulary. Pure.
|
|
710
|
+
* Inspects only the first {@link MIGRATION_CAUSE_STDERR_BYTES} bytes of stderr for
|
|
711
|
+
* fixed phrases and returns a token — never any part of the input.
|
|
712
|
+
*/
|
|
713
|
+
export function classifyWorkerDatabaseMigrationFailure(result) {
|
|
714
|
+
if (result.timedOut)
|
|
715
|
+
return "timeout";
|
|
716
|
+
const raw = typeof result.stderr === "string" ? result.stderr : "";
|
|
717
|
+
const text = Buffer.from(raw, "utf8").subarray(0, MIGRATION_CAUSE_STDERR_BYTES).toString("utf8").toLowerCase();
|
|
718
|
+
if (text.includes("multiple head revisions"))
|
|
719
|
+
return "multiple_heads";
|
|
720
|
+
if (text.includes("can't locate revision"))
|
|
721
|
+
return "revision_missing";
|
|
722
|
+
if (text.includes("server does not support ssl, but ssl was required"))
|
|
723
|
+
return "ssl_refused";
|
|
724
|
+
if (text.includes("connection refused") || text.includes("could not connect"))
|
|
725
|
+
return "connection_refused";
|
|
726
|
+
if (text.includes("permission denied") || text.includes("must be owner"))
|
|
727
|
+
return "permission_denied";
|
|
728
|
+
return "other";
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* The migration subprocess environment. BAPI-1521: delegated to the shared
|
|
732
|
+
* builder so the compatibility-versus-declaration choice, and the declaration
|
|
733
|
+
* rules, are the worker's own. The database target keys stay executor-owned (a
|
|
734
|
+
* declaration can never name them), and only `PATH`/`HOME` are taken from the
|
|
735
|
+
* client environment, as before.
|
|
736
|
+
*/
|
|
737
|
+
function buildAlembicEnv(name, deps, workerEnvOption) {
|
|
738
|
+
const env = buildExecutorBaseWorkerEnv({ PATH: deps.clientPath, HOME: deps.clientHome }, { workerDatabase: { name }, legacyNotice: false, ...workerEnvOption });
|
|
739
|
+
// Two worker-only switches the shared builder always sets; a migration never
|
|
740
|
+
// needed them, and provisioning behavior is unchanged.
|
|
741
|
+
delete env.BRIDGE_SKIP_PREPUSH;
|
|
742
|
+
delete env.MAX_MCP_OUTPUT_TOKENS;
|
|
743
|
+
return env;
|
|
597
744
|
}
|
|
598
745
|
/**
|
|
599
746
|
* Verify the worker role and the `bridgeapi` boundary, create and comment a
|
|
@@ -614,19 +761,24 @@ export async function provisionWorkerDatabase(options, deps) {
|
|
|
614
761
|
const reserve = Math.min(WORKER_DATABASE_DROP_BUDGET_MS, Math.floor(budgetMs / 4));
|
|
615
762
|
const finalDeadline = start + budgetMs;
|
|
616
763
|
const ctx = { deps, signal: options.signal, deadline: finalDeadline - reserve };
|
|
617
|
-
const unavailable = (category, retainedName) => {
|
|
618
|
-
deps.diagnostic?.(formatWorkerDatabaseUnavailableLine(options.jobId, category));
|
|
764
|
+
const unavailable = (category, retainedName, cause) => {
|
|
765
|
+
deps.diagnostic?.(formatWorkerDatabaseUnavailableLine(options.jobId, category, cause));
|
|
766
|
+
const result = { kind: "unavailable", category };
|
|
767
|
+
if (cause)
|
|
768
|
+
result.cause = cause;
|
|
619
769
|
if (retainedName) {
|
|
620
770
|
deps.diagnostic?.(formatWorkerDatabaseDropFailedLine(options.jobId, retainedName));
|
|
621
|
-
|
|
771
|
+
result.retainedName = retainedName;
|
|
622
772
|
}
|
|
623
|
-
return
|
|
773
|
+
return result;
|
|
624
774
|
};
|
|
625
|
-
const rollback = async (name, category) => {
|
|
775
|
+
const rollback = async (name, category, cause) => {
|
|
626
776
|
// A small floor keeps a rollback possible even when a runner overshot its timeout.
|
|
627
777
|
const rollbackBudget = Math.max(Math.min(reserve, 5_000), finalDeadline - deps.now(), 1);
|
|
628
778
|
const outcome = await guardedDropWorkerDatabase(name, deps, rollbackBudget);
|
|
629
|
-
|
|
779
|
+
// A cancelled job was not a migration failure, so it carries no cause.
|
|
780
|
+
const kept = category === "cancelled" ? undefined : cause;
|
|
781
|
+
return outcome.kind === "dropped" ? unavailable(category, undefined, kept) : unavailable(category, name, kept);
|
|
630
782
|
};
|
|
631
783
|
if (options.signal?.aborted)
|
|
632
784
|
return unavailable("cancelled");
|
|
@@ -679,7 +831,7 @@ export async function provisionWorkerDatabase(options, deps) {
|
|
|
679
831
|
if (!succeeded(commented))
|
|
680
832
|
return rollback(name, interruption(ctx, commented) ?? "create_failed");
|
|
681
833
|
// (d) migrate with the job worktree's migrations, then verify the head.
|
|
682
|
-
const env = buildAlembicEnv(name, deps);
|
|
834
|
+
const env = buildAlembicEnv(name, deps, hasWorkerEnvOption(options) ? { workerEnv: options.workerEnv } : {});
|
|
683
835
|
const runAlembic = (args) => deps.runProcess({
|
|
684
836
|
file: alembic,
|
|
685
837
|
args,
|
|
@@ -691,21 +843,23 @@ export async function provisionWorkerDatabase(options, deps) {
|
|
|
691
843
|
if (remaining(ctx) <= 0)
|
|
692
844
|
return rollback(name, "timeout");
|
|
693
845
|
const upgraded = await runAlembic(["-c", "alembic.ini", "upgrade", "head"]);
|
|
694
|
-
if (!succeeded(upgraded))
|
|
695
|
-
return rollback(name, alembicFailureCategory(ctx, upgraded));
|
|
846
|
+
if (!succeeded(upgraded)) {
|
|
847
|
+
return rollback(name, alembicFailureCategory(ctx, upgraded), classifyWorkerDatabaseMigrationFailure(upgraded));
|
|
848
|
+
}
|
|
696
849
|
const outputs = [];
|
|
697
850
|
for (const args of [["-c", "alembic.ini", "heads"], ["-c", "alembic.ini", "current"]]) {
|
|
698
851
|
if (remaining(ctx) <= 0)
|
|
699
852
|
return rollback(name, "timeout");
|
|
700
853
|
const r = await runAlembic(args);
|
|
701
|
-
if (!succeeded(r))
|
|
702
|
-
return rollback(name, alembicFailureCategory(ctx, r));
|
|
854
|
+
if (!succeeded(r)) {
|
|
855
|
+
return rollback(name, alembicFailureCategory(ctx, r), classifyWorkerDatabaseMigrationFailure(r));
|
|
856
|
+
}
|
|
703
857
|
outputs.push(r.stdout);
|
|
704
858
|
}
|
|
705
859
|
const heads = parseAlembicRevisions(outputs[0]);
|
|
706
860
|
const current = parseAlembicRevisions(outputs[1]);
|
|
707
861
|
if (!heads || heads.length !== 1 || !current || current.length !== 1 || heads[0] !== current[0]) {
|
|
708
|
-
return rollback(name, "migration_failed");
|
|
862
|
+
return rollback(name, "migration_failed", heads && heads.length >= 2 ? "multiple_heads" : "other");
|
|
709
863
|
}
|
|
710
864
|
if (options.signal?.aborted)
|
|
711
865
|
return rollback(name, "cancelled");
|
|
@@ -810,9 +964,94 @@ export async function sweepOrphanedWorkerDatabases(options, deps) {
|
|
|
810
964
|
// Read-only inspection for doctor
|
|
811
965
|
// ---------------------------------------------------------------------------
|
|
812
966
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
967
|
+
* The offline Alembic environment: the SAME shared construction as
|
|
968
|
+
* {@link buildAlembicEnv} but with the executor's sentinel database target and no
|
|
969
|
+
* ambient environment — no operator `DATABASE_URL`, `PG*`/`POSTGRES_*`
|
|
970
|
+
* credential, or unrelated secret. Only client-owned `PATH`/`HOME` are carried.
|
|
971
|
+
*/
|
|
972
|
+
function buildOfflineAlembicEnv(deps) {
|
|
973
|
+
const env = buildExecutorBaseWorkerEnv({ PATH: deps.clientPath, HOME: deps.clientHome }, { legacyNotice: false });
|
|
974
|
+
delete env.BRIDGE_SKIP_PREPUSH;
|
|
975
|
+
delete env.MAX_MCP_OUTPUT_TOKENS;
|
|
976
|
+
return env;
|
|
977
|
+
}
|
|
978
|
+
/** Run one offline Alembic command and map interruption and failure to a row result. */
|
|
979
|
+
async function runOfflineAlembicStep(ctx, file, cwd, env, args) {
|
|
980
|
+
if (remaining(ctx) <= 0)
|
|
981
|
+
return { kind: "row", row: { state: "unsafe", cause: "timeout" } };
|
|
982
|
+
if (ctx.signal?.aborted)
|
|
983
|
+
return { kind: "row", row: { state: "unknown" } };
|
|
984
|
+
const r = await ctx.deps.runProcess({
|
|
985
|
+
file,
|
|
986
|
+
args,
|
|
987
|
+
cwd,
|
|
988
|
+
env,
|
|
989
|
+
timeoutMs: stepTimeout(ctx, WORKER_DATABASE_ALEMBIC_INSPECTION_STEP_TIMEOUT_MS),
|
|
990
|
+
signal: ctx.signal,
|
|
991
|
+
});
|
|
992
|
+
if (r.aborted || ctx.signal?.aborted || r.spawnFailed)
|
|
993
|
+
return { kind: "row", row: { state: "unknown" } };
|
|
994
|
+
if (r.timedOut)
|
|
995
|
+
return { kind: "row", row: { state: "unsafe", cause: "timeout" } };
|
|
996
|
+
if (r.exitCode === null)
|
|
997
|
+
return { kind: "row", row: { state: "unknown" } };
|
|
998
|
+
if (r.exitCode !== 0) {
|
|
999
|
+
return { kind: "row", row: { state: "unsafe", cause: classifyWorkerDatabaseMigrationFailure(r) } };
|
|
1000
|
+
}
|
|
1001
|
+
return { kind: "ok", stdout: r.stdout };
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* The two offline Alembic checks: `heads` (one head?) and, only after that,
|
|
1005
|
+
* `upgrade base:head --sql` (does the whole chain render?). Argument arrays, `--sql`
|
|
1006
|
+
* (offline mode), and the controlled environment keep this read-only; the
|
|
1007
|
+
* guarantee rests on the repository's offline `env.py`, not on process-level
|
|
1008
|
+
* network isolation. Rendered SQL is discarded at once and never stored.
|
|
1009
|
+
*/
|
|
1010
|
+
async function inspectOfflineAlembic(options, ctx) {
|
|
1011
|
+
const { deps } = ctx;
|
|
1012
|
+
let alembic;
|
|
1013
|
+
try {
|
|
1014
|
+
alembic = resolveRepositoryAlembicCommand(options.operatorRepositoryRoot, deps.platform);
|
|
1015
|
+
if (!(await deps.isExecutable(alembic)))
|
|
1016
|
+
return { state: "unsafe" };
|
|
1017
|
+
}
|
|
1018
|
+
catch {
|
|
1019
|
+
return { state: "unknown" };
|
|
1020
|
+
}
|
|
1021
|
+
try {
|
|
1022
|
+
const env = buildOfflineAlembicEnv(deps);
|
|
1023
|
+
const cwd = options.operatorRepositoryRoot;
|
|
1024
|
+
const heads = await runOfflineAlembicStep(ctx, alembic, cwd, env, ["-c", "alembic.ini", "heads"]);
|
|
1025
|
+
if (heads.kind === "row")
|
|
1026
|
+
return heads.row;
|
|
1027
|
+
const revisions = parseAlembicRevisions(heads.stdout);
|
|
1028
|
+
if (!revisions)
|
|
1029
|
+
return { state: "unsafe", cause: "other" };
|
|
1030
|
+
if (revisions.length >= 2)
|
|
1031
|
+
return { state: "unsafe", cause: "multiple_heads" };
|
|
1032
|
+
const rendered = await runOfflineAlembicStep(ctx, alembic, cwd, env, [
|
|
1033
|
+
"-c",
|
|
1034
|
+
"alembic.ini",
|
|
1035
|
+
"upgrade",
|
|
1036
|
+
"base:head",
|
|
1037
|
+
"--sql",
|
|
1038
|
+
]);
|
|
1039
|
+
if (rendered.kind === "row")
|
|
1040
|
+
return rendered.row;
|
|
1041
|
+
return { state: "healthy" };
|
|
1042
|
+
}
|
|
1043
|
+
catch {
|
|
1044
|
+
return { state: "unknown" };
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Doctor's worker-database rows. STRICTLY read-only: only SELECT statements, a
|
|
1049
|
+
* `bridgeapi` connection attempt, and exactly two offline Alembic commands —
|
|
1050
|
+
* `alembic -c alembic.ini heads` and `alembic -c alembic.ini upgrade base:head --sql`
|
|
1051
|
+
* (argument arrays, `--sql` offline render, controlled non-ambient environment,
|
|
1052
|
+
* run last) — no CREATE, DROP, COMMENT, or session termination, and no directory
|
|
1053
|
+
* creation. Alembic's read-only behavior relies on the repository's offline
|
|
1054
|
+
* `env.py`, not on process-level network isolation.
|
|
816
1055
|
*/
|
|
817
1056
|
export async function inspectWorkerDatabaseReadiness(options, deps) {
|
|
818
1057
|
const ctx = {
|
|
@@ -820,13 +1059,17 @@ export async function inspectWorkerDatabaseReadiness(options, deps) {
|
|
|
820
1059
|
signal: options.signal,
|
|
821
1060
|
deadline: deps.now() + Math.max(1, options.budgetMs ?? WORKER_DATABASE_SWEEP_BUDGET_MS),
|
|
822
1061
|
};
|
|
1062
|
+
const timings = {};
|
|
1063
|
+
let started = monotonicNow();
|
|
823
1064
|
const roleOutcome = await checkWorkerRole(ctx);
|
|
1065
|
+
timings["worker-db-role"] = elapsedMs(started);
|
|
824
1066
|
const role = roleOutcome.kind === "ok"
|
|
825
1067
|
? { state: "healthy" }
|
|
826
1068
|
: { state: roleOutcome.kind === "unsafe" ? "unsafe" : "unknown", category: roleOutcome.category };
|
|
827
1069
|
// The boundary probe is meaningful only once the maintenance connection worked
|
|
828
1070
|
// (a role row came back, healthy or not).
|
|
829
1071
|
const maintenanceConnected = roleOutcome.kind === "ok" || (roleOutcome.kind === "unsafe" && roleOutcome.category === "role_misconfigured");
|
|
1072
|
+
started = monotonicNow();
|
|
830
1073
|
let boundary;
|
|
831
1074
|
if (!maintenanceConnected) {
|
|
832
1075
|
boundary = { state: "unknown", category: "boundary_unknown" };
|
|
@@ -838,25 +1081,32 @@ export async function inspectWorkerDatabaseReadiness(options, deps) {
|
|
|
838
1081
|
? { state: "healthy" }
|
|
839
1082
|
: { state: b.kind === "unsafe" ? "unsafe" : "unknown", category: b.category };
|
|
840
1083
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const exists = await deps.isExecutable(resolveRepositoryAlembicCommand(options.operatorRepositoryRoot, deps.platform));
|
|
844
|
-
alembic = { state: exists ? "healthy" : "unsafe" };
|
|
845
|
-
}
|
|
846
|
-
catch {
|
|
847
|
-
alembic = { state: "unknown" };
|
|
848
|
-
}
|
|
1084
|
+
timings["worker-db-boundary"] = elapsedMs(started);
|
|
1085
|
+
started = monotonicNow();
|
|
849
1086
|
let inventory = { state: "unknown" };
|
|
850
1087
|
const listing = await listWorkerDatabases(ctx);
|
|
851
1088
|
if (listing.kind === "ok") {
|
|
852
|
-
const harness = await runPsql(deps, MAINTENANCE_DATABASE,
|
|
853
|
-
|
|
854
|
-
|
|
1089
|
+
const harness = await runPsql(deps, MAINTENANCE_DATABASE, harnessListingSql(options.ciHarnessOwnerRole), stepTimeout(ctx, WORKER_DATABASE_PSQL_STEP_TIMEOUT_MS), options.signal);
|
|
1090
|
+
let harnessListing = succeeded(harness) ? parseHarnessListing(harness.stdout) : null;
|
|
1091
|
+
// Only a failed activity request qualifies for fallback. Malformed successful
|
|
1092
|
+
// output remains unknown; never conceal it with an inventory retry.
|
|
1093
|
+
if (!succeeded(harness)) {
|
|
1094
|
+
const fallback = await runPsql(deps, MAINTENANCE_DATABASE, harnessListingSql(options.ciHarnessOwnerRole, false), stepTimeout(ctx, WORKER_DATABASE_PSQL_STEP_TIMEOUT_MS), options.signal);
|
|
1095
|
+
harnessListing = succeeded(fallback) ? parseHarnessListing(fallback.stdout) : null;
|
|
1096
|
+
if (harnessListing)
|
|
1097
|
+
harnessListing.coverage = {
|
|
1098
|
+
total: harnessListing.count, activity: "unknown", inUse: null, ciOwned: harnessListing.coverage?.ciOwned ?? 0, covered: null, uncovered: null,
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
if (harnessListing) {
|
|
855
1102
|
const value = {
|
|
856
1103
|
active: [],
|
|
857
1104
|
leftovers: [],
|
|
858
1105
|
unverifiable: [],
|
|
859
|
-
harnessCount:
|
|
1106
|
+
harnessCount: harnessListing.count,
|
|
1107
|
+
harnessCoverage: harnessListing.coverage,
|
|
1108
|
+
harnessOwners: harnessListing.owners,
|
|
1109
|
+
harnessOwnerCount: harnessListing.ownerCount,
|
|
860
1110
|
};
|
|
861
1111
|
for (const entry of listing.rows) {
|
|
862
1112
|
const ownership = classifyOwnership(entry, options.hostDigest);
|
|
@@ -875,7 +1125,14 @@ export async function inspectWorkerDatabaseReadiness(options, deps) {
|
|
|
875
1125
|
inventory = { state: "known", value };
|
|
876
1126
|
}
|
|
877
1127
|
}
|
|
878
|
-
|
|
1128
|
+
const inventoryMs = elapsedMs(started);
|
|
1129
|
+
for (const id of ["worker-db-leftovers", "worker-db-unverifiable", "worker-db-harness"])
|
|
1130
|
+
timings[id] = inventoryMs;
|
|
1131
|
+
// Alembic is probed LAST so a slow or failing check can never cost the earlier rows.
|
|
1132
|
+
started = monotonicNow();
|
|
1133
|
+
const alembic = await inspectOfflineAlembic(options, ctx);
|
|
1134
|
+
timings["worker-db-alembic"] = elapsedMs(started);
|
|
1135
|
+
return { role, boundary, alembic, inventory, timings };
|
|
879
1136
|
}
|
|
880
1137
|
// ---------------------------------------------------------------------------
|
|
881
1138
|
// Diagnostics
|
|
@@ -889,14 +1146,16 @@ function safeJobIdForLog(jobId) {
|
|
|
889
1146
|
* host operator and the runbook section; `bridgeapi_reachable` gets distinct
|
|
890
1147
|
* wording because it is an unsafe boundary, not a missing prerequisite.
|
|
891
1148
|
*/
|
|
892
|
-
export function formatWorkerDatabaseUnavailableLine(jobId, category) {
|
|
1149
|
+
export function formatWorkerDatabaseUnavailableLine(jobId, category, cause) {
|
|
893
1150
|
const id = safeJobIdForLog(jobId);
|
|
894
1151
|
if (category === "bridgeapi_reachable") {
|
|
895
1152
|
return (`[executor] job ${id}: UNSAFE worker database boundary: the worker role can connect to bridgeapi; ` +
|
|
896
1153
|
`no worker database was created; continuing with the sentinel database — host operator: see ${WORKER_DATABASE_RUNBOOK_SECTION}`);
|
|
897
1154
|
}
|
|
898
1155
|
const safeCategory = UNAVAILABLE_CATEGORIES.has(category) ? category : "unknown";
|
|
899
|
-
|
|
1156
|
+
const remedy = cause === "ssl_refused" ? "; declare the repository’s required setting in worker_env" : "";
|
|
1157
|
+
const causeSuffix = isWorkerDatabaseMigrationCause(cause) ? ` (cause: ${cause})` : "";
|
|
1158
|
+
return (`[executor] job ${id}: worker database unavailable (non-fatal): ${safeCategory}${causeSuffix}${remedy}; ` +
|
|
900
1159
|
`continuing with the sentinel database — host operator: see ${WORKER_DATABASE_RUNBOOK_SECTION}`);
|
|
901
1160
|
}
|
|
902
1161
|
/** The ONE bounded, non-fatal line for a teardown failure. */
|
|
@@ -518,7 +518,7 @@ const MAX_HOLD_BLOCKERS_IN_MESSAGE = 8;
|
|
|
518
518
|
* worker HEAD equal to it; and an origin tip equal to both. Anything less is not
|
|
519
519
|
* server confirmation, and the caller falls through to its existing checks.
|
|
520
520
|
*/
|
|
521
|
-
function
|
|
521
|
+
function confirmedDeliveryState(delivery, workerHeadSha, originSha) {
|
|
522
522
|
if (!delivery || delivery.bound !== true || delivery.unavailable === true)
|
|
523
523
|
return null;
|
|
524
524
|
if (typeof delivery.attemptId !== "string" || !delivery.attemptId)
|
|
@@ -537,6 +537,26 @@ function confirmedDeliveryHold(delivery, workerHeadSha, originSha) {
|
|
|
537
537
|
blockers: (delivery.blockers ?? []).map((b) => typeof b.step_id === "number" ? { kind: b.kind, step_id: b.step_id } : { kind: b.kind }),
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* BAPI-1563: the hold the server confirmed for THIS head, or null. Only an actual
|
|
542
|
+
* server hold outcome (`blocked`, `verification_failed`, `evidence_missing_or_stale`)
|
|
543
|
+
* is a hold. `awaiting_post_pr` and `complete` PERMIT publication and success, so
|
|
544
|
+
* they are never translated into a required-check or required-work failure here;
|
|
545
|
+
* a missing pull request is judged separately by {@link confirmedAwaitingWithoutPr}.
|
|
546
|
+
*/
|
|
547
|
+
function confirmedDeliveryHold(delivery, workerHeadSha, originSha) {
|
|
548
|
+
const state = confirmedDeliveryState(delivery, workerHeadSha, originSha);
|
|
549
|
+
return state !== null && DELIVERY_HOLD_OUTCOMES.has(state.outcome) ? state : null;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* BAPI-1426: an `awaiting_post_pr` attempt confirmed at THIS head. Its remaining
|
|
553
|
+
* work needs a pull request, so it is a hold only while none is attached. This is
|
|
554
|
+
* about the missing PR, not about verification: with a PR it is a success path.
|
|
555
|
+
*/
|
|
556
|
+
function confirmedAwaitingWithoutPr(delivery, workerHeadSha, originSha) {
|
|
557
|
+
const state = confirmedDeliveryState(delivery, workerHeadSha, originSha);
|
|
558
|
+
return state !== null && state.outcome === "awaiting_post_pr" ? state : null;
|
|
559
|
+
}
|
|
540
560
|
/**
|
|
541
561
|
* BAPI-1426: the intentional checkpoint a managed ticket ends with when the
|
|
542
562
|
* server holds its delivery. This is a `/fail`, never a success, and it never
|
|
@@ -547,7 +567,7 @@ function confirmedDeliveryHold(delivery, workerHeadSha, originSha) {
|
|
|
547
567
|
* The message carries only public identifiers, the closed outcome token, a
|
|
548
568
|
* truncated head, and blocker kinds with step ids — never evidence text.
|
|
549
569
|
*/
|
|
550
|
-
function deliveryHoldFailure(job, branch, hold) {
|
|
570
|
+
function deliveryHoldFailure(job, branch, hold, observedPr) {
|
|
551
571
|
const label = job.ticket_key ? `${job.ticket_key} (job ${job.id})` : `job ${job.id}`;
|
|
552
572
|
const shown = hold.blockers.slice(0, MAX_HOLD_BLOCKERS_IN_MESSAGE);
|
|
553
573
|
const blockerText = shown.length
|
|
@@ -567,8 +587,19 @@ function deliveryHoldFailure(job, branch, hold) {
|
|
|
567
587
|
classification: "clean_exit",
|
|
568
588
|
last_commit_sha: hold.preserved_head_sha,
|
|
569
589
|
telemetry,
|
|
590
|
+
// BAPI-1563: a hold still reports the pull request the executor discovered.
|
|
591
|
+
...(observedPr ? { observed_pr: observedPr } : {}),
|
|
570
592
|
};
|
|
571
593
|
}
|
|
594
|
+
/** BAPI-1563: the discovered pull request as a wire fact, or undefined when not fully known. */
|
|
595
|
+
function observedPrOf(pr) {
|
|
596
|
+
if (!pr.found || typeof pr.prNumber !== "number" || !Number.isInteger(pr.prNumber) || pr.prNumber <= 0) {
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
if (pr.headRefOid === null || !FULL_SHA_RE.test(pr.headRefOid) || pr.baseRef === null)
|
|
600
|
+
return undefined;
|
|
601
|
+
return { number: pr.prNumber, head_sha: pr.headRefOid, base_ref: pr.baseRef };
|
|
602
|
+
}
|
|
572
603
|
/**
|
|
573
604
|
* BAPI-1426: the delivery hold a finalization failure carries, or null. Read
|
|
574
605
|
* from the failure's own structured marker, never from its message.
|
|
@@ -747,11 +778,32 @@ export async function validateWorkerFinalization(input) {
|
|
|
747
778
|
// is attached, and before the attachment contract can call it missing.
|
|
748
779
|
// BAPI-1516: a `ci_fix` is never a delivery hold, even when an outcome reaches
|
|
749
780
|
// this seam directly; its success rests on the attachment contract below.
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
781
|
+
const observedPr = observedPrOf(pr);
|
|
782
|
+
if (observedPr && input.onObservedPr) {
|
|
783
|
+
try {
|
|
784
|
+
input.onObservedPr({ number: observedPr.number, headSha: observedPr.head_sha, baseRef: observedPr.base_ref });
|
|
785
|
+
}
|
|
786
|
+
catch {
|
|
787
|
+
/* observational only */
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
// BAPI-1563: the verdict acted on is a FRESH one, read after the final head is
|
|
791
|
+
// proven on origin and the PR has been discovered. A failed or absent refresh
|
|
792
|
+
// keeps the earlier read; it never invents a verdict.
|
|
793
|
+
let deliveryOutcome = input.deliveryOutcome;
|
|
794
|
+
if (job.job_type !== "ci_fix" && input.refreshDeliveryOutcome) {
|
|
795
|
+
try {
|
|
796
|
+
const fresh = await input.refreshDeliveryOutcome();
|
|
797
|
+
if (fresh !== undefined)
|
|
798
|
+
deliveryOutcome = fresh;
|
|
799
|
+
}
|
|
800
|
+
catch {
|
|
801
|
+
/* keep the earlier read */
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
const hold = job.job_type === "ci_fix" ? null : confirmedDeliveryHold(deliveryOutcome, trimmedHeadSha, remoteSha);
|
|
805
|
+
if (hold) {
|
|
806
|
+
return { ok: false, failure: deliveryHoldFailure(job, trimmedBranch, hold, observedPr) };
|
|
755
807
|
}
|
|
756
808
|
let contract = evaluatePrContract(pr, trimmedHeadSha, covered);
|
|
757
809
|
for (let attempt = 1; attempt < attempts && !contract.ok && contract.retryable; attempt++) {
|
|
@@ -761,12 +813,13 @@ export async function validateWorkerFinalization(input) {
|
|
|
761
813
|
}
|
|
762
814
|
// BAPI-1426: post-PR work needs a pull request. While neither the provider nor
|
|
763
815
|
// the server shows one, a confirmed `awaiting_post_pr` attempt is a hold too.
|
|
816
|
+
const awaitingHold = job.job_type === "ci_fix" ? null : confirmedAwaitingWithoutPr(deliveryOutcome, trimmedHeadSha, remoteSha);
|
|
764
817
|
if (!contract.ok &&
|
|
765
818
|
contract.unverified !== true &&
|
|
766
819
|
!pr.found &&
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
return { ok: false, failure: deliveryHoldFailure(job, trimmedBranch,
|
|
820
|
+
awaitingHold !== null &&
|
|
821
|
+
deliveryOutcome?.prNumber == null) {
|
|
822
|
+
return { ok: false, failure: deliveryHoldFailure(job, trimmedBranch, awaitingHold) };
|
|
770
823
|
}
|
|
771
824
|
if (!contract.ok && contract.unverified === true) {
|
|
772
825
|
return {
|
|
@@ -784,6 +837,8 @@ export async function validateWorkerFinalization(input) {
|
|
|
784
837
|
ok: true,
|
|
785
838
|
prUrl: pr.url ?? undefined,
|
|
786
839
|
prNumber: pr.prNumber,
|
|
840
|
+
// Only when a fresh assessment was requested, so the legacy success shape is unchanged.
|
|
841
|
+
...(input.refreshDeliveryOutcome !== undefined && deliveryOutcome !== undefined ? { deliveryOutcome } : {}),
|
|
787
842
|
// BAPI-1311: the verified origin tip — proven equal to the worker's HEAD above
|
|
788
843
|
// whenever that HEAD was known. Only for a caller that asked for it.
|
|
789
844
|
...(input.exposePushedHead === true ? { pushedHeadSha: remoteSha } : {}),
|
|
@@ -111,6 +111,12 @@ export function renderWorkerGuardReason(category, family, form) {
|
|
|
111
111
|
"made outside the worker. Do not run regenerate-plan or call its route; record the " +
|
|
112
112
|
"step escalated with its reason and continue.");
|
|
113
113
|
}
|
|
114
|
+
if (category === "operator-verb" && family === "acknowledge-gaps") {
|
|
115
|
+
return (`${WORKER_GUARD_REASON_PREFIX}: denied ${family} (${category}). ` +
|
|
116
|
+
"Acknowledging the run's carried-gap list is the run owner's decision, made " +
|
|
117
|
+
"outside the worker. Do not run acknowledge-gaps or call its route; record what " +
|
|
118
|
+
"you could not verify in your phase result and continue.");
|
|
119
|
+
}
|
|
114
120
|
if (category === "operator-verb") {
|
|
115
121
|
return (`${WORKER_GUARD_REASON_PREFIX}: denied ${family} (${category}). ` +
|
|
116
122
|
"Resolving a verification hand-off is the run owner's decision, made outside the " +
|
|
@@ -1012,9 +1018,11 @@ function isClaudeWorkflowPrintLaunch(segment) {
|
|
|
1012
1018
|
/**
|
|
1013
1019
|
* The operator-only subcommands a worker may never run, and their route segments.
|
|
1014
1020
|
* BAPI-1532 adds `regenerate-plan` beside `resolve-handoff`, with its own family so
|
|
1015
|
-
* the denial names the verb that was attempted.
|
|
1021
|
+
* the denial names the verb that was attempted. BAPI-1562 adds `acknowledge-gaps`,
|
|
1022
|
+
* the owner's one acknowledgement of the run's carried-gap list (route segment
|
|
1023
|
+
* `/acknowledge-gaps`), the same way.
|
|
1016
1024
|
*/
|
|
1017
|
-
const OPERATOR_ONLY_VERBS = ["resolve-handoff", "regenerate-plan"];
|
|
1025
|
+
const OPERATOR_ONLY_VERBS = ["resolve-handoff", "regenerate-plan", "acknowledge-gaps"];
|
|
1018
1026
|
/** The packaged MCP-server package token after `npx` (any version suffix). */
|
|
1019
1027
|
const BRIDGE_PACKAGE_TOKEN = /^@bridge_gpt\/mcp-server(?:@\S+)?$/;
|
|
1020
1028
|
/** Package runners whose package argument launches the packaged CLI. */
|
|
@@ -39,7 +39,18 @@ export function createProductionWorkerResources(input) {
|
|
|
39
39
|
let launcherDeps;
|
|
40
40
|
const cliDeps = () => (launcherDeps ??= createDefaultWorkerCliLauncherDeps({ stateDir }));
|
|
41
41
|
return {
|
|
42
|
-
provisionDatabase: (
|
|
42
|
+
provisionDatabase: (request) => provisionWorkerDatabase({
|
|
43
|
+
jobId: request.jobId,
|
|
44
|
+
operatorRepositoryRoot: input.cwd,
|
|
45
|
+
worktreePath: request.worktreePath,
|
|
46
|
+
executorPid,
|
|
47
|
+
hostDigest,
|
|
48
|
+
signal: request.signal,
|
|
49
|
+
// BAPI-1521 — forwarded only when the request owns it, so absence survives.
|
|
50
|
+
...(Object.prototype.hasOwnProperty.call(request, "workerEnv")
|
|
51
|
+
? { workerEnv: request.workerEnv }
|
|
52
|
+
: {}),
|
|
53
|
+
}, dbDeps()),
|
|
43
54
|
dropDatabase: (target) => dropWorkerDatabase(target, dbDeps()),
|
|
44
55
|
createLauncher: ({ jobId }) => createWorkerCliLauncher({ jobId }, cliDeps()),
|
|
45
56
|
sweepOrphanedDatabases: (signal) => sweepOrphanedWorkerDatabases({ hostDigest, executorPid, signal }, dbDeps()),
|