@bridge_gpt/mcp-server 0.2.69 → 0.2.71
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 +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
package/build/executor/env.js
CHANGED
|
@@ -48,6 +48,21 @@
|
|
|
48
48
|
* value already in the environment WINS over a `.env` entry, which is what makes
|
|
49
49
|
* the sentinel effective even if a file ever survived the strip.
|
|
50
50
|
*
|
|
51
|
+
* BAPI-1479: "secret-free" means no AMBIENT credential reaches a worker. It does
|
|
52
|
+
* not mean the worker carries no key whose name looks secret. Two kinds of value
|
|
53
|
+
* are injected by the executor from its own constants and explicit job state,
|
|
54
|
+
* after the allowlist has filtered the parent environment:
|
|
55
|
+
*
|
|
56
|
+
* - `CI_WORKER_ENV_CONSTANTS` — CI's throwaway, non-secret test values (the four
|
|
57
|
+
* `BGPT_*` keys and `ENVIRONMENT=LOCAL`), so a worker can import `main` the way
|
|
58
|
+
* CI does. The allowlist still refuses these names from `parentEnv`.
|
|
59
|
+
* - a DISPOSABLE job database (`ExecutorWorkerEnvOptions.workerDatabase`), which
|
|
60
|
+
* the job runner provisions per job and drops afterwards. When it is present
|
|
61
|
+
* the four sentinel keys name that database instead and the loopback role keys
|
|
62
|
+
* (including an empty `POSTGRES_PASSWORD`) are added; when it is absent the
|
|
63
|
+
* sentinel stays exactly as BAPI-1019 set it. The worker role is refused on
|
|
64
|
+
* `bridgeapi`, so the job database is never the operational one.
|
|
65
|
+
*
|
|
51
66
|
* The `mcp-invoke` shim (a separate process) resolves `BAPI_API_KEY` itself at
|
|
52
67
|
* call time from the operator's real user-scoped credential store, exactly as it
|
|
53
68
|
* did before BAPI-731, so this worker environment never carries it. The model is
|
|
@@ -57,7 +72,71 @@
|
|
|
57
72
|
import { PR_BASE_BRANCH_ENV_VAR, WORKER_BRANCH_ENV_VAR } from "../pr-base-contract.js";
|
|
58
73
|
import { DECLARED_TOUCHED_FILES_ENV, normalizeDeclaredTouchedFiles, } from "../conductor/file-scope-guard.js";
|
|
59
74
|
import { INDEX_SCOPE_ENV_VAR, validateOptionalIndexScope } from "../index-scope-contract.js";
|
|
75
|
+
import { delimiter as PLATFORM_PATH_DELIMITER } from "node:path";
|
|
60
76
|
import { EPIC_IMPLEMENTER_ENV_PREFIX, EPIC_IMPLEMENTER_NODE_PATH_ENV, LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX, LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV, } from "../epic-implementer-env.js";
|
|
77
|
+
import { buildWorkerDatabaseEnv } from "./worker-database-target.js";
|
|
78
|
+
/** Entry rules for a declared worker variable (BAPI-1520), rechecked by the executor. */
|
|
79
|
+
const MAX_WORKER_ENV_ENTRIES = 32;
|
|
80
|
+
const MAX_WORKER_ENV_VALUE_BYTES = 1024;
|
|
81
|
+
const WORKER_ENV_NAME_PATTERN = /^[A-Z_][A-Z0-9_]{0,63}$/;
|
|
82
|
+
/**
|
|
83
|
+
* Names a declared worker variable may never use. A SORTED COPY of
|
|
84
|
+
* `WORKER_ENV_RESERVED_NAMES_SORTED` in `api/library/epic_implementer/gate_profile.py`
|
|
85
|
+
* (the authority): `tests/fixtures/executor/worker_env_reserved_names.json` is held
|
|
86
|
+
* to that authority by a Python test and to this export by `env.test.ts`. The
|
|
87
|
+
* executor owns its own copy because it may import only an allowlisted set of
|
|
88
|
+
* conductor modules.
|
|
89
|
+
*/
|
|
90
|
+
const WORKER_ENV_RESERVED_NAMES = [
|
|
91
|
+
"BASH_ENV",
|
|
92
|
+
"BRIDGE_SKIP_PREPUSH",
|
|
93
|
+
"CI",
|
|
94
|
+
LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV,
|
|
95
|
+
"DATABASE_URL",
|
|
96
|
+
"EPIC_IMPLEMENTER_NODE_PATH",
|
|
97
|
+
"GH_TOKEN",
|
|
98
|
+
"GITHUB_MERGE_TOKEN",
|
|
99
|
+
"GITHUB_TOKEN",
|
|
100
|
+
"HOME",
|
|
101
|
+
"LANG",
|
|
102
|
+
"LC_ALL",
|
|
103
|
+
"LD_PRELOAD",
|
|
104
|
+
"LOGNAME",
|
|
105
|
+
"MAX_MCP_OUTPUT_TOKENS",
|
|
106
|
+
"NODE_OPTIONS",
|
|
107
|
+
"NO_COLOR",
|
|
108
|
+
"OPENAI_API_KEY",
|
|
109
|
+
"PATH",
|
|
110
|
+
"PGDATABASE",
|
|
111
|
+
"PGHOST",
|
|
112
|
+
"PGPASSFILE",
|
|
113
|
+
"PGPASSWORD",
|
|
114
|
+
"PGPORT",
|
|
115
|
+
"PGSERVICE",
|
|
116
|
+
"PGUSER",
|
|
117
|
+
"POSTGRES_DATABASE",
|
|
118
|
+
"POSTGRES_DB",
|
|
119
|
+
"POSTGRES_HOST",
|
|
120
|
+
"POSTGRES_PASSWORD",
|
|
121
|
+
"POSTGRES_PORT",
|
|
122
|
+
"POSTGRES_USER",
|
|
123
|
+
"SHELL",
|
|
124
|
+
"TEMP",
|
|
125
|
+
"TERM",
|
|
126
|
+
"TMP",
|
|
127
|
+
"TMPDIR",
|
|
128
|
+
"USER",
|
|
129
|
+
"XDG_CONFIG_HOME",
|
|
130
|
+
];
|
|
131
|
+
/** Reserved name prefixes; a sorted copy of `WORKER_ENV_RESERVED_PREFIXES_SORTED`. */
|
|
132
|
+
const WORKER_ENV_RESERVED_PREFIXES = [
|
|
133
|
+
"ANTHROPIC_",
|
|
134
|
+
"BAPI_",
|
|
135
|
+
"BRIDGE_",
|
|
136
|
+
"CLAUDE_",
|
|
137
|
+
"DYLD_",
|
|
138
|
+
"GIT_CONFIG_",
|
|
139
|
+
];
|
|
61
140
|
/** Non-secret operational keys forwarded to the worker when present. */
|
|
62
141
|
const ALLOWED_ENV_KEYS = [
|
|
63
142
|
"PATH",
|
|
@@ -103,8 +182,146 @@ export const WORKER_SENTINEL_DATABASE_ENV_KEYS = [
|
|
|
103
182
|
"POSTGRES_DB",
|
|
104
183
|
"PGDATABASE",
|
|
105
184
|
];
|
|
185
|
+
/**
|
|
186
|
+
* CI's non-secret test values, injected into EVERY worker environment (BAPI-1479).
|
|
187
|
+
*
|
|
188
|
+
* These are the exact literals the Python lane of
|
|
189
|
+
* `.github/workflows/epic-implementer-ci.yml` sets. They are throwaway CI values,
|
|
190
|
+
* deliberately NOT secrets, and they encrypt nothing real — `BGPT_ENCRYPTION_KEY`
|
|
191
|
+
* only has to be a syntactically valid Fernet key so crypto paths import.
|
|
192
|
+
* Without them a worker cannot run any test that imports `main`
|
|
193
|
+
* (`KeyError: BGPT_SESSION_SECRET`), so it could not run the checks CI runs.
|
|
194
|
+
*
|
|
195
|
+
* Executor-INJECTED, never inherited: the builder assigns them after the
|
|
196
|
+
* allowlist loop from this map, so an operator's ambient value (possibly a real
|
|
197
|
+
* secret) can never reach a worker under these names. The allowlist is untouched
|
|
198
|
+
* — `isExecutorEnvKeyAllowed("BGPT_SESSION_SECRET")` is still `false`, and none
|
|
199
|
+
* of these keys is in `ALLOWED_ENV_KEYS`.
|
|
200
|
+
*/
|
|
201
|
+
export const CI_WORKER_ENV_CONSTANTS = Object.freeze({
|
|
202
|
+
BGPT_ENCRYPTION_KEY: "YmFwaTYxMC1jaS10ZXN0LWtleS1ub3QtYS1zZWNyZXQ=",
|
|
203
|
+
BGPT_DEMO_SECRET: "test-demo-secret",
|
|
204
|
+
BGPT_SESSION_SECRET: "test-session-secret",
|
|
205
|
+
BGPT_INVITE_SECRET: "test-invite-secret",
|
|
206
|
+
ENVIRONMENT: "LOCAL",
|
|
207
|
+
});
|
|
208
|
+
/**
|
|
209
|
+
* BAPI-1521 — the ONE reserved-name policy for repository-declared worker
|
|
210
|
+
* variables. The exact names and prefixes are the sorted copies of
|
|
211
|
+
* `WORKER_ENV_RESERVED_NAMES_SORTED` / `WORKER_ENV_RESERVED_PREFIXES_SORTED` in
|
|
212
|
+
* `api/library/epic_implementer/gate_profile.py` (the authority; a drift test
|
|
213
|
+
* compares them). Every caller that applies a declaration depends on this export
|
|
214
|
+
* rather than keeping its own list.
|
|
215
|
+
*
|
|
216
|
+
* The executor-owned keys this builder sets or denies (`EXPLICIT_DENY_KEYS`, the
|
|
217
|
+
* allowlisted process names, the database keys `buildWorkerDatabaseEnv` emits)
|
|
218
|
+
* are all covered by those names and prefixes; {@link isWorkerEnvNameReserved}
|
|
219
|
+
* additionally checks `EXPLICIT_DENY_KEYS` and `ALLOWED_ENV_KEYS` so a future
|
|
220
|
+
* executor-owned key cannot be overwritten before the Python list catches up.
|
|
221
|
+
*/
|
|
222
|
+
export const WORKER_ENV_RESERVED_POLICY = Object.freeze({
|
|
223
|
+
names: WORKER_ENV_RESERVED_NAMES,
|
|
224
|
+
prefixes: WORKER_ENV_RESERVED_PREFIXES,
|
|
225
|
+
});
|
|
226
|
+
/** True when a declared worker variable may not use `name`. */
|
|
227
|
+
export function isWorkerEnvNameReserved(name) {
|
|
228
|
+
return (WORKER_ENV_RESERVED_POLICY.names.includes(name) ||
|
|
229
|
+
WORKER_ENV_RESERVED_POLICY.prefixes.some((prefix) => name.startsWith(prefix)) ||
|
|
230
|
+
EXPLICIT_DENY_KEYS.includes(name) ||
|
|
231
|
+
ALLOWED_ENV_KEYS.includes(name));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The `{ workerEnv }` option a job payload implies: present exactly when the
|
|
235
|
+
* payload OWNS a `worker_env` key (whatever its value), empty otherwise. Spread it
|
|
236
|
+
* into an options object so absence stays absence. Never reads the value.
|
|
237
|
+
*/
|
|
238
|
+
export function payloadWorkerEnvOption(payload) {
|
|
239
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload))
|
|
240
|
+
return {};
|
|
241
|
+
if (!Object.prototype.hasOwnProperty.call(payload, "worker_env"))
|
|
242
|
+
return {};
|
|
243
|
+
return { workerEnv: payload.worker_env };
|
|
244
|
+
}
|
|
245
|
+
/** Printed in place of a name that is not a safely printable variable name. */
|
|
246
|
+
const WORKER_ENV_UNPRINTABLE_NAME_LABEL = "(unprintable name)";
|
|
247
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
248
|
+
function logWorkerEnvSkip(name, reason) {
|
|
249
|
+
const label = typeof name === "string" && WORKER_ENV_NAME_PATTERN.test(name)
|
|
250
|
+
? name
|
|
251
|
+
: WORKER_ENV_UNPRINTABLE_NAME_LABEL;
|
|
252
|
+
console.error(`executor: skipped declared worker variable ${label}: ${reason}`);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Validate a payload `worker_env` declaration against the server's entry rules
|
|
256
|
+
* (BAPI-1520) and return the entries safe to assign. Never throws: an invalid or
|
|
257
|
+
* over-bound entry is skipped with a closed reason and a sanitized name, and the
|
|
258
|
+
* rest of the list still applies. The first occurrence of a name wins.
|
|
259
|
+
*
|
|
260
|
+
* `taken` holds keys the executor already owns in the environment under
|
|
261
|
+
* construction; a declaration naming one is skipped as reserved.
|
|
262
|
+
*/
|
|
263
|
+
export function validateWorkerEnvDeclarations(raw, taken = new Set()) {
|
|
264
|
+
if (!Array.isArray(raw)) {
|
|
265
|
+
// Field name only: never the received value.
|
|
266
|
+
console.error("executor: worker_env is present but is not a list; applying no declarations");
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
const accepted = [];
|
|
270
|
+
const seen = new Set();
|
|
271
|
+
for (let index = 0; index < raw.length; index++) {
|
|
272
|
+
if (index >= MAX_WORKER_ENV_ENTRIES) {
|
|
273
|
+
logWorkerEnvSkip(undefined, "worker_env_over_bound");
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
const item = raw[index];
|
|
277
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
278
|
+
logWorkerEnvSkip(undefined, "worker_env_invalid_entry");
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const entry = item;
|
|
282
|
+
const name = entry.name;
|
|
283
|
+
if (typeof name !== "string" || !WORKER_ENV_NAME_PATTERN.test(name)) {
|
|
284
|
+
logWorkerEnvSkip(name, "worker_env_invalid_name");
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const value = entry.value;
|
|
288
|
+
if (typeof value !== "string" || LONE_SURROGATE.test(value) || /[\u0000\r\n]/.test(value)) {
|
|
289
|
+
logWorkerEnvSkip(name, "worker_env_invalid_value");
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (Buffer.byteLength(value, "utf8") > MAX_WORKER_ENV_VALUE_BYTES) {
|
|
293
|
+
logWorkerEnvSkip(name, "worker_env_over_bound");
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const flag = entry.committed_literal;
|
|
297
|
+
if (flag !== undefined && typeof flag !== "boolean") {
|
|
298
|
+
logWorkerEnvSkip(name, "worker_env_invalid_entry");
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (isWorkerEnvNameReserved(name) || taken.has(name)) {
|
|
302
|
+
logWorkerEnvSkip(name, "worker_env_reserved_name");
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (isSecretLookingWorkerEnvName(name) && flag !== true) {
|
|
306
|
+
logWorkerEnvSkip(name, "worker_env_secret_name");
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (seen.has(name)) {
|
|
310
|
+
logWorkerEnvSkip(name, "worker_env_duplicate");
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
seen.add(name);
|
|
314
|
+
accepted.push({ name, value });
|
|
315
|
+
}
|
|
316
|
+
return accepted;
|
|
317
|
+
}
|
|
106
318
|
/** Substrings that mark a key as secret-bearing (case-insensitive). */
|
|
107
319
|
const SECRET_NAME_FRAGMENTS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY"];
|
|
320
|
+
/** True when `name` looks secret, so a declaration of it needs `committed_literal: true`. */
|
|
321
|
+
function isSecretLookingWorkerEnvName(name) {
|
|
322
|
+
const upper = name.toUpperCase();
|
|
323
|
+
return SECRET_NAME_FRAGMENTS.some((fragment) => upper.includes(fragment));
|
|
324
|
+
}
|
|
108
325
|
/**
|
|
109
326
|
* Explicit deny-list of known secret / MCP / conductor keys.
|
|
110
327
|
*
|
|
@@ -126,6 +343,11 @@ export const EXPLICIT_DENY_KEYS = [
|
|
|
126
343
|
// launched the executor must never reach a worker: whoever chose the tag
|
|
127
344
|
// could make an unrelated process look job-owned to the cleanup sweep.
|
|
128
345
|
"BRIDGE_EXECUTOR_JOB_TAG",
|
|
346
|
+
// BAPI-1544: the claimed executor job's ID. Like the ownership tag it is
|
|
347
|
+
// injected AFTER this builder and the agent adapter have run (`job-runner.ts`,
|
|
348
|
+
// from the claimed job row), so an ambient value, a job payload, or an adapter
|
|
349
|
+
// can never choose which job a worker registers its delivery binding against.
|
|
350
|
+
"BRIDGE_EXECUTOR_JOB_ID",
|
|
129
351
|
EPIC_IMPLEMENTER_NODE_PATH_ENV,
|
|
130
352
|
// BAPI-1190: the legacy spelling stays denied so a stale ambient value from an
|
|
131
353
|
// older package can never reach a worker during a version-skew window.
|
|
@@ -148,6 +370,16 @@ export const EXPLICIT_DENY_KEYS = [
|
|
|
148
370
|
"OPENAI_API_KEY",
|
|
149
371
|
"GITHUB_TOKEN",
|
|
150
372
|
"GH_TOKEN",
|
|
373
|
+
// BAPI-1452: the canonical local merge credential. The executor PROCESS keeps
|
|
374
|
+
// it — the local merge job authenticates with it — so it is deliberately NOT
|
|
375
|
+
// on `EXECUTOR_PROCESS_GITHUB_CREDENTIAL_DENY_KEYS` below. A worker never
|
|
376
|
+
// needs it, and denying it here keeps a merge-capable token out of every
|
|
377
|
+
// agent session even if a future edit widens the allowlist.
|
|
378
|
+
"GITHUB_MERGE_TOKEN",
|
|
379
|
+
// BAPI-1461: its deprecated alias and the machine-user key, denied explicitly
|
|
380
|
+
// for the same reason. The executor process keeps both; a worker never does.
|
|
381
|
+
"BAPI_LOCAL_MERGE_TOKEN",
|
|
382
|
+
"BAPI_MACHINE_MERGE_TOKEN",
|
|
151
383
|
"CLAUDE_CONFIG_DIR",
|
|
152
384
|
"XDG_CONFIG_HOME",
|
|
153
385
|
// BAPI-844: the index-scope declaration follows the BAPI_BASE_BRANCH rule —
|
|
@@ -268,6 +500,10 @@ export function isExecutorEnvKeyAllowed(key) {
|
|
|
268
500
|
return false;
|
|
269
501
|
return true;
|
|
270
502
|
}
|
|
503
|
+
/** True when the options object owns a `workerEnv` property (value irrelevant). */
|
|
504
|
+
export function hasWorkerEnvOption(options) {
|
|
505
|
+
return options !== undefined && Object.prototype.hasOwnProperty.call(options, "workerEnv");
|
|
506
|
+
}
|
|
271
507
|
export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
|
|
272
508
|
const env = {};
|
|
273
509
|
for (const key of ALLOWED_ENV_KEYS) {
|
|
@@ -288,6 +524,36 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
|
|
|
288
524
|
env.POSTGRES_DATABASE = WORKER_SENTINEL_DATABASE_NAME;
|
|
289
525
|
env.POSTGRES_DB = WORKER_SENTINEL_DATABASE_NAME;
|
|
290
526
|
env.PGDATABASE = WORKER_SENTINEL_DATABASE_NAME;
|
|
527
|
+
// BAPI-1479 — a provisioned job database replaces the four sentinel keys
|
|
528
|
+
// TOGETHER and adds the loopback role keys. Validated before anything is set, so
|
|
529
|
+
// an invalid name throws rather than leaving a half-pointed environment.
|
|
530
|
+
if (options.workerDatabase !== undefined) {
|
|
531
|
+
Object.assign(env, buildWorkerDatabaseEnv(options.workerDatabase));
|
|
532
|
+
}
|
|
533
|
+
// BAPI-1479 — CI's throwaway test values, from constants and never from
|
|
534
|
+
// `parentEnv`, for every job type and every adapter. BAPI-1521: only when the
|
|
535
|
+
// payload did not carry a `worker_env` declaration at all. A present declaration
|
|
536
|
+
// — even an empty or malformed one — replaces the constants, so a repository
|
|
537
|
+
// that cleared its variables gets none, not the legacy defaults.
|
|
538
|
+
const workerEnvPresent = hasWorkerEnvOption(options);
|
|
539
|
+
if (!workerEnvPresent) {
|
|
540
|
+
if (options.legacyNotice !== false) {
|
|
541
|
+
console.error("executor: payload carries no worker_env; applying legacy compatibility constants");
|
|
542
|
+
}
|
|
543
|
+
Object.assign(env, CI_WORKER_ENV_CONSTANTS);
|
|
544
|
+
}
|
|
545
|
+
// BAPI-1479 — the own-build launcher directory goes FIRST on PATH, from the
|
|
546
|
+
// explicit option only. The inherited PATH follows it unchanged; an empty or
|
|
547
|
+
// absent inherited PATH adds no empty component (an empty component means
|
|
548
|
+
// "the current directory" to a shell, which a worktree must not be).
|
|
549
|
+
if (typeof options.workerLauncherDirectory === "string" &&
|
|
550
|
+
options.workerLauncherDirectory.length > 0) {
|
|
551
|
+
const inherited = env.PATH;
|
|
552
|
+
env.PATH =
|
|
553
|
+
typeof inherited === "string" && inherited.length > 0
|
|
554
|
+
? `${options.workerLauncherDirectory}${PLATFORM_PATH_DELIMITER}${inherited}`
|
|
555
|
+
: options.workerLauncherDirectory;
|
|
556
|
+
}
|
|
291
557
|
if (options.correctionIntentVersion !== undefined) {
|
|
292
558
|
if (options.correctionIntentVersion !== 1)
|
|
293
559
|
throw new Error("unsupported correction intent version");
|
|
@@ -321,6 +587,14 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
|
|
|
321
587
|
if (Array.isArray(options.declaredTouchedFiles)) {
|
|
322
588
|
env[DECLARED_TOUCHED_FILES_ENV] = JSON.stringify(normalizeDeclaredTouchedFiles(options.declaredTouchedFiles));
|
|
323
589
|
}
|
|
590
|
+
// BAPI-1521 — repository-declared variables go in LAST among the base keys and
|
|
591
|
+
// can never overwrite a key the executor already owns in `env`.
|
|
592
|
+
if (workerEnvPresent) {
|
|
593
|
+
const taken = new Set(Object.keys(env));
|
|
594
|
+
for (const { name, value } of validateWorkerEnvDeclarations(options.workerEnv, taken)) {
|
|
595
|
+
env[name] = value;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
324
598
|
// Nothing agent-specific is added here, and deliberately nothing secret. An
|
|
325
599
|
// adapter that needs to forward an operator-owned credential declares it as a
|
|
326
600
|
// passthrough and copies it onto the object this function returns; see
|
|
@@ -346,5 +620,6 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
|
|
|
346
620
|
* capability probes are not filtered.
|
|
347
621
|
*/
|
|
348
622
|
export function buildHeadlessAgentEnv(parentEnv) {
|
|
349
|
-
|
|
623
|
+
// BAPI-1521: not a job, so no legacy notice either; it keeps the constants silently.
|
|
624
|
+
return buildExecutorBaseWorkerEnv(parentEnv, { legacyNotice: false });
|
|
350
625
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed `telemetry.failure_reason_code` vocabulary (BAPI-1453).
|
|
3
|
+
*
|
|
4
|
+
* A failed executor job already reports a structured `error_kind`, which is the
|
|
5
|
+
* ROUTING signal: the server's terminal disposition and the merge re-fire lane
|
|
6
|
+
* decide on `error_kind` and `classification` alone (R14 rule 3). That kind is
|
|
7
|
+
* deliberately coarse — `MergeRetryable` covers a dozen distinct reasons — so an
|
|
8
|
+
* operator reading `explain_run` could not tell a `gh_pr_view_failed` from a
|
|
9
|
+
* `ci_not_green`. The precise reason existed only in the free-text
|
|
10
|
+
* `error_message`, which `explain_run` never reads.
|
|
11
|
+
*
|
|
12
|
+
* This module names that precise reason as one value from a CLOSED list, so the
|
|
13
|
+
* server can show it without ever reading free text. Two rules keep it safe:
|
|
14
|
+
*
|
|
15
|
+
* - **Display only.** No disposition, retry, park, or rebase decision may read a
|
|
16
|
+
* failure reason code. A row whose code disagrees with its `error_kind` is
|
|
17
|
+
* classified by its `error_kind`.
|
|
18
|
+
* - **Builders own it.** The failure builders in `merge-job.ts` and
|
|
19
|
+
* `job-runner.ts` set it. Observation state never carries it, so a snapshot
|
|
20
|
+
* can never overwrite or invent one.
|
|
21
|
+
*
|
|
22
|
+
* The list is mirrored in `api/library/epic_implementer/failure_reason_codes.py`.
|
|
23
|
+
* A parity test fails when the two drift, so add every new value to both.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Every reason the local merge executor (`conductor/local-merge.ts`) can return
|
|
27
|
+
* on the merge-job path, plus the server's migration-graph refusals that reach
|
|
28
|
+
* the same classifier. The `ci_poll_http_<status>` family is matched by
|
|
29
|
+
* {@link CI_POLL_HTTP_REASON_PATTERN} rather than listed.
|
|
30
|
+
*/
|
|
31
|
+
const MERGE_REASON_CODES = [
|
|
32
|
+
"gh_pr_view_timeout",
|
|
33
|
+
"gh_pr_view_failed",
|
|
34
|
+
"gh_pr_view_unparseable",
|
|
35
|
+
"ci_poll_failed",
|
|
36
|
+
"ci_poll_timeout",
|
|
37
|
+
"ci_poll_network",
|
|
38
|
+
"ci_poll_unauthorized",
|
|
39
|
+
"ci_poll_server",
|
|
40
|
+
"ci_poll_http",
|
|
41
|
+
"ci_not_green",
|
|
42
|
+
"gh_merge_timeout",
|
|
43
|
+
"gh_merge_failed",
|
|
44
|
+
"gh_merge_conflict",
|
|
45
|
+
"merge_aborted",
|
|
46
|
+
"head_drift",
|
|
47
|
+
"pr_not_open",
|
|
48
|
+
"ref_mismatch",
|
|
49
|
+
"migration_graph_invalid",
|
|
50
|
+
"migration_graph_unreadable",
|
|
51
|
+
"local_merge_approval_required",
|
|
52
|
+
"local_gh_unavailable",
|
|
53
|
+
"local_merge_credential_missing",
|
|
54
|
+
"machine_merge_credential_missing",
|
|
55
|
+
"local_merge_credential_invalid",
|
|
56
|
+
"machine_merge_credential_invalid",
|
|
57
|
+
"local_merge_credential_unpermitted",
|
|
58
|
+
"machine_merge_credential_unpermitted",
|
|
59
|
+
"local_merge_probe_unavailable",
|
|
60
|
+
"machine_merge_probe_unavailable",
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Merge-flow outcomes the executor itself produces, outside `local-merge.ts`.
|
|
64
|
+
* New contract values introduced by BAPI-1453.
|
|
65
|
+
*/
|
|
66
|
+
const EXECUTOR_MERGE_REASON_CODES = [
|
|
67
|
+
/** The claimed job's merge payload failed validation. */
|
|
68
|
+
"merge_payload_invalid",
|
|
69
|
+
/** Bridge API access for the CI re-poll could not be resolved. */
|
|
70
|
+
"merge_access_unavailable",
|
|
71
|
+
/** The whole merge flow exceeded its `timeout_seconds`. */
|
|
72
|
+
"merge_flow_timeout",
|
|
73
|
+
/** The merge flow threw. */
|
|
74
|
+
"merge_flow_error",
|
|
75
|
+
/** The merge flow finished without producing an outcome. */
|
|
76
|
+
"merge_no_outcome",
|
|
77
|
+
/** A failed merge response carried no recognized reason. */
|
|
78
|
+
"merge_failure_unclassified",
|
|
79
|
+
];
|
|
80
|
+
/**
|
|
81
|
+
* BAPI-1453: the permission probe that runs after a `gh_pr_view_failed` PROVED
|
|
82
|
+
* the merge credential cannot access the repository.
|
|
83
|
+
*/
|
|
84
|
+
export const GH_REPO_ACCESS_DENIED = "gh_repo_access_denied";
|
|
85
|
+
/** The four pre-spawn verification refusals (`PreSpawnVerificationReason`). */
|
|
86
|
+
const PRE_SPAWN_REASON_CODES = ["dirty", "status-unverifiable", "head-unverifiable", "head-mismatch"];
|
|
87
|
+
/**
|
|
88
|
+
* BAPI-1530: display-only categories for a pre-worker worktree failure. They
|
|
89
|
+
* describe a structured outcome and are never read by any disposition decision.
|
|
90
|
+
*/
|
|
91
|
+
const WORKTREE_REASON_CODES = ["worktree_stale_branch", "worktree_lineage_refused", "worktree_fetch_failed"];
|
|
92
|
+
/** Every fixed failure reason code. */
|
|
93
|
+
export const FAILURE_REASON_CODES = [
|
|
94
|
+
...MERGE_REASON_CODES,
|
|
95
|
+
...EXECUTOR_MERGE_REASON_CODES,
|
|
96
|
+
GH_REPO_ACCESS_DENIED,
|
|
97
|
+
...PRE_SPAWN_REASON_CODES,
|
|
98
|
+
...WORKTREE_REASON_CODES,
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* The bounded `ci_poll_http_<status>` family. Anchored, exactly three digits,
|
|
102
|
+
* matched against the WHOLE string: a trailing newline, an extra suffix, a case
|
|
103
|
+
* change, or any other `ci_poll_*` spelling is rejected. Mirrored byte for byte
|
|
104
|
+
* in the Python module.
|
|
105
|
+
*/
|
|
106
|
+
export const CI_POLL_HTTP_REASON_PATTERN = /^ci_poll_http_[0-9]{3}$/;
|
|
107
|
+
/** Longest accepted code. Mirrors the Python bound. */
|
|
108
|
+
export const MAX_FAILURE_REASON_CODE_CHARS = 64;
|
|
109
|
+
const FIXED_CODES = new Set(FAILURE_REASON_CODES);
|
|
110
|
+
/** True only for a value in the closed vocabulary. */
|
|
111
|
+
export function isFailureReasonCode(value) {
|
|
112
|
+
if (typeof value !== "string" || value.length > MAX_FAILURE_REASON_CODE_CHARS)
|
|
113
|
+
return false;
|
|
114
|
+
return FIXED_CODES.has(value) || CI_POLL_HTTP_REASON_PATTERN.test(value);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Narrow a known-good literal to {@link FailureReasonCode}. Throws on a value
|
|
118
|
+
* outside the vocabulary, so a misspelled builder code fails its first test
|
|
119
|
+
* rather than reaching the server as a silently dropped `null`.
|
|
120
|
+
*/
|
|
121
|
+
export function failureReasonCode(value) {
|
|
122
|
+
if (!isFailureReasonCode(value)) {
|
|
123
|
+
throw new Error(`not a failure reason code: ${value}`);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
@@ -219,7 +219,15 @@ export function parseGateQualificationPayload(job) {
|
|
|
219
219
|
return refuse(MESSAGES.contract);
|
|
220
220
|
return {
|
|
221
221
|
ok: true,
|
|
222
|
-
payload: {
|
|
222
|
+
payload: {
|
|
223
|
+
repoName: envelope.repo_name,
|
|
224
|
+
revision: envelope.revision,
|
|
225
|
+
commands,
|
|
226
|
+
digest,
|
|
227
|
+
workerEnvOption: Object.prototype.hasOwnProperty.call(envelope, "worker_env")
|
|
228
|
+
? { workerEnv: envelope.worker_env }
|
|
229
|
+
: {},
|
|
230
|
+
},
|
|
223
231
|
};
|
|
224
232
|
}
|
|
225
233
|
// ---------------------------------------------------------------------------
|
|
@@ -386,6 +394,10 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
386
394
|
}, OWNERSHIP_POLL_MS);
|
|
387
395
|
};
|
|
388
396
|
watchOwnership();
|
|
397
|
+
// BAPI-1521 — the effective environment is built here, AFTER the envelope was
|
|
398
|
+
// verified and BEFORE any command runs, from the sealed declaration. The
|
|
399
|
+
// injected dependencies are never mutated.
|
|
400
|
+
const commandEnv = deps.commandEnv ?? buildGateQualificationEnv(deps.baseEnv ?? {}, payload.workerEnvOption);
|
|
389
401
|
const commands = payload.commands.map((command) => ({
|
|
390
402
|
identity: command.identity,
|
|
391
403
|
position: command.position,
|
|
@@ -398,7 +410,7 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
398
410
|
const run = await runRequiredVerificationCommands({
|
|
399
411
|
commands,
|
|
400
412
|
worktreePath: dir,
|
|
401
|
-
env:
|
|
413
|
+
env: commandEnv,
|
|
402
414
|
launch: deps.launch,
|
|
403
415
|
now: deps.now,
|
|
404
416
|
deadlineAtMs,
|
|
@@ -449,9 +461,12 @@ export async function runGateQualificationJob(job, input, deps) {
|
|
|
449
461
|
* The explicit command environment: the executor's worker base environment
|
|
450
462
|
* (allowlisted keys, parent credentials stripped, sentinel database values,
|
|
451
463
|
* `BRIDGE_SKIP_PREPUSH=1`) plus `CI=1`, so test tooling runs non-interactively.
|
|
464
|
+
* BAPI-1521: the sealed declaration's `worker_env` is passed with its presence
|
|
465
|
+
* intact — absent keeps the compatibility constants, present replaces them.
|
|
452
466
|
*/
|
|
453
|
-
export function buildGateQualificationEnv(parentEnv) {
|
|
454
|
-
|
|
467
|
+
export function buildGateQualificationEnv(parentEnv, workerEnvOption = {}) {
|
|
468
|
+
// BAPI-1521: `CI=1` is applied last, so a declaration can never turn it off.
|
|
469
|
+
return { ...buildExecutorBaseWorkerEnv(parentEnv, workerEnvOption), CI: "1" };
|
|
455
470
|
}
|
|
456
471
|
/**
|
|
457
472
|
* Production dependencies built from the executor's own boundary.
|
|
@@ -480,7 +495,7 @@ export function createProductionGateQualificationDeps(input) {
|
|
|
480
495
|
deps,
|
|
481
496
|
...(input.registerLive ? { registerLive: input.registerLive } : {}),
|
|
482
497
|
}),
|
|
483
|
-
|
|
498
|
+
baseEnv: deps.env,
|
|
484
499
|
repoRoot: deps.cwd,
|
|
485
500
|
fallbackBaseBranch: options.baseBranch,
|
|
486
501
|
makeTempDir,
|
|
@@ -197,3 +197,41 @@ export async function runHeartbeatLoop(params) {
|
|
|
197
197
|
}
|
|
198
198
|
return ownership.abandoned ? { kind: "abandoned" } : { kind: "done" };
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Send ONE awaited heartbeat carrying an ownership context, through the same
|
|
202
|
+
* transport, response interpretation, and ownership bookkeeping the periodic loop
|
|
203
|
+
* uses (BAPI-1504). The covered runner calls it BEFORE spawning a worker, with
|
|
204
|
+
* `worker: null`, so a cleanup-capable row's stored ownership is non-null whenever
|
|
205
|
+
* a worker may exist. It is only ever called while no periodic loop is running, so
|
|
206
|
+
* the two can never overlap or arrive out of order.
|
|
207
|
+
*
|
|
208
|
+
* `stale_claim` marks the claim abandoned, exactly like the loop. A stop request
|
|
209
|
+
* and an auth failure are reported to the caller without touching ownership; the
|
|
210
|
+
* caller owns what happens next. It never signals any process.
|
|
211
|
+
*/
|
|
212
|
+
export async function sendImmediateHeartbeat(params) {
|
|
213
|
+
const { job, httpClient, deps, ownership, observation } = params;
|
|
214
|
+
const git = await params.collectTelemetry();
|
|
215
|
+
observation.setGitTelemetry(git);
|
|
216
|
+
const result = normalizeHeartbeatResult(await httpClient.heartbeat(job, {
|
|
217
|
+
local_commit_count: git.local_commit_count,
|
|
218
|
+
last_commit_sha: git.last_commit_sha,
|
|
219
|
+
telemetry: observation.snapshot(),
|
|
220
|
+
ownership_context: params.ownershipContext,
|
|
221
|
+
}));
|
|
222
|
+
if (result.stop_requested === true)
|
|
223
|
+
return { kind: "server_stop" };
|
|
224
|
+
if (result.outcome === "auth_fatal") {
|
|
225
|
+
return { kind: "auth_fatal", httpStatus: result.authHttpStatus ?? 401 };
|
|
226
|
+
}
|
|
227
|
+
if (result.outcome === "updated") {
|
|
228
|
+
ownership.lastSuccessfulHeartbeatAt = deps.now();
|
|
229
|
+
return { kind: "accepted" };
|
|
230
|
+
}
|
|
231
|
+
if (result.outcome === "stale_claim") {
|
|
232
|
+
ownership.abandoned = true;
|
|
233
|
+
ownership.abandonReason = "stale_claim";
|
|
234
|
+
return { kind: "stale_claim" };
|
|
235
|
+
}
|
|
236
|
+
return { kind: "transient" };
|
|
237
|
+
}
|
|
@@ -217,6 +217,25 @@ function mapMutationResponse(status, bodyText, allowInvalidResult) {
|
|
|
217
217
|
return { outcome: "auth_fatal", authHttpStatus: status };
|
|
218
218
|
return { outcome: "fatal_http_error" };
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* The closed `error_code` of a cleanup-report 409 refusal, or `null` for anything
|
|
222
|
+
* else. Reads only the code; the body is never retained (BAPI-1504).
|
|
223
|
+
*/
|
|
224
|
+
function parseCleanupRefusalCode(bodyText) {
|
|
225
|
+
try {
|
|
226
|
+
const parsed = JSON.parse(bodyText);
|
|
227
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
228
|
+
return null;
|
|
229
|
+
const detail = parsed.detail;
|
|
230
|
+
if (typeof detail !== "object" || detail === null)
|
|
231
|
+
return null;
|
|
232
|
+
const code = detail.error_code;
|
|
233
|
+
return code === "CLEANUP_REPORT_NOT_APPLICABLE" || code === "CLEANUP_REPORT_JOB_RUNNING" ? code : null;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
220
239
|
/**
|
|
221
240
|
* Adapt the executor's injected `FetchLike` transport to the narrower
|
|
222
241
|
* `ConductorFetch` shape the shared read-only Bridge API GET helper expects
|
|
@@ -419,6 +438,59 @@ export function createExecutorHttpClient(config) {
|
|
|
419
438
|
return "failed";
|
|
420
439
|
}
|
|
421
440
|
},
|
|
441
|
+
/**
|
|
442
|
+
* Deliver one cleanup confirmation (BAPI-1504).
|
|
443
|
+
*
|
|
444
|
+
* Only a validated 200 body or an explicit `409 CLEANUP_REPORT_NOT_APPLICABLE`
|
|
445
|
+
* is terminal. Everything else retains the local ownership record. Nothing
|
|
446
|
+
* from the response body, the token, or a raw transport error is returned.
|
|
447
|
+
*/
|
|
448
|
+
async reportCleanup(request) {
|
|
449
|
+
let status;
|
|
450
|
+
let text;
|
|
451
|
+
try {
|
|
452
|
+
const res = await post(`/${request.jobId}/cleanup-report`, {
|
|
453
|
+
repo_name: request.repoName,
|
|
454
|
+
ownership_token: request.ownershipToken,
|
|
455
|
+
cleanup_verdict: "confirmed",
|
|
456
|
+
path: request.path,
|
|
457
|
+
}, request.repoName);
|
|
458
|
+
status = res.status;
|
|
459
|
+
text = res.text;
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
return { kind: "retained", reason: "network_error", retryable: true };
|
|
463
|
+
}
|
|
464
|
+
if (status >= 200 && status < 300) {
|
|
465
|
+
return isOkBody(text)
|
|
466
|
+
? { kind: "accepted" }
|
|
467
|
+
: { kind: "retained", reason: "malformed_response", retryable: false };
|
|
468
|
+
}
|
|
469
|
+
if (status === 409) {
|
|
470
|
+
const code = parseCleanupRefusalCode(text);
|
|
471
|
+
if (code === "CLEANUP_REPORT_NOT_APPLICABLE")
|
|
472
|
+
return { kind: "not_applicable" };
|
|
473
|
+
if (code === "CLEANUP_REPORT_JOB_RUNNING") {
|
|
474
|
+
return { kind: "retained", reason: "job_running", retryable: true };
|
|
475
|
+
}
|
|
476
|
+
return { kind: "retained", reason: "malformed_response", retryable: false };
|
|
477
|
+
}
|
|
478
|
+
if (status === 401 || status === 403) {
|
|
479
|
+
return { kind: "retained", reason: "unauthorized", retryable: false };
|
|
480
|
+
}
|
|
481
|
+
if (status === 404) {
|
|
482
|
+
// A server that predates the route: keep the record for a later start.
|
|
483
|
+
(config.warn ?? ((message) => console.error(message)))(`cleanup_report_unsupported job=${request.jobId}`);
|
|
484
|
+
return { kind: "retained", reason: "unsupported", retryable: false };
|
|
485
|
+
}
|
|
486
|
+
if (status === 429)
|
|
487
|
+
return { kind: "retained", reason: "rate_limited", retryable: true };
|
|
488
|
+
if (status === 503)
|
|
489
|
+
return { kind: "retained", reason: "retry_later", retryable: true };
|
|
490
|
+
if (status >= 500)
|
|
491
|
+
return { kind: "retained", reason: "server_error", retryable: true };
|
|
492
|
+
return { kind: "retained", reason: "malformed_response", retryable: false };
|
|
493
|
+
},
|
|
422
494
|
complete(job, completion) {
|
|
423
495
|
const body = {
|
|
424
496
|
repo_name: job.repo_name,
|