Skip to content

Commit a345c46

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/nuia-core-test
# Conflicts: # src/commands/doctor-session-sqlite.test.ts
2 parents 81b664f + ef3a0cf commit a345c46

12 files changed

Lines changed: 709 additions & 59 deletions

‎.github/workflows/openclaw-release-telegram-qa.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ jobs:
21702170
env:
21712171
BOUNDARY_EVIDENCE_DIR: ${{ steps.create_sut.outputs.boundary_evidence_dir }}
21722172
OUTPUT_DIR: ${{ steps.run_lane.outputs.output_dir }}
2173+
RUN_LANE_OUTCOME: ${{ steps.run_lane.outcome }}
21732174
shell: bash
21742175
run: |
21752176
set -euo pipefail
@@ -2213,6 +2214,7 @@ jobs:
22132214
(.candidateArtifact.version | length > 0)
22142215
' "$context_path" >/dev/null
22152216
jq -e \
2217+
--arg runLaneOutcome "$RUN_LANE_OUTCOME" \
22162218
'
22172219
.version == 1 and
22182220
.kind == "qa-gateway-process-boundary" and
@@ -2243,7 +2245,10 @@ jobs:
22432245
)
22442246
)
22452247
) and
2246-
([.launches[] | select(.terminalState == "ready-exited")] | length >= 2)
2248+
(
2249+
[.launches[] | select(.terminalState == "ready-exited")] | length >=
2250+
(if $runLaneOutcome == "success" then 2 else 1 end)
2251+
)
22472252
' "$runtime_path" >/dev/null
22482253
22492254
while IFS=$'\t' read -r relative_path expected_sha256; do

‎AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ Skills own workflows; root owns hard policy and routing.
170170
- `scripts/pr` subcommands require a PR number; no subcommand `--help` placeholder.
171171
- `scripts/pr` review: checkout main baseline, then PR, before artifact validation.
172172
- `rg`: options before `--`; use `--` before patterns starting with `-`.
173+
- `gh --jq` is not standalone `jq`; pipe JSON to `jq` for variables or `--arg`.
174+
- Actions checkout refs: use full 40-char SHAs; short SHAs resolve as branches/tags.
175+
- zsh Git object paths: use `${sha}:path`; `$sha:path` invokes parameter modifiers.
173176
- Bare issue/PR URL/number: inspect live and take the efficient maintainer path; switch branches/refs when useful.
174177
- No unsolicited PR labels/retitles/rebases/fixups/landing. Comments/reviews ok only for reviewable findings, pre-merge proof, or close/duplicate reason after explicit close/sweep/landing request.
175178
- Maintainer decision closes the cluster: if deciding reported behavior/proposed fix is not planned, comment+close all directly associated open issues/PRs unless explicitly told to keep one open. Associated means linked PRs/issues, duplicates, companion workaround PRs, and the canonical issue for the rejected behavior.

‎docs/cli/doctor.md‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ SQLite deletes reclaim pages inside the database first; they do not necessarily
291291
shrink the database file immediately. After deleting or archiving large
292292
transcripts, run `openclaw doctor --session-sqlite compact --session-sqlite-all-agents`
293293
to checkpoint WAL files, run `VACUUM`, and report before/after database and WAL
294-
sizes. This is explicit doctor maintenance so normal Gateway writes do not pause
295-
for background vacuum work.
294+
sizes. Compaction requires a regular file with the current agent schema, the
295+
selected agent's durable owner metadata, and no open handle in the doctor
296+
process. This is explicit offline maintenance: stop the Gateway first so normal
297+
writes cannot race the checkpoint or `VACUUM`.
296298

