[Bug]: ACP v2 plan replacements and removals lose their target between turns

未关闭
#35,827 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

Start with apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts; the issue provides a deterministic regression test that passes for same-turn operations and fails across turns. Trace how ACP v2 plan IDs and removals are handled across turns in the adapter, then run the focused test with the repository's Vite+ test runner. Done when replacements reuse the session plan ID and removals emit a superseded update across turn boundaries.

由索引模型根据 Issue 内容生成。

描述

vouch:denounced
Summary

An ACP agent cannot update or remove a previously reported plan after the next turn starts. T3 ignores the removal and creates another plan artifact for the replacement, leaving the earlier artifact unchanged. A deterministic adapter reproduction confirms that the same operations work within one turn and fail across turns.

Before submitting
  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.
Area

apps/server

Steps to reproduce
  1. Run the script below against the stated checkout with its lockfile dependencies installed.
  2. In the control turn, create, replace and remove a plan with ID control, then create plans later-remove and later-replace.
  3. In a second turn of the same session, send plan_removed for later-remove and a replacement plan_update for later-replace.
  4. Compare emitted plan.updated events across both turns.

The final portable reproduction returned RESULT: defect reproduced on its first run. An earlier focused adapter probe produced the same event counts and identity mismatch.

Save the following as repro-plan.sh and run sh repro-plan.sh /path/to/t3code. Prerequisites are Git, Python 3, Node compatible with the checkout, and the checkout’s installed lockfile dependencies including Vite+. The script prints tool versions, creates a disposable detached worktree and isolated HOME, TMPDIR and T3 state/cache directories, inserts one focused test into the existing adapter test fixture, and removes its worktree and inputs on exit. It launches only T3’s mock ACP peer. The control requires all three same-turn events to share one T3 plan ID, verifies that the replacement contains only the new entry, and verifies the removal becomes superseded. Exit 0 means expected behavior, 1 means the defect reproduced, and 2 means setup or the control was inconclusive.

