Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: stop sending agent_context: null in cloud settings saves (#1021)

Hiep Le51c22c22c4b2
diff --git a/__tests__/api/cloud/settings-service.test.ts b/__tests__/api/cloud/settings-service.test.ts
index 0a56a5f40e..cffa18d710 100644
--- a/__tests__/api/cloud/settings-service.test.ts
+++ b/__tests__/api/cloud/settings-service.test.ts
@@ -153,3 +153,57 @@ describe("cloud settings via local proxy", () => {
});
});
});
+
+describe("saveCloudSettings drops agent_context: null (agent-canvas#981)", () => {
+ it("strips a null agent_context while preserving sibling agent settings", async () => {
+ // Arrange: the cloud rejects agent_context: null against OpenHandsAgentSettings.
+ vi.mocked(axios.post).mockResolvedValue({ data: {} });
+
+ // Act
+ await saveCloudSettings({
+ agent_settings_diff: {
+ llm: { model: "anthropic/claude-sonnet-4-20250514" },
+ agent_context: null,
+ },
+ });
+
+ // Assert: agent_context never reaches the wire, but the real llm change does.
+ const [, body] = vi.mocked(axios.post).mock.calls[0]!;
+ const proxiedBody = (body as { body: Record<string, unknown> }).body;
+ expect(proxiedBody).toEqual({
+ agent_settings_diff: {
+ llm: { model: "anthropic/claude-sonnet-4-20250514" },
+ },
+ });
+ });
+
+ it("preserves a null mcp_config so clearing MCP config still round-trips", async () => {
+ // Arrange: mcp_config: null is an intentional "clear" signal, not an error.
+ vi.mocked(axios.post).mockResolvedValue({ data: {} });
+
+ // Act
+ await saveCloudSettings({
+ agent_settings_diff: { mcp_config: null },
+ });
+
+ // Assert: the null mcp_config must survive (don't over-strip nulls).
+ const [, body] = vi.mocked(axios.post).mock.calls[0]!;
+ const proxiedBody = (body as { body: Record<string, unknown> }).body;
+ expect(proxiedBody).toEqual({ agent_settings_diff: { mcp_config: null } });
+ });
+
+ it("omits agent_settings_diff when agent_context: null is its only key", async () => {
+ // Arrange
+ vi.mocked(axios.post).mockResolvedValue({ data: {} });
+
+ // Act
+ await saveCloudSettings({
+ agent_settings_diff: { agent_context: null },
+ });
+
+ // Assert: nothing is left to send, so no agent_settings_diff goes on the wire.
+ const [, body] = vi.mocked(axios.post).mock.calls[0]!;
+ const proxiedBody = (body as { body: Record<string, unknown> }).body;
+ expect(proxiedBody).toEqual({});
+ });
+});
diff --git a/src/api/cloud/settings-service.api.ts b/src/api/cloud/settings-service.api.ts
index 82c2fd21fd..5e3bb80e4a 100644
--- a/src/api/cloud/settings-service.api.ts
+++ b/src/api/cloud/settings-service.api.ts
@@ -154,11 +154,21 @@ export async function saveCloudSettings(diff: {
}): Promise<void> {
const backend = getActiveCloudBackend();
const body: Record<string, unknown> = {};
- if (
- diff.agent_settings_diff &&
- Object.keys(diff.agent_settings_diff).length > 0
- ) {
- body.agent_settings_diff = diff.agent_settings_diff;
+ if (diff.agent_settings_diff) {
+ const agentDiff: Record<string, SettingsValue> = {
+ ...diff.agent_settings_diff,
+ };
+ // The cloud validates agent settings against the SDK's
+ // OpenHandsAgentSettings, whose `agent_context` is a required
+ // AgentContext (not Optional). A literal `agent_context: null` fails
+ // backend validation, so drop it and let the backend keep/default it.
+ // See OpenHands/agent-canvas#981.
+ if (agentDiff.agent_context === null) {
+ delete agentDiff.agent_context;
+ }
+ if (Object.keys(agentDiff).length > 0) {
+ body.agent_settings_diff = agentDiff;
+ }
}
if (
diff.conversation_settings_diff &&