Skip to content

[codex] add Go session lineage backend - #68

Merged
gnanam1990 merged 2 commits into
mainfrom
feat/m4-session-lineage
Jun 5, 2026
Merged

gnanam1990 merged 2 commits into
mainfrom
feat/m4-session-lineage

Conversation

@gnanam1990

@gnanam1990 gnanam1990 commented Jun 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add Go session lineage metadata for forked and child sessions, including root session, agent/task identifiers, and parent spawn event anchors.
  • Add child-session backend APIs to create delegated child sessions, list direct children, walk root-to-child lineage, and build session trees for future agent orchestration surfaces.
  • Add a Go zero sessions inspector command with text and JSON output for list, children, lineage, and tree views.

PRD Alignment

  • Covers the Gnanam-owned M4 dependency for parent/child session APIs that future subagent framework and /agents UI work can consume.
  • Keeps task execution/subagent orchestration out of this PR; this slice is only the durable backend contract and inspectable CLI surface.

Validation

  • go test -run 'TestStoreCreatesChildSessionsAndRecordsLineageEvents|TestStoreListsChildrenLineageAndTree' -count=1 ./internal/sessions
  • go test -run 'TestRunSessionsListsLineageAndTree|TestRunSessionsValidatesArgs|TestRunCommandsDoNotLaunchTUI|TestRunPrintsHelp' -count=1 ./internal/cli
  • go test -count=1 ./internal/sessions ./internal/cli
  • go test -count=1 -p 1 ./...
  • npx --yes bun run typecheck
  • npx --yes bun test ./tests --timeout 15000 (291 pass / 0 fail)
  • npx --yes bun run build
  • npx --yes bun run smoke:build
  • npx --yes bun run smoke:go
  • ./zero --help
  • ./zero sessions --help
  • ./zero sessions list --json
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Added a sessions command group (list, children, lineage, tree) with optional --json output to inspect local session lineage and relationships.
    • Child sessions inherit runtime context and record parent/child linkage so lineage and tree views reflect full ancestry.
  • Bug Fixes

    • Improved CLI argument validation and clearer usage/error messages.
  • Tests

    • Added comprehensive CLI and unit tests covering session creation, lineage, ordering, and tree output.

@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Typecheck: bun run typecheck
  • [pass] Tests: bun run test
  • [pass] Build: bun run build
  • [pass] Smoke build: bun run smoke:build

Scope

Head: 0e0a9e05585e
Changed files (7): internal/cli/app.go, internal/cli/app_test.go, internal/cli/sessions.go, internal/cli/sessions_test.go, internal/sessions/lineage.go, internal/sessions/store.go, internal/sessions/store_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f9411432-9e5c-4037-9610-79862ff86acb

📥 Commits

Reviewing files that changed from the base of the PR and between 0f874cd and 0e0a9e0.

📒 Files selected for processing (3)
  • internal/cli/sessions.go
  • internal/cli/sessions_test.go
  • internal/sessions/lineage.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/cli/sessions_test.go
  • internal/sessions/lineage.go
  • internal/cli/sessions.go

Walkthrough

Implements session lineage: expands session model with lineage fields, adds Store methods CreateChild/ListChildren/Lineage/Tree, exposes them via a new sessions CLI (list, children, lineage, tree), and adds unit and CLI tests covering behavior and argument validation.

Changes

Session Lineage and CLI

Layer / File(s) Summary
Session data model expansion
internal/sessions/store.go
Metadata and CreateInput gain session-kind, lineage (parent/root/spawned-from), and agent/task fields. Adds ChildInput and TreeNode, EventSessionChild, and updates Store.Create/Store.Fork to populate lineage fields.
Lineage operations
internal/sessions/lineage.go
Adds Store.CreateChild, ListChildren, Lineage, and Tree with cycle detection, stable child ordering, recursive tree construction, and helpers for child title and link payload.
Lineage operation tests
internal/sessions/store_test.go
Tests child creation recording linkage events and metadata inheritance; verifies ListChildren ordering, Lineage traversal, and Tree nesting for a small hierarchy.
Sessions CLI implementation
internal/cli/sessions.go
Adds runSessions dispatcher and subcommands (list,children,lineage,tree), arg parsing including --json/help, redacted JSON or human-readable output, formatting helpers, and normalized session error handling.
Sessions CLI tests
internal/cli/sessions_test.go
CLI tests for sessions list, sessions lineage <id>, sessions tree <id> --json, deterministic timestamps, and argument/usage error cases (unknown subcommand, extra positional arg).
CLI integration and tests
internal/cli/app.go, internal/cli/app_test.go
Wires sessions into app router and help text; extends TUI-prevention test to include sessions/session.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] add Go session lineage backend' directly describes the main change: adding session lineage functionality to the Go backend, which aligns with the changeset's core purpose of adding lineage metadata, APIs, and CLI support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/m4-session-lineage

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/cli/sessions_test.go (1)

