Skip to content

fix(ui): preserve agent file edits during save - #105359

Merged
steipete merged 2 commits into
mainfrom
codex/preserve-agent-file-draft
Jul 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/preserve-agent-file-draft

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Agents > Files editor silently discarded text entered while an earlier save was in flight. The textarea remained writable, but the successful agents.files.set response replaced the newer draft with the older submitted content.

Fixes #105354.

Why This Change Was Made

Treat the save response as a new persisted base without assuming the draft is still unchanged. The draft synchronizes to the saved content only when it still matches the submitted text; a later edit remains visible and dirty.

User Impact

Users can keep editing agent notes, identity, persona, and tool-guidance files while Save is pending without losing the newer text. Ordinary saves still mark an unchanged submitted draft as current.

Evidence

  • Exact current-main before-proof: newer marker present before settlement, absent afterward; no visible/browser error; file restored and verified.
  • Real Gateway after-proof: newer marker present both before and after settlement; original file restored and verified; no visible/browser error.
  • Testbox focused controller suite: 4 passed, covering stale clients, unchanged drafts, and concurrent edits.
  • Testbox changed gates: passed.
  • Production Control UI build: passed.
  • Source-blind behavior contract: 6/6 clauses passed.
  • Direct Gateway contract check: agents.files.set writes and returns the exact submitted content.
  • Fresh autoreview: no accepted/actionable findings; confidence 0.97.

No screenshots or transcript artifacts uploaded.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: XS maintainer Maintainer-authored PR labels Jul 12, 2026
@steipete

steipete commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head ee2da78751389f2dcbe42e67e777c93305838cb0:

  • node scripts/crabbox-wrapper.mjs run --id tbx_01kxb414j6a7xzqsmn6z20xznm -- corepack pnpm test ui/src/pages/agents/files.test.ts — 4/4 passed (Testbox run).
  • node scripts/crabbox-wrapper.mjs run --id tbx_01kxb414j6a7xzqsmn6z20xznm -- env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed -- ui/src/pages/agents/files.ts ui/src/pages/agents/files.test.ts — passed.
  • OPENCLAW_BUILD_ALL_NO_PNPM=1 node scripts/ui.js build — passed.
  • Current-main live before-proof: later draft present before settlement, absent afterward; no visible/browser error; original notes file restored and verified.
  • Live after-proof: later draft present before and after settlement; saved base advanced; original file restored and verified; no visible/browser error.
  • Source-blind behavior contract — 6/6 clauses passed.
  • Direct callee inspection confirms agents.files.set writes and returns the exact submitted content.
  • Fresh exact-branch autoreview — no accepted/actionable findings; confidence 0.98.
  • Changelog intentionally absent; native prepare owns release-note generation.

Known proof gaps: none for the changed Agent Files state controller. No screenshots or transcript artifacts uploaded.

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 12, 2026, 8:26 AM ET / 12:26 UTC.

Summary
The PR conditionally advances the saved agent-file baseline while preserving any newer draft typed during the pending save, with focused regression coverage.

PR surface: Source +4, Tests +39. Total +43 across 2 files.

Reproducibility: yes. The linked issue provides two current-main Playwright reproductions against a real isolated Gateway, and the source path independently shows the unconditional overwrite.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #105354
Summary: This PR is the direct candidate fix for the linked current-main agent-file save race.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The branch is behind current main, so maintainers should refresh the merge result and confirm the two-file behavior remains intact before landing.
  • [P1] Six non-skipped checks remain pending; this affects merge readiness but does not indicate a patch defect or justify a merge-risk label.

Maintainer options:

  1. Decide the mitigation before merge
    Refresh the branch onto current main, confirm the exact merged head retains the conditional draft-settlement tests and real Gateway behavior, then land it so the linked issue closes with the fix.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] Refresh the behind branch and complete the explicit protected-label landing decision; no automated code repair is needed.

Maintainer decision needed

  • Question: Should this protected maintainer-labeled data-loss fix be refreshed onto current main and landed once the exact-head gates are green?
  • Rationale: The implementation and proof are strong, but the protected label requires explicit maintainer handling and the branch is behind the current base.
  • Likely owner: steipete — Their prior merged file-editor work establishes relevant area ownership, and they are best positioned to make the protected-label landing decision.
  • Options:
    • Refresh and land (recommended): Update the branch onto current main and merge after the exact-head checks and focused real-Gateway proof remain green.
    • Pause for area review: Keep the PR open until another Control UI area owner explicitly confirms the draft-state invariant.

