Skip to content

bug: UI Push commits runtime state (.cache, .claude/sessions, .claude.json, .sudo_as_admin_successful, etc.) — git add -A against too-narrow .gitignore #462

Closed

Description

@romainability

Summary

Clicking the Push button in the agent UI runs git add -A && git commit -m "Trinity sync: <timestamp>" inside the agent container and pushes runtime state to GitHub — .cache/, .claude/sessions/, .claude/shell-snapshots/, .claude.json, .local/lib/python3.11/site-packages/, .sudo_as_admin_successful, etc. The platform's own docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md:126-169 lists these exact paths under "Instance-specific files — DO NOT COMMIT". The Push button is not respecting the agent-value-vs-runtime split that Trinity's own docs require of agent repos.

In one observed instance, a single Push pushed 1,599 runtime files to GitHub, making the PR diff and main history unreadable.

Context

The full call chain:

  1. UI Push → POST /api/agents/{name}/git/sync (src/backend/routers/git.py:100)
  2. → git_service.sync_to_github(agent_name, ...) (src/backend/services/git_service.py:466)
  3. → calls http://agent-{name}:8000/api/git/sync (git_service.py:509)
  4. → agent-side handler sync_to_github at docker/base-image/agent_server/routers/git.py:557
  5. → runs git add -A (line 692) when no paths are passed — i.e., the default UI Push path
  6. → commits with Trinity sync: <timestamp> (line 721) and pushes

git add -A stages everything not gitignored. The platform-injected .gitignore (written once during initialize_git_in_container at src/backend/services/git_service.py:719-728) only covers:

.bash_logout, .bashrc, .profile, .bash_history,
.cache/, .local/, .npm/, .ssh/

Compare to what docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md:126-169 requires every Trinity-compatible agent to exclude:

# Credentials - NEVER COMMIT
.mcp.json
.env
*.pem
*.key
credentials.json

# Large generated content
content/

# Instance-specific directories
.npm/
.ssh/
.trinity/
.cache/

# Instance-specific files
.claude.json
.claude.json.backup
.sudo_as_admin_successful

# Claude Code - commit commands/skills/agents, exclude runtime data
.claude/projects/
.claude/statsig/
.claude/todos/
.claude/debug/

Missing from the platform-injected .gitignore (vs. what the docs codify):

So the platform writes a .gitignore that the platform itself would reject as incomplete, then runs git add -A against it on every Push.

Relationship to #458: same root cause (narrow platform-injected .gitignore), different surface. #458 is about the initial commit during initialize_github_sync. This issue is about every subsequent Push via sync_to_github. Fixing #458's .gitignore content would also fix the runtime-noise half of this bug. The git add -A policy is independently worth re-examining — even with a perfect .gitignore, blindly staging everything is a sharp tool to hand a UI button.

Reproduction

  1. Initialize an agent and call initialize_github_sync (or use the UI Init flow)
  2. Let the agent run for a while so Claude Code writes session data, shell snapshots, etc., to ~/.claude/
  3. Click the Push button in the Trinity UI
  4. Inspect the resulting Trinity sync: <timestamp> commit on GitHub → it contains 1000+ runtime files including .cache/, .claude/sessions/, .claude.json, .sudo_as_admin_successful, .local/lib/python3.11/site-packages/, etc.

Acceptance Criteria

  • The platform-injected .gitignore (written by initialize_git_in_container) covers at minimum the full deny-list documented in docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md:126-169. Single source of truth — both should be derived from the same constant or doc fragment, not maintained in parallel
  • After the fix, a Push on a freshly-initialized agent produces zero files matching the documented exclusion list (verified by inspecting the commit tree)
  • Decide and document the policy for git add -A in docker/base-image/agent_server/routers/git.py:692. Options: (a) keep -A but trust the now-correct .gitignore; (b) switch to a curated allow-list (e.g., only stage tracked files + explicitly named agent-value paths). Pick one with rationale in the PR
  • Existing agents (already initialized with the narrow .gitignore) get a migration path — either an idempotent "fix-up" on next Push that appends the missing entries, or a one-shot maintenance endpoint. Without this, the fix only helps newly-created agents
  • For tracked-but-now-ignored files (e.g., .cache/ files that were previously committed and are still in the index), the migration also runs git rm --cached so the next Push removes them from the tree
  • Regression test: deploy an agent → run something that creates .claude/sessions/<file> and .cache/<file> → Push → assert those paths are NOT in the resulting commit

Technical Notes

Files:

  • docker/base-image/agent_server/routers/git.py:557 — agent-side sync_to_github (the git add -A is at :692)
  • src/backend/services/git_service.py:466 — platform-side caller
  • src/backend/services/git_service.py:717-733 — the .gitignore write (the same lines bug: initialize_github_sync commits .env and .mcp.json despite .gitignore #458 calls out)
  • src/backend/routers/git.py:100 — HTTP entry point for the UI Push button
  • docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md:126-169 — the canonical exclusion list

Suggested fix:

  1. Extract the exclusion list from TRINITY_COMPATIBLE_AGENT_GUIDE.md into a Python constant (e.g., DEFAULT_AGENT_GITIGNORE in git_service.py) and use it in initialize_git_in_container. Update the doc to reference the constant or generate the doc snippet from it
  2. Apply the same constant to the legacy /home/developer/workspace branch (currently no .gitignore written there at all — see git_service.py:718)
  3. On Push, before git add -A, idempotently append any missing default entries to the workspace .gitignore and git rm --cached any newly-ignored tracked files. This handles existing agents without requiring a manual migration
  4. Open question for the PR: should git add -A become git add against an explicit allow-list of agent-value paths (skills, commands, agents, code, docs)? That's a more invasive change but eliminates the entire class of "we forgot to ignore X" bugs

Related: #458 (credential leak in initial commit, same root cause in the .gitignore write)

Severity rationale: P1, not P0. Unlike #458 this isn't an active credential exfiltration path (assuming #458 is fixed), but it fires on every Push, makes PR diffs unreadable, bloats main history, and visibly contradicts the platform's own documentation about what an agent repo should look like.

Activity

  1. vybe commented on Apr 27, 2026

    @vybe
    Contributor

    Closed by merged PR.

  2. added
    complexity-low
    theme-infrastructure
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p1theme-infrastructuretype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions