ComputerAgent icon indicating copy to clipboard operation
ComputerAgent copied to clipboard

engine-gitagent: in-process multi-turn agent.chat() drops messages after turn 1

Open shreyas-lyzr opened this issue 6 months ago • 0 comments

Symptom

Two sequential `agent.chat()` calls on the same `ComputerAgent` instance, with `harness: "gitagent"`, produce a normal response on turn 1 and an empty response on turn 2.

Live repro against the real Anthropic API:

``` turn 1 → "Got it, your favorite number is 42!" turn 2 → "" ```

The same pattern works correctly for `harness: "claude-agent-sdk"` (issue #2 fix landed) — turn 2 reliably recalls the fact from turn 1.

Root cause

`gitclaw`'s `query()` is not streaming-input — it consumes one turn's worth of user input, emits the response, and the AsyncIterable terminates. The framework's user-message queue is left open (`streamingInput: true` is set by the SDK), but there's no consumer for new messages because the engine generator already returned.

The `engine-gitagent` source already acknowledges this in a comment at `packages/engine-gitagent/src/engine.ts:57`:

SessionStore replay: gitclaw has no native sessionStore parameter, so when one is configured we synthesize resume by loading prior turns and injecting them via systemPromptSuffix, then writing each new exchange back.

So gitagent does support multi-turn — but only via SessionStore, where each "turn" is a fresh `query()` call that rehydrates prior context from disk. The bridge that makes claude-agent-sdk's in-process multi-turn work (a single `query()` consuming a streaming user-message iterable) doesn't exist for gitclaw.

What works today

Pattern claude-agent-sdk gitagent
Multi-turn `agent.chat()` on one instance ✅ works ✗ turn 2 empty
Multi-turn via `runTask` + `sessionStore` + same `sessionId` ✅ works ✅ works
In-process multi-turn `agent.chat()` + `sessionStore` ✅ works partial (sessionStore writes are fine, but engine is dead after turn 1, so turn 2 never consumes the new message)

Live-validated against `LocalSubstrate` × `gitagent` × `{in-memory, file SessionStore}`. Cross-process resume passes; in-process multi-turn does not.

Options for a fix

  1. Internal loop in `engine-gitagent`: wrap `query()` in an outer `for await` over the user-message queue. Each new user message triggers a fresh `query()` with the prior turns folded into `systemPromptSuffix` (the resume path already does this). One `engine.startSession()` invocation handles arbitrarily many turns, exactly like claude-agent-sdk's streaming-input flow. Recommended — keeps the engine alive across turns without changing gitclaw.

  2. Surface engine capability: add `streamingInput: false` to gitagent's `EngineCapabilities` and have the SDK auto-route multi-turn through a fresh session per turn when the engine doesn't support streaming. Requires SDK changes.

  3. Document the limitation: tell users to use `runTask` + `sessionStore` for multi-turn with gitagent. Cheapest, but is a footgun — the failure is silent (empty response, not an error).

Option 1 is the right call IMO — it makes gitagent behaviorally indistinguishable from claude-agent-sdk for the in-process case, and the workaround is the same one we already implement for cross-process resume. Estimated diff: ~40 LOC in `engine-gitagent/src/engine.ts`, no protocol changes.

Definition of done

  • A failing test in `packages/engine-gitagent` that does two `chat()` calls on one agent and asserts both responses are distinct + non-empty.
  • Fix in `engine.ts` (option 1 above).
  • Existing `engine-gitagent` tests stay green (13 of them).
  • Integration test in `packages/sdk/src/computer-agent.test.ts` mirroring the existing claude-agent-sdk multi-turn test (line 161) but with `harness: "gitagent"`.

Severity

Medium — affects multi-turn UX with gitagent specifically. Workaround exists (one `runTask` per turn with `sessionStore`). But the failure mode is silent (empty response, no error), which is the worst kind of footgun. Two distinct GAP repos that target gitagent (`marketing-agent` and any future gitclaw-tuned agent) would hit this.

Related

  • #2 — multi-turn fix for claude-agent-sdk (landed, validates the SDK side of the contract; this issue is about closing the symmetric gap for the other engine).

shreyas-lyzr avatar May 15 '26 03:05 shreyas-lyzr