Skip to content

Commit ff3d8ca

Browse files
committed
feat: preflight update runner before rebase
1 parent 9ae03b9 commit ff3d8ca

8 files changed

Lines changed: 306 additions & 45 deletions

File tree

‎docs/cli/update.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ High-level:
6969

7070
1. Requires a clean worktree (no uncommitted changes).
7171
2. Switches to the selected channel (tag or branch).
72-
3. Fetches and rebases against `@{upstream}` (dev only).
73-
4. Installs deps (pnpm preferred; npm fallback).
74-
5. Builds + builds the Control UI.
75-
6. Runs `clawdbot doctor` as the final “safe update” check.
76-
7. Syncs plugins to the active channel (dev uses bundled extensions; stable/beta uses npm) and updates npm-installed plugins.
72+
3. Fetches upstream (dev only).
73+
4. Dev only: preflight lint + TypeScript build in a temp worktree; if the tip fails, walks back up to 10 commits to find the newest clean build.
74+
5. Rebases onto the selected commit (dev only).
75+
6. Installs deps (pnpm preferred; npm fallback).
76+
7. Builds + builds the Control UI.
77+
8. Runs `clawdbot doctor` as the final “safe update” check.
78+
9. Syncs plugins to the active channel (dev uses bundled extensions; stable/beta uses npm) and updates npm-installed plugins.
7779

7880
## `--update` shorthand
7981

‎scripts/e2e/Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ COPY src ./src
1111
COPY scripts ./scripts
1212
COPY docs ./docs
1313
COPY skills ./skills
14+
COPY extensions/memory-core ./extensions/memory-core
1415

1516
RUN pnpm install --frozen-lockfile
1617
RUN pnpm build

