Skip to content

fix(codex) when using /list command, correctly read codex project session names - #1639

Merged
chenhg5 merged 3 commits into
chenhg5:mainfrom
shaojiahao:codex/filter-subagent-sessions
Aug 17, 2026
Merged

fix(codex) when using /list command, correctly read codex project session names#1639
chenhg5 merged 3 commits into
chenhg5:mainfrom
shaojiahao:codex/filter-subagent-sessions

Conversation

@shaojiahao

Copy link
Copy Markdown
Contributor

What changed

  • Use the first session_meta entry as the rollout identity so copied parent metadata cannot turn subagent rollouts into duplicate top-level sessions.
  • Exclude Codex subagent rollouts from /list results.
  • Read generated session names from session_index.jsonl, with the existing user-message summary as a fallback.
  • Add regression coverage for subagent filtering, copied parent metadata, and Codex session names.

Why

/list could show many internal subagent rollouts and display concrete user messages instead of the project session names shown by Codex. This made session counts and names differ between cc-connect and Codex for the same project.

Root cause

Subagent rollout files can contain copied parent history with additional session_meta entries. The parser kept overwriting the rollout identity, so some subagent files were misclassified as duplicate parent sessions. The list implementation also derived summaries only from transcript messages and did not consult Codex's session-name index.

User impact

Telegram /list, /switch, and other session-list consumers now see the same top-level Codex sessions and generated session names as the Codex project session picker.

Validation

  • go test ./agent/codex -count=1
  • Verified against local Codex data containing 118 rollout files: the result was reduced to the expected 5 top-level sessions, with names matching Codex.
  • A full go test ./... was attempted; unrelated existing Windows path/permission assertions, a missing web/dist, and the agent/pi Windows build currently prevent a clean repository-wide run.

@chenhg5 chenhg5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Conclusion: Comment (DRAFT, advisory — no request-changes)

Overall assessment:

  • Core fix is correct, test coverage is solid, diff is contained in agent/codex, and the PR description is exemplary. /list now properly reads session_index.jsonl's thread_name and filters out subagent rollouts. 3rd-party author, recommend keeping --comment until DRAFT is flipped to ready-for-review.

Review scope:

  • Read agent/codex/list.go and the new agent/codex/list_test.go.
  • Ran go test -race ./agent/codex/... -count=1 (ok 2.575s); new 3 tests pass standalone with -race too.
  • Focused on correctness of subagent filtering, error paths in session_index.jsonl parsing, blast radius.

✅ What looks good:

  • Root-cause analysis is accurate: subagent rollout files may contain a copied parent meta, the old parser was always overwriting sessionID/sessionCwd/sessionSource, which misclassified subagents as their parent. The new if sessionID != "" { continue } locks the first meta — a tight, well-targeted minimal fix.
  • Using Codex's own session_index.jsonl as the thread-name source (instead of inventing a parallel naming scheme) avoids drift with the Codex picker.
  • Subagent filtering aligns with the existing pattern in agent/gemini/gemini.go:540 and agent/antigravity/antigravity.go:540, bringing codex to parity.
  • Tests use Agent.ListSessions as a black box and t.TempDir(), locking in three independent invariants (subagent filtered, copied parent meta not adopted, thread_name overrides user-message summary).
  • errcheck follow-up is strictly scoped to the new defer calls; pre-existing defer f.Close() at list.go:118/255 and context_usage.go:193 are left alone.
  • PR description is gold standard: what/why/root-cause/user-impact/validation, with concrete 118-rollout → 5 top-level validation data.

🟠 Should improve (non-blocking; author can decide whether to bundle before ready-for-review):

  • The thread_name override skips the 60-rune Summary truncation in parseCodexSessionFile (list.go:64–66 vs 204–206). Codex currently emits short thread_names so no real-world impact, but if Codex ever generates longer names, IM cards will receive uncapped content. Recommend adding if len([]rune(title)) > 60 { title = string([]rune(title)[:60]) + "..." } before the assignment, plus a TestAgentListSessions_LongThreadNameTruncated test to lock the invariant.
  • isSubagentSessionSource returns true for {"subagent": null} (list.go:218–225). Codex doesn't actually emit null so impact is zero, but for strict shape matching one could read the value and require it to be non-null. Lower priority than the cap above.

🔵 Optional:

  • Test name TestAgentListSessions_ExcludesSubagentRolloutWithCopiedParentMeta is verbose; TestAgentListSessions_FirstSessionMetaWinsOverCopiedParent would directly telegraph the invariant.
  • loadCodexSessionTitles silently returns nil on os.Open failure; a slog.Warn would help diagnose permissions/IO issues.
  • The defensive if sessionID != "" { continue } deserves a one-line comment explaining the first-meta-wins rationale (the PR description has it; the source doesn't).

❓ Questions: None.

Testing / Risk:

  • Verified: PR ships with 3 new unit tests + author's local 118-rollout end-to-end validation; local go test -race ./agent/codex/... -count=1 is all ok; go build / go vet clean.
  • Uncovered: corrupt session_index.jsonl line (per code it skips, but no test locks that); latest-wins behavior with multiple index entries for same ID after rename; rollout exists but no index entry fallback. All reasonable as follow-ups.

DRAFT note: PR is currently in DRAFT. Per QA policy, even with --approve allowed for 3rd-party, I don't approve while in DRAFT — leaving a comment for the author to convert to ready. If you want to be conservative, you can land the P2 #1 (60-rune title cap + corresponding test) in the same PR; otherwise the current diff is good to merge as-is.

Next step: Author flips the PR from DRAFT to ready-for-review. If desired, include the P2 #1 (60-rune title cap + test); otherwise the diff is sufficient — QA has no hard blocker.

@shaojiahao
shaojiahao marked this pull request as ready for review August 15, 2026 01:41
@chenhg5
chenhg5 merged commit 3727b74 into chenhg5:main Aug 17, 2026
5 checks passed
happyTonakai added a commit to happyTonakai/cc-connect that referenced this pull request Aug 17, 2026
tayhe added a commit to tayhe/cc-connect that referenced this pull request Aug 17, 2026
Sync main to fork's next-publishable identifier. Content: upstream
v1.5.0-beta.3 (P1 stability chenhg5#1693) + codex /list fix chenhg5#1639 + 6 fork-local
commits (mimocode adapter etc.) per merge commit 55159fb.
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.

2 participants