Skip to content

Commit faaab9b

Browse files
authored
fix(onboard): rebase non-interactive commit onto first-agent write (#113601)
1 parent 6c39503 commit faaab9b

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎src/commands/onboard-agent.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe("onboarding main-agent creation", () => {
3131
.mockResolvedValueOnce({
3232
exists: true,
3333
valid: true,
34+
hash: "hash-after-create",
3435
sourceConfig: {
3536
agents: { list: [{ id: "main", default: true }] },
3637
gateway: { controlUi: { enabled: true } },
@@ -81,4 +82,28 @@ describe("onboarding main-agent creation", () => {
8182
expect(mocks.readConfigFileSnapshot).not.toHaveBeenCalled();
8283
expect(mocks.createAgent).not.toHaveBeenCalled();
8384
});
85+
it("reports the post-create config hash so callers can rebase their commit", async () => {
86+
// Regression (#112678): creating the first roster agent writes the config
87+
// file, so a caller holding a pre-create hash would fail its own optimistic
88+
// write with ConfigMutationConflictError and leave onboarding half-applied.
89+
const result = await ensureOnboardingAgent({
90+
config: { agents: { defaults: { model: "openai/gpt-5.5" } } },
91+
workspace: "/tmp/work",
92+
});
93+
94+
expect(result.configHash).toBe("hash-after-create");
95+
});
96+
97+
it("omits the config hash when no agent had to be created", async () => {
98+
const config = { agents: { list: [{ id: "main", default: true }] } };
99+
100+
const result = await ensureOnboardingAgent({
101+
config,
102+
workspace: "/tmp/work",
103+
preserveCandidateRoster: true,
104+
});
105+
106+
expect(result.configHash).toBeUndefined();
107+
expect(mocks.createAgent).not.toHaveBeenCalled();
108+
});
84109
});

‎src/commands/onboard-agent.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ export async function ensureOnboardingAgent(params: {
4545
workspace: string;
4646
preserveCandidateRoster?: boolean;
4747
baseConfig?: OpenClawConfig;
48-
}): Promise<{ config: OpenClawConfig; agentId: string; bootstrapPending: boolean }> {
48+
}): Promise<{
49+
config: OpenClawConfig;
50+
agentId: string;
51+
bootstrapPending: boolean;
52+
/**
53+
* Config hash observed after this helper created the first roster agent.
54+
* Callers that captured a hash before calling must adopt it for their own
55+
* commit: the create wrote the file, so their baseline is stale but not
56+
* foreign, and the optimistic guard would otherwise reject their write.
57+
*/
58+
configHash?: string;
59+
}> {
4960
const candidateRoster = listAgentEntries(params.config);
5061
if (
5162
candidateRoster.length > 0 &&
@@ -99,6 +110,7 @@ export async function ensureOnboardingAgent(params: {
99110
}),
100111
agentId: created.agentId,
101112
bootstrapPending: created.bootstrapPending,
113+
...(after.hash !== undefined ? { configHash: after.hash } : {}),
102114
};
103115
}
104116

‎src/commands/onboard-non-interactive/local.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export async function runNonInteractiveLocalSetup(params: {
206206
baseConfig,
207207
});
208208
nextConfig = applyLocalSetupWorkspaceConfig(created.config, requestedWorkspaceDir);
209+
// Creating the first roster agent writes the config file, so the hash captured
210+
// before this step no longer matches. Adopt the post-create hash; foreign
211+
// writes are still rejected because we only trust the write we just made.
212+
const effectiveBaseHash = created.configHash ?? baseHash;
209213
if (opts.skipBootstrap) {
210214
nextConfig = applySkipBootstrapConfig(nextConfig);
211215
}
@@ -271,7 +275,7 @@ export async function runNonInteractiveLocalSetup(params: {
271275
nextConfig = await commitNonInteractiveOnboardConfig({
272276
nextConfig,
273277
baseConfig,
274-
baseHash,
278+
baseHash: effectiveBaseHash,
275279
reset: opts.reset,
276280
});
277281
logConfigUpdated(runtime);

0 commit comments

Comments
 (0)