@bridge_gpt/mcp-server 0.2.73 → 0.2.75
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 +14 -7
- package/build/agent-launchers/claude-executor-adapter.js +12 -0
- package/build/agent-launchers/prompt.js +9 -21
- package/build/agents.generated.js +4 -4
- package/build/authored-plan.js +542 -0
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +11 -0
- package/build/command-provisioning.js +4 -3
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +692 -47
- package/build/conductor/command-drift.js +1 -1
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +2 -0
- package/build/conductor/driver-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -0
- package/build/conductor/epic-branch-ci-inspection.js +61 -16
- package/build/conductor/epic-implementer-cli.js +370 -93
- package/build/conductor/epic-server-sfcc-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +58 -80
- package/build/conductor/epic-server.js +57 -4
- package/build/conductor/gate-discovery.js +253 -13
- package/build/conductor/gate-settings-review.js +58 -25
- package/build/conductor/launch-plan.js +58 -12
- package/build/conductor/open-decision-phrases.js +50 -0
- package/build/conductor/prerequisite-inputs.js +181 -14
- package/build/connect-github-api.js +18 -0
- package/build/connect-github.js +35 -18
- package/build/credential-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +50 -0
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +47 -1
- package/build/docs.generated.js +8 -1
- package/build/doctor.js +41 -0
- package/build/drive-epic.js +684 -49
- package/build/epic-branch-ci-summary.js +18 -1
- package/build/epic-capability-statement.js +71 -3
- package/build/epic-ci-workflow-drift.js +52 -13
- package/build/epic-ci-workflow-install.js +31 -6
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +129 -7
- package/build/epic-implementer-bin.js +288 -83
- package/build/epic-implementer-bundle-cli.js +61 -0
- package/build/epic-implementer-claude-hook-bin.js +1 -1
- package/build/epic-implementer-env.js +3 -4
- package/build/epic-integration-pr.js +5 -2
- package/build/epic-launch-context.js +102 -7
- package/build/epic-server-record.js +30 -15
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +39 -1
- package/build/executor/epic-server-context.js +23 -7
- package/build/executor/gate-qualification-job.js +193 -23
- package/build/executor/gate-qualification-tests-ran.js +232 -0
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/job-runner.js +167 -738
- package/build/executor/job-type-wrappers.js +734 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/preflight.js +6 -2
- package/build/executor/process-containment.js +8 -1
- package/build/executor/prompt-spec.js +37 -3
- package/build/executor/required-verification.js +28 -2
- package/build/executor/runner.js +4 -1
- package/build/executor/types.js +9 -0
- package/build/executor/worker-database.js +6 -1
- package/build/executor/worker-guard-hook.js +24 -2
- package/build/executor-launch.js +4 -2
- package/build/generated/ticket-status.js +20 -0
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +589 -326
- package/build/install-bridge-conductor-answers.js +112 -22
- package/build/install-bridge-conductor-apply.js +38 -1
- package/build/install-bridge-conductor-assessment.js +482 -53
- package/build/install-bridge-conductor-compact.js +29 -2
- package/build/install-bridge-conductor-contracts.js +10 -1
- package/build/install-bridge-conductor-gate.js +379 -89
- package/build/install-bridge-conductor-setup.js +46 -8
- package/build/install-bridge-conductor-trial-report.js +170 -0
- package/build/install-bridge-conductor.js +925 -141
- package/build/install-bridge.js +88 -11
- package/build/install-doctor.js +38 -8
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/mcp-grant-candidates.js +108 -96
- package/build/mcp-invoke.js +168 -4
- package/build/mcp-provisioning.js +21 -4
- package/build/mcp-server-invocation.js +13 -0
- package/build/merge-workflow-install.js +9 -1
- package/build/pipelines.generated.js +8 -7
- package/build/plan-generation.js +17 -0
- package/build/plane/status.js +8 -2
- package/build/printed-remedy-commands.js +59 -0
- package/build/project-root.js +40 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +5 -2
- package/build/repository-toolchains.js +16 -7
- package/build/scripts/saved-commands-config-field-driver.js +65 -0
- package/build/setup-epic.js +126 -16
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +35 -4
- package/build/v2-readiness-requirements.js +5 -1
- package/build/version.generated.js +3 -3
- package/build/with-credentials.js +208 -0
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-credential-delivery.js +340 -0
- package/docs/EPIC-IMPLEMENTER.md +4 -4
- package/docs/install/github-app.md +79 -92
- package/package.json +1 -1
- package/build/conductor/epic-reconcile.js +0 -603
- package/build/conductor/epic-runtime.js +0 -2020
- package/build/conductor/epic-state.js +0 -774
|
@@ -5,7 +5,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { findWorktreeByBranch, parseGitWorktreePorcelain } from "./worktree-inspection.js";
|
|
7
7
|
import { resolveExecutorBranch, configureExecutorBranch } from "./worktree.js";
|
|
8
|
-
import { renderWorkerVerificationGuidance, renderWorkerPrBaseGuidance, renderWorkerPushEachCommitGuidance, renderWorkerTimeBudgetGuidance } from "./worker-verification-guidance.js";
|
|
8
|
+
import { renderWorkerVerificationGuidance, renderWorkerPrBaseGuidance, renderWorkerPushEachCommitGuidance, renderWorkerTimeBudgetGuidance, } from "./worker-verification-guidance.js";
|
|
9
9
|
/**
|
|
10
10
|
* Claimed-job execution engine (BAPI-534 core, BAPI-535 job behaviors; TDD §7/§8/§9).
|
|
11
11
|
*
|
|
@@ -22,39 +22,39 @@ import { renderWorkerVerificationGuidance, renderWorkerPrBaseGuidance, renderWor
|
|
|
22
22
|
* `spec_review`, plus per-job worker-log tee, watch registry, and optional
|
|
23
23
|
* read-only viewer tabs wired around every spawned worker.
|
|
24
24
|
*/
|
|
25
|
-
import { rm, readdir, lstat, unlink, realpath, rename as fsRename, stat as fsStat } from "node:fs/promises";
|
|
26
|
-
import { accessSync, constants as fsConstants, realpathSync, statSync } from "node:fs";
|
|
27
|
-
import { provisionWorktreeSettingsExclude } from "./permissions.js";
|
|
25
|
+
import { rm, readdir, lstat, unlink, realpath, rename as fsRename, stat as fsStat, } from "node:fs/promises";
|
|
26
|
+
import { accessSync, constants as fsConstants, realpathSync, statSync, } from "node:fs";
|
|
27
|
+
import { provisionWorktreeSettingsExclude, } from "./permissions.js";
|
|
28
28
|
import os from "node:os";
|
|
29
29
|
import { runHeartbeatLoop, sendImmediateHeartbeat } from "./heartbeat.js";
|
|
30
|
+
import { createFlowProcess, runCiRerunExecutorJob, runGateQualificationExecutorJob, runMergeJob, runSmokeJob, sendTerminalMutationWithAuthReport, superviseProcess, terminalToRunResult, toWireClassification, } from "./job-type-wrappers.js";
|
|
31
|
+
export { DEFAULT_SMOKE_DURATION_MS, GATE_QUALIFICATION_SETTLE_MAX_MS, createFlowProcess, createMergeFlowProcess, createNoopProcess, defaultRunMergeForClaimed, runCiRerunExecutorJob, runGateQualificationExecutorJob, runMergeJob, runSmokeJob, sendTerminalMutationWithAuthReport, superviseProcess, terminalToRunResult, toWireClassification, } from "./job-type-wrappers.js";
|
|
30
32
|
import { cleanupReportPermitsRecordRemoval, retryWakeCleanupReport, submitCleanupReport, } from "./cleanup-report.js";
|
|
31
33
|
import { isExecutorNamedError, toExecutorFailure, RebaseNotVerified, secretFreeErrorMessage, secretFreeWorktreeMessage, WorktreeSetupRefused, MissingVerdictArtifact, PackagedRecipeUndeliverable, PreSpawnVerification, RequiredMcpRegistration, McpSurfaceMismatch, WorkerStartupFatal, WORKER_STARTUP_FATAL_MESSAGE, WorkerEndedWithPendingBackgroundWork, WORKER_ENDED_WITH_PENDING_BACKGROUND_WORK_MESSAGE, formatMcpSurfaceMismatch, ClaudeNotAuthenticated, CLAUDE_NOT_AUTHENTICATED_MESSAGE, ExecutorAdapterUnavailable, ExecutorNamedError, WorktreeBusy, StaleArtifactCleanupFailed, CiFixContext, WORKTREE_BUSY_MESSAGE, WorkerEnvFilePresent, WORKER_ENV_FILE_PRESENT_MESSAGE, } from "./job-errors.js";
|
|
32
|
-
import { buildConductorMergeAccessForExecutorJob, buildMergeLocalDepsForJob, runExecutorMergeJob, MERGE_RETRYABLE, MERGE_FAILED, MERGE_ACCESS_UNAVAILABLE, MERGE_FLOW_ERROR, MERGE_FLOW_TIMEOUT, MERGE_NO_OUTCOME, } from "./merge-job.js";
|
|
33
|
-
import { createProductionCiRerunDeps, runCiRerunJob, } from "./ci-rerun-job.js";
|
|
34
|
-
import { createProductionGateQualificationDeps, runGateQualificationJob, GATE_QUALIFICATION_FAILED, GATE_QUALIFICATION_INTERRUPTED, } from "./gate-qualification-job.js";
|
|
35
34
|
import { createObservationState } from "./observation.js";
|
|
36
35
|
import { getWorktreeMcpRegistrationTargets, normalizeWorktreePathForRegistration, provisionMcpRegistrationForWorktree, } from "../mcp-provisioning.js";
|
|
36
|
+
import { hasBridgeConsumer, legacyReferenceBackedTargets, } from "../credential-delivery.js";
|
|
37
|
+
import { credentialNoticeLines, formatCredentialAuditLines, prepareExecutorCredentialDelivery, readExecutorCredentialApprovals, } from "./credential-delivery-step.js";
|
|
37
38
|
import { resolveExecutorAgentAdapter } from "../agent-launchers/executor-adapter-registry.js";
|
|
38
39
|
import { redactAdapterDiagnostic } from "../agent-launchers/executor-adapter.js";
|
|
39
40
|
import { resolveExecutorAgentId } from "./agent-identity.js";
|
|
40
41
|
import { closeStdinBounded, createProcessTerminationController, runProcessWithTimeout, writeStdinBounded, } from "./process.js";
|
|
41
42
|
import { buildNotLaunchedEnvelope, claimRequiresCleanupReport, claimRequiresCompletionEvidence, COMPLETION_CONTRACT_MARKER_VALUES, isCoveredJobType, MAX_EVENT_BYTES, runtimeMatchesSupported, successRefusalReason, unresolvedRequiredTasks, verificationVerdictFromFacts, } from "./completion-contract.js";
|
|
42
|
-
import { COMPLETION_CAUSE_ERROR_KINDS, EOF_DRAIN_BOUND_MS, STDIN_CLOSE_GRACE_MS, finalizationFacts, finalizationObligations, planCompletionAllowance, readCompletionBinding, readDeclaredChecks, readOptionalWatchers, readRequiredVerification, renderApprovedVerificationGuidance, } from "./completion-supervision.js";
|
|
43
|
+
import { COMPLETION_CAUSE_ERROR_KINDS, EOF_DRAIN_BOUND_MS, FINALIZATION_RESERVE_MS, REPORT_RESERVE_MS, STDIN_CLOSE_GRACE_MS, finalizationFacts, finalizationObligations, planCompletionAllowance, readCompletionBinding, readDeclaredChecks, readOptionalWatchers, readRequiredVerification, renderApprovedVerificationGuidance, } from "./completion-supervision.js";
|
|
43
44
|
import { compareFinalArtifact, createRequiredVerificationRunner, createSupervisedCommandLauncher, observeFinalArtifact, OWNERSHIP_POLL_MS, preCheckArtifactState, toCompletionCheckFact, } from "./required-verification.js";
|
|
44
45
|
import { createClosureSupervisor, createRequiredWorkLedger } from "./required-work-ledger.js";
|
|
45
46
|
import { COMPLETION_WINDOW_CLOSED_ON_LIVE_AGENT, requiredWorkKindTokens, } from "./required-work-diagnostics.js";
|
|
46
47
|
import { buildCleanupVerdict, CLEANUP_RESIDUALS_NOT_COVERED, createDefaultOwnershipRecordFs, createDescendantTracker, createMacProcessInspector, createOwnershipToken, hostIdentityDigest, ownershipTokenDigest, removeOwnershipRecord, runOwnedProcessSweep, withExecutorJobId, withOwnershipTag, writeOwnershipRecord, } from "./process-containment.js";
|
|
47
48
|
import { resolveCompletionEvidenceCapability } from "../agent-launchers/executor-adapter.js";
|
|
48
49
|
import { autoCheckpointDirtyState, PRIOR_ATTEMPT_WIP_COMMIT_MESSAGE, prepareResumeSpawn, prepareRetainedContinuationWorktree, readContinuationBinding, verifyContinuationHeadLineage, } from "./resume-pre-spawn.js";
|
|
49
|
-
import { buildEpicWorkaroundWorkerInstruction, buildEpicCapabilityStatementWorkerInstruction, buildEpicServerWorkerInstruction, ciFixContextError, readCiFixDispatchContext, renderPromptSpecPrompt, } from "./prompt-spec.js";
|
|
50
|
+
import { buildEpicWorkaroundWorkerInstruction, buildCredentialNoticeWorkerInstruction, buildEpicCapabilityStatementWorkerInstruction, buildEpicServerWorkerInstruction, ciFixContextError, readCiFixDispatchContext, renderPromptSpecPrompt, } from "./prompt-spec.js";
|
|
50
51
|
import { createDefaultEpicServerContextDeps, readEpicServerWorkerContext, withEpicServerEnv, } from "./epic-server-context.js";
|
|
51
52
|
/** BAPI-1399: the job type whose worker implements ticket requirements from scratch. */
|
|
52
53
|
const WORKAROUND_CONTRACT_JOB_TYPES = new Set(["implement"]);
|
|
53
54
|
import { defaultResolveBinPath } from "../start-tickets-conductor.js";
|
|
54
55
|
/** The packaged bin basename of the deterministic worker guard (BAPI-1020). */
|
|
55
56
|
const WORKER_GUARD_BIN_FILENAME = "worker-guard-hook-bin.js";
|
|
56
|
-
import { buildGenericSuccessResult, CI_FIX_CLAIMS_STATUS_KEY, readCiFixResultArtifact, readCiFixTestRunsArtifact,
|
|
57
|
-
import { sendTerminalMutationWithRetry } from "./terminal-mutation.js";
|
|
57
|
+
import { buildGenericSuccessResult, CI_FIX_CLAIMS_STATUS_KEY, readCiFixResultArtifact, readCiFixTestRunsArtifact, commitResidue, readCompletionArtifacts, RESULT_JSONB_MAX_BYTES, resolveJobTimeoutSeconds, } from "./results.js";
|
|
58
58
|
import { removeStaleVerdictArtifacts } from "./stale-artifacts.js";
|
|
59
59
|
import { stripWorkerEnvFiles } from "./env-file-guard.js";
|
|
60
60
|
import { buildDependencyInstallEnv, payloadCiDatabase, payloadDependencyInstallOption, payloadPrePrChecksOption, payloadWorkerEnvOption, validateDependencyInstallDeclarations, } from "./env.js";
|
|
@@ -69,7 +69,7 @@ import { createWorkerLogClaimId, createWorkerLogTee, closeWorkerLogTee, distinct
|
|
|
69
69
|
import { acquireExecutorWorktreeLock, } from "./worktree-lock.js";
|
|
70
70
|
import { resolveExecutorStateDir, activateJobLog, deactivateJobLog, registerExecutorJobLog, markExecutorJobLogFinished, } from "./job-log-registry.js";
|
|
71
71
|
import { EXECUTOR_JOB_END_LOG_CHUNK, executorViewerTabsEnabled, openExecutorViewerTab, } from "./viewer-tabs.js";
|
|
72
|
-
import { isImplementationStyleJobType, isRecoveryJobType, isSpawnJobType } from "./job-types.js";
|
|
72
|
+
import { isImplementationStyleJobType, isRecoveryJobType, isSpawnJobType, } from "./job-types.js";
|
|
73
73
|
import { cleanupInterruptedWorktree } from "./interrupted-worktree.js";
|
|
74
74
|
import { lazyProviderCheckPoller, runReconcileOverlapJob, } from "./reconcile-overlap-job.js";
|
|
75
75
|
import { resolveExecutorJobBaseBranch } from "./base-branch.js";
|
|
@@ -104,8 +104,6 @@ const ENV_FILE_TRACKED_LOOKUP_TIMEOUT_MS = 5_000;
|
|
|
104
104
|
* exempted.
|
|
105
105
|
*/
|
|
106
106
|
const ENV_FILE_TRACKED_LOOKUP_FAILED_MESSAGE = "[executor] tracked env-file lookup unavailable; exempting nothing";
|
|
107
|
-
/** Default runtime for the no-op smoke process (ms). */
|
|
108
|
-
const DEFAULT_SMOKE_DURATION_MS = 100;
|
|
109
107
|
/**
|
|
110
108
|
* BAPI-1426: implementation-style job types that never read a delivery outcome.
|
|
111
109
|
* `reconcile_overlap`'s push is the wrapper's own, not a ticket delivery attempt.
|
|
@@ -193,9 +191,6 @@ function unresolvedKindsSuffix(envelope) {
|
|
|
193
191
|
const tokens = requiredWorkKindTokens(unresolvedRequiredTasks(envelope).map((task) => task.kind));
|
|
194
192
|
return tokens.length > 0 ? `; unresolved: ${tokens.join(", ")}` : "";
|
|
195
193
|
}
|
|
196
|
-
function toWireClassification(c) {
|
|
197
|
-
return c;
|
|
198
|
-
}
|
|
199
194
|
function classificationToErrorKind(c) {
|
|
200
195
|
switch (c) {
|
|
201
196
|
case "timeout":
|
|
@@ -306,7 +301,7 @@ function buildJobLogRegistryDeps(deps) {
|
|
|
306
301
|
* only correct value is the one the caller threads down from the validated
|
|
307
302
|
* runtime configuration.
|
|
308
303
|
*/
|
|
309
|
-
function buildExecutorMcpProvisioningDeps(deps, bridgeApiBaseUrl, trustedRepoName) {
|
|
304
|
+
function buildExecutorMcpProvisioningDeps(deps, bridgeApiBaseUrl, trustedRepoName, reference) {
|
|
310
305
|
return {
|
|
311
306
|
readFile: deps.readFile,
|
|
312
307
|
writeFile: deps.writeFile,
|
|
@@ -320,6 +315,9 @@ function buildExecutorMcpProvisioningDeps(deps, bridgeApiBaseUrl, trustedRepoNam
|
|
|
320
315
|
env: deps.env.XDG_CONFIG_HOME !== undefined ? { XDG_CONFIG_HOME: deps.env.XDG_CONFIG_HOME } : {},
|
|
321
316
|
homedir: deps.homedir,
|
|
322
317
|
...(trustedRepoName !== undefined ? { trustedRepoName } : {}),
|
|
318
|
+
// BAPI-1647: names-only reference inputs for the legacy (no-grant) path.
|
|
319
|
+
...(reference?.credentialReferenceTargets ? { credentialReferenceTargets: reference.credentialReferenceTargets } : {}),
|
|
320
|
+
...(reference?.bapiReferenceRepo !== undefined ? { bapiReferenceRepo: reference.bapiReferenceRepo } : {}),
|
|
323
321
|
};
|
|
324
322
|
}
|
|
325
323
|
/**
|
|
@@ -407,8 +405,16 @@ async function reportWorkerLogSessionInvariant(tee, deps) {
|
|
|
407
405
|
deps.errorLog(formatWorkerLogSessionInvariantWarning(sessions.length));
|
|
408
406
|
}
|
|
409
407
|
}
|
|
410
|
-
async function provisionMcpForPreparedSpawn(job, branch, worktreePath, deps, seams, bridgeApiBaseUrl) {
|
|
408
|
+
async function provisionMcpForPreparedSpawn(job, branch, worktreePath, deps, seams, bridgeApiBaseUrl, credentialApprovals) {
|
|
411
409
|
const provision = seams.provisionMcp ?? provisionMcpRegistrationForWorktree;
|
|
410
|
+
// BAPI-1647: from the one names-only record read made for this start.
|
|
411
|
+
const credentialMetadata = credentialApprovals?.state === "ok" ? credentialApprovals.metadata : null;
|
|
412
|
+
const reference = credentialMetadata
|
|
413
|
+
? {
|
|
414
|
+
credentialReferenceTargets: (manifest) => legacyReferenceBackedTargets(credentialMetadata, manifest.mcp),
|
|
415
|
+
...(hasBridgeConsumer(credentialMetadata) ? { bapiReferenceRepo: job.repo_name } : {}),
|
|
416
|
+
}
|
|
417
|
+
: {};
|
|
412
418
|
const row = {
|
|
413
419
|
key: job.ticket_key ?? String(job.id),
|
|
414
420
|
branch,
|
|
@@ -419,7 +425,7 @@ async function provisionMcpForPreparedSpawn(job, branch, worktreePath, deps, sea
|
|
|
419
425
|
// BAPI-1545: the claimed job's `repo_name` comes from the server's claim
|
|
420
426
|
// response, never from a worktree file, so it is the trusted identity the
|
|
421
427
|
// grant is selected by.
|
|
422
|
-
const result = await provision(row, buildExecutorMcpProvisioningDeps(deps, bridgeApiBaseUrl, job.repo_name));
|
|
428
|
+
const result = await provision(row, buildExecutorMcpProvisioningDeps(deps, bridgeApiBaseUrl, job.repo_name, reference));
|
|
423
429
|
for (const warning of result.warnings ?? []) {
|
|
424
430
|
deps.errorLog(`MCP provisioning warning: ${warning}`);
|
|
425
431
|
}
|
|
@@ -621,85 +627,6 @@ async function checkAdapterMcpAdvisoryForPreparedWorktree(worktreePath, deps, ad
|
|
|
621
627
|
deps.errorLog("worker MCP advisory inspection did not complete; continuing without an advisory verdict");
|
|
622
628
|
}
|
|
623
629
|
}
|
|
624
|
-
/**
|
|
625
|
-
* Default merge dispatch: resolve Bridge API access, then run the deterministic
|
|
626
|
-
* merge. Exported for unit tests (access-resolution failure → retryable). The
|
|
627
|
-
* `controls.signal` (overall-timeout abort) is threaded into local merge deps
|
|
628
|
-
* without changing the local `gh` credential model.
|
|
629
|
-
*/
|
|
630
|
-
export async function defaultRunMergeForClaimed(job, deps, options, controls) {
|
|
631
|
-
const accessResult = await buildConductorMergeAccessForExecutorJob({
|
|
632
|
-
env: deps.env,
|
|
633
|
-
cwd: deps.cwd,
|
|
634
|
-
homedir: deps.homedir,
|
|
635
|
-
platform: deps.platform,
|
|
636
|
-
readFile: deps.readFile,
|
|
637
|
-
stat: deps.stat,
|
|
638
|
-
});
|
|
639
|
-
if (!accessResult.ok) {
|
|
640
|
-
// Access resolution feeds only the executor's read-only CI re-poll; a missing
|
|
641
|
-
// or temporarily-unavailable Bridge API access is transient infrastructure, so
|
|
642
|
-
// it is RETRYABLE (BAPI-572). The local `gh` credential model is unchanged.
|
|
643
|
-
return {
|
|
644
|
-
ok: false,
|
|
645
|
-
failure: {
|
|
646
|
-
error_kind: MERGE_RETRYABLE,
|
|
647
|
-
error_message: accessResult.error,
|
|
648
|
-
classification: "crashed",
|
|
649
|
-
telemetry: { failure_reason_code: MERGE_ACCESS_UNAVAILABLE },
|
|
650
|
-
},
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
return runExecutorMergeJob(job, {
|
|
654
|
-
access: accessResult.access,
|
|
655
|
-
// Thread the overall-timeout abort signal into local merge deps WITHOUT
|
|
656
|
-
// changing the local `gh` credential model (the signal is not a credential).
|
|
657
|
-
// BAPI-1453: the same signal bounds the post-`gh_pr_view_failed` permission
|
|
658
|
-
// probe, so it can never outlive the merge flow's own timeout.
|
|
659
|
-
// BAPI-1461: resolved when the job runs, with the stored-entry fallback for
|
|
660
|
-
// an executor started in the person's own session. A durable-host service
|
|
661
|
-
// executor declared itself with --scrub-inherited-github-credentials and
|
|
662
|
-
// never reads a stored GitHub credential.
|
|
663
|
-
localMergeDeps: await buildMergeLocalDepsForJob(job, deps, { allowStoredEntry: options.scrubInheritedGithubCredentials !== true }, controls?.signal),
|
|
664
|
-
// BAPI-951: the executor's own configured base — resolveExecutorJobBaseBranch
|
|
665
|
-
// (called inside runExecutorMergeJob) resolves the CHILD PR's base from the
|
|
666
|
-
// job's persisted run base, falling back to this value for a legacy job.
|
|
667
|
-
repositoryBaseBranch: options.baseBranch,
|
|
668
|
-
epicIntegrationAdvisoryLog: deps.errorLog,
|
|
669
|
-
diagnosticLog: deps.errorLog,
|
|
670
|
-
cwd: deps.cwd,
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
/** An in-memory owned process for the no-op `smoke` acceptance job. */
|
|
674
|
-
function createNoopProcess(deps, durationMs, message) {
|
|
675
|
-
let killResolve = null;
|
|
676
|
-
const killed = new Promise((res) => {
|
|
677
|
-
killResolve = res;
|
|
678
|
-
});
|
|
679
|
-
let done = false;
|
|
680
|
-
async function* stdout() {
|
|
681
|
-
if (message)
|
|
682
|
-
yield message;
|
|
683
|
-
}
|
|
684
|
-
return {
|
|
685
|
-
pid: undefined,
|
|
686
|
-
stdout: stdout(),
|
|
687
|
-
stderr: null,
|
|
688
|
-
async wait() {
|
|
689
|
-
const natural = deps
|
|
690
|
-
.sleep(durationMs)
|
|
691
|
-
.then(() => ({ exitCode: 0, signal: null }));
|
|
692
|
-
const result = await Promise.race([natural, killed]);
|
|
693
|
-
done = true;
|
|
694
|
-
return result;
|
|
695
|
-
},
|
|
696
|
-
kill(signal) {
|
|
697
|
-
if (done)
|
|
698
|
-
return;
|
|
699
|
-
killResolve?.({ exitCode: null, signal });
|
|
700
|
-
},
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
630
|
/**
|
|
704
631
|
* Bounded newline assembly of worker stdout into logical lines for a
|
|
705
632
|
* {@link RequiredWorkLedger} (BAPI-1301 covered path, BAPI-1364 legacy
|
|
@@ -794,132 +721,6 @@ export function createLedgerLineFeeder(ledger, onLine) {
|
|
|
794
721
|
},
|
|
795
722
|
};
|
|
796
723
|
}
|
|
797
|
-
/**
|
|
798
|
-
* Run the process and heartbeat loop concurrently; return the process outcome.
|
|
799
|
-
*
|
|
800
|
-
* BAPI-731: `serverStopRequested` is carried ALONGSIDE the process
|
|
801
|
-
* classification rather than folded into it. When the server cancels a run the
|
|
802
|
-
* worker is SIGKILLed, so its raw classification would read as `killed` — which
|
|
803
|
-
* the caller would otherwise report as a worker fault. Keeping the flag separate
|
|
804
|
-
* is what lets the caller report a deliberate server cancellation distinctly.
|
|
805
|
-
*/
|
|
806
|
-
async function superviseProcess(params) {
|
|
807
|
-
const isDoneRef = { value: false };
|
|
808
|
-
const heartbeatStop = new AbortController();
|
|
809
|
-
const heartbeatDeps = params.cancelHeartbeatSleepOnExit ? { ...params.deps, sleep: (ms) => new Promise((resolve) => {
|
|
810
|
-
if (heartbeatStop.signal.aborted) {
|
|
811
|
-
resolve();
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
let timer;
|
|
815
|
-
const done = () => { params.deps.clearTimer(timer); heartbeatStop.signal.removeEventListener("abort", done); resolve(); };
|
|
816
|
-
timer = params.deps.setTimer(done, ms);
|
|
817
|
-
heartbeatStop.signal.addEventListener("abort", done, { once: true });
|
|
818
|
-
}) } : params.deps;
|
|
819
|
-
const hb = runHeartbeatLoop({
|
|
820
|
-
job: params.job,
|
|
821
|
-
httpClient: params.httpClient,
|
|
822
|
-
options: params.options,
|
|
823
|
-
deps: heartbeatDeps,
|
|
824
|
-
ownership: params.ownership,
|
|
825
|
-
proc: params.proc,
|
|
826
|
-
observation: params.observation,
|
|
827
|
-
collectTelemetry: params.collectTelemetry,
|
|
828
|
-
collectRemoteMarker: params.collectRemoteMarker,
|
|
829
|
-
isDone: () => isDoneRef.value,
|
|
830
|
-
});
|
|
831
|
-
const mcpSurface = params.mcpSurface;
|
|
832
|
-
const result = await runProcessWithTimeout(params.proc, params.timeoutSeconds, params.deps, {
|
|
833
|
-
termGraceMs: params.options.termGraceMs,
|
|
834
|
-
...(params.terminationController
|
|
835
|
-
? { terminationController: params.terminationController }
|
|
836
|
-
: {}),
|
|
837
|
-
onStdout: (chunk) => {
|
|
838
|
-
params.observation.recordStdout(chunk);
|
|
839
|
-
params.onStdoutObserved?.(chunk);
|
|
840
|
-
},
|
|
841
|
-
...(mcpSurface
|
|
842
|
-
? {
|
|
843
|
-
onStdoutTerminationCheck: (chunk) => {
|
|
844
|
-
mcpSurface.observeStdout(chunk);
|
|
845
|
-
return mcpSurface.shouldTerminate();
|
|
846
|
-
},
|
|
847
|
-
}
|
|
848
|
-
: {}),
|
|
849
|
-
});
|
|
850
|
-
isDoneRef.value = true;
|
|
851
|
-
heartbeatStop.abort();
|
|
852
|
-
const loopOutcome = await hb;
|
|
853
|
-
if (params.recordProcessExit !== false)
|
|
854
|
-
params.observation.setExitCode(result.exitCode);
|
|
855
|
-
if (loopOutcome.kind === "auth_fatal") {
|
|
856
|
-
// BAPI-1021 (AC-5): notify the runner immediately with ONLY the bounded
|
|
857
|
-
// identifiers — never carried onto `result` itself, so the process's own
|
|
858
|
-
// classification/completion handling is unaffected and the job continues
|
|
859
|
-
// to drain normally.
|
|
860
|
-
params.control?.reportAuthFatal?.({
|
|
861
|
-
jobId: params.job.id,
|
|
862
|
-
repoName: params.job.repo_name,
|
|
863
|
-
category: "heartbeat",
|
|
864
|
-
httpStatus: loopOutcome.httpStatus,
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
return loopOutcome.kind === "server_stop"
|
|
868
|
-
? { ...result, serverStopRequested: true }
|
|
869
|
-
: result;
|
|
870
|
-
}
|
|
871
|
-
function terminalToRunResult(terminal, successStatus) {
|
|
872
|
-
switch (terminal.outcome) {
|
|
873
|
-
case "success":
|
|
874
|
-
return { status: successStatus };
|
|
875
|
-
case "invalid_job_result":
|
|
876
|
-
return { status: "failed", reason: "invalid_job_result" };
|
|
877
|
-
case "stale_claim":
|
|
878
|
-
return { status: "abandoned", reason: "stale_claim" };
|
|
879
|
-
case "abandoned":
|
|
880
|
-
return { status: "abandoned", reason: "deadman" };
|
|
881
|
-
case "skipped":
|
|
882
|
-
return { status: "abandoned", reason: "already_abandoned" };
|
|
883
|
-
case "auth_fatal":
|
|
884
|
-
// BAPI-1021 (AC-5): a halted authentication/access condition, not an
|
|
885
|
-
// ordinary job failure or a lost/stale claim — `reportAuthFatal` (called
|
|
886
|
-
// by the wrapper below, before this mapping runs) is what actually
|
|
887
|
-
// notifies the runner.
|
|
888
|
-
return { status: "abandoned", reason: "auth_fatal" };
|
|
889
|
-
case "completion_evidence_refused":
|
|
890
|
-
// BAPI-1590: the wrapper below hands this outcome to the caller only when
|
|
891
|
-
// that caller opted into the immediate `/fail` fallback, and that caller
|
|
892
|
-
// handles it before mapping. Reaching here means it did not, so keep the
|
|
893
|
-
// historical reading of a refused `/complete`: a lost claim.
|
|
894
|
-
return { status: "abandoned", reason: "stale_claim" };
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* BAPI-1021 (AC-5): send a terminal mutation via
|
|
899
|
-
* {@link sendTerminalMutationWithRetry}, and — on an `auth_fatal` outcome —
|
|
900
|
-
* notify the runner exactly once via `control.reportAuthFatal`, carrying ONLY
|
|
901
|
-
* the job ID, repository, operation category, and HTTP status. Every other
|
|
902
|
-
* outcome passes through completely unchanged.
|
|
903
|
-
*/
|
|
904
|
-
async function sendTerminalMutationWithAuthReport(params, job, control) {
|
|
905
|
-
const { completionEvidenceFallback, ...sendParams } = params;
|
|
906
|
-
const terminal = await sendTerminalMutationWithRetry(sendParams);
|
|
907
|
-
if (terminal.outcome === "completion_evidence_refused" && completionEvidenceFallback !== true) {
|
|
908
|
-
params.ownership.abandoned = true;
|
|
909
|
-
params.ownership.abandonReason = "stale_claim";
|
|
910
|
-
return { outcome: "stale_claim" };
|
|
911
|
-
}
|
|
912
|
-
if (terminal.outcome === "auth_fatal") {
|
|
913
|
-
const notice = {
|
|
914
|
-
jobId: job.id,
|
|
915
|
-
repoName: job.repo_name,
|
|
916
|
-
category: params.kind,
|
|
917
|
-
httpStatus: terminal.httpStatus,
|
|
918
|
-
};
|
|
919
|
-
control?.reportAuthFatal?.(notice);
|
|
920
|
-
}
|
|
921
|
-
return terminal;
|
|
922
|
-
}
|
|
923
724
|
/** Dispatch and run a single claimed job. */
|
|
924
725
|
/**
|
|
925
726
|
* Run ONE integration-correction worker under a spawn-job driver (BAPI-1259).
|
|
@@ -1074,507 +875,6 @@ control) {
|
|
|
1074
875
|
});
|
|
1075
876
|
return { status: "failed", reason: "unsupported_job_type" };
|
|
1076
877
|
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Bound on waiting for a killed `gate_qualification` body to finish its own
|
|
1079
|
-
* teardown (terminating a running command, removing the detached checkout)
|
|
1080
|
-
* before the terminal report is sent.
|
|
1081
|
-
*/
|
|
1082
|
-
const GATE_QUALIFICATION_SETTLE_MAX_MS = 180_000;
|
|
1083
|
-
/**
|
|
1084
|
-
* Run a deterministic `gate_qualification` job (BAPI-1391).
|
|
1085
|
-
*
|
|
1086
|
-
* The same lifecycle as {@link runCiRerunExecutorJob}: the payload timeout is
|
|
1087
|
-
* resolved first, the body runs as a flow under {@link superviseProcess} (the
|
|
1088
|
-
* one ownership, heartbeat, dead-man, and timeout protocol), and every terminal
|
|
1089
|
-
* report goes through {@link sendTerminalMutationWithAuthReport}.
|
|
1090
|
-
*
|
|
1091
|
-
* The completion carries only the bounded result envelope from
|
|
1092
|
-
* `gate-qualification-job.ts`. An inability goes to `/fail` with a closed
|
|
1093
|
-
* error kind and fixed text; command output never reaches either.
|
|
1094
|
-
*/
|
|
1095
|
-
async function runGateQualificationExecutorJob(job, httpClient, options, deps, ownership, observation, seams, control) {
|
|
1096
|
-
const timeout = resolveJobTimeoutSeconds(job, options.defaultJobTimeoutSeconds);
|
|
1097
|
-
if (!timeout.ok) {
|
|
1098
|
-
await httpClient.fail(job, {
|
|
1099
|
-
error_kind: "ContractError.Timeout",
|
|
1100
|
-
error_message: timeout.error,
|
|
1101
|
-
classification: "crashed",
|
|
1102
|
-
});
|
|
1103
|
-
return { status: "failed", reason: "timeout_contract" };
|
|
1104
|
-
}
|
|
1105
|
-
const timeoutSeconds = timeout.timeoutSeconds;
|
|
1106
|
-
const runGateQualification = seams.runGateQualification ??
|
|
1107
|
-
((claimed, input) => runGateQualificationJob(claimed, input, createProductionGateQualificationDeps({
|
|
1108
|
-
deps,
|
|
1109
|
-
options,
|
|
1110
|
-
registerLive: (controller) => control?.liveWorkers.register(controller),
|
|
1111
|
-
ownershipHeld: () => !ownership.abandoned,
|
|
1112
|
-
})));
|
|
1113
|
-
const flow = createFlowProcess((signal) => runGateQualification(job, { timeoutSeconds, signal }), (result) => result.ok);
|
|
1114
|
-
const procResult = await superviseProcess({
|
|
1115
|
-
job,
|
|
1116
|
-
httpClient,
|
|
1117
|
-
options,
|
|
1118
|
-
deps,
|
|
1119
|
-
ownership,
|
|
1120
|
-
observation,
|
|
1121
|
-
proc: flow.proc,
|
|
1122
|
-
timeoutSeconds,
|
|
1123
|
-
collectTelemetry: async () => ({}),
|
|
1124
|
-
control,
|
|
1125
|
-
});
|
|
1126
|
-
// A killed flow keeps running until its own `finally` has terminated any
|
|
1127
|
-
// command and removed the detached checkout. Wait for that, bounded, so the
|
|
1128
|
-
// terminal report never races the teardown of a checkout it describes.
|
|
1129
|
-
let settleTimer;
|
|
1130
|
-
try {
|
|
1131
|
-
await Promise.race([
|
|
1132
|
-
flow.settled,
|
|
1133
|
-
new Promise((resolve) => {
|
|
1134
|
-
settleTimer = deps.setTimer(resolve, GATE_QUALIFICATION_SETTLE_MAX_MS);
|
|
1135
|
-
}),
|
|
1136
|
-
]);
|
|
1137
|
-
}
|
|
1138
|
-
finally {
|
|
1139
|
-
if (settleTimer !== undefined)
|
|
1140
|
-
deps.clearTimer(settleTimer);
|
|
1141
|
-
}
|
|
1142
|
-
if (ownership.abandoned) {
|
|
1143
|
-
return { status: "abandoned", reason: ownership.abandonReason };
|
|
1144
|
-
}
|
|
1145
|
-
const sendFail = async (errorKind, message, classification) => {
|
|
1146
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1147
|
-
kind: "fail",
|
|
1148
|
-
send: () => httpClient.fail(job, {
|
|
1149
|
-
error_kind: errorKind,
|
|
1150
|
-
error_message: message,
|
|
1151
|
-
classification,
|
|
1152
|
-
telemetry: observation.snapshot(),
|
|
1153
|
-
}),
|
|
1154
|
-
deps,
|
|
1155
|
-
options,
|
|
1156
|
-
ownership,
|
|
1157
|
-
log: deps.log,
|
|
1158
|
-
}, job, control);
|
|
1159
|
-
return terminalToRunResult(terminal, "failed");
|
|
1160
|
-
};
|
|
1161
|
-
if (procResult.classification === "timeout") {
|
|
1162
|
-
return sendFail(GATE_QUALIFICATION_FAILED, "gate_qualification exceeded its job timeout", "timeout");
|
|
1163
|
-
}
|
|
1164
|
-
const outcome = flow.getOutcome();
|
|
1165
|
-
if (outcome === undefined) {
|
|
1166
|
-
// Killed without a timeout (a server stop) — the commands were cut short —
|
|
1167
|
-
// or the body threw, which it is built never to do.
|
|
1168
|
-
return procResult.serverStopRequested
|
|
1169
|
-
? sendFail(GATE_QUALIFICATION_INTERRUPTED, "gate qualification was stopped before it finished", "killed")
|
|
1170
|
-
: sendFail(GATE_QUALIFICATION_FAILED, "gate_qualification completed without an outcome", "crashed");
|
|
1171
|
-
}
|
|
1172
|
-
if (outcome.ok) {
|
|
1173
|
-
const completion = {
|
|
1174
|
-
job_type: "gate_qualification",
|
|
1175
|
-
exit_code: 0,
|
|
1176
|
-
classification: "clean_exit",
|
|
1177
|
-
// The bounded result envelope, verbatim. The backend model is
|
|
1178
|
-
// `extra="forbid"` and recomputes the outcome against the STORED payload.
|
|
1179
|
-
result: outcome.result,
|
|
1180
|
-
telemetry: observation.snapshot(),
|
|
1181
|
-
};
|
|
1182
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1183
|
-
kind: "complete",
|
|
1184
|
-
send: () => httpClient.complete(job, completion),
|
|
1185
|
-
deps,
|
|
1186
|
-
options,
|
|
1187
|
-
ownership,
|
|
1188
|
-
log: deps.log,
|
|
1189
|
-
}, job, control);
|
|
1190
|
-
return terminalToRunResult(terminal, "completed");
|
|
1191
|
-
}
|
|
1192
|
-
// An inability: a closed error kind and fixed text, never command output.
|
|
1193
|
-
return sendFail(outcome.failure.errorKind, outcome.failure.message, "crashed");
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* Run a deterministic `ci_rerun` job (BAPI-1160).
|
|
1197
|
-
*
|
|
1198
|
-
* Supervised through the SAME ownership, heartbeat, dead-man, and timeout
|
|
1199
|
-
* protocol as {@link runMergeJob} — via {@link createFlowProcess} — so a
|
|
1200
|
-
* deterministic job is not a second, weaker lifecycle. The body itself spawns no
|
|
1201
|
-
* subprocess of its own beyond the bounded `gh` invocations inside
|
|
1202
|
-
* `ci-rerun-job.ts`, and there is NO fallback to a worker on failure.
|
|
1203
|
-
*
|
|
1204
|
-
* The completion carries only the job's fact envelope. It names no gate,
|
|
1205
|
-
* requests no transition, and asserts no verdict: the reconciler re-observes the
|
|
1206
|
-
* head independently and remains the sole transition authority (R14 rule 3).
|
|
1207
|
-
*/
|
|
1208
|
-
async function runCiRerunExecutorJob(job, httpClient, options, deps, ownership, observation, seams, control) {
|
|
1209
|
-
// Resolve + enforce payload.timeout_seconds BEFORE any provider work, exactly
|
|
1210
|
-
// as the merge branch does.
|
|
1211
|
-
const timeout = resolveJobTimeoutSeconds(job, options.defaultJobTimeoutSeconds);
|
|
1212
|
-
if (!timeout.ok) {
|
|
1213
|
-
await httpClient.fail(job, {
|
|
1214
|
-
error_kind: "ContractError.Timeout",
|
|
1215
|
-
error_message: timeout.error,
|
|
1216
|
-
classification: "crashed",
|
|
1217
|
-
});
|
|
1218
|
-
return { status: "failed", reason: "timeout_contract" };
|
|
1219
|
-
}
|
|
1220
|
-
const runCiRerun = seams.runCiRerun ??
|
|
1221
|
-
((payload) => runCiRerunJob(payload, createProductionCiRerunDeps()));
|
|
1222
|
-
const flow = createFlowProcess(() => runCiRerun(job.payload), (result) => result.ok);
|
|
1223
|
-
const procResult = await superviseProcess({
|
|
1224
|
-
job,
|
|
1225
|
-
httpClient,
|
|
1226
|
-
options,
|
|
1227
|
-
deps,
|
|
1228
|
-
ownership,
|
|
1229
|
-
observation,
|
|
1230
|
-
proc: flow.proc,
|
|
1231
|
-
timeoutSeconds: timeout.timeoutSeconds,
|
|
1232
|
-
collectTelemetry: async () => ({}),
|
|
1233
|
-
control,
|
|
1234
|
-
});
|
|
1235
|
-
if (ownership.abandoned) {
|
|
1236
|
-
return { status: "abandoned", reason: ownership.abandonReason };
|
|
1237
|
-
}
|
|
1238
|
-
if (procResult.classification === "timeout") {
|
|
1239
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1240
|
-
kind: "fail",
|
|
1241
|
-
send: () => httpClient.fail(job, {
|
|
1242
|
-
error_kind: "CiRerunFailed",
|
|
1243
|
-
error_message: "ci_rerun exceeded its job timeout",
|
|
1244
|
-
classification: "timeout",
|
|
1245
|
-
telemetry: observation.snapshot(),
|
|
1246
|
-
}),
|
|
1247
|
-
deps,
|
|
1248
|
-
options,
|
|
1249
|
-
ownership,
|
|
1250
|
-
log: deps.log,
|
|
1251
|
-
}, job, control);
|
|
1252
|
-
return terminalToRunResult(terminal, "failed");
|
|
1253
|
-
}
|
|
1254
|
-
const outcome = flow.getOutcome();
|
|
1255
|
-
if (outcome === undefined) {
|
|
1256
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1257
|
-
kind: "fail",
|
|
1258
|
-
send: () => httpClient.fail(job, {
|
|
1259
|
-
error_kind: "CiRerunFailed",
|
|
1260
|
-
error_message: "ci_rerun completed without an outcome",
|
|
1261
|
-
classification: "crashed",
|
|
1262
|
-
telemetry: observation.snapshot(),
|
|
1263
|
-
}),
|
|
1264
|
-
deps,
|
|
1265
|
-
options,
|
|
1266
|
-
ownership,
|
|
1267
|
-
log: deps.log,
|
|
1268
|
-
}, job, control);
|
|
1269
|
-
return terminalToRunResult(terminal, "failed");
|
|
1270
|
-
}
|
|
1271
|
-
if (outcome.ok) {
|
|
1272
|
-
const completion = {
|
|
1273
|
-
job_type: "ci_rerun",
|
|
1274
|
-
exit_code: 0,
|
|
1275
|
-
classification: "clean_exit",
|
|
1276
|
-
// The FACT ENVELOPE, verbatim. No gate, no transition, no verdict — the
|
|
1277
|
-
// backend model is `extra="forbid"`, so anything else fails validation
|
|
1278
|
-
// rather than being silently ignored.
|
|
1279
|
-
result: outcome.result,
|
|
1280
|
-
telemetry: observation.snapshot(),
|
|
1281
|
-
};
|
|
1282
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1283
|
-
kind: "complete",
|
|
1284
|
-
send: () => httpClient.complete(job, completion),
|
|
1285
|
-
deps,
|
|
1286
|
-
options,
|
|
1287
|
-
ownership,
|
|
1288
|
-
log: deps.log,
|
|
1289
|
-
}, job, control);
|
|
1290
|
-
return terminalToRunResult(terminal, "completed");
|
|
1291
|
-
}
|
|
1292
|
-
// A refused or failed re-run. The reserved infrastructure attempt stays
|
|
1293
|
-
// CONSUMED — see `ci-rerun-job.ts` — and the reason is a closed token, never
|
|
1294
|
-
// provider text.
|
|
1295
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1296
|
-
kind: "fail",
|
|
1297
|
-
send: () => httpClient.fail(job, {
|
|
1298
|
-
error_kind: outcome.failure.errorKind,
|
|
1299
|
-
error_message: outcome.failure.reason,
|
|
1300
|
-
classification: "crashed",
|
|
1301
|
-
telemetry: observation.snapshot(),
|
|
1302
|
-
}),
|
|
1303
|
-
deps,
|
|
1304
|
-
options,
|
|
1305
|
-
ownership,
|
|
1306
|
-
log: deps.log,
|
|
1307
|
-
}, job, control);
|
|
1308
|
-
return terminalToRunResult(terminal, "failed");
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Adapt a `runMerge(...)` promise into an {@link OwnedChildProcess} so the merge
|
|
1312
|
-
* flow is supervised by the SAME heartbeat/deadman/timeout path as spawn/smoke
|
|
1313
|
-
* jobs even though it spawns no worker. `wait()` resolves when the merge outcome
|
|
1314
|
-
* is available (exit_code 0 on `ok`, 1 otherwise); `kill()` aborts the internal
|
|
1315
|
-
* {@link AbortController} (cancelling in-flight local `gh` work) and resolves the
|
|
1316
|
-
* owned process as killed. The stored outcome/error let the runner map the
|
|
1317
|
-
* supervised result to `/complete` or `/fail` afterwards (killed/timeout is read
|
|
1318
|
-
* from the supervised `ProcessRunResult`/`ownership`, not from this adapter).
|
|
1319
|
-
*/
|
|
1320
|
-
function createMergeFlowProcess(startMerge) {
|
|
1321
|
-
const flow = createFlowProcess(startMerge, (result) => result.ok);
|
|
1322
|
-
return { proc: flow.proc, getOutcome: flow.getOutcome, getError: flow.getError };
|
|
1323
|
-
}
|
|
1324
|
-
/**
|
|
1325
|
-
* The generic form of {@link createMergeFlowProcess} (BAPI-1152): adapt any
|
|
1326
|
-
* in-process flow into an {@link OwnedChildProcess} so it is supervised by the
|
|
1327
|
-
* SAME heartbeat/deadman/timeout path as a worker. `settled` resolves once the
|
|
1328
|
-
* flow's own promise has settled — after a timeout or kill the supervised
|
|
1329
|
-
* process resolves immediately, but the flow may still be finishing a bounded
|
|
1330
|
-
* subprocess, and a caller that is about to reset the worktree must wait for it.
|
|
1331
|
-
*/
|
|
1332
|
-
function createFlowProcess(start, isOk) {
|
|
1333
|
-
const controller = new AbortController();
|
|
1334
|
-
let outcome;
|
|
1335
|
-
let error;
|
|
1336
|
-
let done = false;
|
|
1337
|
-
let settleWait = () => { };
|
|
1338
|
-
const waitPromise = new Promise((resolve) => {
|
|
1339
|
-
settleWait = resolve;
|
|
1340
|
-
});
|
|
1341
|
-
// Start the flow immediately; capture its resolution/rejection.
|
|
1342
|
-
const settled = start(controller.signal).then((result) => {
|
|
1343
|
-
outcome = result;
|
|
1344
|
-
if (!done) {
|
|
1345
|
-
done = true;
|
|
1346
|
-
settleWait({ exitCode: isOk(result) ? 0 : 1, signal: null });
|
|
1347
|
-
}
|
|
1348
|
-
}, (err) => {
|
|
1349
|
-
error = err;
|
|
1350
|
-
if (!done) {
|
|
1351
|
-
done = true;
|
|
1352
|
-
settleWait({ exitCode: 1, signal: null });
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1355
|
-
const proc = {
|
|
1356
|
-
pid: undefined,
|
|
1357
|
-
stdout: null,
|
|
1358
|
-
stderr: null,
|
|
1359
|
-
async wait() {
|
|
1360
|
-
return waitPromise;
|
|
1361
|
-
},
|
|
1362
|
-
kill(signal) {
|
|
1363
|
-
if (done)
|
|
1364
|
-
return;
|
|
1365
|
-
controller.abort();
|
|
1366
|
-
done = true;
|
|
1367
|
-
settleWait({ exitCode: null, signal });
|
|
1368
|
-
},
|
|
1369
|
-
};
|
|
1370
|
-
return {
|
|
1371
|
-
proc,
|
|
1372
|
-
getOutcome: () => outcome,
|
|
1373
|
-
getError: () => error,
|
|
1374
|
-
settled,
|
|
1375
|
-
};
|
|
1376
|
-
}
|
|
1377
|
-
/**
|
|
1378
|
-
* Run a deterministic `merge` job: NO worktree ensured, NO worker spawned. Unlike
|
|
1379
|
-
* the pre-BAPI-572 version, the merge flow now runs under the SHARED heartbeat/
|
|
1380
|
-
* deadman/timeout supervision path (via {@link superviseProcess}) so a live merge
|
|
1381
|
-
* heartbeats (the janitor never re-queues a healthy multi-minute merge) and the
|
|
1382
|
-
* whole flow honors `payload.timeout_seconds`. A timeout is reported as a
|
|
1383
|
-
* RETRYABLE failure and a late merge resolution after timeout/abandonment is
|
|
1384
|
-
* ignored. The local merge executor's outcome otherwise drives `/complete`
|
|
1385
|
-
* (success) or `/fail`; stale/retry/invalid terminal outcomes reuse T3a handling.
|
|
1386
|
-
*/
|
|
1387
|
-
async function runMergeJob(job, httpClient, options, deps, ownership, observation, seams, control) {
|
|
1388
|
-
// Resolve + enforce payload.timeout_seconds BEFORE starting any merge work.
|
|
1389
|
-
const timeout = resolveJobTimeoutSeconds(job, options.defaultJobTimeoutSeconds);
|
|
1390
|
-
if (!timeout.ok) {
|
|
1391
|
-
await httpClient.fail(job, {
|
|
1392
|
-
error_kind: "ContractError.Timeout",
|
|
1393
|
-
error_message: timeout.error,
|
|
1394
|
-
classification: "crashed",
|
|
1395
|
-
});
|
|
1396
|
-
return { status: "failed", reason: "timeout_contract" };
|
|
1397
|
-
}
|
|
1398
|
-
const timeoutSeconds = timeout.timeoutSeconds;
|
|
1399
|
-
const runMerge = seams.runMerge ?? defaultRunMergeForClaimed;
|
|
1400
|
-
const flow = createMergeFlowProcess((signal) => runMerge(job, deps, options, { signal }));
|
|
1401
|
-
const procResult = await superviseProcess({
|
|
1402
|
-
job,
|
|
1403
|
-
httpClient,
|
|
1404
|
-
options,
|
|
1405
|
-
deps,
|
|
1406
|
-
ownership,
|
|
1407
|
-
observation,
|
|
1408
|
-
proc: flow.proc,
|
|
1409
|
-
timeoutSeconds,
|
|
1410
|
-
collectTelemetry: async () => ({}),
|
|
1411
|
-
control,
|
|
1412
|
-
});
|
|
1413
|
-
// Ownership abandonment (stale-claim / dead-man) wins: never send a terminal
|
|
1414
|
-
// mutation for a claim we no longer own, and never process a late outcome.
|
|
1415
|
-
if (ownership.abandoned) {
|
|
1416
|
-
return { status: "abandoned", reason: ownership.abandonReason };
|
|
1417
|
-
}
|
|
1418
|
-
// Overall merge flow timed out: fail the active claim as RETRYABLE and ignore
|
|
1419
|
-
// any later merge promise resolution (the abort has already been signalled).
|
|
1420
|
-
if (procResult.classification === "timeout") {
|
|
1421
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1422
|
-
kind: "fail",
|
|
1423
|
-
send: () => httpClient.fail(job, {
|
|
1424
|
-
error_kind: MERGE_RETRYABLE,
|
|
1425
|
-
error_message: `merge flow timed out after ${timeoutSeconds} seconds`,
|
|
1426
|
-
classification: "timeout",
|
|
1427
|
-
telemetry: { failure_reason_code: MERGE_FLOW_TIMEOUT, ...observation.snapshot() },
|
|
1428
|
-
}),
|
|
1429
|
-
deps,
|
|
1430
|
-
options,
|
|
1431
|
-
ownership,
|
|
1432
|
-
log: deps.log,
|
|
1433
|
-
}, job, control);
|
|
1434
|
-
return terminalToRunResult(terminal, "failed");
|
|
1435
|
-
}
|
|
1436
|
-
// A thrown error inside the merge flow maps to a bounded MergeFailed.
|
|
1437
|
-
const flowError = flow.getError();
|
|
1438
|
-
if (flowError !== undefined) {
|
|
1439
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1440
|
-
kind: "fail",
|
|
1441
|
-
send: () => httpClient.fail(job, {
|
|
1442
|
-
error_kind: MERGE_FAILED,
|
|
1443
|
-
error_message: secretFreeErrorMessage(flowError),
|
|
1444
|
-
classification: "crashed",
|
|
1445
|
-
telemetry: { failure_reason_code: MERGE_FLOW_ERROR, ...observation.snapshot() },
|
|
1446
|
-
}),
|
|
1447
|
-
deps,
|
|
1448
|
-
options,
|
|
1449
|
-
ownership,
|
|
1450
|
-
log: deps.log,
|
|
1451
|
-
}, job, control);
|
|
1452
|
-
return terminalToRunResult(terminal, "failed");
|
|
1453
|
-
}
|
|
1454
|
-
const outcome = flow.getOutcome();
|
|
1455
|
-
if (outcome === undefined) {
|
|
1456
|
-
// Clean process result with no stored outcome — an internal invariant break;
|
|
1457
|
-
// fail loud rather than silently reporting success.
|
|
1458
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1459
|
-
kind: "fail",
|
|
1460
|
-
send: () => httpClient.fail(job, {
|
|
1461
|
-
error_kind: MERGE_FAILED,
|
|
1462
|
-
error_message: "merge flow completed without an outcome",
|
|
1463
|
-
classification: "crashed",
|
|
1464
|
-
telemetry: { failure_reason_code: MERGE_NO_OUTCOME, ...observation.snapshot() },
|
|
1465
|
-
}),
|
|
1466
|
-
deps,
|
|
1467
|
-
options,
|
|
1468
|
-
ownership,
|
|
1469
|
-
log: deps.log,
|
|
1470
|
-
}, job, control);
|
|
1471
|
-
return terminalToRunResult(terminal, "failed");
|
|
1472
|
-
}
|
|
1473
|
-
if (outcome.ok) {
|
|
1474
|
-
const completion = {
|
|
1475
|
-
job_type: "merge",
|
|
1476
|
-
exit_code: 0,
|
|
1477
|
-
classification: "clean_exit",
|
|
1478
|
-
result: outcome.result,
|
|
1479
|
-
telemetry: observation.snapshot(),
|
|
1480
|
-
};
|
|
1481
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1482
|
-
kind: "complete",
|
|
1483
|
-
send: () => httpClient.complete(job, completion),
|
|
1484
|
-
deps,
|
|
1485
|
-
options,
|
|
1486
|
-
ownership,
|
|
1487
|
-
log: deps.log,
|
|
1488
|
-
}, job, control);
|
|
1489
|
-
return terminalToRunResult(terminal, "completed");
|
|
1490
|
-
}
|
|
1491
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1492
|
-
kind: "fail",
|
|
1493
|
-
// BAPI-1453: MERGE the builder's telemetry with the snapshot rather than
|
|
1494
|
-
// replacing it, so `failure_reason_code` survives. Observation state never
|
|
1495
|
-
// carries a code, so the snapshot cannot overwrite it.
|
|
1496
|
-
send: () => httpClient.fail(job, {
|
|
1497
|
-
...outcome.failure,
|
|
1498
|
-
telemetry: { ...outcome.failure.telemetry, ...observation.snapshot() },
|
|
1499
|
-
}),
|
|
1500
|
-
deps,
|
|
1501
|
-
options,
|
|
1502
|
-
ownership,
|
|
1503
|
-
log: deps.log,
|
|
1504
|
-
}, job, control);
|
|
1505
|
-
return terminalToRunResult(terminal, "failed");
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* BAPI-724 design note (deliberate, not an accidental AC-5 gap): `smoke` stays
|
|
1509
|
-
* on this no-worktree, no-real-worker-LLM `createNoopProcess` path and does
|
|
1510
|
-
* NOT receive MCP registration. The ratified requirement anchors MCP
|
|
1511
|
-
* provisioning to "the executor's worktree-preparation path
|
|
1512
|
-
* (`job-runner.ts`), alongside the existing deny-layer provisioning call"
|
|
1513
|
-
* (which BAPI-781 moved behind the adapter's `provisionWorktreeDenyLayer` hook)
|
|
1514
|
-
* — that call, like the new MCP provisioning call, exists ONLY inside
|
|
1515
|
-
* `runSpawnJob`, which `smoke` never reaches (see `isSpawnJobType` /
|
|
1516
|
-
* `job-types.ts`, and this module's own "no real worker LLM" framing of the
|
|
1517
|
-
* acceptance spine). Converting smoke into a worktree-having, worker-spawning
|
|
1518
|
-
* job to give it something to register MCP into would be a materially larger,
|
|
1519
|
-
* unratified change to that architectural boundary, not a wiring task.
|
|
1520
|
-
*/
|
|
1521
|
-
async function runSmokeJob(job, httpClient, options, deps, ownership, observation, control) {
|
|
1522
|
-
const timeout = resolveJobTimeoutSeconds(job, options.defaultJobTimeoutSeconds);
|
|
1523
|
-
if (!timeout.ok) {
|
|
1524
|
-
// Consistent with runSpawnJob: a timeout-contract failure fails the job
|
|
1525
|
-
// rather than silently substituting a default.
|
|
1526
|
-
await httpClient.fail(job, {
|
|
1527
|
-
error_kind: "ContractError.Timeout",
|
|
1528
|
-
error_message: timeout.error,
|
|
1529
|
-
classification: "crashed",
|
|
1530
|
-
});
|
|
1531
|
-
return { status: "failed", reason: "timeout_contract" };
|
|
1532
|
-
}
|
|
1533
|
-
const timeoutSeconds = timeout.timeoutSeconds;
|
|
1534
|
-
const payload = job.payload && typeof job.payload === "object" ? job.payload : {};
|
|
1535
|
-
const durationMs = typeof payload.duration_ms === "number" && payload.duration_ms > 0
|
|
1536
|
-
? payload.duration_ms
|
|
1537
|
-
: DEFAULT_SMOKE_DURATION_MS;
|
|
1538
|
-
const message = typeof payload.message === "string" ? payload.message : "smoke ok";
|
|
1539
|
-
const proc = createNoopProcess(deps, durationMs, message);
|
|
1540
|
-
const procResult = await superviseProcess({
|
|
1541
|
-
job,
|
|
1542
|
-
httpClient,
|
|
1543
|
-
options,
|
|
1544
|
-
deps,
|
|
1545
|
-
ownership,
|
|
1546
|
-
observation,
|
|
1547
|
-
proc,
|
|
1548
|
-
timeoutSeconds,
|
|
1549
|
-
collectTelemetry: async () => ({}),
|
|
1550
|
-
control,
|
|
1551
|
-
});
|
|
1552
|
-
if (ownership.abandoned) {
|
|
1553
|
-
return { status: "abandoned", reason: ownership.abandonReason };
|
|
1554
|
-
}
|
|
1555
|
-
const evidence = {
|
|
1556
|
-
message,
|
|
1557
|
-
exit_code: procResult.exitCode,
|
|
1558
|
-
classification: procResult.classification,
|
|
1559
|
-
};
|
|
1560
|
-
const result = buildSmokeResult(evidence, procResult.classification === "clean_exit" ? "pass" : "fail");
|
|
1561
|
-
const completion = {
|
|
1562
|
-
job_type: "smoke",
|
|
1563
|
-
exit_code: procResult.exitCode ?? 0,
|
|
1564
|
-
classification: toWireClassification(procResult.classification),
|
|
1565
|
-
result,
|
|
1566
|
-
telemetry: observation.snapshot(),
|
|
1567
|
-
};
|
|
1568
|
-
const terminal = await sendTerminalMutationWithAuthReport({
|
|
1569
|
-
kind: "complete",
|
|
1570
|
-
send: () => httpClient.complete(job, completion),
|
|
1571
|
-
deps,
|
|
1572
|
-
options,
|
|
1573
|
-
ownership,
|
|
1574
|
-
log: deps.log,
|
|
1575
|
-
}, job, control);
|
|
1576
|
-
return terminalToRunResult(terminal, "completed");
|
|
1577
|
-
}
|
|
1578
878
|
/** Build the reconcile module's seams from executor deps (BAPI-1152). */
|
|
1579
879
|
function buildReconcileOverlapSeams(deps) {
|
|
1580
880
|
return {
|
|
@@ -1692,7 +992,7 @@ async function reportDriverPhaseInterruption(phase, ctx) {
|
|
|
1692
992
|
if (phase.kind === "server_stop") {
|
|
1693
993
|
await ctx.httpClient.fail(ctx.job, {
|
|
1694
994
|
error_kind: "ServerStopRequested",
|
|
1695
|
-
error_message: "the server
|
|
995
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on); the reconciliation was stopped",
|
|
1696
996
|
classification: "killed",
|
|
1697
997
|
telemetry: ctx.observation.snapshot(),
|
|
1698
998
|
});
|
|
@@ -2430,7 +1730,7 @@ async function superviseFocusedRebaseWait(params) {
|
|
|
2430
1730
|
await params.finalizeRegistry();
|
|
2431
1731
|
await httpClient.fail(job, {
|
|
2432
1732
|
error_kind: "ServerStopRequested",
|
|
2433
|
-
error_message: "the server
|
|
1733
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on); the focused rebase wait was stopped",
|
|
2434
1734
|
classification: "killed",
|
|
2435
1735
|
telemetry: observation.snapshot(),
|
|
2436
1736
|
});
|
|
@@ -2644,6 +1944,7 @@ async function runSpawnJob(job, httpClient, options, deps, ownership, observatio
|
|
|
2644
1944
|
* seams gets the real operation, matching the worktree-lock fallback direction.
|
|
2645
1945
|
*/
|
|
2646
1946
|
function excludeProvisioningDeps(deps) {
|
|
1947
|
+
const lock = executorExcludeLockDeps(deps);
|
|
2647
1948
|
return {
|
|
2648
1949
|
readFile: deps.readFile,
|
|
2649
1950
|
writeFile: deps.writeFile,
|
|
@@ -2651,6 +1952,36 @@ function excludeProvisioningDeps(deps) {
|
|
|
2651
1952
|
stat: deps.stat ?? ((filePath) => fsStat(filePath)),
|
|
2652
1953
|
rename: deps.rename ?? ((from, to) => fsRename(from, to)),
|
|
2653
1954
|
removeFile: deps.removeFile ?? ((filePath) => rm(filePath, { force: true })),
|
|
1955
|
+
...(lock ? { excludeLock: lock } : {}),
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* BAPI-1647: the cross-process exclude lock, built from the executor's OWN
|
|
1960
|
+
* injected filesystem and clock (exclusive create, remove, mkdir, realpath,
|
|
1961
|
+
* mtime, sleep), so the lock never opens a file handle the runner did not hand
|
|
1962
|
+
* it. Absent when the deps cannot create a file exclusively.
|
|
1963
|
+
*/
|
|
1964
|
+
function executorExcludeLockDeps(deps) {
|
|
1965
|
+
const createExclusive = deps.writeFileExclusive;
|
|
1966
|
+
const remove = deps.removeFile;
|
|
1967
|
+
if (!createExclusive || !remove)
|
|
1968
|
+
return undefined;
|
|
1969
|
+
return {
|
|
1970
|
+
open: async (p) => {
|
|
1971
|
+
await createExclusive(p, "");
|
|
1972
|
+
return { close: async () => undefined };
|
|
1973
|
+
},
|
|
1974
|
+
unlink: (p) => remove(p),
|
|
1975
|
+
mkdir: (p, o) => deps.mkdir(p, o),
|
|
1976
|
+
realpath: deps.realpath ?? (async (p) => path.resolve(p)),
|
|
1977
|
+
mtimeMs: async (p) => {
|
|
1978
|
+
const mtime = deps.statMtimeMs ? await deps.statMtimeMs(p) : null;
|
|
1979
|
+
if (mtime === null)
|
|
1980
|
+
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
|
|
1981
|
+
return mtime;
|
|
1982
|
+
},
|
|
1983
|
+
now: deps.now,
|
|
1984
|
+
sleep: deps.sleep,
|
|
2654
1985
|
};
|
|
2655
1986
|
}
|
|
2656
1987
|
async function runReservedSpawnJob(job, httpClient, options, deps, ownership, observation, seams, control,
|
|
@@ -3150,7 +2481,7 @@ async function prepareDependencyRefresh(params) {
|
|
|
3150
2481
|
if (phase.kind === "server_stop") {
|
|
3151
2482
|
await params.httpClient.fail(job, {
|
|
3152
2483
|
error_kind: "ServerStopRequested",
|
|
3153
|
-
error_message: "the server
|
|
2484
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on) before the worker started",
|
|
3154
2485
|
classification: "killed",
|
|
3155
2486
|
telemetry: params.observation.snapshot(),
|
|
3156
2487
|
});
|
|
@@ -3328,7 +2659,7 @@ async function prepareWorkerResources(params) {
|
|
|
3328
2659
|
if (phase.kind === "server_stop") {
|
|
3329
2660
|
await params.httpClient.fail(job, {
|
|
3330
2661
|
error_kind: "ServerStopRequested",
|
|
3331
|
-
error_message: "the server
|
|
2662
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on) before the worker started",
|
|
3332
2663
|
classification: "killed",
|
|
3333
2664
|
telemetry: params.observation.snapshot(),
|
|
3334
2665
|
});
|
|
@@ -3389,12 +2720,19 @@ export const fileSystemExecutableCheck = (candidate, options) => {
|
|
|
3389
2720
|
function retainedHeadPublisher(params) {
|
|
3390
2721
|
return async () => {
|
|
3391
2722
|
const { job, branch, worktreePath, prep, deps, ownership, observation, remainingMs } = params;
|
|
3392
|
-
|
|
2723
|
+
const createStartSha = prep.comparisonSha ?? prep.expectedHeadSha;
|
|
2724
|
+
const createOnly = !prep.publicationBaseline && params.allowCreateOnly === true && prep.publicationRemoteAbsent === true;
|
|
2725
|
+
if (!prep.publicationBaseline && !createOnly)
|
|
2726
|
+
return { status: "refused", reason: "invalid_input" };
|
|
2727
|
+
if (createOnly && !createStartSha)
|
|
3393
2728
|
return { status: "refused", reason: "invalid_input" };
|
|
3394
2729
|
const phase = await superviseDriverPhase({ job, httpClient: params.httpClient, options: params.options, deps, ownership, observation, control: params.control,
|
|
3395
2730
|
timeoutSeconds: Math.max(1, Math.ceil(remainingMs() / 1000)), collectTelemetry: async () => ({}),
|
|
3396
2731
|
run: async (signal) => {
|
|
3397
|
-
const result = await guardedFastForwardPush({ branch,
|
|
2732
|
+
const result = await guardedFastForwardPush({ branch,
|
|
2733
|
+
...(createOnly ? { expectedOriginSha: null, createOnly: { startSha: createStartSha } }
|
|
2734
|
+
: { expectedOriginSha: prep.publicationBaseline }),
|
|
2735
|
+
...(params.candidateSha !== undefined ? { candidateSha: params.candidateSha } : {}),
|
|
3398
2736
|
worktreePath, runCommand: deps.runCommand, env: deps.env, remainingMs, signal,
|
|
3399
2737
|
mayMutate: () => !ownership.abandoned && !signal.aborted });
|
|
3400
2738
|
if (result.status === "published")
|
|
@@ -3527,6 +2865,10 @@ async function runPreparedSpawn(params) {
|
|
|
3527
2865
|
if (remote.exitCode === 0 && fields.length === 2 && fields[1] === `refs/heads/${branch}` && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(fields[0])) {
|
|
3528
2866
|
prep.publicationBaseline = isRecoveryJobType(job.job_type) ? prep.expectedHeadSha : fields[0];
|
|
3529
2867
|
}
|
|
2868
|
+
else if (remote.exitCode === 2 && remote.stdout.trim() === "") {
|
|
2869
|
+
// Confirmed absence. Any other failed or odd read stays unknown, never absence.
|
|
2870
|
+
prep.publicationRemoteAbsent = true;
|
|
2871
|
+
}
|
|
3530
2872
|
}
|
|
3531
2873
|
catch { /* no eligible lease baseline */ }
|
|
3532
2874
|
}
|
|
@@ -3683,6 +3025,19 @@ async function runPreparedSpawn(params) {
|
|
|
3683
3025
|
// unchanged and deliberately still fail-OPEN: a provisioning hiccup shrinks
|
|
3684
3026
|
// safety margin but must not kill a job. Refusing to CLAIM on unenforced deny
|
|
3685
3027
|
// remains a separate, fatal preflight concern.
|
|
3028
|
+
// --- Referenced credentials: names-only read (fail-open, BAPI-1647) --
|
|
3029
|
+
// Keyed on the claimed job's `repo_name` (the server's claim response, the
|
|
3030
|
+
// same trusted identity the MCP grant uses), read fresh at every worker start.
|
|
3031
|
+
// It supplies the restricted source paths for the deny layer below and the
|
|
3032
|
+
// reference inputs for MCP provisioning. Never fails the job.
|
|
3033
|
+
const credentialEnvDeps = {
|
|
3034
|
+
env: deps.env,
|
|
3035
|
+
homedir: deps.homedir,
|
|
3036
|
+
platform: deps.platform,
|
|
3037
|
+
readFile: deps.readFile,
|
|
3038
|
+
runCommand: (file, args, opts) => deps.runCommand(file, args, opts),
|
|
3039
|
+
};
|
|
3040
|
+
const credentialApprovals = await readExecutorCredentialApprovals(job.repo_name, credentialEnvDeps, seams.credentialReferences);
|
|
3686
3041
|
const denyCapability = adapter.denyEnforcement;
|
|
3687
3042
|
const correctionWork = isRemainingWork(job.job_type, job.payload);
|
|
3688
3043
|
let correctionDenyInstalled = false;
|
|
@@ -3703,6 +3058,10 @@ async function runPreparedSpawn(params) {
|
|
|
3703
3058
|
workerBranch: branch,
|
|
3704
3059
|
...(correctionWork ? { correctionIntentVersion: 1 } : {}),
|
|
3705
3060
|
workerGuardHookBinPath: correctionHookBinPath,
|
|
3061
|
+
// BAPI-1647: one exact Read deny rule per restricted credential source.
|
|
3062
|
+
...(credentialApprovals.restrictedSourcePaths.length > 0
|
|
3063
|
+
? { restrictedSourcePaths: credentialApprovals.restrictedSourcePaths }
|
|
3064
|
+
: {}),
|
|
3706
3065
|
});
|
|
3707
3066
|
// Log on WARNING PRESENCE, not on `!ok` (BAPI-815/R2). The git-exclude
|
|
3708
3067
|
// hygiene step can degrade without failing the deny layer — present-but-
|
|
@@ -3756,7 +3115,7 @@ async function runPreparedSpawn(params) {
|
|
|
3756
3115
|
// BAPI-727: the validated endpoint travels from executor bootstrap through the
|
|
3757
3116
|
// runtime options to the generated registration, so the worker's MCP server
|
|
3758
3117
|
// targets the same Bridge API this executor claimed the job from.
|
|
3759
|
-
const grantRegistration = await provisionMcpForPreparedSpawn(job, branch, worktreePath, deps, seams, options.resolvedBaseUrl);
|
|
3118
|
+
const grantRegistration = await provisionMcpForPreparedSpawn(job, branch, worktreePath, deps, seams, options.resolvedBaseUrl, credentialApprovals.approvals);
|
|
3760
3119
|
// --- Required Bridge MCP registration (FAIL-CLOSED) -------------------
|
|
3761
3120
|
// Provisioning itself stays fail-OPEN: a skipped or malformed Tier-2 target is
|
|
3762
3121
|
// a warning, and every valid worktree-provisioned server is kept. The REQUIRED
|
|
@@ -3807,6 +3166,16 @@ async function runPreparedSpawn(params) {
|
|
|
3807
3166
|
return { status: "failed", reason: "required_mcp_registration" };
|
|
3808
3167
|
}
|
|
3809
3168
|
const mcpContract = registration.contract;
|
|
3169
|
+
// --- Referenced credentials: file links + sandbox variables (BAPI-1647) --
|
|
3170
|
+
// After MCP provisioning and its verification, and before the final `.env*`
|
|
3171
|
+
// strip below, which is unchanged (child 1 refuses `.env` sources and
|
|
3172
|
+
// destinations, so the two never meet). Files are linked through the shared
|
|
3173
|
+
// reconciled, exclusion-first delivery; variables stay in memory until the env
|
|
3174
|
+
// builder admits them. Every problem is a names-only notice: the job is never
|
|
3175
|
+
// failed or parked because of a credential.
|
|
3176
|
+
const credentialPrep = await prepareExecutorCredentialDelivery(job.repo_name, worktreePath, credentialApprovals.approvals, credentialEnvDeps, seams.credentialReferences);
|
|
3177
|
+
const credentialNotice = buildCredentialNoticeWorkerInstruction(credentialNoticeLines(credentialPrep));
|
|
3178
|
+
let credentialAdmission = null;
|
|
3810
3179
|
// --- Worker log tee + watch registry + viewer tab (BAPI-535 §8) ------
|
|
3811
3180
|
// BAPI-1330: ONE attempt identity — the server's job id and attempt number
|
|
3812
3181
|
// plus a claim id minted here — names this attempt's log file, its registry
|
|
@@ -4123,6 +3492,17 @@ async function runPreparedSpawn(params) {
|
|
|
4123
3492
|
// job type. Absent keeps the legacy compatibility constants; a present
|
|
4124
3493
|
// value, even `[]` or a malformed one, replaces them.
|
|
4125
3494
|
...payloadWorkerEnvOption(job.payload),
|
|
3495
|
+
// BAPI-1647 — approved sandbox credential variables, resolved above in this
|
|
3496
|
+
// process. Present only when there are any, so every other job's
|
|
3497
|
+
// environment is byte-identical.
|
|
3498
|
+
...(Object.keys(credentialPrep.declaredCredentialEnv).length > 0
|
|
3499
|
+
? {
|
|
3500
|
+
declaredCredentialEnv: credentialPrep.declaredCredentialEnv,
|
|
3501
|
+
onDeclaredCredentialEnv: (outcome) => {
|
|
3502
|
+
credentialAdmission = outcome;
|
|
3503
|
+
},
|
|
3504
|
+
}
|
|
3505
|
+
: {}),
|
|
4126
3506
|
parentEnv: deps.env,
|
|
4127
3507
|
};
|
|
4128
3508
|
// The PATH the worker will receive: the launcher directory (when provisioned)
|
|
@@ -4161,10 +3541,23 @@ async function runPreparedSpawn(params) {
|
|
|
4161
3541
|
const prePrChecks = job.job_type === "implement"
|
|
4162
3542
|
? renderPrePrChecks(validatePrePrCheckDeclarations(payloadPrePrChecksOption(job.payload), deps.errorLog))
|
|
4163
3543
|
: "";
|
|
3544
|
+
// BAPI-1647: the credential notice follows the job prompt; LOCAL
|
|
3545
|
+
// ENVIRONMENT LIMITS stays last. No notice renders nothing.
|
|
4164
3546
|
spawnShape = invocation.value.buildSpawnShape({
|
|
4165
|
-
prompt: [prompt, required, prePrChecks, limits].filter((section) => section.length > 0).join("\n\n"),
|
|
3547
|
+
prompt: [prompt, credentialNotice, required, prePrChecks, limits].filter((section) => section.length > 0).join("\n\n"),
|
|
4166
3548
|
...shapeInput,
|
|
4167
3549
|
});
|
|
3550
|
+
// BAPI-1647: names-only audit in the executor's local per-job log. Never
|
|
3551
|
+
// the job row and never the server.
|
|
3552
|
+
try {
|
|
3553
|
+
const admission = credentialAdmission;
|
|
3554
|
+
for (const line of formatCredentialAuditLines(job.id, credentialPrep, admission?.admitted ?? null, admission?.dropped ?? [])) {
|
|
3555
|
+
deps.errorLog(line);
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
catch {
|
|
3559
|
+
/* audit is supplemental */
|
|
3560
|
+
}
|
|
4168
3561
|
// BAPI-1546: the trusted browser target (and run id for turns), injected AFTER
|
|
4169
3562
|
// the environment builder ran, like the job tag. `disabled` leaves the shape untouched.
|
|
4170
3563
|
if (epicServerContext.kind !== "disabled" && spawnShape.env) {
|
|
@@ -4527,7 +3920,7 @@ async function runPreparedSpawn(params) {
|
|
|
4527
3920
|
await driver.abandon(driverBaseContext);
|
|
4528
3921
|
await httpClient.fail(job, {
|
|
4529
3922
|
error_kind: "ServerStopRequested",
|
|
4530
|
-
error_message: "the server
|
|
3923
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on); the owned worker was terminated",
|
|
4531
3924
|
classification: "killed",
|
|
4532
3925
|
...commitResidue(finalTelemetry),
|
|
4533
3926
|
telemetry: observation.snapshot(),
|
|
@@ -5292,7 +4685,7 @@ async function runCoveredAttempt(params) {
|
|
|
5292
4685
|
if (beat.kind === "server_stop") {
|
|
5293
4686
|
// Report first, then mark the claim abandoned, exactly as the post-spawn
|
|
5294
4687
|
// server-stop path does: an abandoned claim skips the terminal report.
|
|
5295
|
-
const stopped = await notLaunched("the server
|
|
4688
|
+
const stopped = await notLaunched("the server asked this job to stop (its run stopped, or its gate moved on) before the worker launched");
|
|
5296
4689
|
ownership.abandoned = true;
|
|
5297
4690
|
ownership.abandonReason = "server_stop";
|
|
5298
4691
|
return stopped.status === "failed" ? { status: "abandoned", reason: "server_stop" } : stopped;
|
|
@@ -5707,7 +5100,7 @@ async function runCoveredAttempt(params) {
|
|
|
5707
5100
|
// outlives the worker, so a lost claim or a server stop can arrive during
|
|
5708
5101
|
// cleanup, verification or finalization, and must still win over a report
|
|
5709
5102
|
// built from those phases.
|
|
5710
|
-
const strongerOutcome = async () => {
|
|
5103
|
+
const strongerOutcome = async (serverStopTelemetry) => {
|
|
5711
5104
|
if (ownership.abandoned) {
|
|
5712
5105
|
await finalizeRegistry();
|
|
5713
5106
|
return finish({ status: "abandoned", reason: ownership.abandonReason });
|
|
@@ -5716,8 +5109,9 @@ async function runCoveredAttempt(params) {
|
|
|
5716
5109
|
if (hbNow?.kind === "server_stop") {
|
|
5717
5110
|
const result = await failWith({
|
|
5718
5111
|
error_kind: "ServerStopRequested",
|
|
5719
|
-
error_message: "the server
|
|
5112
|
+
error_message: "the server asked this job to stop (its run stopped, or its gate moved on); the owned worker was terminated",
|
|
5720
5113
|
classification: "killed",
|
|
5114
|
+
...(serverStopTelemetry ? { telemetry: serverStopTelemetry } : {}),
|
|
5721
5115
|
}, { ...unverifiedEnvelope(), end_cause: "server_stop" });
|
|
5722
5116
|
ownership.abandoned = true;
|
|
5723
5117
|
ownership.abandonReason = "server_stop";
|
|
@@ -5749,6 +5143,40 @@ async function runCoveredAttempt(params) {
|
|
|
5749
5143
|
errorLog: deps.errorLog,
|
|
5750
5144
|
});
|
|
5751
5145
|
}
|
|
5146
|
+
// Covered-timeout publication: a worker that timed out may still have committed
|
|
5147
|
+
// useful work. Publish the exact reported head, but only when every fact below
|
|
5148
|
+
// holds, and never let the outcome change: the timeout failure is still reported.
|
|
5149
|
+
let timeoutPublication;
|
|
5150
|
+
if (procResult.classification === "timeout" && isCoveredJobType(job.job_type)) {
|
|
5151
|
+
const ownershipHeld = () => !ownership.abandoned && heartbeatOutcome?.kind !== "server_stop";
|
|
5152
|
+
const baseline = prep.publicationBaseline ??
|
|
5153
|
+
(prep.publicationRemoteAbsent === true ? (prep.comparisonSha ?? prep.expectedHeadSha) : undefined);
|
|
5154
|
+
// One fixed deadline: a fresh allowance must not be re-derived on each read.
|
|
5155
|
+
const publicationDeadlineAtMs = Math.min(deps.now() + FINALIZATION_RESERVE_MS, plan.deadlineAtMs - REPORT_RESERVE_MS);
|
|
5156
|
+
const publicationRemainingMs = () => Math.max(0, publicationDeadlineAtMs - deps.now());
|
|
5157
|
+
if (!ownershipHeld())
|
|
5158
|
+
timeoutPublication = "ownership_abandoned";
|
|
5159
|
+
else if (cleanup.verdict !== "confirmed" || cleanup.survivors !== 0)
|
|
5160
|
+
timeoutPublication = "cleanup_not_confirmed";
|
|
5161
|
+
else if (finalHeadSha === null || finalHeadSha === baseline)
|
|
5162
|
+
timeoutPublication = "nothing_to_publish";
|
|
5163
|
+
else if (publicationRemainingMs() <= 0)
|
|
5164
|
+
timeoutPublication = "no_time_left";
|
|
5165
|
+
else {
|
|
5166
|
+
// The publisher supervises its own phase; the expired worker signal is never passed.
|
|
5167
|
+
const outcome = await retainedHeadPublisher({
|
|
5168
|
+
job, branch, worktreePath, prep, deps, ownership, observation, httpClient, options: jobOptions, control,
|
|
5169
|
+
remainingMs: publicationRemainingMs, candidateSha: finalHeadSha, allowCreateOnly: true,
|
|
5170
|
+
})();
|
|
5171
|
+
if (outcome.status === "refused") {
|
|
5172
|
+
timeoutPublication = outcome.reason !== "timeout" && publicationRemainingMs() <= 0 ? "no_time_left" : outcome.reason;
|
|
5173
|
+
}
|
|
5174
|
+
}
|
|
5175
|
+
// Supervision may have found a server stop or abandoned ownership meanwhile.
|
|
5176
|
+
const stronger = await strongerOutcome(timeoutPublication === "ownership_abandoned" ? { timeout_publication: "ownership_abandoned" } : undefined);
|
|
5177
|
+
if (stronger)
|
|
5178
|
+
return stronger;
|
|
5179
|
+
}
|
|
5752
5180
|
const authDetection = adapter.authFailureDetection;
|
|
5753
5181
|
const authFailure = authDetection?.supported === true && authDetection.value.classify(procResult.stdoutExcerpt).notAuthenticated;
|
|
5754
5182
|
const capacityEvidence = authFailure
|
|
@@ -5767,6 +5195,7 @@ async function runCoveredAttempt(params) {
|
|
|
5767
5195
|
: `worker exited (${procResult.classification}, exit_code=${procResult.exitCode})`,
|
|
5768
5196
|
classification: toWireClassification(procResult.classification),
|
|
5769
5197
|
...observedExitCode(procResult.exitCode),
|
|
5198
|
+
...(timeoutPublication !== undefined ? { telemetry: { timeout_publication: timeoutPublication } } : {}),
|
|
5770
5199
|
}, envelope, capacityEvidence !== undefined ? { capacity_evidence: capacityEvidence } : {}));
|
|
5771
5200
|
}
|
|
5772
5201
|
// --- Phase 3: independent declared checks (BAPI-1302, D4c) ---------------------
|