The open-source agent harness - the runtime layer that turns an LLM into a working agent.
bugfix: fix debounce logic in custom parameter edits in json (#1024)
harshil-209618d4051baec0
diff --git a/.changeset/defer-custom-param-sync.md b/.changeset/defer-custom-param-sync.mdnew file mode 100644index 000000000..78bf799a2--- /dev/null+++ b/.changeset/defer-custom-param-sync.md@@ -0,0 +1,5 @@+---+'@truefoundry/trueforge-ui': patch+---++Keep draft spec sync on its existing debounce by flushing the agent config drawer only when it unmounts.diff --git a/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx b/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsxindex 83fcac967..f4653a83a 100644--- a/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx+++ b/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx@@ -108,8 +108,7 @@ export function AgentModelSettingsContent({ spec, model, onChange }: AgentModelSconst nextEnabled = !customEnabled;setCustomEnabled(nextEnabled);if (nextEnabled) {- const restored = savedCustomParams.current ?? {};- replaceCustomParams(restored);+ replaceCustomParams(savedCustomParams.current ?? {});return;}savedCustomParams.current = customParamsFrom(params);diff --git a/packages/trueforge-ui/src/containers/AgentConfigDrawerContainer.tsx b/packages/trueforge-ui/src/containers/AgentConfigDrawerContainer.tsxindex 7a9dec4b9..9a4e7fbe6 100644--- a/packages/trueforge-ui/src/containers/AgentConfigDrawerContainer.tsx+++ b/packages/trueforge-ui/src/containers/AgentConfigDrawerContainer.tsx@@ -5,7 +5,7 @@ import {useTrueForgeFlushAgentSpec,useTrueForgeUpdateAgentSpec,} from '@truefoundry/trueforge-assistant-ui-runtime';-import { useCallback, useEffect, useState } from 'react';+import { useCallback, useEffect, useRef, useState } from 'react';import type { AgentConfigEditor } from '../atoms/draft/AgentConfigEditors.js';import { useAgentConfigInstructions } from '../atoms/draft/AgentConfigInstructionsContext.js';@@ -67,18 +67,21 @@ export function AgentConfigDrawerContainer({ showClose = false }: { showClose?:return () => window.removeEventListener('keydown', onKeyDown);}, [closeDrawer, editor, shell.agentConfigOpen, showClose]);- // Flush pending edits on unmount. ChatProvider remount (runtimeKey) tears the- // runtime down first — flush then throws; ignore so the new draft can mount.+ // Flush only on unmount. These callbacks are new every render; depending on them+ // runs this cleanup between keystrokes and sends the in-flight spec sync immediately.+ const flushOnUnmountRef = useRef({ flushAgentSpec, flushInstructions });+ flushOnUnmountRef.current = { flushAgentSpec, flushInstructions };useEffect(() => () => {- flushInstructions();+ const { flushAgentSpec: flushSpec, flushInstructions: flushDraft } = flushOnUnmountRef.current;+ flushDraft();try {- void flushAgentSpec();+ void flushSpec();} catch {// Runtime already gone.}},- [flushAgentSpec, flushInstructions],+ [],);const commitSpec = useCallback(diff --git a/packages/trueforge-ui/test/containers/AgentConfigDrawerContainer.test.tsx b/packages/trueforge-ui/test/containers/AgentConfigDrawerContainer.test.tsxindex ac5623683..cbdd17355 100644--- a/packages/trueforge-ui/test/containers/AgentConfigDrawerContainer.test.tsx+++ b/packages/trueforge-ui/test/containers/AgentConfigDrawerContainer.test.tsx@@ -18,7 +18,7 @@ vi.mock('@truefoundry/trueforge-assistant-ui-runtime', () => ({agentSpec: { model: { name: 'openai/gpt-4.1' } },draftSessionId: 'draft-1',}),- useTrueForgeFlushAgentSpec: () => flushAgentSpec,+ useTrueForgeFlushAgentSpec: () => () => flushAgentSpec(),useTrueForgeUpdateAgentSpec: () => updateAgentSpec,useTrueForgeAdoptAgentSpec: () => vi.fn(),}));@@ -104,6 +104,7 @@ describe('AgentConfigDrawerContainer', () => {});it('opens Runtime Config in a second right-side drawer', async () => {+ flushAgentSpec.mockClear();render(<SlotsProvider><ServerProvider server={createMockAgentUIServer()}>@@ -128,6 +129,7 @@ describe('AgentConfigDrawerContainer', () => {config: { generativeUi: { enabled: false } },instructions: undefined,});+ expect(flushAgentSpec).not.toHaveBeenCalled();});it('commits drawer instructions and messages in one spec update', () => {