You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(bots): keep the user's GEMINI.md bytes and concurrent saves when Orca removes its block - #49122
Bots that used to run on Gemini CLI left a copy of their instructions in the folder's GEMINI.md. When an Antigravity chat starts, Orca takes that copy back out. That cleanup could undo a save the user made at the same moment, and it could strip the indentation off a code block in the user's own text. Now it removes only Orca's block and leaves every other byte as the user wrote it. If the file changed after Orca read it, Orca starts over from the new version.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$55
$\color{#cf222e}{\Huge{\mathbf{−}}}$1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$54
Prod
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$152
$\color{#cf222e}{\Huge{\mathbf{−}}}$32
$\color{#1a7f37}{\Huge{\mathbf{+}}}$120
What Changed
Before, cleanup read GEMINI.md, built the new text from that read, and then renamed it over the file, or deleted the file if Orca had written all of it. A save that landed between the read and the rename was lost, and a user's replacement file could be deleted. It also ran trimEnd/trimStart on the text on both sides of Orca's block, so a code block right after the block lost its leading spaces.
Now:
Cleanup removes Orca's <!-- orca:begin -->…<!-- orca:end --> lines, the line break after them, and the one blank line Orca put in front when it appended them. Nothing else changes: CRLF, tabs, indentation and trailing spaces all stay. A file with no Orca block is not touched.
Every change to a folder context file goes through one path in acp-folder-context-file.ts. Orca writes a complete staged copy, re-reads the file, and renames over it only while the file still holds the bytes the change was computed from. A file that didn't exist is linked in, and the link fails rather than replacing a file someone else created. If the file changed, Orca re-reads it and builds the change again, up to 3 times. The file is never missing at any point, so a second launch never mistakes it for absent.
The per-agent writers (.hermes.md, QWEN.md, .goosehints, .kimi-code/AGENTS.md, .cline/rules/orca.md, AGENTS.local.md, CODEBUDDY.local.md) used the same read-then-rename path and had the same lost-save window. They now use the new path too. They still rewrite the file on every launch as before, so the 0600 permission repair from STA-16956 still runs.
Why
The original code assumed that renaming a staged file into place made the update safe. A rename does keep readers from ever seeing a half-written file. It does nothing about a save that landed after Orca read the file. The cleanup added when Gemini CLI was removed reused that path, and added the trims to keep the joins tidy. Those trims also run over text the user owns.
An earlier version of this fix moved the file aside before comparing it, which closes the window completely. But the file then went missing for a moment: a second launch running at the same time took it as absent and wrote Orca's own file over the user's text, and a crash at that point would have left the user's file under a temporary name. Comparing a staged copy and then renaming it never leaves the file missing. A save that lands in the microseconds between the final compare and the rename can still be replaced, because Node has no compare-and-swap rename. That is documented in the code. The synchronous guarded helpers in atomic-file-publication.ts aren't allowed here, because this runs on Electron main during chat launch.
Linked Issue
STA-18108
Visual Proof
N/A: nothing on screen changes. The fix is in how a file in the user's folder is rewritten.
Testing
acp-folder-context-file.test.ts gained these tests:
Removing the block leaves the user's surrounding bytes exact. The test covers CRLF, an indented code block, trailing spaces and a tab.
A save that lands during cleanup survives. This runs for both Orca's own file and a user file, and checks that no staged file is left behind. Both tests fail on main: the indentation is stripped, the save is overwritten, and the save is deleted.
A 0644 file that already holds Orca's current text still goes back to 0600.
Ran 300 rounds of two launches writing the same QWEN.md at once, and two cleanups of the same GEMINI.md at once. User text was never lost and no stray files were left (throwaway script, not committed).
Tested on macOS. Linux, Windows and SSH hosts (orcad) run the same code. Filesystems without hard links fall back through the shared isHardLinkUnsupported check.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
Small and per launch only. Changing an existing context file now reads it twice instead of once (the second read is the compare before the rename). A conflict costs at most 3 passes. Cleanup of a GEMINI.md with no Orca block still does one read and no write. Nothing runs on a timer, per event or per worktree, and all the filesystem work is async.
Risk
Level: Low
The riskiest part is the new publish step for context files on unusual filesystems. If it went wrong, a bot's instructions would not be written for that launch, or the cleanup would leave the old block in place. The user's own text is never replaced. A plain revert backs this out.
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Not changed here and existing before this PR: when appending its block, the writer still trims trailing whitespace from the end of a user's file, and it decodes the file as UTF-8.
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
Context-file writes and removals now retry up to three times when the target changes during an update. Creation uses a hard link when supported, with an exclusive-copy fallback. Removal deletes Orca-owned files or removes only Orca’s block from user-authored files while preserving surrounding text. Tests cover restrictive permissions, exact content preservation, invalid UTF-8 files, and saves during removal. A save after the final comparison but before rename or removal can still be replaced.
Merge Risk: Low · up to 3d31e
Removing Orca's block from context files now preserves user bytes and retries when the file changes mid-update. A save landing in the very small gap between the final check and the rename can still be lost, which is a documented limitation. In rare cases, a read failure during the final comparison could also fail an agent launch instead of skipping the update. Both are narrow, so the change is mergeable with owner awareness.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Orca's removal of its GEMINI.md block now keeps the user's bytes and concurrent saves. It matches the changeset, which adds byte-preserving cleanup and a compare-then-…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is thorough and follows the repository template. It includes an ELI5 section, a clear What Changed section with the before and after behavior, a Why section that explains the alternati…
Full details: Title check
Explanation
The title names the main change: Orca's removal of its GEMINI.md block now keeps the user's bytes and concurrent saves. It matches the changeset, which adds byte-preserving cleanup and a compare-then-publish update path for folder context files. The title uses the fix() prefix and is specific. It is long (91 characters), but it stays on topic.
Full details: Description check
Explanation
The description is thorough and follows the repository template. It includes an ELI5 section, a clear What Changed section with the before and after behavior, a Why section that explains the alternatives considered (moving the file aside, and the synchronous guarded helpers), a Linked Issue (STA-18108), a Visual Proof marked N/A with a reason, a Testing section with specific tests and stress runs, a Performance line, a Risk section with a Low level and a rollback method, and the Agent skill boundary box checked. The main gaps are the Linked Issue line, which reads 'STA-18108' without the 'Fixes #' form the template uses, and the unchecked lint, typecheck, test, and build item. The Testing section also says Linux, Windows, and SSH run the same code but were not tested. The Performance and Risk sections are filled in. The AI Disclosure section is empty. Because the repository is outside the stablyai team, that section is needed for an outside contributor, but it is not clear whether the author is internal.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Quick win
Treat a failed comparison read as a skipped update, not a launch error.
The comparison read in readIfPresent rethrows every error except a definitive absence. publishIfUnchanged removes its staged file and rejects. The rejection then passes through replaceWhileUnchanged, writeFolderContextFile, and the per-agent deliverers, such as deliverHermesInstructions. None of these catch it. acpLaunchInstructions does not catch it either, so launch fails unless its caller handles the rejection.
This path is new. A read error on an existing file was already ignored by the initial read. The comparison read now turns the same error into a launch failure. The doc comment says an unreadable file stays untouched, so the comparison read should match the initial read. Treat a failed comparison as a mismatch. The update loop then stops on its next read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Bots that used to run on Gemini CLI left a copy of their instructions in the folder's
GEMINI.md. When an Antigravity chat starts, Orca takes that copy back out. That cleanup could undo a save the user made at the same moment, and it could strip the indentation off a code block in the user's own text. Now it removes only Orca's block and leaves every other byte as the user wrote it. If the file changed after Orca read it, Orca starts over from the new version.What Changed
Before, cleanup read
GEMINI.md, built the new text from that read, and then renamed it over the file, or deleted the file if Orca had written all of it. A save that landed between the read and the rename was lost, and a user's replacement file could be deleted. It also rantrimEnd/trimStarton the text on both sides of Orca's block, so a code block right after the block lost its leading spaces.Now:
<!-- orca:begin -->…<!-- orca:end -->lines, the line break after them, and the one blank line Orca put in front when it appended them. Nothing else changes: CRLF, tabs, indentation and trailing spaces all stay. A file with no Orca block is not touched.acp-folder-context-file.ts. Orca writes a complete staged copy, re-reads the file, and renames over it only while the file still holds the bytes the change was computed from. A file that didn't exist is linked in, and the link fails rather than replacing a file someone else created. If the file changed, Orca re-reads it and builds the change again, up to 3 times. The file is never missing at any point, so a second launch never mistakes it for absent..hermes.md,QWEN.md,.goosehints,.kimi-code/AGENTS.md,.cline/rules/orca.md,AGENTS.local.md,CODEBUDDY.local.md) used the same read-then-rename path and had the same lost-save window. They now use the new path too. They still rewrite the file on every launch as before, so the 0600 permission repair from STA-16956 still runs.Why
The original code assumed that renaming a staged file into place made the update safe. A rename does keep readers from ever seeing a half-written file. It does nothing about a save that landed after Orca read the file. The cleanup added when Gemini CLI was removed reused that path, and added the trims to keep the joins tidy. Those trims also run over text the user owns.
An earlier version of this fix moved the file aside before comparing it, which closes the window completely. But the file then went missing for a moment: a second launch running at the same time took it as absent and wrote Orca's own file over the user's text, and a crash at that point would have left the user's file under a temporary name. Comparing a staged copy and then renaming it never leaves the file missing. A save that lands in the microseconds between the final compare and the rename can still be replaced, because Node has no compare-and-swap rename. That is documented in the code. The synchronous guarded helpers in
atomic-file-publication.tsaren't allowed here, because this runs on Electron main during chat launch.Linked Issue
STA-18108
Visual Proof
N/A: nothing on screen changes. The fix is in how a file in the user's folder is rewritten.
Testing
acp-folder-context-file.test.tsgained these tests:Ran 300 rounds of two launches writing the same
QWEN.mdat once, and two cleanups of the sameGEMINI.mdat once. User text was never lost and no stray files were left (throwaway script, not committed).Tested on macOS. Linux, Windows and SSH hosts (orcad) run the same code. Filesystems without hard links fall back through the shared
isHardLinkUnsupportedcheck.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
Small and per launch only. Changing an existing context file now reads it twice instead of once (the second read is the compare before the rename). A conflict costs at most 3 passes. Cleanup of a
GEMINI.mdwith no Orca block still does one read and no write. Nothing runs on a timer, per event or per worktree, and all the filesystem work is async.Risk
Level: Low
The riskiest part is the new publish step for context files on unusual filesystems. If it went wrong, a bot's instructions would not be written for that launch, or the cleanup would leave the old block in place. The user's own text is never replaced. A plain revert backs this out.
AI Disclosure
Review
Agent skill upstream boundary
Notes
Not changed here and existing before this PR: when appending its block, the writer still trims trailing whitespace from the end of a user's file, and it decodes the file as UTF-8.
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)