Loading
fix(minder): report sessions started without a GitLab remote
Description
When a coding agent ran in a folder where glab could not identify a GitLab project, for example a folder without a remote on a GitLab host glab is logged in to, the agent hook failed to resolve a project and, running silently, left no trace. The session was never synced, the background sync never saw it, and glab minder doctor said nothing, so it looked like capture was broken.
recordSessionMetanow records such a session with its agent type and transcript, but no project. A session already recorded with a project keeps it, and an unreadable record is left alone.glab minder audit sync --allreports these sessions in the status thatglab minder doctorreads, asnot synced: claude-code sessions in a folder where glab could not identify a GitLab project. Resolving the project also fails outside a Git repository, whenGITLAB_HOSTmatches no remote, on a network error or with an invalid-R, so the reason names whatglabknows rather than a missing remote.- Each hook call rewrites the record, so the background sync reads its modification time as the session's last activity. After a day without activity, the session is marked completed. The record is kept, like other completed sessions, until the agent can no longer resume the session, because it is what makes a resumed session skip its earlier activity.
- When a later hook call for the same session runs in a folder with a GitLab project,
glabuploads only activity from that point. Before recording the project, it moves the session's cursor to the end of the transcript, found from the earlier record like--alldoes, so earlier work in another folder or repository is not uploaded. If that fails, the session keeps no project and the hook does not sync. The turn where the project appeared is skipped too. The per-project split in https://gitlab.com/gitlab-org/cli/-/work_items/8722 attributes each entry to the folder it ran in.
Sessions found by discovery (Codex and Cursor) are reported the same way in !4400 (merged), which is stacked on this MR.
Related to https://gitlab.com/gitlab-org/cli/-/work_items/8722
How has this been tested?
New tests in sync_test.go and sync_all_test.go cover:
- recording a session without a project, keeping an existing project and leaving an unreadable record alone
- the not-synced report, including a session whose transcript is gone
- completing an idle session and keeping its record
- a session that gains a project: the cursor moves to the end of the recorded transcript, also when the hook runs from another folder or resumes after idle completion, a failed move keeps the session without a project, and a session that starts in a GitLab repository uploads from the start
skipToEndfrom a non-zero cursor with a partly written last line
go test ./internal/commands/govern/...Edited by Jean van der Walt