Repository navigation
Description
Summary
Follow-up to #670 (persistent agent memory). #670 shipped a local file-based memory: a directory of Markdown fact-files under a configurable dir (default ~/.infer/memory), catalogued by a MEMORY.md index and injected into context at session start. It is local-only - there is no way to share or persist that memory beyond the machine the agent runs on.
This adds a configurable memory sync backend so the memory directory can be backed by a remote (starting with git/GitHub): clone/pull the memory into the local home dir when a run starts, and run a deterministic command to commit and push it back when the run finishes - only if something changed.
Requested in #670:
I want to have a memory backend configurable, for example in github - that whenever the project runs it will clone the memory to its local home dir and when it finished a deterministic command will be executed to push it back to github, if there were any changes.
Motivation
- Memory today lives only on the local disk of whatever machine the agent runs on. A laptop, a CI runner, and the channels-manager daemon each keep separate, divergent memory.
- Teams want a single shared memory (a git repo) the agent reads at start and writes back at the end - version-controlled, diffable, and auditable.
- The headless runtimes are especially affected: channels-manager / scheduler / heartbeat each spawn a fresh
infer agentsubprocess per fire, so without a remote, durable cross-run memory never accumulates in ephemeral or containerized deployments.
Proposed design
Config (memory.yaml)
Extend MemoryConfig (config/memory.go) with a backend block. The default type: local preserves today's behavior exactly (no remote, no-op):
enabled: true
dir: "" # ~/.infer/memory (unchanged)
max_chars: 4000
backend:
type: local # local (default) | git
git:
repo: "[email protected]:my-org/agent-memory.git"
branch: main
# Auth uses the ambient git credential chain (ssh-agent, gh auth, GIT_*/token env).
sync:
on_start: pull # clone if the dir is absent, else fast-forward / rebase pull
on_finish: push # commit + push, only when `git diff` shows changes
commit_message: "chore(memory): sync" # deterministic, non-LLMEnv overrides should follow the existing INFER_* convention. Note that memory.yaml is a split-out config file (Memory is tagged yaml:"-" mapstructure:"-" on the main Config), so wire env handling the same way its siblings (Heartbeat/Channels/ComputerUse) do rather than assuming viper picks it up from config.yaml.
Where it attaches
The agent loop already exposes symmetric hook points (internal/domain/hooks.go): HookPreSession ("run begins, before the first stream") and HookPostSession ("run finished"). A git backend attaches:
- pre_session -> clone (if
diris missing) or pull intoResolveMemoryDir(). - post_session ->
git add -A; if there are staged changes, commit with the configured message and push; otherwise no-op (the "if there were any changes" part).
These are deterministic git commands run by the runtime, not the LLM - matching the request. They are the command-action sibling of the existing reminder/hook machinery (HookCommand in internal/domain/hooks.go), so they can flow through the same dispatch seam and bash allow-list.
Backend abstraction
Mirror the storage backend pattern (internal/infra/storage/factory.go selects jsonl/sqlite/postgres/redis by a type field):
- New
domain.MemoryBackendinterface (e.g.SyncIn(ctx) error/SyncOut(ctx) error) ininternal/domain- adding an interface here triggers a mock regeneration, so add the counterfeiter line perCLAUDE.md. - A
localno-op implementation and agitimplementation underinternal/infra. - A factory that selects by
backend.type, wired into the container alongside the existing memory plumbing.
Safety / robustness
- Best-effort, never fatal. A failed clone/pull/push logs and continues; it must never break the agent run (same posture as a git-context or storage degrade).
- Auth. Reuse the ambient git credential chain; do not invent new secret storage. Document SSH vs
gh authvs token-in-URL. - Concurrency. channels-manager / scheduler / heartbeat can run overlapping
infer agentsubprocesses against the same remote. Pull-with-rebase + push-with-retry (or a local lock) to avoid clobbering; document the race and the chosen mitigation. - Sandbox. The memory dir is already a carve-out (
isWithinMemoryDir,config/config.go); a git working copy living there must stay readable/writable while.infer/protection holds elsewhere.
Alternatives considered
Users can already hand-wire this today with pre_session / post_session command hooks (hooks.yaml) running raw git pull / git commit && git push. This feature turns that into a first-class, turnkey memory.backend with sane defaults, auth handling, change-detection, and concurrency safety - instead of every user re-deriving the git incantations and the bash allow-list entries.
Out of scope (future)
- Non-git backends (S3 / object store, a hosted memory service).
- Conflict-resolution UX beyond pull-rebase / last-writer-wins.
- Encrypted-at-rest memory or per-fact ACLs.
- Selective sync (e.g. push
projectfacts, keepuserfacts local).
Acceptance criteria
-
memory.backendblock (type+gitsettings) with defaults (type: local, behavior unchanged), validation, and env overrides following theINFER_*convention. -
domain.MemoryBackendinterface with alocalno-op and agitimplementation, selected by a factory (mirrors storage). - On run start the git backend clones-or-pulls the memory dir; on run finish it commits + pushes only when there are changes, via deterministic (non-LLM) commands.
- Wired at
HookPreSession/HookPostSession; failures are best-effort (log + continue) and never abort the run. - Auth uses the ambient git credential chain; concurrent-run safety is addressed and documented.
- Works in headless
infer agentruns (channels / scheduler / heartbeat). - Tests cover local no-op, clone-on-missing, pull-on-present, push-only-when-dirty, and failure degradation;
task lint/task testpass; docs updated.
Follow-up to #670.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
edenreich commentedon Jul 2, 2026
@claude I think we're missing docs for this in docs repo? Can you file it if we're missing it?
inference-gateway-maintainer commentedon Jul 2, 2026
Claude finished @edenreich's task in 2m 48s —— View job
Docs coverage check for memory sync backend (#683)
You're right - the docs were missing. I filed a tracking issue in the docs repo.
Filed: inference-gateway/docs#296 - [DOCS] Document memory git sync backend (memory.backend)
inference-gateway/docsfor existing memory / memory-backend docs[DOCS]issue (none existed already)What I found
The feature merged in #707 (
feat(memory): configurable git sync backend), which closed this issue.The docs repo's
cli.mdhas a Persistent Memory section, but its Configuration (memory.yaml) subsection only documents the original local knobs from #679:enabled,dir,max_charsbackendblockINFER_MEMORY_ENABLED/DIR/MAX_CHARSINFER_MEMORY_BACKEND_*(7 vars)Specifically undocumented:
backend.type(local/git),backend.git.{repo,branch,commit_message,timeout},backend.git.sync.{on_start,on_finish}, theirINFER_MEMORY_BACKEND_*env vars, plus the behavior notes (clone-or-pull on start, push-only-when-dirty with push->rebase->retry +flock, chat-vs-headless push points, best-effort degradation, and the ambient git-credential auth model).I searched the docs repo first and confirmed no existing
[DOCS]issue or coverage for this, so the new issue is not a duplicate. The issue body includes the full config surface, the env-var table, and the behavior notes for whoever picks it up. No code changes were needed here.inference-gateway-releaser commentedon Jul 2, 2026
🎉 This issue has been resolved in version 0.127.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
fix(pricing): bill subscription-gated models at zero cost (#1263)