Skip to content

feat: reuse provider sessions per agent - #811

Merged
tomdps merged 9 commits into
mainfrom
codex/migrate-pr-808-to-main
Jul 28, 2026
Merged

feat: reuse provider sessions per agent#811
tomdps merged 9 commits into
mainfrom
codex/migrate-pr-808-to-main

Conversation

@tomdps

@tomdps tomdps commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Main-trunk migration

Replaces #808 after the main-trunk cutover. This branch starts at the new main, preserves the original isolated diff and commit author, and removes the legacy dev history from the PR.

Original PR body

Summary

  • capture Claude session IDs and Codex thread IDs from provider JSONL output
  • persist continuation state on the owning logical agent and restore it with cluster state
  • resume only that same agent by explicit session ID; never use cwd-wide latest-session selection
  • fail closed to a fresh session on provider changes, failed tasks, unsupported CLI versions, or Docker isolation
  • make manual task resume use the captured explicit provider session for Claude and Codex

This follows the revised scope in #482: provider-side session reuse rather than direct API cache_control plumbing.

Validation

  • npm run check
  • npm run check:agent-cli-provider:ci (135 passing)
  • focused provider/session/persistence tests (24 passing)
  • opcore check --changed --json
  • npm test: 1705 passing, 18 pending; 7 local attach/PTTY tests fail with the environment-level node-pty error posix_spawnp failed

Fixes #482

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown

Greptile Summary

Adds explicit, agent-owned Claude and Codex provider-session reuse.

  • Captures provider session identifiers from JSONL output and validates resumed-session identity.
  • Persists continuation provenance with agent state and restores it only across matching durable task boundaries.
  • Clears continuation state after logical, hook, provider, isolation, or workspace failures.
  • Uses continuation-specific context and durable ledger/guidance cursors.
  • Extends task resume, status, inspection, provider contracts, and test coverage for session reuse.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported failed-session reuse path is closed: continuation is installed only after logical validation and the completion hook succeed, every failure path clears it, and durable restoration requires an exact matching TASK_COMPLETED boundary.

Important Files Changed

Filename Overview
src/agent/agent-lifecycle.js Commits continuation state only after logical success and completion hooks, while clearing it on failure paths.
src/agent/provider-session.js Defines session normalization, provenance matching, continuation eligibility, and fail-closed durable restoration.
src/agent/agent-task-executor.js Captures provider session identity and includes it only in logically successful completion results.
src/agent-wrapper.js Resolves eligible agent-owned sessions and selects full or continuation context for each task.
src/agent-cli-provider/adapters/claude.ts Adds explicit Claude session extraction, resume capability detection, and safe resume command construction.
src/agent-cli-provider/adapters/codex.ts Adds Codex thread extraction and explicit exec-resume command support with capability checks.
src/orchestrator.js Persists and restores provider continuation state as part of each logical agent’s durable state.
task-lib/provider-session-capture.js Tracks observed session identifiers and rejects missing, forked, or ambiguous resumed identities.

Sequence Diagram

sequenceDiagram
    participant Agent
    participant Provider
    participant Hook as onComplete Hook
    participant Ledger
    Agent->>Provider: Execute task or resume explicit session ID
    Provider-->>Agent: Output and observed session ID
    Agent->>Agent: Validate output and session identity
    Agent->>Hook: Run completion hook
    Hook-->>Agent: Success
    Agent->>Agent: Install provider continuation
    Agent->>Ledger: Publish durable TASK_COMPLETED
    Note over Agent,Ledger: Any validation, hook, or task failure clears continuation state
Loading

Reviews (8): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

@tomdps
tomdps force-pushed the codex/migrate-pr-808-to-main branch from 3bec06e to 57a12fd Compare July 27, 2026 15:31
@tomdps
tomdps added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit 0dab9f0 Jul 28, 2026
10 checks passed
@tomdps
tomdps deleted the codex/migrate-pr-808-to-main branch July 28, 2026 22:45
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: opt into provider-side prompt caching to reduce per-cluster token cost

1 participant