83-99: ⚡ Quick win

Add regression cases for invalid sessions invocations.

Please add CLI tests for sessions foo and sessions list extra expecting exitUsage; these are important guardrails for parser behavior and prevent silent fallback regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/sessions_test.go` around lines 83 - 99, Add two regression test
cases in TestRunSessionsValidatesArgs (or a new test in
internal/cli/sessions_test.go) that exercise invalid CLI invocations: one
calling runWithDeps with args []string{"sessions","foo"} and another with
[]string{"sessions","list","extra"}; both should use the same
appDeps.newSessionStore returning the prepared store, assert the returned
exitCode equals exitUsage, and assert stderr contains the
usage/malformed-invocation message similar to the existing "Zero session not
found: missing" check (i.e., verify the CLI reports a usage error for these
invalid argument patterns).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/sessions/lineage.go`:
- Around line 47-53: CreateChild can persist the child linkage event and then
fail appending the parent event, leaving asymmetric lineage; to fix, make the
two appends atomic: either call a transactional/batch API (e.g., use a
hypothetical store.AppendEvents or store.Transaction that appends both payloads
for child.SessionID and parent.SessionID in one operation), or if no transaction
exists, append the parent event first (store.AppendEvent with Payload from
childLinkPayload) then append the child event, or implement compensation by
removing the child event on parent-append failure (use the store's delete/revert
API). Update the code around childLinkPayload, store.AppendEvent,
EventSessionChild, child.SessionID and parent.SessionID accordingly so both
session events are persisted together or cleaned up on error.

---

Nitpick comments:
In `@internal/cli/sessions_test.go`:
- Around line 83-99: Add two regression test cases in
TestRunSessionsValidatesArgs (or a new test in internal/cli/sessions_test.go)
that exercise invalid CLI invocations: one calling runWithDeps with args
[]string{"sessions","foo"} and another with []string{"sessions","list","extra"};
both should use the same appDeps.newSessionStore returning the prepared store,
assert the returned exitCode equals exitUsage, and assert stderr contains the
usage/malformed-invocation message similar to the existing "Zero session not
found: missing" check (i.e., verify the CLI reports a usage error for these
invalid argument patterns).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e3f1de0-9a3b-492a-b74c-56f7452f09e1

📥 Commits

Reviewing files that changed from the base of the PR and between a09a721 and 0f874cd.

📒 Files selected for processing (7)
  • internal/cli/app.go
  • internal/cli/app_test.go
  • internal/cli/sessions.go
  • internal/cli/sessions_test.go
  • internal/sessions/lineage.go
  • internal/sessions/store.go
  • internal/sessions/store_test.go

Comment thread internal/cli/sessions.go Resolved
Comment thread internal/sessions/lineage.go Resolved
@gnanam1990

Copy link
Copy Markdown
Collaborator Author

Review feedback addressed in commit 0e0a9e0.

Fixed:

  • zero sessions foo now fails with a usage error instead of falling through to list.
  • zero sessions list extra now fails with a usage error.
  • CreateChild now appends the parent session linkage event before writing the child-side linkage event.

Validation:

  • go test -run 'TestRunSessionsListsLineageAndTree|TestRunSessionsValidatesArgs' -count=1 ./internal/cli
  • go test -run 'TestStoreCreatesChildSessionsAndRecordsLineageEvents|TestStoreListsChildrenLineageAndTree' -count=1 ./internal/sessions
  • go test -count=1 -p 1 ./...
  • npx --yes bun run typecheck
  • npx --yes bun test ./tests --timeout 15000
  • npx --yes bun run build
  • npx --yes bun run smoke:build
  • npx --yes bun run smoke:go
  • ./zero --help
  • ./zero sessions --help
  • ./zero sessions list --json
  • git diff --check

