Skip to content

bug(ui): after Discard loads a remote change, a refetch flags the next draft as changed elsewhere #4049

Closed

Description

@yannickmonney

Summary

An editor built on useFormEditor keeps a stale baseline after Discard loads a change made in another session. From then on, any refetch of the same data flags the person's next draft as changed elsewhere, even when nothing changed. Seen live on Settings › Governance › Models › Standard agent: after the person's own header switch saved, the editor said "These settings changed in another session. Discard your draft to load them, or save to replace them." The alert invites them to throw away a draft for no reason, and it stays until they discard or save.

Source and environment

  • Source: origin/main at 1842d09f4 (2026-10-01), in a detached worktree with no local changes.
  • Stack: an isolated local stack started with bun scripts/dev.ts and TALE_DEV_SKIP_DOCKER=1 TALE_E2E=1. Vite runs on localhost:3581, the backend on 127.0.0.1:3586, and the occurrence has its own PostgreSQL cluster on 127.0.0.1:55358.
  • Browser: headless Chromium 1208 through the repository's playwright-core 1.58.2, at 1280×900, en-US.
  • Data: a synthetic organization and its owner. The "other session" is that owner's own API write, POST /api/app/governance/policies/standard_agent.

Reproduction

  1. Open Settings › Governance › Models with the standard agent on, and type a draft in its Instructions.
  2. From another session, save different instructions. Here: POST /api/app/governance/policies/standard_agent with {config: {enabled: true, instructions: "Remote k2"}}. The alert "These settings changed in another session…" appears, which is correct.
  3. Select Discard in the settings header. The field now shows Remote k2 and the alert is gone, which is correct.
  4. Type a new draft in Instructions.
  5. Switch Provide a standard agent off. This is the page's own instant save. Then switch it on again.

Observed

After step 5, the alert "These settings changed in another session. Discard your draft to load them, or save to replace them." is back, and it stays after switching on again. Nothing changed elsewhere: the only write was this page's own switch, which keeps the saved instructions (Remote k2).

Expected

No alert. The switch's own save changed nothing the form holds.

Control

Same page, no earlier remote update: type a draft, switch off, switch on. No alert, and the draft is kept. The alert after step 2 is also correct. Only the alert after a Discard that loaded a remote change is false.

Root cause

packages/ui/src/components/editor/use-form-editor.ts:

  • The effect at :145–163 skips a refetch when structuralEqual(lastDataRef.current, data). Otherwise it flags hasRemoteUpdate if the form is dirty, or resets the form and adopts data as lastDataRef if not.
  • When a remote change arrives while the form is dirty, it only flags. lastDataRef keeps the old baseline.
  • reset() (:256–262, what Discard calls) does form.reset(dataRef.current) and clears the flag, but never moves lastDataRef to the data it just loaded.
  • The next refetch with the same values, here the governance policy re-read after the switch's write, is therefore compared against the stale baseline. It differs, the new draft makes the form dirty, and the editor raises hasRemoteUpdate again.

useFormEditor is the shared editor hook (@tale/ui/editor). Every editor that renders hasRemoteUpdate can show this false alert after a Discard that loaded a remote change. Any later refetch can trigger it: an own instant-save beside the form, a live-update hint, or a refetch on focus.

Acceptance checks

  • After Discard loads remote data, a refetch that returns the same data doesn't flag a remote update while the person types a new draft. This is the reproduction above.
  • A real change from another session after that Discard still flags.
  • A unit test in packages/ui covers it: remote change while dirty → reset() → new edit → same data again → hasRemoteUpdate === false.

Retained evidence

Evidence is retained locally under /agent/workspace/.tale358/r20261001T1415/, and attached as a tarball to Tale task TALE-358:

  • evidence/p8-false-remote.log: the case (K2) and the control (K1);
  • evidence/p6-editor.log (E5–E6): the first sighting;
  • evidence/p6/K2-false-alert.png;
  • scripts/p8-false-remote.ts: the probe.

Limits

  • Driven on the standard agent editor only. The other useFormEditor editors share the code path by reading.
  • Whether typing during the refetch that follows a successful Save can raise the same false alert wasn't staged.
  • Local stack only; production wasn't touched.

Activity

  1. added
    agent-ready
    on Oct 29, 2026
  2. added a commit that references this issue on Oct 30, 2026
    06474f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions