Skip to content

fix(execenv): clean stale Codex memories on env reuse (fixes #3130)#3147

Open
kagura-agent wants to merge 1 commit into
multica-ai:mainfrom
kagura-agent:fix/clean-codex-memories-on-reuse
Open

fix(execenv): clean stale Codex memories on env reuse (fixes #3130)#3147
kagura-agent wants to merge 1 commit into
multica-ai:mainfrom
kagura-agent:fix/clean-codex-memories-on-reuse

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Summary

Fixes #3130 — reused CODEX_HOME leaks stale memories from a prior task into unrelated issue assignments.

Root Cause

prepareCodexHomeWithOpts() seeds a per-task CODEX_HOME with symlinks (auth, sessions) and copied config files, but never clears Codex-generated runtime state. On the Prepare path this doesn't matter because Prepare() nukes the entire envRoot first. On the Reuse path (when task.PriorWorkDir is set for the same agent+issue pair), the old codex-home/memories/ directory — containing raw_memories.md and summaries from a prior task — persists and gets injected into the new task's Codex context.

This can cause cross-task and cross-project memory contamination, where a new issue receives stale project-specific instructions, architecture assumptions, and paths from a deleted project.

Changes

  • server/internal/daemon/execenv/codex_home.go: Add os.RemoveAll(memories/) at the start of prepareCodexHomeWithOpts(), after MkdirAll and before symlink/copy seeding. On Prepare this is a harmless no-op; on Reuse it prevents stale memory leakage.
  • server/internal/daemon/execenv/codex_home_memories_test.go: Two new tests:
    • TestPrepareCodexHome_CleansStaleMemories: seeds a stale memories/raw_memories.md, runs prepareCodexHome, verifies the directory is removed.
    • TestPrepareCodexHome_NoMemoriesDir_NoError: verifies no error when memories/ doesn't exist (fresh task path).

Testing

go test ./internal/daemon/execenv/... -v   # all 70+ tests pass

…ai#3130)

prepareCodexHomeWithOpts now removes the memories/ directory before
seeding the per-task CODEX_HOME. On the Prepare path this is a no-op
(the entire envRoot is already wiped). On the Reuse path it prevents
a prior task's raw_memories.md from leaking into the new task's
Codex context, which caused cross-task and cross-project memory
contamination.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@kagura-agent is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug]: Reused Codex CODEX_HOME leaks stale memories into unrelated issue tasks

1 participant