@Vasanthdev2004

Copy link
Copy Markdown
Collaborator

Looks Good

I reviewed the Go session lineage backend and the new zero sessions inspector surface against current origin/main at head 0e0a9e05585e6accfc356e61ac881f3683fe33fa.

Blockers

  • None.

Non-Blocking

  • The PR intentionally keeps this to the durable backend + inspector CLI contract. There is no user-facing child-session creation/orchestration flow yet, so future subagent work still needs to wire creation through the agent/runtime surfaces and preserve the same lineage invariants.

Looks Good

  • CreateChild, ListChildren, Lineage, and Tree are anchored on validated session ids, preserve root/parent linkage, and keep cycle checks in the traversal paths.
  • Parent/child link events are written to both sides, while child metadata inherits cwd/model/provider context from the parent unless explicitly overridden.
  • The zero sessions CLI keeps list/children/lineage/tree as read-only inspection commands, supports text and JSON output, redacts rendered metadata before output, and does not launch the TUI for these commands.
  • Local validation passed:
    • go test -run 'TestStoreCreatesChildSessionsAndRecordsLineageEvents|TestStoreListsChildrenLineageAndTree' -count=1 ./internal/sessions
    • go test -run 'TestRunSessionsListsLineageAndTree|TestRunSessionsValidatesArgs|TestRunCommandsDoNotLaunchTUI|TestRunPrintsHelp' -count=1 ./internal/cli
    • go test -count=1 ./internal/sessions ./internal/cli
    • go test -count=1 -p 1 ./...
    • go build ./cmd/zero
    • bun install --frozen-lockfile
    • bun run typecheck
    • bun test ./tests --timeout 15000 — 291 pass / 0 fail
    • bun run build
    • bun run smoke:build
    • bun run smoke:go
    • ./zero.exe --help
    • ./zero.exe sessions --help
    • ./zero.exe sessions list --json
    • git diff --check origin/main..HEAD
  • GitHub checks are green: Smoke on Ubuntu/macOS/Windows, Performance Smoke, Zero Review, and CodeRabbit.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks Good

I reviewed the Go session lineage backend and the new zero sessions inspector surface against current origin/main at head 0e0a9e05585e6accfc356e61ac881f3683fe33fa.

Blockers

  • None.

Non-Blocking

  • The PR intentionally keeps this to the durable backend + inspector CLI contract. There is no user-facing child-session creation/orchestration flow yet, so future subagent work still needs to wire creation through the agent/runtime surfaces and preserve the same lineage invariants.

Looks Good

  • CreateChild, ListChildren, Lineage, and Tree are anchored on validated session ids, preserve root/parent linkage, and keep cycle checks in the traversal paths.
  • Parent/child link events are written to both sides, while child metadata inherits cwd/model/provider context from the parent unless explicitly overridden.
  • The zero sessions CLI keeps list/children/lineage/tree as read-only inspection commands, supports text and JSON output, redacts rendered metadata before output, and does not launch the TUI for these commands.
  • Local validation passed:
    • go test -run 'TestStoreCreatesChildSessionsAndRecordsLineageEvents|TestStoreListsChildrenLineageAndTree' -count=1 ./internal/sessions
    • go test -run 'TestRunSessionsListsLineageAndTree|TestRunSessionsValidatesArgs|TestRunCommandsDoNotLaunchTUI|TestRunPrintsHelp' -count=1 ./internal/cli
    • go test -count=1 ./internal/sessions ./internal/cli
    • go test -count=1 -p 1 ./...
    • go build ./cmd/zero
    • bun install --frozen-lockfile
    • bun run typecheck
    • bun test ./tests --timeout 15000 — 291 pass / 0 fail
    • bun run build
    • bun run smoke:build
    • bun run smoke:go
    • ./zero.exe --help
    • ./zero.exe sessions --help
    • ./zero.exe sessions list --json
    • git diff --check origin/main..HEAD
  • GitHub checks are green: Smoke on Ubuntu/macOS/Windows, Performance Smoke, Zero Review, and CodeRabbit.

@gnanam1990
gnanam1990 merged commit 53097ab into main Jun 5, 2026
6 checks passed
@Vasanthdev2004
Vasanthdev2004 deleted the feat/m4-session-lineage branch June 28, 2026 08:27
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