[Nexthop][fboss2-dev] ConfigSession: always create initial commit on fresh /etc/coop#1191
Open
vybhav-nexthop wants to merge 1 commit into
Open
[Nexthop][fboss2-dev] ConfigSession: always create initial commit on fresh /etc/coop#1191vybhav-nexthop wants to merge 1 commit into
vybhav-nexthop wants to merge 1 commit into
Conversation
## Summary
- On a fresh box with no git history, `initializeGit()` only created
an initial commit if `cli/agent.conf` already existed. On first-ever
use that file doesn't exist yet, so both concurrent users end up with
`base_ = ""`.
- When User1 commits and HEAD moves, User2's stale-session check
(`!base_.empty() && currentHead != base_`) short-circuits on the empty
string, letting User2 silently overwrite User1's changes.
- Fix: always create an initial commit when the repo has no commits.
Commit `agent.conf` if it exists (as a copy — we can't rename because
`/etc/coop/agent.conf` must stay in place; `commit()` replaces it
with a symlink later), falling back to an empty `{}` JSON object. A
try/catch handles the concurrent-init race.
## Test plan
- [x] Run `ConfigConcurrentSessionsTest.ConflictAndRebase` on a fresh
box (no prior git history in `/etc/coop`) — should now fail User2's
commit with "system configuration has changed"
- [x] Confirm existing `ConfigSession` unit/integration tests still
pass
Co-Authored-By: Vybhav Acharya <vybhav@nexthop.ai>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit run##Summary
initializeGit()only createdan initial commit if
cli/agent.confalready existed. On first-everuse that file doesn't exist yet, so concurrent users end up with
base_ = "".(
!base_.empty() && currentHead != base_) short-circuits on the emptystring, letting User2 silently overwrite User1's changes.
Commit
agent.confif it exists (as a copy — we can't rename because/etc/coop/agent.confmust stay in place;commit()replaces itwith a symlink later), falling back to an empty
{}JSON object. Atry/catch handles the concurrent-init race.
Test plan
ConfigConcurrentSessionsTest.ConflictAndRebaseon a freshbox (no prior git history in
/etc/coop) — should now fail User2'scommit with "system configuration has changed"
ConfigSessionunit/integration tests stillpass