Repository navigation
Description
Summary
Freshly deployed agents observe M .gitignore in their workspace immediately after deployment, before any user-driven sync. The drift pre-dates any push, doesn't block a fast-forward, and the file content looks "right" — but git diff against origin/main still reports a modification. Investigate the root cause and either fix the divergence at the source or normalize it so freshly-cloned workspaces present a clean git status.
Context
The container's startup.sh ensures a few canonical entries land in /home/developer/.gitignore regardless of what the cloned repo already shipped:
# docker/base-image/startup.sh ~L116-120
grep -q ".local/" /home/developer/.gitignore || echo ".local/" >> /home/developer/.gitignore
# docker/base-image/startup.sh ~L378-383
grep -q "^content/$" /home/developer/.gitignore || echo "content/" >> /home/developer/.gitignore
grep -q "^\.local/$" /home/developer/.gitignore || echo ".local/" >> /home/developer/.gitignore
For agents whose workspace IS the trinity repo (the local "trinity agent" being the canonical case), the repo's checked-in .gitignore already contains .local/, content/, .cache/, .claude.json, .trinity/, .sudo_as_admin_successful, and friends. The grep -q guards should make the appends no-ops in that case — but field observation says we're seeing M .gitignore anyway.
Plausible root causes to verify:
- Pattern match mismatch —
grep -q ".local/"(no anchors) succeeds, but the second guardgrep -q "^\.local/$"requires an exact line. If the committed.gitignorehas a trailing comment or whitespace on the line containing.local/, the anchored grep fails andechore-appends a duplicate line. - Missing trailing newline — if the committed
.gitignoredoesn't end in\n,echo ".local/" >>produceslast_linecontent/, corrupting the previous line. - Historical drift — an older base image appended these entries before the repo committed them. The mods stuck; subsequent rebases preserve the divergence even though the appender is now a no-op.
- CRLF / encoding — repo
.gitignorecould land with\r\nline endings under a misconfiguredcore.autocrlf, causinggrep -q "^content/$"to miss the match and the appender to write a\n-terminated duplicate.
Side observation from the field report: the runtime untracked items (.cache/, .claude.json, .trinity/, .sudo_as_admin_successful) are correctly ignored — only .gitignore itself shows modified. That's consistent with the "appender mutates the file it just consulted" hypothesis.
The _GITIGNORE_PATTERNS constant + idempotent merge command in src/backend/services/git_service.py:661-713 is the right design — startup.sh predates it and uses a thinner, less defensive variant. Migrating the shell-level append to call into the same canonical block (or removing it entirely once git_service.py runs on init for every agent) is the likely fix.
Acceptance Criteria
- Reproduce the
M .gitignoredrift on a freshly-deployed agent whose workspace is a repo containing the canonical patterns already - Identify which of the listed root causes (or another) is actually firing — capture the byte-level diff between the in-container
.gitignoreandorigin/main - Decide whether
startup.shshould stop touching.gitignoreentirely (delegating togit_service.py's_build_gitignore_merge_command), or whether the existing append needs anchor/newline fixes - After the fix,
git statuson a freshly deployed agent's workspace reports no modifications attributable to startup - No regression for agents whose workspace did NOT ship a
.gitignore— they still get the canonical patterns written on first boot
Technical Notes
- Two append sites in
docker/base-image/startup.sh— both should be reviewed together - Canonical pattern list and idempotent merge:
src/backend/services/git_service.py:661-713(_GITIGNORE_PATTERNS+_build_gitignore_merge_command) - Migration helper that runs on every Push:
_migrate_workspace_gitignoreatsrc/backend/services/git_service.py:761— if this is already running per-push, the shell-level append instartup.shis redundant and a likely source of drift - Related: bug: UI Push commits runtime state (.cache, .claude/sessions, .claude.json, .sudo_as_admin_successful, etc.) — git add -A against too-narrow .gitignore #462 (gitignore widen + migrate on push), which established the canonical merge pattern but didn't retire the shell appender
- Priority p3 per the originating field report ("Not urgent — flag for a future status look")
Activity
fix(base-image): stop appending to .gitignore from startup.sh (#953) (#…
fix(git-sync): merge the canonical .gitignore at agent creation (#2069)…
fix(git-sync): the canonical .gitignore stops reversing the agent's o…