297299
Each import writes a manifest under
298300
`~/.openclaw/session-sqlite-migration-runs/` before moving transcript artifacts
@@ -308,11 +310,19 @@ manifest's archived artifacts, validates the affected targets, refreshes the
308310
sanitized `.failure.md` and `.failure.json` reports, and prepares a GitHub issue
309311
body that avoids transcript contents, raw environment, secrets, and unbounded
310312
config. When no failed migration manifest exists but a selected agent SQLite
311-
database is corrupt or not a database, recovery preserves the DB, WAL, and SHM
312-
files by renaming them with a `.corrupt-<timestamp>` suffix so the next startup
313-
can create a fresh database. With `--github-issue --yes`, doctor uses the GitHub
314-
CLI to create the issue in `openclaw/openclaw`; without confirmation it writes
315-
the local support report and prints a prefilled issue URL.
313+
database is corrupt, not a database, or has journal sidecars without a main
314+
database, recovery copies the complete file set to a temporary inspection
315+
directory. SQLite can roll back a valid hot journal in that disposable copy
316+
before `quick_check`, `integrity_check`, and `foreign_key_check` run, while the
317+
original forensic files remain untouched. Failed integrity checks or orphaned
318+
sidecars preserve the DB, WAL, SHM, and rollback-journal files by renaming the
319+
whole discovered set with one `.corrupt-<timestamp>` suffix. A caught rename
320+
failure rolls already-moved files back before reporting failure, so a
321+
recoverable file set is not silently split. Stop the Gateway before recovery;
322+
copying or renaming an actively changing SQLite file set is unsafe and behaves
323+
differently across operating systems. With `--github-issue --yes`, doctor uses
324+
the GitHub CLI to create the issue in `openclaw/openclaw`; without confirmation
325+
it writes the local support report and prints a prefilled issue URL.
316326

317327
`restore` remains the lower-level undo operation. It uses manifest
318328
`sourcePath -> archivePath` records, moves archived artifacts back only when the

‎scripts/check-kysely-guardrails.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const rawSqliteAllowPathGroups = {
5757
"src/commands/doctor-sqlite-compact.ts",
5858
"src/commands/doctor-session-sqlite.ts",
5959
"src/commands/doctor-session-sqlite-readers.ts",
60+
"src/commands/doctor-session-sqlite-recover-report.ts",
6061
"src/commands/doctor-state-sqlite-compact.ts",
6162
"src/infra/state-migrations.ts",
6263
"src/infra/state-migrations.debug-proxy.ts",

‎scripts/test-projects.test-support.mjs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ const BROAD_TOOLING_SCRIPT_TEST_PATTERNS = new Set([
291291
"test/scripts/*.test.ts",
292292
]);
293293
const BROAD_TOOLING_SCRIPT_TEST_TARGET_CHUNK_SIZE = 60;
294+
const FULL_SUITE_AGENTS_CORE_TEST_TARGET_CHUNK_COUNT = 6;
294295
const FULL_SUITE_TOOLING_TEST_TARGET_CHUNK_SIZE = 2;
295296
const FULL_SUITE_UNIT_FAST_TEST_TARGET_CHUNK_SIZE = 70;
296297
const TUI_VITEST_CONFIG = "test/vitest/vitest.tui.config.ts";
@@ -2515,6 +2516,18 @@ function listUnitFastFullSuiteTestTargets() {
25152516
return getUnitFastTestFiles().filter((file) => !timerTargets.has(file));
25162517
}
25172518

2519+
function listAgentsCoreFullSuiteTestTargets(cwd) {
2520+
const agentsDir = path.join(cwd, "src/agents");
2521+
if (!fs.existsSync(agentsDir)) {
2522+
return [];
2523+
}
2524+
return fs
2525+
.readdirSync(agentsDir, { withFileTypes: true })
2526+
.filter((entry) => entry.isFile() && entry.name.endsWith(".test.ts"))
2527+
.map((entry) => `src/agents/${entry.name}`)
2528+
.toSorted((left, right) => left.localeCompare(right));
2529+
}
2530+
25182531
function createBroadToolingScriptPlans({ config, forwardedArgs, includePatterns, watchMode, cwd }) {
25192532
if (watchMode || config !== TOOLING_VITEST_CONFIG || !includePatterns) {
25202533
return null;
@@ -4232,7 +4245,14 @@ export function buildFullSuiteVitestRunPlans(args, cwd = process.cwd()) {
42324245
return configs.flatMap((config) => {
42334246
if (expandShard && targetArgs.length === 0) {
42344247
let chunks = [];
4235-
if (config === UNIT_FAST_VITEST_CONFIG) {
4248+
if (config === AGENTS_CORE_VITEST_CONFIG) {
4249+
// A single non-isolated agents-core process grows until its worker can
4250+
// exit under the full-suite memory load. Bound each process lifetime.
4251+
chunks = splitTargetChunks(
4252+
listAgentsCoreFullSuiteTestTargets(cwd),
4253+
FULL_SUITE_AGENTS_CORE_TEST_TARGET_CHUNK_COUNT,
4254+
);
4255+
} else if (config === UNIT_FAST_VITEST_CONFIG) {
42364256
const targets = listUnitFastFullSuiteTestTargets();
42374257
const chunkCount = Math.ceil(
42384258
targets.length / FULL_SUITE_UNIT_FAST_TEST_TARGET_CHUNK_SIZE,

‎src/commands/doctor-session-sqlite-compact.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/** Runs doctor-owned SQLite file compaction for migrated session stores. */
22
import fs from "node:fs";
33
import type { SessionStoreTarget } from "../config/sessions/targets.js";
4+
import {
5+
assertOpenClawAgentDatabaseForMaintenance,
6+
ensureOpenClawAgentDatabasePermissions,
7+
isOpenClawAgentDatabaseOpen,
8+
} from "../state/openclaw-agent-db.js";
49
import { resolveTargetSqlitePath } from "./doctor-session-sqlite-readers.js";
510
import type { DoctorSessionSqliteCompactReport } from "./doctor-session-sqlite-types.js";
611
import { compactDoctorSqliteFile } from "./doctor-sqlite-compact.js";
@@ -11,7 +16,8 @@ export function compactDoctorSessionSqliteTarget(
1116
): DoctorSessionSqliteCompactReport {
1217
const sqlitePath = resolveTargetSqlitePath(target);
1318
const beforeFileSizes = readSqliteFileSizes(sqlitePath);
14-
if (!fs.existsSync(sqlitePath)) {
19+
const stat = readSessionDatabaseStat(sqlitePath);
20+
if (!stat) {
1521
return {
1622
dbSizeAfterBytes: 0,
1723
dbSizeBeforeBytes: 0,
@@ -24,8 +30,28 @@ export function compactDoctorSessionSqliteTarget(
2430
walSizeBeforeBytes: beforeFileSizes.walSizeBytes,
2531
};
2632
}
33+
if (!stat.isFile()) {
34+
throw new Error(`OpenClaw agent database is not a regular file: ${sqlitePath}`);
35+
}
36+
if (isOpenClawAgentDatabaseOpen(sqlitePath)) {
37+
throw new Error(
38+
`OpenClaw agent database ${sqlitePath} is already open in this process. Stop OpenClaw and retry.`,
39+
);
40+
}
2741

28-
const compact = compactDoctorSqliteFile({ sqlitePath });
42+
const compact = compactDoctorSqliteFile({
43+
afterMutation: () =>
44+
ensureOpenClawAgentDatabasePermissions(sqlitePath, {
45+
agentId: target.agentId,
46+
path: sqlitePath,
47+
}),
48+
sqlitePath,
49+
validateBeforeMutation: (database) =>
50+
assertOpenClawAgentDatabaseForMaintenance(database, {
51+
agentId: target.agentId,
52+
pathname: sqlitePath,
53+
}),
54+
});
2955
return {
3056
dbSizeAfterBytes: compact.after.dbSizeBytes,
3157
dbSizeBeforeBytes: compact.before.dbSizeBytes,
@@ -39,6 +65,17 @@ export function compactDoctorSessionSqliteTarget(
3965
};
4066
}
4167

68+
function readSessionDatabaseStat(sqlitePath: string): fs.Stats | undefined {
69+
try {
70+
return fs.lstatSync(sqlitePath);
71+
} catch (error) {
72+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
73+
return undefined;
74+
}
75+
throw error;
76+
}
77+
}
78+
4279
function readSqliteFileSizes(sqlitePath: string): { dbSizeBytes: number; walSizeBytes: number } {
4380
return {
4481
dbSizeBytes: fileSize(sqlitePath),

0 commit comments

Comments
 (0)