Reproduction script: repro-plan.sh
#!/bin/sh
set -u
result=2
checkout=$(cd "${1:?Usage: sh repro.sh /path/to/t3code}" && pwd) || exit 2
scratch=$(mktemp -d) || exit 2
cleanup() {
  git -C "$checkout" worktree remove --force "$scratch/wt" >/dev/null 2>&1 || :
  rm -rf "$scratch"
}
trap cleanup EXIT HUP INT TERM
finish() {
  case "$1" in
    0) echo 'RESULT: expected behavior';;
    1) echo 'RESULT: defect reproduced';;
    *) echo 'RESULT: inconclusive';;
  esac
  exit "$1"
}
node --version || finish 2
python3 --version || finish 2
git --version || finish 2
"$checkout/node_modules/.bin/vp" --version || finish 2
git -C "$checkout" rev-parse HEAD || finish 2
mkdir -p "$scratch/home" "$scratch/tmp" "$scratch/state" || finish 2
export HOME="$scratch/home" TMPDIR="$scratch/tmp" T3CODE_HOME="$scratch/state"
export XDG_CACHE_HOME="$scratch/cache" XDG_CONFIG_HOME="$scratch/config"
export T3CODE_DEV_SEED=0
if ! git -C "$checkout" worktree add --detach "$scratch/wt" HEAD >"$scratch/setup.log" 2>&1; then finish 2; fi
cat > "$scratch/case.ts" <<'CASE'
  it.live("g08 plan replacement and removal survive turn boundaries", () =>
    Effect.gen(function* () {
      const instanceId = ProviderInstanceId.make("g08-plans");
      const threadId = ThreadId.make("g08-plans");
      let notify: Parameters<AcpSessionRuntime.AcpSessionRuntime["Service"]["handleSessionUpdate"]>[0];
      let ordinal = 0;
      const adapter = yield* makeAcpAdapterV2({
        instanceId,
        selfInvocation: yield* resolveSelfInvocation(),
        flavor: {
          driver: ACP_TEST_DRIVER,
          capabilities: AcpProviderCapabilitiesV2,
          makeRuntime: makeMockRuntime({
            childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
            mockAgentPath: yield* bundledMockAgentPath,
            wrapRuntime: (runtime) => ({
              ...runtime,
              handleSessionUpdate: (handler) => Effect.sync(() => { notify = handler; }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
              prompt: () => Effect.gen(function* () {
                ordinal++;
                const send = (update: EffectAcpSchema.SessionUpdate) => notify({ sessionId: "mock-session-1", update });
                const plan = (id: string, text: string) => send({ sessionUpdate: "plan_update", plan: { type: "items", planId: id, entries: [{ content: text, priority: "medium", status: "pending" }] } });
                yield* send({ sessionUpdate: "state_update", state: "running" });
                if (ordinal === 1) {
                  yield* plan("control", "First");
                  yield* plan("control", "Replacement");
                  yield* send({ sessionUpdate: "plan_removed", planId: "control" });
                  yield* plan("later-remove", "Remove on next turn");
                  yield* plan("later-replace", "Old contents");
                } else {
                  yield* send({ sessionUpdate: "plan_removed", planId: "later-remove" });
                  yield* plan("later-replace", "New contents");
                }
                yield* send({ sessionUpdate: "state_update", state: "idle", stopReason: "end_turn" });
                return { stopReason: "end_turn" as const };
              }),
            }),
          }),
        },
      });
      const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd() });
      const modelSelection = { instanceId, model: "default" } as const;
      const runtime = yield* adapter.openSession({ threadId, providerSessionId: ProviderSessionId.make("g08-plans"), modelSelection, runtimePolicy });
      const providerThread = yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });
      const now = yield* DateTime.now;
      const run = (ordinal: number) => Effect.gen(function* () {
        yield* runtime.startTurn(makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal }));
        return Array.from(yield* runtime.events.pipe(Stream.takeUntil((event) => event.type === "turn.terminal"), Stream.runCollect)).flatMap((event) => event.type === "plan.updated" ? [event.plan] : []);
      });
      const first = yield* run(1);
      assert.equal(first.length, 5);
      assert.equal(first[0]!.id, first[1]!.id);
      assert.equal(first[1]!.id, first[2]!.id);
      assert.equal(first[1]!.kind, "todo_list");
      assert.deepEqual(first[1]!.kind === "todo_list" ? first[1]!.steps.map((s) => s.text) : [], ["Replacement"]);
      assert.equal(first[2]!.status, "superseded");
      console.log("PLAN_CONTROL_OK same-turn replacement and removal");
      const second = yield* run(2);
      const removed = second.find((p) => p.id === first[3]!.id && p.status === "superseded");
      const replacement = second.find((p) => p.kind === "todo_list" && p.steps.some((s) => s.text === "New contents"));
      console.log("PLAN_OBSERVED", JSON.stringify({ firstTurnPlanEvents: first.length, secondTurnPlanEvents: second.length, removedPriorPlan: !!removed, reusedReplacedPlanId: replacement?.id === first[4]!.id }));
      assert.isDefined(removed, "plan_removed on a later turn must supersede the existing session plan");
      assert.equal(replacement?.id, first[4]!.id, "the same session plan must be replaced, not duplicated");
    }).pipe(Effect.provide(layerTest), Effect.scoped),
  );

CASE
python3 - "$checkout" "$scratch" <<'PYTHON'
from pathlib import Path
import os,sys
root=Path(sys.argv[1]); scratch=Path(sys.argv[2]); wt=scratch/'wt'
# Link dependencies individually so new runner caches stay in the disposable worktree.
for directory, dirs, files in os.walk(root):
    dirs[:]=[d for d in dirs if d not in ('.git','.repos','.t3')]
    if 'node_modules' not in dirs:
        continue
    dirs.remove('node_modules')
    nm=Path(directory)/'node_modules'; target=wt/nm.relative_to(root)
    target.mkdir(parents=True,exist_ok=True)
    for entry in nm.iterdir():
        (target/entry.name).symlink_to(entry,target_is_directory=entry.is_dir())
p=wt/'apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts'
s=p.read_text(); needle='  beforeAll(() => bundleAgents);'
if s.count(needle)!=1:
    raise RuntimeError('test fixture insertion point changed')
