Skip to content

Agent host: consolidate Claude SDK query build (Tier 0 + C1)#326256

Draft
TylerLeonhardt wants to merge 3 commits into
mainfrom
claude-agent-host-consolidation
Draft

Agent host: consolidate Claude SDK query build (Tier 0 + C1)#326256
TylerLeonhardt wants to merge 3 commits into
mainfrom
claude-agent-host-consolidation

Conversation

@TylerLeonhardt

Copy link
Copy Markdown
Member

What

First step of a planned consolidation of the Claude agent-host runtime (full plan in src/vs/platform/agentHost/node/claude/architecture-analysis/ROADMAP.md). Two low-risk, self-contained changes:

Tier 0 — remove dead code (grep-confirmed zero production callers):

  • ClaudeAgentSession.{seedBijectiveState, attachRematerializer, rebindForClientTools}
  • ClaudeSdkPipeline.{setClientToolOwner, reloadPlugins}
  • ClaudeSdkMessageRouter.setClientToolOwner

C1 — unify the SDK-Options build. The two near-identical buildOptions sites (initial materialize + the rematerializer closure, ~50% copy-paste) collapse into one ClaudeAgentSession._startSdkQuery, with a thin _rebuildSdkQuery wrapper. The pipeline's rebuild hook moves from a post-construction attachRematerializer to a required constructor param — removing the two-phase init and the throw-if-unattached. The closure-captured ctx becomes an explicit _sdkStart field (de-closured). Net: buildOptions has a single caller; model/effort no longer derived a third time; −85 lines.

Why

Reduces the "rematerializer" duplication + two-phase-init smell without changing behavior. It's the enabling step for the bigger reshape — C9: immutable pipeline / session-orchestrated rebind (stacked next) — that removes the passed-in rematerializer entirely. The architecture-analysis/ dir has the coupling/lifecycle/duplication analysis, a synthesis with diagrams, and the sequenced roadmap.

Validation

  • typecheck-client + eslint clean; 213 unit tests pass.
  • Adversarial review (4 finder angles: line-by-line, removed-behavior, cross-file, cleanup): no correctness bugs; 2 cleanups applied (_clientToolOwnerreadonly; reuse resolveCurrentPermissionMode).
  • Live E2E in the authenticated Agents window: materialize (startup isResume=false), pipeline reuse (1 startup / 4 turns), abort→cancellation, and recover-rebind (startup isResume=true → result) all confirmed end-to-end; no "no rematerializer attached" errors.

Not in this PR

  • C9 (immutable pipeline) — stacked on top; C2 folds into it.
  • Config-state model recorded in CONTEXT.md M5 (Desired-on-session / Applied-on-pipeline; per-axis timing).

Review note

Draft — opened early for directional feedback ahead of the stacked C9 PR. The architecture-analysis/ docs are working notes/analysis (candid by design); happy to trim if reviewers prefer a leaner tree.

🤖 Generated with Claude Code

TylerLeonhardt and others added 2 commits July 16, 2026 17:12
Tier 0 - remove dead code (grep-confirmed zero production callers): ClaudeAgentSession.{seedBijectiveState,attachRematerializer,rebindForClientTools}, ClaudeSdkPipeline.{setClientToolOwner,reloadPlugins}, ClaudeSdkMessageRouter.setClientToolOwner.

C1 - unify the two duplicated SDK-Options build sites (materialize + the rematerializer closure, ~50% copy-paste) into one ClaudeAgentSession._startSdkQuery, with a thin _rebuildSdkQuery wrapper. The pipeline's rebuild hook moves from a post-construction attachRematerializer to a required constructor param, removing the two-phase init and the throw-if-unattached. The closure-captured ctx becomes an explicit _sdkStart field (de-closured). buildOptions now has one caller; model/effort no longer derived a third time.

Review cleanups: _clientToolOwner is now readonly; _startSdkQuery reuses the resolveCurrentPermissionMode helper.

