fix: production hardening for merge races, timeouts, and webhook ops
Pin merge SHA, lock conflict repair, bound subprocess/proxy output, fail-fast incomplete R2/webhook config, redact validation/stderr secrets, and document that webhook 202 is best-effort after ACK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d6f33a71c3
commit
039acabd96
29 files changed
+1163
-240
No files matched your search
+93
-65
@@ -39,76 +39,103 @@ function csvListWithDefault(defaultValue: string[]) {
|
||||
}, z.array(z.string()));
|
||||
}
|
||||
|
||||
const configSchema = z.object({
|
||||
port: z.coerce.number().int().positive().default(3000),
|
||||
githubToken: optionalString,
|
||||
githubAppId: optionalString,
|
||||
githubAppPrivateKey: optionalString,
|
||||
githubAppInstallationId: z.preprocess((value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return value;
|
||||
}, z.coerce.number().int().positive().optional()),
|
||||
webhookEnabled: envBoolean.default(false),
|
||||
webhookSecret: optionalString,
|
||||
webhookPath: z.string().startsWith("/").default("/webhooks/github"),
|
||||
webhookChatPermission: z.enum(["anyone", "read", "write"]).default("read"),
|
||||
webhookQueueConcurrency: z.coerce.number().int().positive().max(20).default(2),
|
||||
webhookQueueLimit: z.coerce.number().int().positive().max(10_000).default(500),
|
||||
gooseModel: optionalString.default("gpt-5.4"),
|
||||
gooseThinkingEffort: z.preprocess(
|
||||
(value) => {
|
||||
const configSchema = z
|
||||
.object({
|
||||
port: z.coerce.number().int().positive().default(3000),
|
||||
githubToken: optionalString,
|
||||
githubAppId: optionalString,
|
||||
githubAppPrivateKey: optionalString,
|
||||
githubAppInstallationId: z.preprocess((value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (value === "minimal") {
|
||||
return "low";
|
||||
}
|
||||
|
||||
if (value === "xhigh") {
|
||||
return "max";
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
z.enum(["off", "low", "medium", "high", "max"]).optional()
|
||||
),
|
||||
gooseBaseUrl: optionalString,
|
||||
gooseApiKey: optionalString,
|
||||
reviewPolicy: z.enum(["allow", "require_approval", "reject"]).default("allow"),
|
||||
reviewStrictness: z.enum(["normal", "strict"]).default("normal"),
|
||||
reviewInstructions: optionalString,
|
||||
reviewBranches: csvListWithDefault([]),
|
||||
repositoryKnowledgeEnabled: envBoolean.default(true),
|
||||
repositoryKnowledgeWrite: envBoolean.default(false),
|
||||
r2Endpoint: optionalString,
|
||||
r2BucketName: optionalString,
|
||||
r2Prefix: optionalString,
|
||||
r2AccessKeyId: optionalString,
|
||||
r2SecretAccessKey: optionalString,
|
||||
triageEnabled: envBoolean.default(true),
|
||||
triageLabels: csvListWithDefault([
|
||||
"bug",
|
||||
"enhancement",
|
||||
"documentation",
|
||||
"question",
|
||||
"maintenance"
|
||||
]).refine((labels) => labels.length > 0, "TRIAGE_LABELS must contain at least one label."),
|
||||
triageDuplicateLabel: z.string().min(1).default("duplicate"),
|
||||
triageCandidateLimit: z.coerce.number().int().positive().max(100).default(50),
|
||||
triageInstructions: optionalString,
|
||||
botName: z.string().min(1).default("ghbot"),
|
||||
autoMerge: envBoolean.default(false),
|
||||
autoResolveConflicts: envBoolean.default(false),
|
||||
conflictTestCommand: optionalString,
|
||||
mergeMethod: z.enum(["merge", "squash", "rebase"]).default("squash"),
|
||||
requireChecks: envBoolean.default(true),
|
||||
maxPatchChars: z.coerce.number().int().positive().default(120_000),
|
||||
logLevel: z.string().min(1).default("info")
|
||||
});
|
||||
}, z.coerce.number().int().positive().optional()),
|
||||
webhookEnabled: envBoolean.default(false),
|
||||
webhookSecret: optionalString,
|
||||
webhookPath: z.string().startsWith("/").default("/webhooks/github"),
|
||||
webhookChatPermission: z.enum(["anyone", "read", "write"]).default("read"),
|
||||
webhookQueueConcurrency: z.coerce.number().int().positive().max(20).default(2),
|
||||
webhookQueueLimit: z.coerce.number().int().positive().max(10_000).default(500),
|
||||
runtimeDirectory: optionalString,
|
||||
gooseModel: optionalString.default("gpt-5.4"),
|
||||
gooseThinkingEffort: z.preprocess(
|
||||
(value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (value === "minimal") {
|
||||
return "low";
|
||||
}
|
||||
|
||||
if (value === "xhigh") {
|
||||
return "max";
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
z.enum(["off", "low", "medium", "high", "max"]).optional()
|
||||
),
|
||||
gooseBaseUrl: optionalString.default("https://api.openai.com/v1"),
|
||||
gooseApiKey: optionalString,
|
||||
reviewPolicy: z.enum(["allow", "require_approval", "reject"]).default("allow"),
|
||||
reviewStrictness: z.enum(["normal", "strict"]).default("normal"),
|
||||
reviewInstructions: optionalString,
|
||||
reviewBranches: csvListWithDefault([]),
|
||||
repositoryKnowledgeEnabled: envBoolean.default(true),
|
||||
repositoryKnowledgeWrite: envBoolean.default(false),
|
||||
r2Endpoint: optionalString,
|
||||
r2BucketName: optionalString,
|
||||
r2Prefix: optionalString,
|
||||
r2AccessKeyId: optionalString,
|
||||
r2SecretAccessKey: optionalString,
|
||||
triageEnabled: envBoolean.default(true),
|
||||
triageLabels: csvListWithDefault([
|
||||
"bug",
|
||||
"enhancement",
|
||||
"documentation",
|
||||
"question",
|
||||
"maintenance"
|
||||
]).refine((labels) => labels.length > 0, "TRIAGE_LABELS must contain at least one label."),
|
||||
triageDuplicateLabel: z.string().min(1).default("duplicate"),
|
||||
triageCandidateLimit: z.coerce.number().int().positive().max(100).default(50),
|
||||
triageInstructions: optionalString,
|
||||
botName: z.string().min(1).default("ghbot"),
|
||||
autoMerge: envBoolean.default(false),
|
||||
autoResolveConflicts: envBoolean.default(false),
|
||||
conflictTestCommand: optionalString,
|
||||
mergeMethod: z.enum(["merge", "squash", "rebase"]).default("squash"),
|
||||
requireChecks: envBoolean.default(true),
|
||||
maxPatchChars: z.coerce.number().int().positive().default(120_000),
|
||||
logLevel: z.string().min(1).default("info")
|
||||
})
|
||||
.superRefine((value, ctx) => {
|
||||
if (value.webhookEnabled && !value.webhookSecret) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["webhookSecret"],
|
||||
message: "WEBHOOK_SECRET is required when WEBHOOK_ENABLED=true."
|
||||
});
|
||||
}
|
||||
|
||||
const r2Values = [
|
||||
value.r2Endpoint,
|
||||
value.r2BucketName,
|
||||
value.r2AccessKeyId,
|
||||
value.r2SecretAccessKey
|
||||
];
|
||||
const configuredR2Values = r2Values.filter(Boolean).length;
|
||||
if (configuredR2Values > 0 && configuredR2Values < r2Values.length) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["r2Endpoint"],
|
||||
message:
|
||||
"R2_ENDPOINT, R2_BUCKET_NAME, R2_ACCESS_KEY_ID, and R2_SECRET_ACCESS_KEY must be configured together."
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = configSchema.parse({
|
||||
port: process.env.PORT,
|
||||
@@ -123,6 +150,7 @@ export const config = configSchema.parse({
|
||||
webhookChatPermission: process.env.WEBHOOK_CHAT_PERMISSION,
|
||||
webhookQueueConcurrency: process.env.WEBHOOK_QUEUE_CONCURRENCY,
|
||||
webhookQueueLimit: process.env.WEBHOOK_QUEUE_LIMIT,
|
||||
runtimeDirectory: process.env.GHBOT_RUNTIME_DIR,
|
||||
gooseModel: process.env.GOOSE_MODEL ?? process.env.OPENCODE_MODEL,
|
||||
gooseThinkingEffort: process.env.GOOSE_THINKING_EFFORT ?? process.env.OPENCODE_REASONING_EFFORT,
|
||||
gooseBaseUrl: process.env.GOOSE_BASE_URL ?? process.env.OPENCODE_BASE_URL,
|
||||
|
||||
Reference in new issue
Block a user