p.write_text(s.replace(needle,needle+'\n'+(scratch/'case.ts').read_text(),1))
PYTHON
if [ "$?" -ne 0 ]; then finish 2; fi
cd "$scratch/wt" || finish 2
node_modules/.bin/vp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts -t 'g08 plan' >"$scratch/test.log" 2>&1
status=$?
# The control must pass before a failing assertion can count as this defect.
python3 - "$scratch/test.log" <<'PYTHON'
import sys
for line in open(sys.argv[1]):
    if line.startswith(('PLAN_CONTROL_OK','PLAN_OBSERVED')):
        print(line.rstrip())
PYTHON
if ! grep -q 'PLAN_CONTROL_OK' "$scratch/test.log"; then finish 2; fi
if [ "$status" -eq 0 ]; then finish 0; fi
if grep -q 'plan_removed on a later turn must supersede' "$scratch/test.log"; then finish 1; fi
finish 2
Expected behavior

The same planId identifies one plan throughout an ACP session. A replacement must replace that plan’s contents, and plan_removed must target the previously reported plan regardless of a T3 turn boundary. The pinned upstream Agent Plan document, plan identity, removal, and replacement establish these contracts. The pinned schema, $defs.PlanId and $defs.PlanRemoved defines a session-scoped plan ID and the removal update; this does not rely on a later schema.

Actual behavior

The reproduction opens one ACP session, reports three identified plans during its first turn, then removes one plan and replaces another during the next turn. Same-turn replacement reuses the existing T3 plan ID, and same-turn removal emits superseded. Across turns, plan_removed emits no plan update, while the replacement is assigned a different T3 plan ID; the old artifacts receive no update.

Impact

Minor bug or occasional failure

Impact: P2 - Valid later-turn updates leave stale plan artifacts and duplicate plan identity in provider events, so consumers cannot maintain the agent’s current plan accurately.

The demonstrated scope is one still-open ACP v2 session across two user turns, with item-based plan content. Workaround: NOT_ENOUGH_INFO - no user-side workaround was tested. A real provider’s emission frequency and the appearance in web, desktop and mobile were not measured.

Version or commit

T3 Code commit 59e64eef881632a23f89c4138bcf37f23d92bf93. ACP wire version 2, pinned generated schema schema-v2.0.0-alpha.3. Repository dependencies were kept at their lockfile versions.

Environment

macOS 27.2, arm64; Node v26.12.1, Python 3.15.2, Git 2.56.0, Vite+ CLI 1.4.0, Vite+ test runner 5.0.5, Effect 4.1.3 from the checkout lockfile.

Logs or stack traces

The final script printed the following. No machine paths or private identifiers are included. The Vite+ CLI’s local-package lookup printed Not found from the invoking scratch directory; the actual focused test runner resolved and ran successfully, as established by the control and observation markers.

v26.12.1
Python 3.15.2
git version 2.56.0
vp v1.4.0

Local vite-plus:
  vite-plus  Not found

59e64eef881632a23f89c4138bcf37f23d92bf93
PLAN_CONTROL_OK same-turn replacement and removal
PLAN_OBSERVED {"firstTurnPlanEvents":5,"secondTurnPlanEvents":1,"removedPriorPlan":false,"reusedReplacedPlanId":false}
RESULT: defect reproduced

The runtime parser forwards identified plan updates and removals at packages/provider-acp/src/server/runtimeModel.ts#L1438-L1498. The adapter looks for a removal target only in context.plans and returns when absent at packages/provider-acp/src/server/adapter.ts#L4476-L4484; replacement allocates a fresh artifact when that map has no prior entry at packages/provider-acp/src/server/adapter.ts#L4488-L4504. Each new turn initializes plans: new Map() at packages/provider-acp/src/server/adapter.ts#L8376-L8381. These source paths explain the event stream observed through makeAcpAdapterV2 → openSession → ensureThread → startTurn.

Restoration check

The control remains green, later-turn removal updates the original plan to superseded, and later-turn replacement updates the original plan artifact without leaving its previous contents active.

Workaround

No user-side workaround was verified.

Additional interface context

API: ACP session/update, projected through the shared provider adapter into orchestration events.

Earliest failure stage: State or storage

主要语言
TypeScript
星标
24.8k
派生
6.4k
平均合并
59 分钟
30 天内合并 PR
418

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pingdotgg/t3code 的其他 Issue

查看 pingdotgg/t3code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。