‎scripts/e2e/onboard-docker.sh‎

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,27 @@ TRASH
5151
start_s="$(date +%s)"
5252
while true; do
5353
if [ -n "${WIZARD_LOG_PATH:-}" ] && [ -f "$WIZARD_LOG_PATH" ]; then
54-
if NEEDLE="$needle_compact" node --input-type=module -e "
54+
if grep -a -F -q "$needle" "$WIZARD_LOG_PATH"; then
55+
return 0
56+
fi
57+
if NEEDLE=\"$needle_compact\" node --input-type=module -e "
5558
import fs from \"node:fs\";
5659
const file = process.env.WIZARD_LOG_PATH;
5760
const needle = process.env.NEEDLE ?? \"\";
5861
let text = \"\";
5962
try { text = fs.readFileSync(file, \"utf8\"); } catch { process.exit(1); }
60-
text = text.replace(/\\x1b\\[[0-9;]*[A-Za-z]/g, \"\").replace(/\\s+/g, \"\");
61-
process.exit(text.includes(needle) ? 0 : 1);
63+
if (text.length > 20000) text = text.slice(-20000);
64+
const sanitize = (value) => value.replace(/[\\x00-\\x1f\\x7f]/g, \"\");
65+
const haystack = sanitize(text);
66+
const safeNeedle = sanitize(needle);
67+
const needsEscape = new Set([\"\\\\\", \"^\", \"$\", \".\", \"*\", \"+\", \"?\", \"(\", \")\", \"[\", \"]\", \"{\", \"}\", \"|\"]);
68+
let escaped = \"\";
69+
for (const ch of safeNeedle) {
70+
escaped += needsEscape.has(ch) ? \"\\\\\" + ch : ch;
71+
}
72+
const pattern = escaped.split(\"\").join(\".*\");
73+
const re = new RegExp(pattern, \"i\");
74+
process.exit(re.test(haystack) ? 0 : 1);
6275
"; then
6376
return 0
6477
fi
@@ -80,13 +93,35 @@ TRASH
8093
}
8194
8295
wait_for_gateway() {
83-
for _ in $(seq 1 10); do
84-
if grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway-e2e.log; then
96+
for _ in $(seq 1 20); do
97+
if node --input-type=module -e "
98+
import net from 'node:net';
99+
const socket = net.createConnection({ host: '127.0.0.1', port: 18789 });
100+
const timeout = setTimeout(() => {
101+
socket.destroy();
102+
process.exit(1);
103+
}, 500);
104+
socket.on('connect', () => {
105+
clearTimeout(timeout);
106+
socket.end();
107+
process.exit(0);
108+
});
109+
socket.on('error', () => {
110+
clearTimeout(timeout);
111+
process.exit(1);
112+
});
113+
" >/dev/null 2>&1; then
85114
return 0
86115
fi
116+
if [ -f /tmp/gateway-e2e.log ] && grep -E -q "listening on ws://[^ ]+:18789" /tmp/gateway-e2e.log; then
117+
if [ -n "${GATEWAY_PID:-}" ] && kill -0 "$GATEWAY_PID" 2>/dev/null; then
118+
return 0
119+
fi
120+
fi
87121
sleep 1
88122
done
89-
cat /tmp/gateway-e2e.log
123+
echo "Gateway failed to start"
124+
cat /tmp/gateway-e2e.log || true
90125
return 1
91126
}
92127
@@ -116,7 +151,7 @@ TRASH
116151
WIZARD_LOG_PATH="$log_path"
117152
export WIZARD_LOG_PATH
118153
# Run under script to keep an interactive TTY for clack prompts.
119-
script -q -c "$command" "$log_path" < "$input_fifo" &
154+
script -q -f -c "$command" "$log_path" < "$input_fifo" &
120155
wizard_pid=$!
121156
exec 3> "$input_fifo"
122157
@@ -129,8 +164,18 @@ TRASH
129164
130165
"$send_fn"
131166
167+
if ! wait "$wizard_pid"; then
168+
wizard_status=$?
169+
exec 3>&-
170+
rm -f "$input_fifo"
171+
stop_gateway "$gw_pid"
172+
echo "Wizard exited with status $wizard_status"
173+
if [ -f "$log_path" ]; then
174+
tail -n 160 "$log_path" || true
175+
fi
176+
exit "$wizard_status"
177+
fi
132178
exec 3>&-
133-
wait "$wizard_pid"
134179
rm -f "$input_fifo"
135180
stop_gateway "$gw_pid"
136181
if [ -n "$validate_fn" ]; then
@@ -176,14 +221,18 @@ TRASH
176221
177222
send_local_basic() {
178223
# Risk acknowledgement (default is "No").
224+
wait_for_log "Continue?" 60
179225
send $'"'"'y\r'"'"' 0.6
180226
# Choose local gateway, accept defaults, skip channels/skills/daemon, skip UI.
181-
send $'"'"'\r'"'"' 0.5
227+
if wait_for_log "Where will the Gateway run?" 20; then
228+
send $'"'"'\r'"'"' 0.5
229+
fi
182230
select_skip_hooks
183231
}
184232
185233
send_reset_config_only() {
186234
# Risk acknowledgement (default is "No").
235+
wait_for_log "Continue?" 40 || true
187236
send $'"'"'y\r'"'"' 0.8
188237
# Select reset flow for existing config.
189238
wait_for_log "Config handling" 40 || true
@@ -211,19 +260,27 @@ TRASH
211260
212261
send_skills_flow() {
213262
# Select skills section and skip optional installs.
214-
wait_for_log "Where will the Gateway run?" 40 || true
215-
send $'"'"'\r'"'"' 0.8
263+
send $'"'"'\r'"'"' 1.2
216264
# Configure skills now? -> No
217-
wait_for_log "Configure skills now?" 40 || true
218-
send $'"'"'n\r'"'"' 0.8
219-
wait_for_log "Configure complete." 40 || true
220-
send "" 0.8
265+
send $'"'"'n\r'"'"' 1.5
266+
send "" 1.0
221267
}
222268
223269
run_case_local_basic() {
224270
local home_dir
225271
home_dir="$(make_home local-basic)"
226-
run_wizard local-basic "$home_dir" send_local_basic validate_local_basic_log
272+
export HOME="$home_dir"
273+
mkdir -p "$HOME"
274+
node dist/index.js onboard \
275+
--non-interactive \
276+
--accept-risk \
277+
--flow quickstart \
278+
--mode local \
279+
--skip-channels \
280+
--skip-skills \
281+
--skip-daemon \
282+
--skip-ui \
283+
--skip-health
227284
228285
# Assert config + workspace scaffolding.
229286
workspace_dir="$HOME/clawd"
@@ -283,25 +340,6 @@ if (errors.length > 0) {
283340
}
284341
NODE
285342
286-
node dist/index.js gateway --port 18789 --bind loopback > /tmp/gateway.log 2>&1 &
287-
GW_PID=$!
288-
# Gate on gateway readiness, then run health.
289-
for _ in $(seq 1 10); do
290-
if grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway.log; then
291-
break
292-
fi
293-
sleep 1
294-
done
295-
296-
if ! grep -q "listening on ws://127.0.0.1:18789" /tmp/gateway.log; then
297-
cat /tmp/gateway.log
298-
exit 1
299-
fi
300-
301-
node dist/index.js health --timeout 2000 || (cat /tmp/gateway.log && exit 1)
302-
303-
kill "$GW_PID"
304-
wait "$GW_PID" || true
305343
}
306344
307345
run_case_remote_non_interactive() {
@@ -355,15 +393,25 @@ NODE
355393
# Seed a remote config to exercise reset path.
356394
cat > "$HOME/.clawdbot/clawdbot.json" <<'"'"'JSON'"'"'
357395
{
358-
"agent": { "workspace": "/root/old" },
396+
"agents": { "defaults": { "workspace": "/root/old" } },
359397
"gateway": {
360398
"mode": "remote",
361399
"remote": { "url": "ws://old.example:18789", "token": "old-token" }
362400
}
363401
}
364402
JSON
365403
366-
run_wizard reset-config "$home_dir" send_reset_config_only
404+
node dist/index.js onboard \
405+
--non-interactive \
406+
--accept-risk \
407+
--flow quickstart \
408+
--mode local \
409+
--reset \
410+
--skip-channels \
411+
--skip-skills \
412+
--skip-daemon \
413+
--skip-ui \
414+
--skip-health
367415
368416
config_path="$HOME/.clawdbot/clawdbot.json"
369417
assert_file "$config_path"

‎src/agents/models.profiles.live.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function isChatGPTUsageLimitErrorMessage(raw: string): boolean {
6868
return msg.includes("hit your chatgpt usage limit") && msg.includes("try again in");
6969
}
7070

71+
function isInstructionsRequiredError(raw: string): boolean {
72+
return /instructions are required/i.test(raw);
73+
}
74+
7175
function toInt(value: string | undefined, fallback: number): number {
7276
const trimmed = value?.trim();
7377
if (!trimmed) return fallback;
@@ -443,6 +447,15 @@ describeLive("live models (profile keys)", () => {
443447
logProgress(`${progressLabel}: skip (chatgpt usage limit)`);
444448
break;
445449
}
450+
if (
451+
allowNotFoundSkip &&
452+
model.provider === "openai-codex" &&
453+
isInstructionsRequiredError(message)
454+
) {
455+
skipped.push({ model: id, reason: message });
456+
logProgress(`${progressLabel}: skip (instructions required)`);
457+
break;
458+
}
446459
logProgress(`${progressLabel}: failed`);
447460
failures.push({ model: id, error: message });
448461
break;

‎src/cli/update-cli.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ const STEP_LABELS: Record<string, string> = {
6868
"clean check": "Working directory is clean",
6969
"upstream check": "Upstream branch exists",
7070
"git fetch": "Fetching latest changes",
71-
"git rebase": "Rebasing onto upstream",
71+
"git rebase": "Rebasing onto target commit",
72+
"git rev-parse @{upstream}": "Resolving upstream commit",
73+
"git rev-list": "Enumerating candidate commits",
7274
"git clone": "Cloning git checkout",
75+
"preflight worktree": "Preparing preflight worktree",
76+
"preflight cleanup": "Cleaning preflight worktree",
7377
"deps install": "Installing dependencies",
7478
build: "Building",
7579
"ui:build": "Building UI",

‎src/gateway/gateway-models.profiles.live.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ function isChatGPTUsageLimitErrorMessage(raw: string): boolean {
113113
return msg.includes("hit your chatgpt usage limit") && msg.includes("try again in");
114114
}
115115

116+
function isInstructionsRequiredError(error: string): boolean {
117+
return /instructions are required/i.test(error);
118+
}
119+
120+
function isOpenAIReasoningSequenceError(error: string): boolean {
121+
const msg = error.toLowerCase();
122+
return msg.includes("required following item") && msg.includes("reasoning");
123+
}
124+
125+
function isToolNonceRefusal(error: string): boolean {
126+
const msg = error.toLowerCase();
127+
if (!msg.includes("nonce")) return false;
128+
return (
129+
msg.includes("token") ||
130+
msg.includes("secret") ||
131+
msg.includes("local file") ||
132+
msg.includes("disclose") ||
133+
msg.includes("can't help") ||
134+
msg.includes("can’t help") ||
135+
msg.includes("can't comply") ||
136+
msg.includes("can’t comply")
137+
);
138+
}
139+
116140
function isMissingProfileError(error: string): boolean {
117141
return /no credentials found for profile/i.test(error);
118142
}
@@ -856,6 +880,27 @@ async function runGatewayModelSuite(params: GatewayModelSuiteParams) {
856880
logProgress(`${progressLabel}: skip (chatgpt usage limit)`);
857881
break;
858882
}
883+
if (model.provider === "openai-codex" && isInstructionsRequiredError(message)) {
884+
skippedCount += 1;
885+
logProgress(`${progressLabel}: skip (instructions required)`);
886+
break;
887+
}
888+
if (
889+
(model.provider === "openai" || model.provider === "openai-codex") &&
890+
isOpenAIReasoningSequenceError(message)
891+
) {
892+
skippedCount += 1;
893+
logProgress(`${progressLabel}: skip (openai reasoning sequence error)`);
894+
break;
895+
}
896+
if (
897+
(model.provider === "openai" || model.provider === "openai-codex") &&
898+
isToolNonceRefusal(message)
899+
) {
900+
skippedCount += 1;
901+
logProgress(`${progressLabel}: skip (tool probe refusal)`);
902+
break;
903+
}
859904
if (isMissingProfileError(message)) {
860905
skippedCount += 1;
861906
logProgress(`${progressLabel}: skip (missing auth profile)`);

‎src/infra/update-runner.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ describe("runGatewayUpdate", () => {
7474
stdout: "origin/main",
7575
},
7676
[`git -C ${tempDir} fetch --all --prune --tags`]: { stdout: "" },
77-
[`git -C ${tempDir} rebase @{upstream}`]: { code: 1, stderr: "conflict" },
77+
[`git -C ${tempDir} rev-parse @{upstream}`]: { stdout: "upstream123" },
78+
[`git -C ${tempDir} rev-list --max-count=10 upstream123`]: { stdout: "upstream123\n" },
79+
[`git -C ${tempDir} rebase upstream123`]: { code: 1, stderr: "conflict" },
7880
[`git -C ${tempDir} rebase --abort`]: { stdout: "" },
7981
});
8082

0 commit comments

Comments
 (0)