Skip to content

docs: upstream multi-session safety, troubleshooting, and config examples#76

Merged
TimeToBuildBob merged 2 commits intomasterfrom
feat/upstream-agent-improvements
Mar 22, 2026
Merged

docs: upstream multi-session safety, troubleshooting, and config examples#76
TimeToBuildBob merged 2 commits intomasterfrom
feat/upstream-agent-improvements

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Member

Summary

  • Multi-session git safety: Add git safe-commit pattern for concurrent session environments (flock-based wrapper prevents prek stash/restore race conditions)
  • Submodule prerequisite: Add callout warning to update gptme-contrib before running pre-commit hooks (prevents false positive link errors)
  • Troubleshooting section: Common issues with pre-commit hooks, import errors, context script, and submodule problems
  • Config examples: Add commented [plugins], [env], and [mcp] sections to gptme.toml so agents can see what's available
  • make help target: Lists all available Makefile targets with descriptions

All patterns upstreamed from Bob's production workspace (1700+ sessions).

Test plan

  • Pre-commit hooks pass
  • Verify make help output is formatted correctly
  • Review troubleshooting steps against current gptme-contrib infrastructure

…ples

- Add git safe-commit pattern for concurrent session environments
- Add submodule update warning before pre-commit hooks
- Add troubleshooting section (pre-commit, imports, context, submodule)
- Add [plugins], [env], and [mcp] config examples to gptme.toml
- Add `make help` target to list available commands
@TimeToBuildBob
Copy link
Copy Markdown
Member Author

@greptileai review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 22, 2026

Greptile Summary

This PR upstreams several production-tested patterns from a 1700+ session workspace into the template, making it more robust for concurrent multi-agent usage and easier to onboard into.

  • Multi-session git safety (bin/git-safe-commit, AGENTS.md): A new flock-based wrapper serializes git commit calls (including pre-commit hooks) to prevent prek's stash/restore cycle from racing with concurrent sessions sharing .git/index. The script is correctly wired as a git sub-command via bin/ and the PATH setup instruction is included.
  • Submodule prerequisite (AGENTS.md): Adds a callout to run git submodule update --init --recursive before hooks to prevent false-positive link-check failures from gptme-contrib/lessons/.
  • Troubleshooting section (AGENTS.md): Covers the most common failure modes: hook failures, import errors, slow context scripts, and submodule issues. Each section is concise and maps directly to a runnable fix.
  • Config examples (gptme.toml): Adds documented [plugins], [env], and [mcp] stanzas so agents can discover what's configurable without reading external docs.
  • make help (Makefile): Standard grep+awk pattern makes make self-documenting; help is correctly the first target so it becomes the new default.

One portability note: bin/git-safe-commit depends on flock (part of Linux's util-linux) which is not present on macOS by default. This is unlikely to affect the primary Linux/server use-case but is worth noting for contributors developing on macOS.

Confidence Score: 5/5

  • This PR is safe to merge — all changes are additive documentation and tooling with no breaking changes.
  • All changes are additive (new script, new docs sections, config examples, Makefile target). The core logic of git-safe-commit is correct and well-commented. Prior reviewer concerns are resolved: the script is now included in bin/, and the TOML section behavior is confirmed safe. The only open item is a minor macOS portability note on flock, which doesn't affect the primary Linux/server deployment target.
  • No files require special attention.

Important Files Changed

Filename Overview
bin/git-safe-commit New script that serializes concurrent git commits using flock to prevent prek stash/restore race conditions. Logic is sound; minor portability concern as flock is Linux-only (not available on macOS without extra tooling).
AGENTS.md Adds multi-session safety guidance (git safe-commit), submodule prerequisite callout, and a Troubleshooting section. All advice is clear and actionable; the bin/git-safe-commit script is now included in the PR, resolving the prior missing-file concern.
Makefile Adds a standard help target using grep+awk to list all annotated targets. The help target is correctly placed first so make with no arguments shows available commands. Properly added to .PHONY.
gptme.toml Adds commented-out [plugins], [env], and [mcp] example sections. [plugins] and [env] headers are intentionally active (gptme handles them safely as empty tables), while [mcp] is fully commented because an active but empty [[mcp.servers]] array would cause parse errors.

Sequence Diagram

sequenceDiagram
    participant S1 as Session 1 (autonomous)
    participant S2 as Session 2 (operator)
    participant FL as flock (commit.lock)
    participant PK as prek (pre-commit runner)
    participant GI as .git/index

    S1->>FL: git safe-commit — acquire lock
    FL-->>S1: lock acquired
    S1->>GI: git add file1.py
    S1->>PK: run pre-commit hooks
    PK->>GI: stash unstaged changes
    Note over S2,FL: S2 tries to commit concurrently
    S2->>FL: git safe-commit — acquire lock (blocked, timeout=60s)
    FL-->>S2: waiting...
    PK-->>GI: restore stashed changes
    S1->>GI: git commit
    S1->>FL: release lock
    FL-->>S2: lock acquired
    S2->>GI: git add file2.py
    S2->>PK: run pre-commit hooks (safe, no index conflict)
    S2->>GI: git commit
    S2->>FL: release lock
Loading

Reviews (2): Last reviewed commit: "fix(template): add bin/git-safe-commit a..." | Re-trigger Greptile

Addresses Greptile P2: git safe-commit was referenced without
providing the actual script. Added bin/git-safe-commit (flock-based
wrapper) and clarified that bin/ must be in PATH.

Co-authored-by: Bob <bob@superuserlabs.org>
@TimeToBuildBob
Copy link
Copy Markdown
Member Author

Greptile review addressed

P2 (git safe-commit not in template) — Fixed in a8c4adf:

  • Added bin/git-safe-commit (flock-based wrapper) to the template
  • Updated AGENTS.md to note that bin/ must be in PATH (e.g. via .envrc)

P1 (empty [plugins]/[env] sections may cause parse errors) — False positive:

  • Checked gptme's config parser (gptme/config/models.py): both sections are explicitly handled via config_data.pop("plugins", {}) and config_data.pop("env", {}), so empty tables are perfectly safe
  • [mcp] is fully commented because [[mcp.servers]] array tables would error if the header is active but empty — [plugins]/[env] don't have that issue

@TimeToBuildBob
Copy link
Copy Markdown
Member Author

@greptileai review

LOCKFILE="$GIT_DIR/commit.lock"

# Serialize commits with 60s timeout (prek hooks can take ~30s)
exec flock --timeout 60 "$LOCKFILE" git commit "$@"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 flock is Linux-only — not available on macOS by default

flock is part of util-linux and is not installed on macOS out of the box. Developers working on this template from a Mac (or running the CI on macOS) will see flock: command not found and the script will fail completely.

Consider adding a guard at the top that provides a meaningful error message:

Suggested change
exec flock --timeout 60 "$LOCKFILE" git commit "$@"
if ! command -v flock &>/dev/null; then
echo "error: 'flock' is required but not found (Linux: util-linux; macOS: brew install util-linux)" >&2
exit 1
fi
# Serialize commits with 60s timeout (prek hooks can take ~30s)
exec flock --timeout 60 "$LOCKFILE" git commit "$@"

Alternatively, add a note in the script header documenting the dependency on Linux.

@TimeToBuildBob TimeToBuildBob merged commit 23ac893 into master Mar 22, 2026
5 checks passed
@TimeToBuildBob TimeToBuildBob deleted the feat/upstream-agent-improvements branch March 27, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant