Skip to content

Freshly deployed agents report M .gitignore against origin/main #953

Closed

Description

@vybe

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:

  1. Pattern match mismatch — grep -q ".local/" (no anchors) succeeds, but the second guard grep -q "^\.local/$" requires an exact line. If the committed .gitignore has a trailing comment or whitespace on the line containing .local/, the anchored grep fails and echo re-appends a duplicate line.
  2. Missing trailing newline — if the committed .gitignore doesn't end in \n, echo ".local/" >> produces last_linecontent/, corrupting the previous line.
  3. 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.
  4. CRLF / encoding — repo .gitignore could land with \r\n line endings under a misconfigured core.autocrlf, causing grep -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 .gitignore drift 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 .gitignore and origin/main
  • Decide whether startup.sh should stop touching .gitignore entirely (delegating to git_service.py's _build_gitignore_merge_command), or whether the existing append needs anchor/newline fixes
  • After the fix, git status on 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_gitignore at src/backend/services/git_service.py:761 — if this is already running per-push, the shell-level append in startup.sh is 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

  1. added
    priority-p3
    type-bug
    on May 26, 2026
  2. self-assigned this
    on May 29, 2026
  3. added
    theme-reliability
    on Jun 3, 2026
  4. added
    complexity-low
    status-ready
    on Jun 12, 2026
  5. removed
    status-ready
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p3theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions