LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

SOP sandboxes never install the HTTPS Git credential helper, so git push fails in agent commands (Codex + per-host credentials)

Open 331931009 opened this issue 1 week ago • 4 comments

Problem

In a Compose deployment with Codex as the SOP executor and an HTTPS Git remote, an agent's plain git push fails inside the SOP sandbox even though the user has a matching per-host HTTPS credential configured:

$ git push origin HEAD:refs/heads/feature/fix-...
fatal: could not read Username for 'https://gitlab.cenboomh.com': terminal prompts disabled

The same run may still succeed if the model happens to discover the credential relay on its own, which makes the failure look intermittent. In our run, attempt 1 hand-rolled a relay call and pushed; attempt 2 used a plain git push and reported human ("环境缺少 GitLab HTTPS 凭据").

Root cause

The two code paths that provision agent-side Git credentials are not equivalent.

Conversation workspaces install the credential helper through command environment (internal/runtime/command_binding.go:361-368):

environment["GIT_CONFIG_COUNT"] = "2"
environment["GIT_CONFIG_KEY_0"] = "credential.helper"
environment["GIT_CONFIG_VALUE_0"] = ""
environment["GIT_CONFIG_KEY_1"] = "credential.helper"
environment["GIT_CONFIG_VALUE_1"] = "!" + shellSingleQuote(helper) + " git-credential"

SOP agent commands go through prepareRunGitBinding (internal/runtime/run_git_credentials.go), which injects only the relay URL and the host list:

credentials.GitHTTPHosts = hosts
command = WithCommandEnvironment(command, map[string]string{GitHostsEnv: workspaceGitHosts(hosts)})
command = WithCommandEnvironment(command, map[string]string{SessionGatewayEnv: base + "/internal/agent-tools/" + token + "/mcp"})

No GIT_CONFIG_* helper is set, and the sandbox's system config written by the platform contains only the identity:

$ cat /workspace/.agentflow/runtime/gitconfig-system
[user]
	name = "admin"
	email = "[email protected]"

The helper binary is present and functional in the same sandbox: /workspace/.agentflow/runtime/bin/agentflow-helper git-credential (relay-backed JSON-RPC agentflow/gitCredential).

Verified env of the agent's docker exec in both attempts:

-e AGENTFLOW_GIT_HOSTS=gitlab.cenboomh.com=gitlab
-e AGENTFLOW_GIT_HTTP_HOST=          # empty
-e AGENTFLOW_GIT_HTTP_USER=          # empty
-e AGENTFLOW_SESSION_GATEWAY=http://172.18.0.3:38823/internal/agent-tools/<token>/mcp

So the platform knows the host and exposes the relay, but nothing points git at the helper.

Workaround (validated)

Add a system Git config to the sandbox image so the relay helper is used:

[credential]
	helper = "!/workspace/.agentflow/runtime/bin/agentflow-helper git-credential"

With that, git credential fill and plain git push both work inside the SOP sandbox. (The conversation-workspace path deliberately clears helpers first with an empty credential.helper entry, so this does not change its behaviour.)

Suggested fix

In prepareRunGitBinding, inject the same helper entries the workspace path uses (GIT_CONFIG_COUNT / GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n with an empty first helper), or write the helper into gitconfig-system when the binding has at least one HTTPS host. Keep the relay URL and host list as they are.

Acceptance criteria:

  1. In a SOP sandbox with a configured per-host HTTPS credential, git push origin <branch> succeeds using the platform helper — the agent does not have to discover or call the relay manually.
  2. git credential fill for a host without a credential returns nothing (still scoped per host, no fallback).
  3. Conversation workspaces keep their current behaviour (helper cleared then set).

Impact

Every SOP delivery step on an HTTPS remote (commit/push/MR) is unreliable with an executor whose subprocess environment is not fully inherited (Codex runs tools with shell_environment_policy.inherit=core), and failures surface as "requires human" instead of a clear credentials error, losing the run's workspace afterwards.

331931009 avatar Nov 23 '26 05:11 331931009

Additional evidence from a real 0.4.1-rc.1 run (Codex executor, GitLab over HTTPS), after applying the system-gitconfig workaround described above:

882 :: The local branch matches the successful review commit, but `git ls-remote` still reports
       that the credential helper is not recognizing this as a LoopForge turn.

So the helper is invoked once it is wired into git config, but it refuses to answer because the turn credentials it needs are stripped from the agent's subprocess environment. internal/runtime/provider_codex.go copies the turn environment into Codex's shell_environment_policy.set but its filter drops every key containing KEY/TOKEN/SECRET/PASSWORD/AUTHORIZATION:

func codexIsolationEnvKey(key string) bool {
	for _, needle := range []string{"KEY", "TOKEN", "SECRET", "PASSWORD", "AUTHORIZATION"} {
		if strings.Contains(upper, needle) {
			return false
		}
	}
	...
}

That is exactly what protects model API keys, but the relay/session credential the helper needs also matches those patterns, so a tool shell can never authenticate. In our run the Codex model worked around it by reading /proc/<codex pid>/environ and re-exporting the values for the git child only:

899 :: The credentials are present in the platform-injected Codex process environment, but this
       shell inherited only a reduced set. I'll import the relevant variables in-memory...

That workaround is not something the platform should rely on (it depends on /proc being readable and on the model thinking of it).

Suggested fix, in addition to installing the helper (above):

  1. Allow-list the specific turn/relay variables the helper needs (for example the session-gateway URL and its turn token) even though their names match the secret filter, or
  2. Make the helper authenticate through something that does not live in the tool environment at all (a socket under the workspace, a file the helper alone can read), so a tool shell cannot leak it.
  3. Either way, assert it in a test: a SOP sandbox on an HTTPS remote must be able to run git ls-remote origin and git push with only the environment Codex gives to tool shells.

331931009 avatar Nov 23 '26 06:11 331931009

Thanks for the detailed report. As I understand it, in a Compose deployment with Codex as the SOP executor, a plain git push to an HTTPS remote fails inside the SOP sandbox (could not read Username … terminal prompts disabled) even when a matching per-host HTTPS credential is already configured; the same push can succeed when the agent calls the credential relay itself.

We've seen this issue and will look at it alongside the existing issue queue.

cocofhu00 avatar Nov 23 '26 06:11 cocofhu00

Same gap still reproduces on v0.4.2 (stable) with Codex, after wiring the helper into git via system config:

[credential]
	helper = "!/workspace/.agentflow/runtime/bin/agentflow-helper git-credential"

The mr node of a run then reported:

git credential fill 退出码 128:'agentflow: not running in a LoopForge workspace turn'
git push 退出码 128:'could not read Username'

So the helper is invoked and refuses: it does not consider the tool shell's environment a workspace turn. Meanwhile the same run's implement node did manage to push (remote tip == its commit), by reading /proc/<pid>/environ of the Codex process — i.e. success depends on the model thinking of that trick, not on the platform.

Two asks, both cheap:

  1. Make the helper's "workspace turn" check satisfiable from the sandbox: either pass the turn credential through the environment keys that Codex keeps (codexIsolationEnvKey currently drops anything containing KEY/TOKEN/SECRET/PASSWORD/AUTHORIZATION), or have the helper read it from a workspace-local file/socket that a tool shell cannot enumerate.
  2. Install the helper into gitconfig-system for SOP sandboxes (already requested above), so plain git push origin <branch> works without the agent discovering the relay.

Evidence for reproduction: run run-1795488271227139262 on a self-hosted 0.4.2 with a GitLab HTTPS remote — mr fails with the message above while implement pushes via /proc; both nodes use the same credential and the same sandbox.

331931009 avatar Nov 24 '26 03:11 331931009

补充一份 2026-11-25、GitHub HTTPS + Codex + macOS Runner 的实操观察,避免重复开 Issue。此处是当日部署记录,尚未在 2026-12-01 最新版重新复现。

环境:原平台镜像基于 0.4.0;后来使用当时下载的源码配套构建平台、Runner 0.11.2 和 Linux arm64 helper(原 Runner 为 0.10.2)。源码下载包无可用 Git commit,不将其称为官方 0.4.2/0.4.3。最终重试节点输出 Codex CLI 0.172.0。

最小流程:个人配置设置并校验 github.com 凭据 → 绑定有推送权限的练习仓库 → Codex 在 Docker 隔离 SOP 内完成修改/评审/测试 → 发布节点使用标准 Git 链路推送独立分支并创建 open PR。

实际观察:

  • 页面凭据校验有效;旧凭据到 per-host 表的迁移也已补执行,仅核对配置存在,未输出值。
  • 业务六项测试通过,代码提交保留;发布节点多次重试仍报告 git push 与 git credential fill 均退出 128,未能取得 GitHub 用户名/可用凭据,未创建 PR。
  • 当日最后一次发布 attempt 的节点记录为 19:09:57—19:11:58(Asia/Shanghai),随后正确停在人工确认,上游结果保留。
  • 这是节点执行记录及 UI 证据;我们尚未独立确认具体是 helper 未接入、工具子进程环境过滤,还是其他注入问题,不能据此宣称已经证明和本帖完全同根因。

希望回归同时覆盖 GitHub 与已有 GitLab 场景:按责任人/host 的标准 helper 在真实 Codex 工具子进程内可完成凭据获取和普通 push;不需要模型寻找进程环境、手写中继或复制令牌。缺失时给出结构化原因与修复入口;修复后只重跑发布节点并复用已有 PR,禁止自动合并。

未附令牌、私有地址、环境文件、内部运行 ID 或未脱敏日志。

luyangshao avatar Dec 01 '26 09:12 luyangshao