Validated: typecheck-client + eslint clean; 213 unit tests pass; live E2E in the authenticated Agents window confirmed materialize (startup isResume=false), pipeline reuse, and recover-rebind (startup isResume=true) end to end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ate model

Add architecture-analysis/ - the /improve-codebase-architecture output: coupling, lifecycle, rematerializer-duplication, responsibility-overlap and test-surface reports; a synthesis with visual aids; a sequenced consolidation roadmap (Tier 0 + C1 done; C2-C9 proposed, with C9 = immutable pipeline / session-orchestrated rebind as the end-state that removes the rematerializer); and the C1 E2E scenarios.

CONTEXT.md M5: record the settled two-state config model (Desired on the session, Applied on the pipeline; no host-side staging) with per-axis timing (model/effort = next turn per SDK docs; permissionMode = immediate; agent = re-verify) and the permissions != permissionMode distinction.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 17, 2026 00:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Consolidates Claude SDK query construction and removes unused APIs.

Changes:

  • Centralizes initial and rebuilt SDK query startup.
  • Requires rematerialization during pipeline construction.
  • Updates tests and adds architecture planning documentation.
Show a summary per file
File Description
claudeSdkPipeline.test.ts Updates rematerializer test wiring.
claudeAgent.test.ts Corrects state-seeding terminology.
CONTEXT.md Documents config ownership and timing.
claudeSdkPipeline.ts Requires rebuild callback; removes dead APIs.
claudeSdkMessageRouter.ts Makes tool-owner resolver immutable.
claudeAgentSession.ts Centralizes SDK query startup and rebuilding.
architecture-analysis/ROADMAP.md Defines the consolidation roadmap.
architecture-analysis/README.md Indexes architecture reports.
architecture-analysis/C1-e2e-scenarios.md Documents C1 validation scenarios.
architecture-analysis/05-test-surface.md Analyzes testability.
architecture-analysis/04-responsibility-overlap.md Analyzes responsibility boundaries.
architecture-analysis/03-rematerializer-and-duplication.md Analyzes query-build duplication.
architecture-analysis/02-lifecycle-and-ownership.md Audits lifecycle ownership.
architecture-analysis/01-call-graph-and-closures.md Maps dependencies and callbacks.
architecture-analysis/00-SYNTHESIS.md Synthesizes architecture findings.

Review details

  • Files reviewed: 15/15 changed files
  • Comments generated: 6
  • Review effort level: Medium

Comment thread src/vs/platform/agentHost/node/claude/CONTEXT.md Outdated
Comment thread src/vs/platform/agentHost/node/claude/architecture-analysis/README.md Outdated
Comment thread src/vs/platform/agentHost/node/claude/claudeAgentSession.ts Outdated
Comment thread src/vs/platform/agentHost/node/claude/claudeAgentSession.ts
Comment thread src/vs/platform/agentHost/node/claude/claudeAgentSession.ts
Comment thread src/vs/platform/agentHost/test/node/claudeSdkPipeline.test.ts Outdated
Trim verbose JSDoc/comments to the VS Code 1-2 sentence guideline (_sdkStart, _startSdkQuery, _rebuildSdkQuery, the test-harness comment). Label CONTEXT.md M5 config-state as the C9 target and document today's interim _current* cache on the pipeline. Update the analysis README roadmap range to C1-C9.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TylerLeonhardt

Copy link
Copy Markdown
Member Author

Thanks — all 6 addressed in 1950d05:

  1. CONTEXT.md M5 (config-state) — relabeled as the C9 target state and documented the interim _currentModel / _currentEffort / _currentPermissionMode cache the pipeline still holds today, so it no longer contradicts the runtime.
  2. architecture-analysis/README.md — roadmap range updated to C1–C9.
  3. _sdkStart JSDoc — trimmed to one line (the field type conveys the rest).
  4. _startSdkQuery JSDoc — reduced to the contract.
  5. _rebuildSdkQuery JSDoc — reduced to the contract.
  6. claudeSdkPipeline.test.ts harness comment — condensed to one line.

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