Security
Cleared: The controller-and-test-only diff adds no dependency, permission, secret, workflow, downloaded-code, or supply-chain surface.

Review details

Best possible solution:

Refresh the branch onto current main, confirm the exact merged head retains the conditional draft-settlement tests and real Gateway behavior, then land it so the linked issue closes with the fix.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked issue provides two current-main Playwright reproductions against a real isolated Gateway, and the source path independently shows the unconditional overwrite.

Is this the best way to solve the issue?

Yes. The patch mirrors the existing load-time dirty-draft preservation invariant, relies on the Gateway's exact submitted-content contract, and fixes the race without introducing a competing state path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b1fcd7c1782d.

Label changes

Label changes:

  • add P0: The linked current-main reproduction demonstrates silent loss of user-entered agent-file text during an ordinary Control UI save.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR provides real Gateway before/after live output showing concurrent text lost on current main and retained after the fix; the later head only removes a changelog entry and does not change the proven runtime patch.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.

Label justifications:

  • P0: The linked current-main reproduction demonstrates silent loss of user-entered agent-file text during an ordinary Control UI save.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides real Gateway before/after live output showing concurrent text lost on current main and retained after the fix; the later head only removes a changelog entry and does not change the proven runtime patch.
Evidence reviewed

PR surface:

Source +4, Tests +39. Total +43 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 39 0 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 44 1 +43

Acceptance criteria:

  • [P1] pnpm test ui/src/pages/agents/files.test.ts.
  • [P1] pnpm check:changed -- ui/src/pages/agents/files.ts ui/src/pages/agents/files.test.ts.
  • [P1] Build the production Control UI and repeat the real Gateway concurrent-edit scenario on the exact merged head.

What I checked:

  • Current-main defect: Successful save settlement unconditionally replaces both the persisted baseline and live draft with the submitted snapshot, discarding text entered while the request is pending. (ui/src/pages/agents/files.ts:113, b1fcd7c1782d)
  • Correct settlement invariant: The PR always advances the persisted baseline but synchronizes the live draft only when it is absent or still equals the submitted text, preserving later edits as dirty state. (ui/src/pages/agents/files.ts:113, ee2da7875138)
  • Focused regression coverage: The added tests cover both an unchanged submitted draft and a draft modified before save resolution, verifying that the baseline advances without overwriting newer text. (ui/src/pages/agents/files.test.ts:93, ee2da7875138)
  • Gateway contract: The agents.files.set handler writes the submitted content and returns that exact content in the successful result, so the submitted snapshot is a valid new persisted baseline. (src/gateway/server-methods/agents.ts:856, b1fcd7c1782d)
  • Caller behavior: After saving, the page refreshes the file list metadata rather than reloading active file contents, so the preserved dirty draft is not subsequently replaced by the caller. (ui/src/pages/agents/agents-page.ts:691, b1fcd7c1782d)
  • Re-review continuity: The commit after the prior review only removes the release-owned changelog entry; the controller and regression-test changes are unchanged. (ee2da7875138)

Likely related people:

  • steipete: Prior merged work introduced the related Control UI workspace file editor and persisted-file write semantics, making them relevant to the base-versus-draft invariant beyond authoring this PR. (role: adjacent owner and likely landing decision owner; confidence: high; commits: 0b02147150b7; files: ui/src/pages/chat/components/file-editor-view.ts)
  • vincentkoc: Current-main blame attributes the agent-files controller and surrounding page snapshot to their recent work, although the checkout's squashed snapshot commit subject is unrelated and makes provenance less precise. (role: recent area contributor; confidence: low; commits: 1b6c492cb5ee; files: ui/src/pages/agents/files.ts, ui/src/pages/agents/agents-page.ts, ui/src/pages/agents/files.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-12T12:19:36.320Z sha 5d592a1 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 35b527c into main Jul 12, 2026
78 checks passed
@steipete
steipete deleted the codex/preserve-agent-file-draft branch July 12, 2026 12:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agents file save discards edits typed while saving

1 participant