Files
archie/task.json
T

1 line
2.4 KiB
JSON

{"id":3,"owner":"sam","repo":"archie-core","issue_number":59,"title":"askpass helper rewritten on every git call despite \"(once)\" comment","body":"## Problem\n\n`Manager.askpass()` in `internal/worktree/worktree.go:36` is documented as writing the helper script \"(once)\":\n\n```go\n// askpass writes (once) a helper script that emits the token, so git\n// authenticates without the token appearing in argv or .git/config.\nfunc (m *Manager) askpass() (string, error) {\n\tpath := filepath.Join(m.WorkDir, \".git-askpass\")\n\tscript := \"#!/bin/sh\\necho \\\"$ARCHIE_GIT_TOKEN\\\"\\n\"\n\tif err := os.MkdirAll(m.WorkDir, 0o755); err != nil {\n\t\treturn \"\", err\n\t}\n\tif err := os.WriteFile(path, []byte(script), 0o700); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn path, nil\n}\n```\n\nIn reality there is no existence check, cache, or `sync.Once` — it unconditionally runs `os.MkdirAll` + `os.WriteFile` every time it's called. It's invoked from `git()` (worktree.go:48-49) on **every single git command** (clone, config, commit, push, diff, etc.), so the same static file is truncated and rewritten repeatedly, contradicting its own comment.\n\n## Why it matters\n\n- Wasted filesystem I/O (mkdir + open/write/close) on every git invocation, for content that never changes.\n- Latent race condition: if concurrent task processing is ever introduced (multiple goroutines calling `git()` against the same `Manager`/`WorkDir` concurrently), this becomes a genuine race — one goroutine's `os.WriteFile` (which truncates then writes) could interleave with another's read of the same path, or with git actually invoking the script mid-truncate, causing an intermittent empty/malformed askpass script and auth failures.\n- Currently low severity since processing is single-threaded and the script content is static/idempotent, but it's tech debt that will bite silently if concurrency is added without revisiting this code.\n\n## Suggested fix\n\nWrite the helper file once (e.g., guarded by `sync.Once`, or check `os.Stat` before writing, or write it once during `Manager` construction) instead of on every `git()` call. If concurrent workers will ever share a `WorkDir`, consider using a per-worker or per-task path, or writing to a temp file and atomically renaming it into place to avoid partial-write races.\n\u003c/refined_body\u003e\n","labels":[""],"workflow":"","branch":"feat/59-askpass-helper-rewritten-on-every-git-call-despite-once-comm"}