diff --git a/.coderabbit.yaml b/.coderabbit.yaml index c0562fd3f8..48161fa057 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -48,17 +48,19 @@ reviews: instructions: >- Act as an adversarial second-opinion reviewer. Verify PR claims against implementation and contracts. Trace changed inputs through normal, boundary, error, cancellation, retry, and - default paths and their consumers. Seek plausible counterexamples and regressions from removed - safeguards. Identify assumptions in changed code that depend on facts outside the diff. First - verify repository conventions, tests, and related implementations. When a potential finding - depends on external behavior, use web search and prefer official documentation, specifications, - or upstream repositories. Report only concrete, actionable conflicts or failure modes, citing - the relevant repository location or external source. Prioritize correctness, security, data loss, - lifecycle, and test gaps. Do not report generic best practices, unsupported concerns, speculative - style comments, or unrelated refactors. When changed code introduces a local implementation of a - cross-cutting concern, check whether it bypasses or duplicates an established repository abstraction - or nearby convention. Report only a concrete inconsistency with behavioral or maintenance impact, - and allow intentional deviations. + default paths and their direct test counterparts. Do not flag defects in files not changed by + this PR unless the defect is directly triggered by changed code and cannot be detected in the + changed file alone. Seek plausible counterexamples and regressions from removed safeguards. + Identify assumptions in changed code that depend on facts outside the diff. First verify + repository conventions, tests, and related implementations. When a potential finding depends on + external behavior, use web search and prefer official documentation, specifications, or upstream + repositories. Report only concrete, actionable conflicts or failure modes, citing the relevant + repository location or external source. Prioritize correctness, security, data loss, lifecycle, + and test gaps. Do not report generic best practices, unsupported concerns, speculative style + comments, or unrelated refactors. When changed code introduces a local implementation of a + cross-cutting concern, check whether it bypasses or duplicates an established repository + abstraction or nearby convention. Report only a concrete inconsistency with behavioral or + maintenance impact, and allow intentional deviations. - path: "**/*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}" instructions: >- diff --git a/.github/workflows/code-qa.yml b/.github/workflows/code-qa.yml index abb344dbd5..79b7b45a28 100644 --- a/.github/workflows/code-qa.yml +++ b/.github/workflows/code-qa.yml @@ -90,6 +90,8 @@ jobs: run: pnpm lint - name: Check types run: pnpm check-types + - name: Validate Code QA workflow + run: pnpm test:code-qa-ci - name: Model-check task lifecycle protocols run: pnpm lifecycle:model-check - name: Validate MCP OAuth integration @@ -135,11 +137,11 @@ jobs: - os: ubuntu-latest name: ubuntu-latest codecov-flag: ubuntu - upload-coverage: true + collect-coverage: true - os: windows-latest name: windows-latest codecov-flag: windows - upload-coverage: false + collect-coverage: false steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -154,25 +156,56 @@ jobs: restore-keys: | ${{ runner.os }}-turbo-${{ hashFiles('**/pnpm-lock.yaml') }}- ${{ runner.os }}-turbo- + # Windows never uploads coverage, so Windows runs the same test + # suites through the uninstrumented Turbo tasks. Ubuntu stays the + # authoritative coverage lane. - name: Run non-extension package coverage + if: matrix.collect-coverage run: pnpm turbo run test:coverage --filter="!@roo-code/core" --filter="!zoo-code" --log-order grouped --output-logs new-only + - name: Run non-extension package tests + if: ${{ !matrix.collect-coverage }} + run: pnpm turbo run test --filter="!@roo-code/core" --filter="!zoo-code" --log-order grouped --output-logs new-only - name: Run extension coverage lanes + if: matrix.collect-coverage run: pnpm turbo run test:coverage:api test:coverage:core test:coverage:services test:coverage:misc test:coverage:tree-sitter --filter="zoo-code" --concurrency=2 --log-order grouped --output-logs new-only + - name: Run extension test lanes + if: ${{ !matrix.collect-coverage }} + run: pnpm turbo run test:api test:core test:services test:misc test:tree-sitter --filter="zoo-code" --concurrency=2 --log-order grouped --output-logs new-only - name: Verify extension coverage contract + if: matrix.collect-coverage run: pnpm --dir src run verify:coverage-contract - name: Run extension dist smoke test run: pnpm turbo run test:dist --filter="zoo-code" --log-order grouped --output-logs new-only - name: Run core unit coverage + if: matrix.collect-coverage run: pnpm turbo run test:coverage:unit --filter="@roo-code/core" --log-order grouped --output-logs new-only + - name: Run core unit tests + if: ${{ !matrix.collect-coverage }} + run: pnpm turbo run test:unit --filter="@roo-code/core" --log-order grouped --output-logs new-only - name: Run core integration coverage + if: matrix.collect-coverage run: pnpm turbo run test:coverage:integration --filter="@roo-code/core" --log-order grouped --output-logs new-only + - name: Run core integration tests + if: ${{ !matrix.collect-coverage }} + run: pnpm turbo run test:integration --filter="@roo-code/core" --log-order grouped --output-logs new-only - name: Verify extension coverage reports + if: matrix.collect-coverage run: | node src/scripts/verify-lcov.mjs src/coverage/api/lcov.info node src/scripts/verify-lcov.mjs src/coverage/core/lcov.info node src/scripts/verify-lcov.mjs src/coverage/services/lcov.info node src/scripts/verify-lcov.mjs src/coverage/misc/lcov.info node src/scripts/verify-lcov.mjs src/coverage/tree-sitter/lcov.info + - name: Merge extension coverage reports + if: matrix.collect-coverage + run: | + mkdir -p src/coverage/merged + pnpm --dir src run merge:coverage + node src/scripts/verify-lcov.mjs src/coverage/merged/lcov.info + # Validate cache boundaries before publishing any new Turbo entries. + - name: Verify coverage cache inputs + if: matrix.collect-coverage + run: pnpm --dir src run verify:coverage-cache-inputs - name: Save Turbo cache if: steps.turbo-cache.outputs.cache-hit != 'true' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -184,21 +217,16 @@ jobs: # there mostly adds Codecov overhead without changing pass/fail # behavior. # Coverage is uploaded in separate steps so each LCOV gets the - # correct flag set. Codecov double-counts overlapping lines when a - # single upload carries multiple flags whose paths overlap, so the - # core lanes and webview lane must be uploaded individually with - # their own flag. + # correct flag set. Extension lanes instrument the same sources, so + # union them before upload; a line is covered when any lane executes + # it. Core and webview reports retain their independent flags. # See https://docs.codecov.com/docs/flags - name: Upload non-core coverage to Codecov - if: matrix.upload-coverage + if: matrix.collect-coverage uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: files: >- - src/coverage/api/lcov.info, - src/coverage/core/lcov.info, - src/coverage/services/lcov.info, - src/coverage/misc/lcov.info, - src/coverage/tree-sitter/lcov.info, + src/coverage/merged/lcov.info, packages/cloud/coverage/lcov.info, packages/telemetry/coverage/lcov.info, apps/cli/coverage/lcov.info @@ -206,7 +234,7 @@ jobs: flags: ${{ matrix.codecov-flag }} token: ${{ secrets.CODECOV_TOKEN }} - name: Upload webview JSDOM coverage to Codecov - if: matrix.upload-coverage + if: matrix.collect-coverage uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: files: webview-ui/coverage/lcov.info @@ -214,7 +242,7 @@ jobs: flags: webview-ui token: ${{ secrets.CODECOV_TOKEN }} - name: Upload core unit coverage to Codecov - if: matrix.upload-coverage + if: matrix.collect-coverage uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: files: packages/core/coverage/unit/lcov.info @@ -222,7 +250,7 @@ jobs: flags: ${{ matrix.codecov-flag }},core-unit token: ${{ secrets.CODECOV_TOKEN }} - name: Upload core integration coverage to Codecov - if: matrix.upload-coverage + if: matrix.collect-coverage uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: files: packages/core/coverage/integration/lcov.info @@ -230,7 +258,7 @@ jobs: flags: ${{ matrix.codecov-flag }},core-integration token: ${{ secrets.CODECOV_TOKEN }} - name: Upload coverage reports to GitHub - if: matrix.upload-coverage + if: matrix.collect-coverage uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: coverage-reports-${{ matrix.name }} @@ -240,6 +268,7 @@ jobs: src/coverage/services/lcov.info src/coverage/misc/lcov.info src/coverage/tree-sitter/lcov.info + src/coverage/merged/lcov.info webview-ui/coverage/lcov.info packages/cloud/coverage/lcov.info packages/telemetry/coverage/lcov.info diff --git a/.github/workflows/label-pr-review-state.yml b/.github/workflows/label-pr-review-state.yml index 0df64ffd2b..98f7428c7a 100644 --- a/.github/workflows/label-pr-review-state.yml +++ b/.github/workflows/label-pr-review-state.yml @@ -14,7 +14,7 @@ on: # This workflow only reads PR metadata and never checks out or executes PR code. # pull_request_target gives fork PRs a token that can update labels and comments. pull_request_target: - types: [opened, reopened, ready_for_review, synchronize, review_requested, labeled, unlabeled] + types: [opened, reopened, ready_for_review, synchronize, review_requested, review_request_removed, labeled, unlabeled] pull_request_review: types: [submitted, dismissed] # Fork review events have a read-only token. CodeRabbit's status-comment update @@ -316,14 +316,24 @@ jobs: return match?.[1] ?? null; } + // Collaborator permissions are repository-level, so memoize them for + // the whole run: a maintainer's current-head CHANGES_REQUESTED reaches + // both review loops, and scheduled sweeps reconcile every open PR. + const permissionCache = new Map(); async function permissionFor(username) { + const key = username.toLowerCase(); + if (permissionCache.has(key)) return permissionCache.get(key); try { const result = await github.rest.repos.getCollaboratorPermissionLevel({ owner, repo, username, }); + permissionCache.set(key, result.data.permission); return result.data.permission; } catch (error) { - if (error.status === 404) return 'none'; + if (error.status === 404) { + permissionCache.set(key, 'none'); + return 'none'; + } throw error; } } @@ -339,7 +349,7 @@ jobs: 'coderabbit-changes': 'Address automated review findings and push fixes.', coderabbit: 'Required CI passed. Waiting for automated review of the latest commit.', 'draft-approved': 'Automated review complete for the latest commit. Mark the draft ready.', - 'maintainer-changes': 'Address maintainer or CODEOWNER feedback, then push an update.', + 'maintainer-changes': 'Address maintainer or CODEOWNER feedback, push an update, then re-request review from the blocking maintainer.', maintainer: 'Awaiting fresh human maintainer or CODEOWNER approval.', approved: 'The required review sequence passed. Remaining merge requirements apply.', }; @@ -641,6 +651,81 @@ jobs: } } + // Durable per-maintainer change-request blockers (issue #1671). + // Unlike approvals and CodeRabbit reviews, a human maintainer's + // CHANGES_REQUESTED stays binding across author pushes, base-branch + // merges, CI runs, and CodeRabbit reviews until that same + // maintainer's blocker is cleared by one of: + // 1. the PR author explicitly re-requesting review from them, + // 2. a newer review from that maintainer (its state decides), or + // 3. GitHub dismissing the blocking review. + // Latest state per reviewer is keyed by review id (monotonically + // increasing) so reordered or duplicate history cannot change the + // result. COMMENTED reviews are neutral and never clear a blocker; + // a DISMISSED latest review clears it. + const latestHumanReview = new Map(); + for (const r of reviews) { + const reviewer = r.user?.login?.toLowerCase(); + if (!reviewer || + r.user?.type === 'Bot' || + codeRabbitLogins.has(reviewer) || + reviewer === pr.user?.login?.toLowerCase() || + r.state === 'COMMENTED') { + continue; + } + const previous = latestHumanReview.get(reviewer); + if (!previous || r.id > previous.id) { + latestHumanReview.set(reviewer, r); + } + } + const maintainerBlockers = new Map(); + for (const [reviewer, review] of latestHumanReview) { + if (review.state !== 'CHANGES_REQUESTED') continue; + if (['admin', 'maintain', 'write'].includes(await permissionFor(review.user.login))) { + maintainerBlockers.set(reviewer, review); + } + } + + // Clear blockers the author explicitly re-requested. Only a + // review_requested timeline event whose actor is the PR author and + // whose requested reviewer is the blocking maintainer clears that + // maintainer's blocker. Team requests carry no requested_reviewer + // and never clear an individual blocker; review_request_removed + // events only trigger reconciliation and are not clearing evidence. + // If the timeline cannot be reconstructed, fail closed: keep every + // blocker so awaiting-author is preserved. + if (maintainerBlockers.size > 0) { + let timelineEvents = null; + try { + timelineEvents = await github.paginate(github.rest.issues.listEventsForTimeline, { + owner, repo, issue_number: pr.number, per_page: 100, + }); + } catch (error) { + core.warning( + `PR #${pr.number}: could not reconstruct review-request history; ` + + `preserving maintainer blockers: ${error.message}` + ); + } + if (timelineEvents) { + const authorLogin = pr.user?.login?.toLowerCase(); + for (const event of timelineEvents) { + if (event.event !== 'review_requested') continue; + if (event.actor?.login?.toLowerCase() !== authorLogin) continue; + const requested = event.requested_reviewer?.login?.toLowerCase(); + if (!requested) continue; + const blocker = maintainerBlockers.get(requested); + if (!blocker) continue; + const requestedAt = Date.parse(event.created_at ?? ''); + const blockedAt = Date.parse(blocker.submitted_at ?? ''); + // A re-request only clears blockers it follows; missing or + // unparsable timestamps fail closed and keep the blocker. + if (!Number.isNaN(requestedAt) && !Number.isNaN(blockedAt) && requestedAt >= blockedAt) { + maintainerBlockers.delete(requested); + } + } + } + } + const codeRabbitReview = latest.get(codeRabbitLogin); const freshCodeRabbitReview = codeRabbitReview?.commit_id === pr.head.sha ? codeRabbitReview @@ -657,9 +742,6 @@ jobs: freshMaintainerReviews.push(review); } } - const maintainerChangeRequest = freshMaintainerReviews.find( - review => review.state === 'CHANGES_REQUESTED' - ); const automatedAuthor = pr.user?.type === 'Bot'; const codeRabbitEligibleAuthor = !automatedAuthor || codeRabbitEligibleBotLogins.has(pr.user?.login.toLowerCase()); @@ -676,7 +758,7 @@ jobs: let phase; let activateCodeRabbit = false; let recycleCodeRabbitLabel = false; - if (codeRabbitChangesRequested || maintainerChangeRequest) { + if (codeRabbitChangesRequested || maintainerBlockers.size > 0) { desiredLabel = 'awaiting-author'; phase = codeRabbitChangesRequested ? 'coderabbit-changes' : 'maintainer-changes'; } else if (!codeRabbitEligibleAuthor) { @@ -740,7 +822,7 @@ jobs: core.info( `PR #${pr.number}: CI passing, reviews=${latest.size}, ` + `coderabbit=${freshCodeRabbitReview?.state ?? (codeRabbitEligibleAuthor ? 'pending' : 'optional')}, ` + - `maintainer=${maintainerApproval?.state ?? 'pending'} → ${desiredLabel ?? '(none)'}` + `maintainer=${maintainerApproval?.state ?? 'pending'}, blockers=${maintainerBlockers.size} → ${desiredLabel ?? '(none)'}` ); const readyForMaintainer = phase === 'maintainer' || phase === 'approved'; diff --git a/.github/workflows/mutation-testing.yml b/.github/workflows/mutation-testing.yml index 9e0987fbd5..2da0c5c5b4 100644 --- a/.github/workflows/mutation-testing.yml +++ b/.github/workflows/mutation-testing.yml @@ -36,13 +36,6 @@ jobs: fetch-depth: 0 persist-credentials: false - - name: Fetch pull request base - if: github.event_name == 'pull_request' - env: - BASE_REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}.git - BASE_SHA: ${{ github.event.pull_request.base.sha }} - run: git fetch --no-tags "$BASE_REPOSITORY_URL" "$BASE_SHA" - - name: Setup Node.js and pnpm if: github.event_name == 'pull_request' uses: ./.github/actions/setup-node-pnpm @@ -56,9 +49,10 @@ jobs: - name: Enforce executable-line scope and run advisory mutation testing if: github.event_name == 'pull_request' env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.sha }} - run: node scripts/stryker-diff.mjs ci --base "$BASE_SHA" --head "$HEAD_SHA" + run: | + BASE_SHA="$(git rev-parse "$HEAD_SHA^1")" + node scripts/stryker-diff.mjs ci --base "$BASE_SHA" --head "$HEAD_SHA" - name: Upload mutation reports id: mutation_report diff --git a/.github/workflows/release-reminder.yml b/.github/workflows/release-reminder.yml index 6f5b6b8ea6..1e384ee834 100644 --- a/.github/workflows/release-reminder.yml +++ b/.github/workflows/release-reminder.yml @@ -26,7 +26,7 @@ jobs: DISCORD_RELEASE_WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }} run: | set -euo pipefail - owners=("Elliott" "Navad" "Toray") + owners=("Elliott" "James" "Toray") anchor_date="2026-07-17" seconds_since_anchor=$(($(date -u +%s) - $(date -u -d "$anchor_date" +%s))) weeks_since_anchor=$((seconds_since_anchor / 604800)) diff --git a/CHANGELOG.md b/CHANGELOG.md index 978efd867a..4b16bfb62f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Zoo Code Changelog +## [3.82.2] + +### Patch Changes + +- Prevent unavailable tools from appearing in system prompts (#505 by @DScoNOIZ, #1240 by @JunyongParkDev, PR #1505 by @DaubnerF) +- Fix DeepSeek Flash image input by adding the new deepseek-flash model ID (PR #1618 by @app/zoomote) +- Fix token usage tracking for Grok and xAI-compatible endpoints whose domains contain "x.ai" (#1483 by @BambinoSK, PR #1484 by @BambinoSK) +- Apply the configured reasoning effort consistently across OpenAI-compatible requests (#993 by @Gringo675, PR #1604 by @JunyongParkDev) +- Preserve the configured LiteLLM model ID in the model picker (#1367 by @easonLiangWorldedtech, PR #1368 by @easonLiangWorldedtech) +- Fix delegated subtasks reading the parent mode in environment details and tool validation (#1623 by @edelauna, PR #1625 by @edelauna) +- Add a file version token to the guarded-write path to prevent stale overwrites (PR #1383 by @easonLiangWorldedtech) +- Extract the code-index manager registry for clearer ownership (PR #1622 by @WebMad) +- Route Roomote pull requests through the CodeRabbit review path (PR #1598 by @app/zoomote) +- Make mutation-testing findings advisory instead of blocking (PR #1610 by @app/zoomote) +- Group mutation warnings by source location to remove duplicate warnings (PR #1619 by @app/zoomote) +- Skip mutation testing while pull requests are in draft (PR #1645 by @app/zoomote) +- Scope the mutation diff against the exact merge base so unrelated changes on main stop inflating the scope (PR #1655 by @app/zoomote) +- Model test bundle dependencies in Turbo so caching stays correct (#114 by @edelauna, PR #1611 by @app/zoomote) +- Separate extension unit tests from bundle smoke tests (PR #1614 by @app/zoomote) +- Move extension source coverage to cacheable test lanes (#118 by @edelauna, PR #1620 by @app/zoomote) +- Cache extension coverage by ownership lanes (#115 by @edelauna, PR #1631 by @app/zoomote) +- Keep coverage caches valid when only verification scripts change (PR #1649 by @app/zoomote) +- Union ownership-lane coverage reports before uploading to Codecov (#1647 by @DaubnerF, PR #1650 by @app/zoomote) +- Validate coverage lanes dynamically in the merge queue (PR #1644 by @app/zoomote) +- Stabilize the accessibility contrast audit during theme changes (#1612 by @edelauna, PR #1613 by @app/zoomote) +- Make CodeRabbit completeness checks advisory (PR #1621 by @app/zoomote) + ## [3.82.1] ### Patch Changes diff --git a/apps/cli/package.json b/apps/cli/package.json index 7e0b78827d..6e769ebb72 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -48,6 +48,6 @@ "rimraf": "6.0.1", "tsup": "8.5.1", "tsx": "4.22.4", - "vitest": "4.1.9" + "vitest": "4.1.11" } } diff --git a/apps/vscode-e2e/src/suite/restart-persistence.test.ts b/apps/vscode-e2e/src/suite/restart-persistence.test.ts index 4778b05857..699b64e9cc 100644 --- a/apps/vscode-e2e/src/suite/restart-persistence.test.ts +++ b/apps/vscode-e2e/src/suite/restart-persistence.test.ts @@ -25,6 +25,16 @@ async function quitGracefully(): Promise { await vscode.commands.executeCommand("workbench.action.quit") } +async function waitForMarkedCompletion(api: RooCodeAPI, taskId: string): Promise { + await waitFor(() => + api.hasTaskApiConversationHistorySequence(taskId, { + userText: "RESTART_PERSISTENCE_SMOKE", + assistantToolName: "attempt_completion", + assistantToolInputText: MARKER, + }), + ) +} + async function runCreate(api: RooCodeAPI): Promise { let taskId: string | undefined let createPhasePassed = false @@ -86,16 +96,7 @@ async function runVerify(api: RooCodeAPI): Promise { const historyItem = await api.getTaskHistoryItem(taskId) assert.ok(historyItem, "Task history item should be available after restart") assert.ok(historyItem.task.includes("RESTART_PERSISTENCE_SMOKE"), "History title should persist after restart") - const restoredCompletion = await api.hasTaskApiConversationHistorySequence(taskId, { - userText: "RESTART_PERSISTENCE_SMOKE", - assistantToolName: "attempt_completion", - assistantToolInputText: MARKER, - }) - assert.strictEqual( - restoredCompletion, - true, - "Fresh-host history should restore the marked user turn followed by its assistant completion", - ) + await waitForMarkedCompletion(api, taskId) await api.resumeTask(taskId) await waitFor(() => taskMessages.some(({ type, ask }) => type === "ask" && ask === "resume_completed_task")) @@ -106,16 +107,7 @@ async function runVerify(api: RooCodeAPI): Promise { reopenedHistoryItem.task.includes("RESTART_PERSISTENCE_SMOKE"), "Reopened task should retain its persisted history title", ) - const reopenedCompletion = await api.hasTaskApiConversationHistorySequence(taskId, { - userText: "RESTART_PERSISTENCE_SMOKE", - assistantToolName: "attempt_completion", - assistantToolInputText: MARKER, - }) - assert.strictEqual( - reopenedCompletion, - true, - "Reopened-host history should restore the marked user turn followed by its assistant completion", - ) + await waitForMarkedCompletion(api, taskId) await writePhaseResult(getResultsDir(), { version: PHASE_RESULT_VERSION, diff --git a/apps/vscode-e2e/src/visual/__screenshots__/electron-chat-dark-sidebar.png b/apps/vscode-e2e/src/visual/__screenshots__/electron-chat-dark-sidebar.png index cb69da51e5..e8497070ef 100644 Binary files a/apps/vscode-e2e/src/visual/__screenshots__/electron-chat-dark-sidebar.png and b/apps/vscode-e2e/src/visual/__screenshots__/electron-chat-dark-sidebar.png differ diff --git a/apps/vscode-e2e/src/visual/electron.visual.ts b/apps/vscode-e2e/src/visual/electron.visual.ts index 8d4072ea7b..d8db7ebec5 100644 --- a/apps/vscode-e2e/src/visual/electron.visual.ts +++ b/apps/vscode-e2e/src/visual/electron.visual.ts @@ -238,7 +238,16 @@ for (const scenario of scenarios) { const sidebar = running.page.locator(".part.sidebar") await expect(sidebar).toBeVisible() - await expect(sidebar).toHaveScreenshot(`electron-${scenario.name}-sidebar.png`) + + // Mask the dynamic token counter so system-prompt changes that alter + // token counts do not cause pixel diffs when layout is unchanged. + const webviewFrame = running.page.frameLocator('iframe[src*="extensionId=ZooCodeOrganization.zoo-code"]') + const tokenCountMask = webviewFrame + .frameLocator("iframe") + .locator('[data-testid="context-tokens-count"],[data-testid="context-window-size"]') + await expect(sidebar).toHaveScreenshot(`electron-${scenario.name}-sidebar.png`, { + mask: [tokenCountMask], + }) if (scenario.webviewSnapshot) { const webview = running.page.locator('iframe[src*="extensionId=ZooCodeOrganization.zoo-code"]') diff --git a/docs/architecture/native-tool-call-parser-scoping-model.md b/docs/architecture/native-tool-call-parser-scoping-model.md index ba7fbedd29..6533b8038f 100644 --- a/docs/architecture/native-tool-call-parser-scoping-model.md +++ b/docs/architecture/native-tool-call-parser-scoping-model.md @@ -12,7 +12,7 @@ For focused debugging, run this submodel directly with: pnpm parser-scope:model-check ``` -The command is composed into the same verification suite, but this remains a separate protocol and state space from the persisted task lifecycle model and shared-store concurrency model. It owns its parser-scoping invariants and adds no parser state to `HistoryItem` or `taskLifecycle.ts`; instead, it replays the public production `NativeToolCallParser` APIs using two independent scope objects. +The command runs this check sequentially with the other lifecycle checks, but this remains a separate protocol and state space from the persisted task lifecycle model and shared-store concurrency model. It owns its parser-scoping invariants and adds no parser state to `HistoryItem` or `taskLifecycle.ts`; instead, it replays the public production `NativeToolCallParser` APIs using two independent scope objects. The authoritative [lifecycle coverage audit and issue tracker](./task-lifecycle-model.md#coverage-audit) records its evidence class and cross-model limits. ## Bounds and replay diff --git a/docs/architecture/task-cleanup-protocol-model.md b/docs/architecture/task-cleanup-protocol-model.md index e46991365b..bd401ff159 100644 --- a/docs/architecture/task-cleanup-protocol-model.md +++ b/docs/architecture/task-cleanup-protocol-model.md @@ -14,6 +14,8 @@ pnpm cleanup-protocol:model-check This is a separate child model from the persisted task lifecycle and shared-store concurrency models. It follows the native tool-call parser model pattern: keep an independent bounded state space for an independent protocol, require every action and semantic landmark to remain reachable, and connect the abstract claims to focused production tests. +The authoritative [lifecycle coverage audit and issue tracker](./task-lifecycle-model.md#coverage-audit) classifies how this abstract model relates to production and other submodels. + ## Bounds and environment actions The model uses two tasks and explores every reachable interleaving through depth 20, with an explicit 100,000-state budget. Abort, disposal, final-save, provider abort/drain phases, and shutdown-cursor state are modeled directly. Independent abort and disposal calls may interleave freely, while provider-initiated calls are gated to the current shutdown task. Cleanup and editor-reversion settlement or rejection are environment actions, so the explorer does not assume they eventually occur. diff --git a/docs/architecture/task-lifecycle-gap-report.md b/docs/architecture/task-lifecycle-gap-report.md new file mode 100644 index 0000000000..66db3eb608 --- /dev/null +++ b/docs/architecture/task-lifecycle-gap-report.md @@ -0,0 +1,334 @@ +# Task lifecycle verification GAP report + +## Purpose and scope + +This report inventories Zoo Code task lifecycle state, mutation, persistence, scheduling, streaming, event, and verification boundaries. It is a documentation and formal-model audit, not a claim that the listed production gaps are fixed. + +The audit covers tracked TypeScript, JSON, YAML, and Markdown under `packages/`, `src/`, `apps/cli`, `apps/vscode-e2e`, `scripts/`, `.github/workflows`, and `docs/architecture`. It traces production symbols to bounded models, focused tests, extension-host E2E, and CI entry points. + +“Exhaustive” means exhaustive over the repository paths, symbol families, and search terms listed here at the audited commit. It does not include ignored/generated output, deployment branch-protection settings, runtime telemetry, dynamically constructed names that evade text search, or behavior in dependencies. GitHub issue links are historical provenance only; stable `LIFE-GAP-*` IDs own the active burn-down. + +## Methodology and audit criteria + +The inventory used structural searches for status and lineage fields, lifecycle reducers, store mutations, registry/stack operations, scheduler/semaphore queues, task start/resume/abort/dispose paths, persistence retries, stream scopes, lifecycle events, webview/API/IPC ingress, copied unions, tests, scripts, and workflow commands. Each claim was then classified by whether the checker executes production code or a model-authored proxy. + +Primary references define the audit criteria: + +- Lamport’s [High-Level View of TLA+](https://lamport.azurewebsites.net/tla/high-level-view.html) defines behavior as state sequences, distinguishes invariants from liveness, and explains that fairness is needed for steps that must eventually occur. Repository criterion: a safety explorer must not claim eventual cleanup, progress, retry, or completion without explicit temporal/fairness semantics. +- Quint’s [model-checker documentation](https://quint-lang.org/docs/model-checkers) states that model checking verifies properties of the model and that bounded checking is tied to a maximum execution length. Repository criterion: every pass claim names its state/depth/task/retry bounds and does not imply unbounded production correctness. +- Quint’s [model-based testing guidance](https://quint-lang.org/docs/model-based-testing) explicitly separates “the design is right” from “the implementation matches the design” and recommends replaying model traces or validating production traces. Repository criterion: model-authored transitions are proxy evidence until a production adapter, generated trace driver, or trace validator connects them to code. +- The [Alloy file-system tutorial](https://alloytools.org/tutorials/online/maintext-FS-1.html) states that “no solution found” guarantees only the selected finite scope and warns that facts can overconstrain away examples. Repository criterion: semantic landmarks and action reachability are required alongside invariants, and finite scope is always disclosed. +- Jepsen’s [consistency reference](https://jepsen.io/consistency) defines a consistency model as the set of legal histories. Repository criterion: cross-host claims must state which histories, conflicts, and dependencies are allowed, not merely that a mutex exists. +- SQLite’s [transactional guarantee](https://www.sqlite.org/transactional.html) ties crash atomicity to explicit crash and power-failure simulation. Repository criterion: Zoo Code’s per-file smoke tests cannot support crash-atomic or power-loss claims without an equivalent failure-injection harness. + +Evidence classes used below: + +| Class | Meaning | +| ------------------------- | ------------------------------------------------------------------------------------------ | +| Production-backed bounded | The checker executes production functions for every state/schedule within declared bounds. | +| Abstract bounded | The checker exhausts model-authored transitions; production refinement is separate. | +| Focused production test | A deterministic production path is exercised, but not all model interleavings. | +| E2E witness | A real extension-host boundary is exercised for one controlled history. | +| Proxy-only | The check demonstrates a premise or analogous mechanism, not the production claim. | +| Known-unsafe witness | CI preserves a reproducible violating history; a pass confirms the witness still exists. | +| Unmodeled | No executable property currently covers the boundary. | + +## Exhaustive lifecycle inventory + +### State owners + +| Owner | State | Primary symbols | Authority boundary | +| -------------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | +| Persisted history schema | Status, lineage, completion summary, pending action, accounting | `packages/types/src/history.ts`: `historyItemSchema`, `pendingTaskActionSchema` | Restart-visible record shape; optional status normalizes to active in lifecycle code. | +| Lifecycle reducers | Legal persisted transitions and parent-child ownership | `src/core/task-persistence/taskLifecycle.ts`: `delegateTaskToChild`, `interruptDelegatedChild`, `completeDelegatedChild`, `abandonDelegatedChild` | Pure transition authority when inputs are authoritative. | +| History store | Per-task files, cache, deltas, reconciliation, migration, repair | `src/core/task-persistence/TaskHistoryStore.ts`; `taskStoreConcurrency.ts` | Per-task files are authoritative; each extension host has an independent cache. | +| Live task | Abort/dispose, ask state, run ownership, mode/profile, streaming, message and completion readiness | `src/core/task/Task.ts` | Process-local execution state; not equivalent to persisted status. | +| Task registry | Live instances, compatibility stack, current focus | `src/core/task/TaskRegistry.ts` | Focus/publication owner; not scheduler admission or persisted lineage. | +| Provider | Transition queues, current task, registry integration, persistence orchestration, event forwarding | `src/core/webview/ClineProvider.ts` | Coordinates layers but does not make them one transaction. | +| Scheduler/semaphore | Waiting, admission, held permits, cancellation, release | `src/core/task/TaskScheduler.ts`; `src/utils/TaskSemaphore.ts` | Provider-local execution gate; default capacity is one. | +| Message queue | Queued user feedback and claims | `src/core/message-queue/MessageQueueService.ts` | Memory-only; disposal clears membership and claims. | +| Parser scope | Raw-index and tool-ID accumulators | `src/core/assistant-message/NativeToolCallParser.ts` | Request-scope parser state; transport and Task caller protocol are separate. | +| Event surfaces | Task, provider, public API, IPC, and webview lifecycle notifications | `packages/types/src/task.ts`, `events.ts`, `ipc.ts`; `src/extension/api.ts` | Related but non-identical payload and settlement contracts. | +| Tool-originated task state | Child initialization, approvals, partial calls, results, pending actions, and replay identity | `BaseTool`, `NewTaskTool`, `UpdateTodoListTool`, `AttemptCompletionTool`, `presentAssistantMessage`, `Task.todoList` | Ownership spans request, call, task, provider, message, and persisted-history scopes. | + +### Persisted lifecycle vocabulary and mutations + +Persisted statuses are `active`, `completed`, `delegated`, and `interrupted`. `VALID_TASK_STATUS_TRANSITIONS` permits active to delegated/completed/interrupted, delegated to active, interrupted to completed, and no transition from completed. Lineage fields are `rootTaskId`, `parentTaskId`, `delegatedToId`, `childIds`, `awaitingChildId`, `completedByChildId`, `completionResultSummary`, and `pendingAction`. + +| Mutation boundary | Production symbols | Modeled/tested evidence | Not covered by that evidence | +| --------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------- | +| Ordinary upsert | `TaskHistoryStore.upsert`, `upsertCore`, `writeTaskFile` | Store unit/cross-instance tests; shared-store delta model | Arbitrary process count, crashes, lock staleness, malicious/malformed records. | +| Single-record atomic update | `atomicReadAndUpdate` | Provider delegation tests; host-local lock abstraction | Cross-host compare-and-swap ownership. | +| Pair update | `atomicUpdatePair` | Pair-order/failure model and tests | Cross-host or crash atomicity; second-write failure can expose committed prefix. | +| Reconciliation | `reconcile`, `reconcileDelegationState` | Reconciliation tests | Immediate convergence, watcher delivery, concurrent repair histories. | +| Journaled repair | `repairActiveDelegation`, `replayDelegationRepairIntent` | Repair/restart tests | Other pair operations have no WAL/intent record. | +| Legacy migration/import | `migrateFromGlobalState`, `importRooTaskHistory` | Migration/import tests | Unified validation policy across generic store and importer. | +| Deletion | `delete`, `deleteMany`, `ClineProvider.deleteTaskWithId` | Focused deletion tests | Atomic history/checkpoint/directory deletion; unlink failures are best effort. | +| Live message save | `Task.saveClineMessages`, `taskMetadata`, `ClineProvider.updateTaskHistory` | Persistence tests; known stale-save witness | Disk-authoritative lifecycle-field ownership. | + +Copied persisted-status membership occurs in `packages/types/src/task.ts`, `src/core/task-persistence/taskMetadata.ts`, `src/core/task/Task.ts`, `apps/cli/src/ui/types.ts`, `HistoryTrigger.tsx`, and the core task-history reader. The runtime `TaskStatus` vocabulary (`running`, `interactive`, `resumable`, `idle`, `none`) is intentionally separate but similarly named. + +### Scheduler and queue transitions + +| Queue/lock | Transition | Scope | Evidence boundary | +| --------------------------- | ----------------------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------- | +| Task semaphore | submitted → waiting → admitted → running → released; queued → cancelled | One provider | Unit tested; modeled permits are abstract. | +| Per-parent transition queue | delegation/interruption/completion/abandonment serialization | Static queue keyed by parent ID | Provider tests and handoff model; no cross-process transaction. | +| History restoration queue | request → serialized rehydration → install | One provider | Provider tests; no model state. | +| Provider-profile queue | profile mutation serialization | One provider | Settings/provider tests; outside lifecycle models. | +| Message queue | add → claim → persist → remove, or release on failure | One live task | Claim path tested; legacy dequeue-before-submit path remains. | + +Registry publication can precede scheduler admission. Therefore “current”, “running”, “active”, and “persisted active” are not interchangeable states. + +### Tool-state ownership boundary + +Tool inputs originate in provider stream transforms, are assembled by `NativeToolCallParser`, converted to authoritative `nativeArgs`, validated centrally and inside handlers, optionally edited through webview approval, and can mutate live `Task`, provider, message, and persisted history state. Tool outputs return through `pushToolResult`, parent result injection, pending-action replay, or public lifecycle events. Those stages do not share one canonical identity or transaction. + +| Boundary | Production path | Current evidence | Ownership limitation | +| --------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | +| Argument assembly | Provider transform → parser scope → `ToolUse.nativeArgs` → `BaseTool.handle` | Production-backed bounded parser replay plus provider/tool tests | Provider transforms, parser state, and downstream handler state are separate owners. | +| Validation | `validateToolUse` plus handler-local parsing and policy checks | Focused tests | Validation mode and configuration may come from shared provider state rather than task context. | +| Approval edits | Handler proposal → `askApproval` → webview edit → handler settlement | Focused single-approval tests | Todo edit state is process-global and carries no task/action/call identity. | +| Child initialization | `new_task` args → pending create action → provider delegation → child `Task` | Focused forwarding and pending-action tests | Some tool-originated child state is live-only and lacks a durable rehydration owner. | +| Completion/result injection | `attempt_completion` pending action → parent UI/API messages → lifecycle pair | Focused tests and separate lifecycle/completion models | Message, lifecycle, and replay commits are separate failure domains. | +| Partial presentation | Singleton tool handler partial methods | Tool-local tests | `BaseTool.lastSeenPartialPath` is shared across calls/tasks. | +| Identity/replay | raw call ID → sanitized ID → history/result/pending action | Duplicate-ID helper tests | Sanitization is non-injective; history deduplication and execution do not share a proven bijection. | + +#### `new_task` and todo evidence + +The normal creation path does not inherit the parent list. The model supplies optional `new_task.todos`; `NewTaskTool.execute` parses only that argument into a fresh array, stores it in a pending action while approval is unresolved, and forwards it as `initialTodos` through `delegateParentAndOpenChild` and `createTask`. The parent task supplies lineage and workspace context, not todos. + +`Task` assigns `initialTodos` to its process-local `todoList`. `UpdateTodoListTool` later writes task-scoped `updateTodoList` messages, and `restoreTodoListForTask` reconstructs the latest list from the reopened task's own messages. `ClineProvider.getStateToPostToWebview` publishes the focused task's `currentTaskTodos`; `ChatView` and `TodoListDisplay` render that state or the current task's message-derived fallback. No frontend path intentionally copies a parent list. + +The reported appearance of inheritance therefore needs two controls: + +1. If the model emits child todos matching the parent, that is explicit tool-call content and not evidence of IDE aliasing. +2. If child todos disappear or change after navigation/restart, that is an IDE-side task-state persistence/scoping question. + +Initial child todos are not placed in a task message or `HistoryItem`. Rehydration constructs a new `Task` without `initialTodos`; before the child's first `update_todo_list`, message-derived restoration yields an empty list. Constructor and todo setter APIs also assign arrays directly, creating latent aliasing for programmatic callers even though the normal `new_task` parser creates fresh objects. No current model contains todo state, task-ID/generation-scoped todo publication, or rehydration equivalence. + +#### Provider-mode causality + +Merged PR #1625 changed the confirmed provider-mode readers for environment details, built-in validation, and custom-tool execution to task-local mode and added focused tests. The historical bug could change mode-sensitive prompt context, validation, and tool availability, but no production path uses provider mode to select or transfer the parent's `todoList`. It is not a direct mechanism for parent todos appearing in a child. Matching lists at creation are evidence of explicit model-supplied `new_task.todos` unless a separate ownership witness shows otherwise. A distinct plausible contamination path is the process-global todo approval edit slot described by `LIFE-GAP-036`. + +The delegated-mode reader checker remains proxy refinement evidence: it executes the handoff selector and pure built-in permission comparison, not the VS Code-dependent downstream readers. The wider provider-mode reader inventory therefore remains open even though the three confirmed regression paths are fixed. + +#### Formal-model decision + +No broad tool-state checker is added in this PR. A green model would have to invent a unified owner across parser, handler singleton, webview approval, task state, message files, lifecycle records, and replay. Initial child-state persistence has no production transition to import; approval correlation lacks task/action identity; canonical call identity spans multiple embedded I/O paths. Until those owners are extracted, stable gaps and deterministic witness criteria are stronger evidence than an abstract passing model. The existing parser, lifecycle, store-concurrency, handoff, cleanup, completion, and delegated-mode-reader checkers remain explicitly local, as does the separate optional fan-out checker. + +### Delegation, interruption, cancellation, completion, and abandonment + +| Flow | Production path | Key ordering | Verification | +| --------------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | +| Delegate | `NewTaskTool` → `delegateParentAndOpenChild` | Snapshot context; flush/remove parent; create paused child; commit parent ownership; then schedule child | Reducer model, handoff model, provider tests, subtask E2E. | +| Interrupt on eviction | `evictCurrentTask` → `markDelegatedChildInterrupted` | Remove live child; revalidate parent ownership; persist interrupted child | Reducer model and provider/E2E tests. | +| User cancel | `cancelTaskInternal` → request abort → bounded drain/save → interrupted persistence/rehydration | Live flags and persisted status converge through multiple fallbacks | Cleanup model is abstract; provider and E2E tests cover selected paths. | +| Complete standalone | `AttemptCompletionTool` → persistence readiness → `TaskCompleted` | Public event follows accepted completion and assistant-history visibility | Abstract completion model, focused tests, fresh-host E2E. | +| Complete child | `AttemptCompletionTool` → `reopenParentFromDelegation` | Validate IDs; write parent messages; remove child; pair update; publish; schedule parent | Reducer/handoff models and provider/E2E tests; message/lifecycle transaction is unmodeled. | +| Abandon | `abandonSubtask` | Require interrupted child; remove live child; pair-detach; process-local stale guard | Reducer/shared-store models and focused/E2E tests. | +| Resume | webview/API/IPC → `resumeTask`/`showTaskWithId` → rehydrate | Surfaces differ in awaiting, error propagation, and publication | Focused/E2E tests; no unified model. | + +### Streams and event consumers + +Each API request creates a parser scope. Provider `tool_call_partial` chunks pass through `NativeToolCallParser`, then `Task` turns parser events into partial/final assistant blocks. End-of-stream finalization is modeled for two scopes; abort/failure cleanup and provider transform semantics are separate. + +`Task` may detach an iterator to drain final usage. That continuation can update accounting/messages after foreground processing stops. Lifecycle generation ownership is not attached to those writes. + +Task events are forwarded by `ClineProvider`, enriched and re-emitted by `src/extension/api.ts`, and serialized to IPC. Node `EventEmitter.emit()` does not await async listeners, so event notification and listener settlement are separate contracts. Public completion status persistence and downstream consumers are not in the completion model. + +## Production-to-model-to-test-to-CI matrix + +| Production boundary | Model/property | Production tests | E2E | CI path | Classification | +| ------------------------- | --------------------------------------------------------------- | --------------------------------------------------- | ---------------------------- | ---------------------------------- | ------------------------------------------------------------------------------- | +| Lifecycle reducers | Exact parent-child ownership, acyclicity, terminal immutability | `taskLifecycle.spec.ts` | `subtasks.test.ts` | `lifecycle:model-check`, unit, E2E | Production-backed bounded | +| Delta/merge/store | Field preservation, status legality, pair order/failure | store unit, cross-instance, real-lock smoke | None direct | model umbrella, unit | Production-backed bounded plus known-unsafe witnesses | +| Handoff selector/reducers | Commit-before-start, publication, permit/redelegation ordering | provider handoff, scheduler, delegation tests | subtask profile/resume paths | model umbrella, unit, E2E | Mixed production/abstract | +| Optional fan-out | Two siblings, result writer/delivery, orphan cleanup | Scheduler primitives only | None | explicit optional command | Planned-only abstract, excluded from baseline | +| Cleanup | At-most-once abort/dispose, settlement order, provider drain | Task/provider cleanup tests | Indirect cancellation paths | model umbrella, unit, E2E | Abstract bounded plus focused tests | +| Parser scopes | Scope-owned IDs/arguments, exactly-once finalization | parser/provider stream tests | Indirect | model umbrella, unit | Production-backed bounded replay | +| Completion readiness | Durability before event, retry/cancel/reopen ordering | Task/completion tool tests | fresh-host restart | model umbrella, unit, E2E | Abstract bounded plus refinement witnesses | +| Mode handoff/readers | Selector snapshot and observable provider/task divergence | selector plus three focused downstream-reader tests | profile handoff | model umbrella, unit, E2E | Write side production-backed; confirmed readers tested; wider inventory partial | +| Status vocabulary | Shared schema plus copied unions | CLI/history tests | None | typecheck, unit | Type/static convention | + +CI runs lint, typecheck, and `pnpm lifecycle:model-check` in `.github/workflows/code-qa.yml`. Unit/integration tests run separately on Ubuntu and Windows. Mocked extension-host E2E and the explicit restart-persistence phase run in `.github/workflows/e2e.yml`. Workflow files prove invocation, not branch-protection required-check configuration. E2E may reuse an identical-source pass marker on pull requests. + +## Assumptions and exclusions + +- Every checker is finite and protocol-local. Bounds are documented in the parent architecture page and checker constants. +- Safety invariants do not establish liveness. No checker includes fairness sufficient to prove eventual queue admission, cleanup, persistence, retry, or completion. +- A model-authored provider, scheduler, cleanup, fan-out, or durability action is not production refinement by itself. +- Per-file locks are treated as effective mutual exclusion in the abstract store model. Lock implementation, stale-lock recovery, rename semantics, process crashes, and power loss are excluded. +- Pair writes, lifecycle plus message writes, deletion plus filesystem cleanup, and registry plus persistence publication are not transactions. +- Parser replay fixes two scopes, one raw index, and local action order. Transport transforms and arbitrary malformed histories are excluded. +- Focused tests and E2E are representative histories, not exhaustive interleavings. +- No public-runtime telemetry or production traces were available for trace validation. + +## Ranked GAP register + +Severity reflects plausible data loss, ownership corruption, permission/context errors, or stuck work. Confidence reflects direct source evidence, deterministic witness, or inference. + +| ID | Severity | Confidence | Gap and production impact | Witness/reproducer | Dependencies | Objective closure criteria | +| ------------ | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| LIFE-GAP-001 | Critical | High | Stale cross-host completion can clear a newer handoff and orphan its child. | Exact shortest witness in shared-store checker. | Disk-authoritative ownership guard or generation. | Deterministic two-store test passes; authoritative child ID is revalidated under disk lock; witness becomes universal invariant. | +| LIFE-GAP-002 | High | High | Stale message save can restore abandoned lineage. | Exact shortest stale-save/abandon witness. | Lifecycle-field ownership, tombstone, or generation. | Stale save cannot alter detached lineage in production test or bounded model; witness promoted. | +| LIFE-GAP-003 | High | High | Legacy dequeue-before-submit can lose queued user feedback on submission failure. | `Task.processQueuedMessages` removes before async submit. | Standardize claim/persist/ack path. | Every queue consumer claims first, removes after durable acceptance, releases on failure; failure test retains message. | +| LIFE-GAP-004 | High | High | Pair writes are not cross-host/crash atomic; partial lifecycle state is observable. | Modeled second-write failure landmark. | WAL/repair intent or explicitly idempotent recovery per pair operation. | Crash injection at each write boundary converges to a documented legal state. | +| LIFE-GAP-005 | High | High | Delegation creates child state and commits parent ownership in separate failure domains. | Provider rollback tests cover selected failures. | Idempotent operation ID or repair intent. | Failure injection before/after every persistence/publication step restores parent or completes delegation without orphan state. | +| LIFE-GAP-006 | High | Medium-high | Parent completion messages can persist before lifecycle completion commit fails. | Source ordering in `reopenParentFromDelegation`. | Transaction/intent or reorder with recovery. | Inject pair-write failure and prove no stale result context, or prove replay safely completes the lifecycle. | +| LIFE-GAP-007 | Medium | High | Three confirmed task-local mode readers are fixed and production-tested, but the repository-wide reader inventory and enforceable task-local boundary remain incomplete. | Merged focused tests cover environment details, built-in validation, and custom-tool execution; the pure checker proves only divergence and selector storage. | Reader inventory and task-local API boundary. | Every mode-sensitive reader is classified; required task-local consumers have divergent production tests in both permission directions; checker/docs distinguish executed readers from proxy evidence. | +| LIFE-GAP-008 | High | High | Responses API argument-only deltas may be dropped; absent indices can alias calls. | Transform requires ID/name and defaults index to zero. | Provider transform correlation design. | Multi-delta and concurrent index-less production tests reconstruct isolated calls; parser model includes mapped transform events. | +| LIFE-GAP-009 | Medium | High | Async lifecycle event listeners have no awaited settlement contract. | Async listeners registered on Node EventEmitter. | Classify notification versus barrier events. | Barrier side effects move to awaited methods; notification listeners have contained rejection tests and documented ordering. | +| LIFE-GAP-010 | Medium | Medium-high | Detached usage drain can write after abort, replacement, delegation, or a newer request generation. | Background iterator mutates/persists without generation guard. | Request-generation ownership. | Late drain may account valid usage but cannot mutate stale UI/message/lifecycle state; controlled delayed-stream test passes. | +| LIFE-GAP-011 | Medium | High | Completion model excludes terminal status persistence and downstream public consumers. | Model ends at emission readiness. | Consumer inventory and contract. | Consequential consumers are enumerated; required status/metadata ordering has production refinement tests. | +| LIFE-GAP-012 | Medium | High | No persisted attempt/generation distinguishes delayed pre-interruption completion from valid post-resume completion of the same child. | Documented model exclusion. | Persisted generation token. | Reducer/store/API/model reject stale generation while accepting resumed generation; restart E2E covers it. | +| LIFE-GAP-013 | Medium | High | Task lifecycle status vocabulary is copied across schema, task metadata, Task, CLI, and history reader. | Literal union inventory. | Shared exported schema-derived type. | Consumers import one owner; CI/static check rejects incompatible local copies. | +| LIFE-GAP-014 | Medium | High | The serial production contract relies on singular reducer ownership and a default one-permit provider scheduler; optional fan-out must not be mistaken for baseline coverage. | The production-backed lifecycle model rejects multiple active awaited children, while the optional fan-out model has no production imports or E2E. | Serial baseline ratchet; separately ticketed fan-out decision. | Baseline: close cross-host violations, assert provider scheduler capacity and serial ordering, and keep fan-out outside baseline CI. Optional fan-out: implement adapters/E2E before reclassification. | +| LIFE-GAP-015 | Medium | High | Independent checks do not establish end-to-end refinement. | Six baseline state spaces plus one optional fan-out state space remain disjoint. | Boundary mappings and tractable joint bounds. | Add joint checker/trace validation for each cross-model claim, or keep every claim explicitly local. | +| LIFE-GAP-016 | Medium | High | Traceability is documentary and can drift from scripts, symbols, tests, and CI. | Shared-store scenario count has drifted in documentation. | Machine-readable manifest/checker summaries. | CI validates stable IDs, model membership, bounds, symbol/test paths, and workflow invocation. | +| LIFE-GAP-017 | Medium | High | Store cache records are exposed without cloning; external mutation may bypass locking. | `get`/`getAll` return cached objects. | Immutability/read API decision. | Freeze/clone records or prove callers cannot mutate; mutation regression test. | +| LIFE-GAP-018 | Medium | High | Ordinary history-file reads cast JSON instead of applying the shared schema. | Store reconciliation/read path. | Validation/quarantine policy. | Malformed records are rejected or quarantined deterministically with tests and recovery documentation. | +| LIFE-GAP-019 | Medium | High | Generic task IDs lack the importer’s explicit path-safety validation. | Importer validates IDs; generic paths interpolate IDs. | Shared safe-ID boundary. | Every filesystem task ID passes one validator; traversal and separator tests cover all entry points. | +| LIFE-GAP-020 | Medium | Medium-high | Watch/reconcile convergence is eventual and failure-tolerant, not coherent. | Debounced watcher plus periodic scan. | Version/notification or documented eventual contract. | Define stale-read window and convergence property; multi-host test covers missed watcher event and concurrent update. | +| LIFE-GAP-021 | Medium | High | Store disposal does not await queued writes. | Synchronous `dispose` stops watcher/timer only. | Async drain/close contract. | Disposal awaits or explicitly cancels writes; no post-dispose writes in deterministic test. | +| LIFE-GAP-022 | Medium | High | Public clear and webview clear use different delegated-child semantics. | API uses eviction; webview removes directly. | One clear contract. | All ingress paths converge on the same lifecycle transition and tests assert identical persisted results. | +| LIFE-GAP-023 | Medium | High | History deletion can be resurrected after swallowed unlink failure. | Cache removal precedes best-effort unlink. | Tombstone or surfaced failure/retry. | Inject unlink failure and prove item stays deleted or operation reports failure without false success. | +| LIFE-GAP-024 | Medium | High | Parser cleanup depends on normal finalization or garbage collection. | Weak scope maps lack universal request `finally`. | Request-level cleanup owner. | Abort/error/success all clear active parser state in production integration tests. | +| LIFE-GAP-025 | Medium | High | Abort listeners may accumulate during successful stream chunks. | Per-chunk listener removed only by abort. | Settle-time listener cleanup. | Long stream keeps bounded listener count and removes listeners on both race outcomes. | +| LIFE-GAP-026 | Medium | Medium-high | Usage-drain timeout cannot interrupt a permanently pending `iterator.next()`. | Elapsed time checked before await. | Deadline race/abort. | Hung iterator settles drain within wall-clock bound in fake-timer test. | +| LIFE-GAP-027 | Medium | High | Task-level delegation listeners are untyped/dead while provider listeners own the same public events. | `src/extension/api.ts` registers both paths. | Single typed event owner. | Remove duplicate/dead listeners or define one source; public API test proves exactly-once emission. | +| LIFE-GAP-028 | Low-medium | High | `TaskSpawned` payload semantics differ across task/provider/public surfaces. | Child-only, ambiguous task ID, and parent+child forms. | Event contract normalization. | Payloads use explicit names and adapters are type-checked with compatibility tests. | +| LIFE-GAP-029 | Low-medium | High | `Task.taskStatus` and `TaskRegistry.getRunning` are projections, not scheduler/persistence truth. | Ask markers and abort flags only. | Naming/contract clarification. | Rename or document exact predicates; callers stop using them as stronger lifecycle evidence. | +| LIFE-GAP-030 | Low-medium | Medium | `Task.run()` may resolve immediately if another path already started the task. | `_started` short-circuit versus scheduler callback. | Single start owner. | Scheduler-facing start returns the actual run promise; duplicate-start test proves settlement identity. | +| LIFE-GAP-031 | Low-medium | High | Queue state is memory-only and cleared on disposal. | `MessageQueueService.dispose`. | Product durability decision. | Document intentional loss or persist claims/messages with restart tests. | +| LIFE-GAP-032 | Low-medium | Medium | Webview abandonment handler exists without a confirmed production UI sender. | Protocol/handler search only. | Reachability decision. | Add supported sender/E2E or remove/deprecate unreachable command. | +| LIFE-GAP-033 | Low-medium | High | Resume ingress differs in awaiting and error propagation. | Webview/API/IPC adapters diverge. | Shared resume operation contract. | Contract tests compare result/error/publication semantics for each surface. | +| LIFE-GAP-034 | Low | High | Bounds and model metadata are handwritten and not mechanically synchronized. | Constants, prose, and console summaries duplicate values. | Machine-readable checker metadata. | CI compares emitted metadata with docs/manifest and rejects undocumented bound/action/landmark changes. | +| LIFE-GAP-035 | Medium | High | Tool-originated child initialization lacks a complete durable ownership contract; initial todo state is the confirmed witness and can disappear after rehydration. | Create a child with explicit initial todos, switch or restart before `update_todo_list`, then reopen it; restoration finds no todo message and yields an empty list. | Canonical durable task-ID-scoped child-initialization owner and publication contract. | Inventory every `new_task`-originated child field; persist required initial state before visibility/run; restore deep-equal independent state across switching, interrupted resume, checkpoint restore, and fresh-host restart; preserve later-update and explicit-empty precedence; add constructor deep-copy, persistence, webview scoping, and E2E witnesses. | +| LIFE-GAP-036 | High | High | Interactive todo approval edit state is process-global and uncorrelated; one task's delayed edit can be consumed by another task's pending approval. | Start approvals for tasks A and B, send A's edited list through `setPendingTodoList`, then resolve B; B reads the shared `approvedTodoList`. | Task/action/tool-call-correlated approval state and webview protocol. | Carry task ID and action/tool-call ID through proposal, webview edit, approval, cancellation, and settlement; reject stale/mismatched edits; deep-clone inputs; test two interleaved approvals, denial, cancellation, task switch, and delayed edits. | +| LIFE-GAP-037 | Medium-high | High | Singleton tool handlers share partial presentation state across calls/tasks, so interleaved paths can cause false or missed stabilization. | Interleave A:`x`, B:`y`, A:`x` or A:`x`, B:`x` through one handler's `lastSeenPartialPath`. | Per-call handler state keyed by task and tool-call identity. | Isolate partial state by `(taskId, toolCallId)` or handler instance; prove independent stabilization and cleanup after success, malformed finalization, rejection, cancellation, abandonment, and incomplete streams. | +| LIFE-GAP-038 | High | High | Lossy tool-ID canonicalization can deduplicate persisted history without deduplicating execution, results, approvals, or pending-action replay. | Distinct raw IDs such as `call:a` and `call/a` both sanitize to `call_a`; history may retain one call while execution retains both. | One collision-resistant canonical call identity before indexing and persistence. | Reject or disambiguate collisions; prove a bijection among parsed call, durable tool use, approval, execution, result, pending action, and replay; test adversarial native/MCP IDs and restart between approval and settlement. | + +## Portfolio remediation plan + +The [1-SP remediation block register](./task-lifecycle-remediation-blocks.md) decomposes this portfolio into small modeling/documentation increments. It assigns every GAP exactly one primary block, preserves dependencies across workstreams, and keeps optional fan-out separate from baseline ownership. + +The 38 IDs are not 38 independent projects. They group into eight programs with shared root causes and implementation surfaces. Complexity classes reflect implementation breadth, coupling, and verification risk rather than schedule or duration. + +| Cluster | Gap IDs | Root fix and likely ownership | Complexity | Engineering risk | Objective portfolio evidence | +| ------------------------------------------ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| P1. Persisted ownership and generation | 001, 002, 012, 017, 020 | Disk-authoritative lifecycle ownership/generation and immutable store reads across history types, lifecycle reducers, `TaskHistoryStore`, provider delegation, and reconciliation. | XL | High: persisted compatibility and cross-host races | Two-host stale-write tests, promoted invariants, restart/reconciliation evidence, backward-compatible optional data. | +| P2. Durable operation and crash recovery | 004, 005, 006, 021, 023 | Operation intent/replay or explicit idempotent recovery for pair writes, delegation, completion messages, shutdown, and deletion. | XL | Very high: failure ordering can create new corruption | Fault injection at every durable boundary, crash/restart convergence, no false success, recovery reachability. | +| P3. Schema, path, and lifecycle vocabulary | 013, 018, 019 | Schema-derived status ownership, validated ordinary history reads, and one safe task-ID boundary across types, persistence, metadata, CLI, and import paths. | M | Medium: malformed legacy data and downgrade behavior | Migration/quarantine fixtures, traversal tests, type/static ratchets. | +| P4. Request, stream, and tool identity | 008, 010, 024, 025, 026, 030, 037, 038 | Request generation plus canonical call identity, then task/generation/call-scoped parser and partial-handler state. Owners include provider transforms, parser, `Task`, `BaseTool`, editing handlers, and tool-ID utilities. | XL | High: provider compatibility and duplicate execution | Adversarial IDs/index-less streams, delayed/cancelled generation tests, cleanup/deadline checks, production-backed call-state model. | +| P5. Tool-owned task state and queueing | 003, 007, 031, 035, 036 | Task-local context, durable child initialization, correlated approval identity, and claim/persist/ack queueing across tools, `Task`, provider/webview, message queue, and history schema. | XL | High: cross-task contamination and persistence precedence | Omitted/explicit child controls, switch/restart E2E, two-approval schedules, queue failure retention, mode-permission tests. | +| P6. Event and ingress contracts | 009, 011, 022, 027, 028, 029, 032, 033 | Classify barriers versus notifications; normalize lifecycle payloads and clear/resume semantics across Task, provider, public API, IPC, and webview. | L | Medium-high: public compatibility and ordering | Exactly-once event tests, consumer inventory, cross-surface contract matrix, compatibility adapters where required. | +| P7. Serial scheduler baseline | 014 | Ratchet the current one-permit provider scheduler and singular active-child ownership; keep live-parent fan-out under separate future scope. | M | Low-medium: current behavior, but cross-host exceptions remain | Production capacity/order assertions plus lifecycle/store invariants proving the bounded serial contract. | +| P8. Verification and traceability platform | 015, 016, 034 | Machine-readable model metadata/traceability and selected cross-model trace validation across checker scripts, package commands, CI, and architecture docs. | L | Medium: vacuity and CI cost | CI validates IDs, symbols, tests, bounds, actions, landmarks, workflows, and executable mappings for cross-model claims. | + +### Root fixes that close multiple gaps + +- One persisted generation and disk-authoritative ownership design should close 001, 002, and 012; immutable reads and explicit reconciliation semantics address 017/020 around that owner. +- One durable operation-intent/replay framework can support 004, 005, 006, 021, and 023, but each operation still needs its own legal recovery states and fault-injection matrix. +- One request-generation/canonical-call identity established before parser indexing can support 008, 010, 024–026, 030, 037, and 038. +- One correlated `(taskId, actionId, toolCallId)` approval protocol can close 036 and support 007/035; it does not itself make child state durable. +- One typed lifecycle operation layer can normalize P6, but public compatibility requires separate adapters rather than a flag-day payload rewrite. + +### Independent work that should not be collapsed + +- Schema/path hardening (P3) is reviewable independently from transaction recovery (P2), despite shared persistence files. +- Optional fan-out is a separate product program and must not be hidden inside baseline scheduler closure. +- Completion consumer contracts (011) are not solved by safe EventEmitter listeners (009). +- Durable child initialization (035) and approval correlation (036) need separate persistence and cancellation owners. +- Verification platform work can proceed in parallel, but cannot promote another cluster before its production transition exists. + +### Sequencing and critical path + +1. **Foundation:** define lifecycle ownership/generation (P1) and canonical request/tool identity (P4), then ratchet the current serial scheduler baseline (P7) against the P1 ownership vocabulary. +2. **Integrity:** build durable operation recovery (P2) on P1. Run P3 in parallel once legacy-data policy is settled. +3. **Task isolation:** implement P5 using P4 identity and P1/P2 persistence rules. +4. **Surface convergence:** implement P6 after barrier/notification and generation semantics are known. +5. **Mechanical assurance:** start P8 metadata early; add cross-model refinement as production owners land. + +Critical path: **P1 ownership/generation → P7 serial baseline → P2 recovery → P5 durable task state → P6 public contracts**. P3 and P8 metadata can run in parallel from the first tranche. P4 can run beside P1 after agreeing how task and request generations relate. + +### Quick wins versus architectural programs + +| Category | Scope | Implementation shape | Notes | +| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------- | +| Quick wins | 013 shared status type; 025 listener cleanup; 029 projection naming/contracts; 034 checker metadata. | Narrow, independently reviewable changes | Reduce drift but do not close cross-host integrity. | +| Focused projects | 019 path safety, 021 disposal drain, 022/033 ingress convergence, 024 parser cleanup, 026 hard deadline, 027/028 event ownership, serial 014. | One or two related subsystem boundaries | Require deterministic tests and explicit compatibility checks. | +| Architectural programs | P1, P2, P4 identity/generation, P5 durable task state, P6 public contracts, or full fan-out. | Cross-cutting owner or protocol changes | Require staged PRs, failure injection, compatibility plans, and model refinement. | + +### Portfolio scale and parallel workstreams + +Baseline closure is a multi-program architecture effort spanning P1 through P8, with current serial behavior as the production target. Concurrent fan-out is excluded and remains separately tracked by #369/#372 or their successor ticket. Its live-parent execution, routing, rollback, orphan cleanup, UI scoping, E2E, and model-refinement prerequisites depend on baseline ownership, identity, and recovery foundations. + +Four workstreams can proceed concurrently after foundation decisions: + +1. persistence ownership/recovery (P1/P2); +2. request/tool identity and streaming (P4); +3. schema/path hardening and verification metadata (P3 plus P8 metadata); +4. event/ingress compatibility design (P6 discovery, implementation after generation semantics). + +### Recommended first tranche + +1. Add deterministic failing tests for 001/002/012, then define their shared ownership/generation primitive. +2. Ratchet current serial behavior for 014 against that ownership contract and leave fan-out to its separately scoped ticket. +3. Define canonical call identity and adversarial tests for 038/008; reuse it for 037 and 036. +4. Land independent hardening for 013, 025, 029, and 034. +5. Add P8 machine-readable mapping incrementally so closure PRs name symbols, witnesses, tests, bounds, and evidence class. + +### Planning assumptions and reconciliations + +- Complexity classes include focused/full tests and relevant E2E, not only code edits. +- Crash-consistency closure requires deterministic interruption and rollback fault injection; happy paths do not close P2. +- Prefer lazy optional-field migrations. Existing lost data is unrecoverable; downgrade readers must ignore new fields safely. +- High severity is reserved for demonstrated corruption, cross-task permission/state contamination, or execution/history divergence. Gap 035 remains Medium because its confirmed witness loses planning state; 036 and 038 remain High because they cross task/call ownership. +- Gap 014 remains Medium because baseline seriality is partly production-backed but not statically ratcheted and cross-host ownership violations remain. Optional fan-out does not affect baseline severity. +- Reassess cluster boundaries after P1 and P4 decisions because they define shared interfaces; keep fan-out in its separate scope. + +## Burn-down dependencies + +| Dependency | Enables | +| ---------------------------------------------- | ------------------------------------------------------------- | +| Disk-authoritative ownership/generation design | LIFE-GAP-001, 002, 012, 020 | +| Durable operation intent/recovery design | LIFE-GAP-004, 005, 006, 021, 023 | +| Task-local execution-context owner | LIFE-GAP-007 and optional future fan-out | +| Request generation and terminal cleanup owner | LIFE-GAP-010, 024, 025, 026 | +| Event notification/barrier contract | LIFE-GAP-009, 011, 027, 028 | +| Machine-readable lifecycle manifest | LIFE-GAP-013, 016, 034 | +| Serial scheduler baseline | LIFE-GAP-014 | +| Optional fan-out product program | Historical #369/#372 scope, outside baseline | +| Durable task-scoped child initialization | LIFE-GAP-035 and future tool/lifecycle composition | +| Correlated approval ownership | LIFE-GAP-036 | +| Task/tool-call-scoped partial state | LIFE-GAP-037 with request-generation cleanup gaps 010 and 024 | +| Canonical tool-call identity | LIFE-GAP-038 with generation/replay gap 012 | + +## Mechanically useful follow-up checklist + +- [ ] Assign an owner and target PR to each active `LIFE-GAP-*` ID without renumbering existing IDs. +- [ ] Add the ID to production tests, model actions/properties, and PR descriptions that address it. +- [ ] Preserve a deterministic failing test or shortest witness before changing production behavior. +- [ ] State whether the resulting evidence is production-backed, abstract, proxy, or E2E. +- [ ] Add negative/failure-path coverage, not only the successful transition. +- [ ] Record bounds and prove action/landmark reachability so an overconstrained model cannot pass vacuously. +- [ ] For cross-host work, enumerate legal histories and inject stale cache, partial write, lock, restart, and reconciliation orderings. +- [ ] For crash-consistency claims, add interruption/failure injection at every durable step. +- [ ] For liveness claims, define fairness and progress assumptions explicitly; do not infer them from safety exploration. +- [ ] For cross-model claims, supply an executable boundary mapping or keep the claim local. +- [ ] Update this report’s inventory, matrix, severity, dependencies, and closure evidence in the same PR. +- [ ] Run `pnpm lifecycle:model-check`, focused production tests, `pnpm test`, typecheck, lint, and required E2E before marking a gap closed. +- [ ] Move issue links only within historical provenance; stable burn-down IDs remain the active identity. +- [ ] For LIFE-GAP-035, inventory all tool-originated child state and test both todo controls: omitted child todos must not copy the parent, while explicit initial child todos must survive task switching and restart. +- [ ] For LIFE-GAP-036, correlate every approval edit and settlement with task ID plus action/tool-call ID; reject stale cross-task edits. +- [ ] For LIFE-GAP-037, interleave equal and unequal partial paths across two calls and two tasks, then verify terminal cleanup. +- [ ] For LIFE-GAP-038, use adversarial raw IDs to verify one-to-one durable call, approval, execution, result, pending-action, and replay identity. + +## Completeness statement + +At the audited commit, this report covers every tracked definition and directly discoverable caller matching the lifecycle domains in scope, including tool argument assembly, validation, approval, child initialization, partial presentation, result/pending-action identity, todo rehydration, all seven baseline checkers and the separate optional fan-out checker, their documented bounds/properties, primary focused suites, lifecycle E2E files, root package scripts, and CI workflow invocations. It does not claim semantic completeness for dynamic calls, generated code, dependencies, ignored files, deployment settings, or production histories. A future code change can invalidate completeness; `LIFE-GAP-016` and `LIFE-GAP-034` exist specifically to make this inventory mechanically maintainable. + +## Historical provenance + +Relevant historical reports include [#1469](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1469), [#1021](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1021), [#1623](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1623), [#369](https://github.com/Zoo-Code-Org/Zoo-Code/issues/369), [#372](https://github.com/Zoo-Code-Org/Zoo-Code/issues/372), [#612](https://github.com/Zoo-Code-Org/Zoo-Code/issues/612), [#1453](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1453), [#1279](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1279), [#921](https://github.com/Zoo-Code-Org/Zoo-Code/issues/921), [#920](https://github.com/Zoo-Code-Org/Zoo-Code/issues/920), and [#1468](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1468). These links provide provenance only; closure is governed by the objective criteria above. diff --git a/docs/architecture/task-lifecycle-model.md b/docs/architecture/task-lifecycle-model.md index 9266d49987..355b08aa7e 100644 --- a/docs/architecture/task-lifecycle-model.md +++ b/docs/architecture/task-lifecycle-model.md @@ -1,24 +1,29 @@ # Task lifecycle model-check suite -Zoo Code checks task lifecycle protocols through one compositional verification suite. Run the complete suite locally with: +Zoo Code checks task lifecycle protocols through one umbrella command for independent bounded checks. Run the complete suite locally with: ```sh pnpm lifecycle:model-check ``` -The command runs six independent bounded submodels in sequence: +The baseline command runs seven independent bounded checks in sequence: 1. the persisted task delegation lifecycle; 2. shared-store concurrency across task-history hosts; -3. production-backed provider handoff and scheduler ordering; +3. production-backed handoff reducers with an abstract provider/scheduler protocol; 4. the task cleanup protocol; -5. request-stream parser scoping; and -6. completion persistence. +5. request-stream parser scoping; +6. completion persistence; and +7. delegated-mode reader refinement. + +The planned two-sibling fan-out protocol is intentionally outside the baseline and CI umbrella. Run it explicitly with `pnpm fanout-protocol:model-check`; it describes optional future functionality, not current production coverage. This umbrella command is the single model-check entry point in the `compile` CI job after type checking. Command-level composition does not merge the submodels' state spaces: each checker retains its own bounds, transitions, invariant ownership, reachability requirements, and counterexample format. In particular, parser state is not part of the persisted lifecycle graph. The focused parser checker remains directly runnable with `pnpm parser-scope:model-check` for debugging. An individual checker fails if it finds an invariant violation, a modeled action becomes unreachable, a named semantic landmark disappears, or exploration exceeds its declared state budget. A lifecycle violation includes the shortest breadth-first event trace, every intermediate state, and the active bounds so the sequence can be replayed as a focused regression test. +A checker printing `passed` means only that its configured bounded invariants, expected witnesses, reachability requirements, and state budget succeeded. It does not close a linked issue, prove arbitrary-task correctness, or establish refinement for production consumers that the checker does not execute. + Executable cross-model composition should be added only when a correctness claim genuinely spans two or more submodels and there is an explicit, production-grounded boundary mapping between their events or state. That composition must state a bounded joint exploration strategy and own cross-model invariants that cannot be proved within either child model alone. Shared command orchestration or conceptual adjacency is not sufficient reason to multiply independent state spaces. ## Why an executable TypeScript model @@ -63,7 +68,7 @@ The same `pnpm lifecycle:model-check` command also runs a second bounded explore - successful pair-operation cache entries publish together after both file writes; if the second write fails, the cache publishes only the first committed record; - cache refresh is explicit and may occur after an external live-task snapshot was captured. -There is no production record version or compare-and-swap token today. The model therefore does not invent one. It universally checks host-mutex and file-lock ownership, whole-file delta rejection, disk-field preservation, `childIds` union, and pair write order. Six scenarios, including distinct-task writes from #920 and a second-write pair failure, and all seven phases (`read`, `prepare`, `revalidate`, `commit`, `refresh`, `reject`, and `fail`) must remain reachable without exceeding the state/depth budgets. Positive semantic landmarks additionally require a stale cache beside newer disk state, the first pair write committed while the second is pending, and the same committed prefix retained after the second write fails. +There is no production record version or compare-and-swap token today. The model therefore does not invent one. It checks host-mutex and file-lock ownership, whole-file delta rejection, disk-field preservation, `childIds` union, and pair write order in every state reachable within six bounded scenarios. Those scenarios include distinct-task writes from #920 and a second-write pair failure, and all seven phases (`read`, `prepare`, `revalidate`, `commit`, `refresh`, `reject`, and `fail`) must remain reachable without exceeding the state/depth budgets. Positive semantic landmarks additionally require a stale cache beside newer disk state, the first pair write committed while the second is pending, and the same committed prefix retained after the second write fails. Two desired properties are currently false and remain issue-keyed shortest-witness ratchets rather than silently allowed assertion failures: @@ -82,12 +87,26 @@ The umbrella command also runs a separate bounded child model for in-memory abor ## Provider handoff and scheduler model -`scripts/check-provider-handoff-scheduler.ts` is a separate bounded adapter model for the runtime boundary that the persisted lifecycle graph does not represent. Its breadth-first explorer normalizes provider-keyed records and owner arrays before deduplicating canonical states, then exhaustively explores enabled action orderings through depth 15 with a 20,000-state budget. It imports `selectHandoffExecutionContext` and the existing `delegateTaskToChild` and `completeDelegatedChild` reducers. A direct saved, unsaved, and locked-profile matrix verifies task-local configuration isolation. Stale provider lookup is caught before this pure selector, so focused provider tests verify the failed lookup, contextual log, and fallback. The protocol state then models two provider instances, their claims and parent snapshots, authoritative parent/child records, current task publication, commit/start ownership, the child scheduler permit, queued and resumed parent state, and one bounded redelegation generation. +`scripts/check-provider-handoff-scheduler.ts` is a separate bounded adapter model for the runtime boundary that the persisted lifecycle graph does not represent. Its breadth-first explorer normalizes provider-keyed records and owner arrays before deduplicating canonical states, then exhaustively explores enabled action orderings through depth 15 with a 20,000-state budget. It imports `selectHandoffExecutionContext` and the existing `delegateTaskToChild` and `completeDelegatedChild` reducers. A direct saved, unsaved, and locked-profile matrix checks task-local configuration selection within those cases. Stale provider lookup is caught before this pure selector, so focused provider tests check the failed lookup, contextual log, and fallback. The protocol state then models two provider instances, their claims and parent snapshots, authoritative parent/child records, current task publication, commit/start ownership, the child scheduler permit, queued and resumed parent state, and one bounded redelegation generation. Provider locking, paused-child/current-task publication, and semaphore admission/release are explicit model abstractions rather than imported production code. Focused provider and `TaskScheduler` tests cover those concrete adapters. Lifecycle commits and completion use the real reducers. Parent publication and its queued continuation share an explicit transition owner: the fixed policy retains that ownership through matching resume invocation, then models the resumed run settling outside transition ownership. This permits a new delegation generation to begin while the prior resumed run remains active without allowing a stale continuation to start across the newer transition. The fixed policy checks every successor for continuous publication, one child start and commit per generation, exact commit-before-start ownership, permit release before parent resume or redelegation, matching parent transition/continuation ownership at resume invocation, and consistent final child/parent publication. It also requires both resume phases, every other action, and named semantic landmarks to remain reachable and fails if the depth boundary has an unseen successor. Six injected legacy transition policies must produce deterministic shortest counterexamples through the same explorer: start before commit, resume before permit release, redelegation before permit release, empty current-task publication, two stale provider commits from competing snapshots, and releasing parent-transition serialization immediately after publication. The last witness must causally include first-child completion and parent publication, a second-child commit, release of the first child's scheduler permit, and then the stale first-child continuation. The checker prints the distinct reachable-state count, complete scenario/action/landmark coverage, bounds, and each named counterexample trace. It deliberately does not add a WAL, global profile projection, or scheduler state to persisted `HistoryItem` records. +For #921, the execution-context matrix checks saved, unsaved, and locked profile selection at the handoff boundary. For that bounded matrix, it establishes only that delegation writes the requested task-local mode and cloned configuration into the child context. It does not prove that every downstream consumer reads that context. The checker retains a divergent-mode witness in which the child task mode differs from the shared provider mode so reader refinements can demonstrate that choosing the wrong source is observable. + +Merged PR #1625 changed the confirmed downstream readers: `getEnvironmentDetails` obtains `cline.getTaskMode()`, `presentAssistantMessage` passes that task-local mode to `validateToolUse`, and custom tool execution receives the same task-local mode. Focused production tests cover those three paths. + +`scripts/check-delegated-mode-readers.ts` does not execute `getEnvironmentDetails`, `presentAssistantMessage`, or `validateToolUse`. It checks the production handoff selector and a pure built-in-mode permission divergence, establishing that the wrong source is observable. It is refinement support, not exhaustive reader coverage. Other mode-sensitive consumers remain an explicit inventory gap, and this suite does not claim universal task-local reader isolation. + +## Task fan-out protocol model + +`scripts/check-task-fanout-protocol.ts` is a separate, optional bounded protocol model for the #369/#372 fan-out safety contract. It explores a live parent with two sibling slots, a two-permit scheduler, independent result readiness, explicit child-to-parent delivery, parent loss, orphan cancellation, and permit release. It checks scheduler capacity and exact permit ownership, one writer and at-most-once delivery per child, readiness before delivery, and no result routing after parent loss. Named landmarks require concurrent siblings beneath a live parent, out-of-order result delivery, single-writer results, parent loss while work is running, and complete orphan cleanup to remain reachable. Injected unsafe states confirm those invariants reject wrong writers, early and duplicate delivery, post-parent-loss routing, and scheduler over-allocation. + +This model checks an intended abstract composition boundary without claiming that concurrent sibling fan-out is enabled in production. It imports no production fan-out transition and is excluded from `pnpm lifecycle:model-check` and baseline CI. `TaskScheduler` provides generic bounded permits, but `ClineProvider` constructs it at the default capacity of one and production delegation persists a singular `awaitingChildId`. Raising production concurrency still requires live-parent result integration and extension-host coverage before fan-out can ship. + +The production-backed lifecycle checker already models the current serial ownership invariant: a parent has at most one `awaitingChildId`, `delegatedToId` matches it, and every active/delegated linked child is the child currently awaited. The reducer rejects re-delegation while that child is active. This is exhaustive only for the checker's three slots and depth 12 and does not erase the documented cross-host stale-write violations, so baseline closure still requires their production fixes and model promotion. + ## Completion persistence model `scripts/check-completion-persistence.ts` models the completion-readiness protocol that protects the public `TaskCompleted` event. It starts from both standalone and delegated tasks and exhaustively interleaves: @@ -126,22 +145,59 @@ The completion persistence checker additionally enforces: These are safety claims within the documented bounds. The checks do not claim liveness, fairness, power-loss durability, filesystem-lock correctness, or exhaustive coverage of arbitrary task counts or retry counts. The completion explorer specifies the event contract rather than importing `Task` or `AttemptCompletionTool`; focused unit tests and the restart E2E verify that concrete production paths implement the modeled guards. Delegated reopen is abstracted as one success-or-failure event after durable child history; fallback from a failed reopen into the normal standalone completion flow remains production-test coverage rather than part of this model. The lifecycle checker also does not distinguish a delayed pre-interruption completion from a legitimate post-resume completion for the same child ID; that requires a persisted attempt/generation token before it can become a sound invariant. -## Open-issue traceability - -The following map separates issue observations from the architectural interpretation encoded here. Open issues can change after this document is written; follow each link for current status. - -| Issue and directly observed evidence | Derived protocol rule | Production transition and current check | -| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [#1469](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1469): the issue report states that a barrier-controlled two-host run reproduced an old child completion clearing a newer handoff 25/25 times. | Completion is conditional on the parent still awaiting that exact child; a live-linked child must remain owned by its parent. | `completeDelegatedChild` rejects stale authoritative input. The lifecycle explorer checks that reducer rule, while the shared-store explorer reproduces the cross-host stale-cache counterexample with an exact causal witness. | -| [#1021](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1021): an in-flight `saveClineMessages` can restore parent/root IDs after abandonment cleared them. | Detachment should be monotonic: later lifecycle work must not reattach an abandoned child. | `abandonDelegatedChild` clears both sides. The shared-store explorer proves the detach commit occurs, then reproduces a refreshed-cache delta that preserves interrupted status while restoring stale live-task lineage. | -| [#1453](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1453), under user report [#1279](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1279): CI observed `TaskCompleted` before restart-visible API history once; 120 local repetitions did not reproduce it. | Completion implies restart-visible assistant history. Delayed or failed writes keep completion pending, and cancellation settles readiness without starting stale retries or emitting completion. | The completion persistence explorer checks the bounded event-ordering and cancellation contract for standalone and delegated tasks. Focused `Task` and `AttemptCompletionTool` tests cover the production adapter; `restart-persistence.test.ts` verifies visibility through a fresh extension host. | -| [#921](https://github.com/Zoo-Code-Org/Zoo-Code/issues/921): delegation across parallel tabs lacks coverage for different view-local mode/profile state. | Delegation must bind an explicit immutable execution-context snapshot rather than read whichever view is focused later. | The persisted ownership transition is covered; mode/profile snapshot isolation is outside this state model and belongs in a production adapter/model-based test. | -| [#920](https://github.com/Zoo-Code-Org/Zoo-Code/issues/920): issue analysis identifies a missing cross-instance history-update test and potential lost writes. | Distinct task writes must not overwrite one another, and same-task conflicts need an explicit merge/ownership rule. | The shared-store explorer checks distinct-task writes and same-record independent deltas. Cross-instance store tests retain production API coverage, and the synchronized real-filesystem smoke test exercises the actual lock/write path without claiming exhaustive filesystem proof. | -| [#369](https://github.com/Zoo-Code-Org/Zoo-Code/issues/369) and [#372](https://github.com/Zoo-Code-Org/Zoo-Code/issues/372): planned fan-out keeps a parent live while a child runs and requires completion routing by explicit parent ID, single-writer result readiness, permit release, and orphan cleanup. | Persisted `delegated` status is ownership, not proof that the parent instance is suspended. Completion must route by IDs; scheduler resources and live-instance state need separate invariants. | Nested and sibling lifecycle ownership are covered. Scheduler permits, live/suspended parent selection, orphan cancellation, and single-writer message readiness must be added when fan-out lands; they should not be folded into `HistoryItem` fields prematurely. | -| [#1468](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1468): a late chunk from one request combined tool identity with arguments from another request; rerun passed. | Every stream accumulator needs a request/task generation key, and late events cannot mutate another scope. | Separate protocol. The [native tool-call parser request-scope model](./native-tool-call-parser-scoping-model.md), whose source of truth is `scripts/check-native-tool-call-parser-scoping.ts`, exhaustively replays bounded production-parser interleavings without adding fields to this lifecycle model. | -| [#612](https://github.com/Zoo-Code-Org/Zoo-Code/issues/612): the CLI copied a status union and omitted `interrupted`. | Lifecycle vocabulary should have one type owner. | `HistoryItemStatus` is derived from `HistoryItem`, and production/checker transitions share `taskLifecycle.ts`; consumers should import rather than copy the union. | - -The issue-derived cases intentionally map to bug classes rather than issue-specific flags. In particular, stale event ownership, monotonic terminal/detached state, explicit scope, and single-writer boundaries generalize to future concurrent task work. +## Coverage audit + +| Protocol area | Coverage status | Production/model relationship | Explicit limits and open points | +| ------------------------------ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Delegation lifecycle | Production-backed bounded universal | The explorer calls the four production reducers for three task slots through depth 12. | Excludes provider instances, persistence failures, scheduler state, most live `Task` behavior, and generation identity for delayed pre-interruption completion. Recovery-compatible active-parent completion is test-only. | +| Shared-store concurrency | Production-backed bounded scenarios plus known-unsafe witnesses | The explorer imports production delta/merge functions and reducers; a real-filesystem test is a smoke check. | Does not prove crash safety, filesystem/lock semantics, arbitrary processes, or loss-free same-field merging. #1469 and #1021 remain unsafe. | +| Provider handoff and scheduler | Mixed: production-backed reducers/selector plus abstract bounded protocol | Commits use production reducers; provider ownership, publication, transition locks, and permits are model abstractions through depth 15. | Selector correctness does not refine all downstream readers. Scheduler tests cover concrete permit behavior separately. | +| Optional fan-out scope | Planned-only abstract bounded protocol outside baseline CI | The model has two sibling slots and two abstract permits and imports no production fan-out transition. | Excluded from baseline closure; production fan-out remains separately scoped future functionality. | +| Cleanup | Abstract bounded universal plus adapter tests | Abort, disposal, settlement, rejection, and provider shutdown are modeled as protocol/environment actions. | No direct execution of all production cleanup methods, filesystem/editor promises, timing liveness, fairness, or arbitrary task counts. | +| Parser request scope | Production-backed bounded schedule replay | The checker executes production parser APIs across 924 order-preserving schedules for two scopes. | Assumes callers stop invoking a finalized scope; transport behavior, arbitrary request counts, indices, and malformed histories are outside the claim. | +| Completion persistence | Abstract bounded universal plus production tests and one fresh-host E2E path | The model abstracts persistence as a durable phase with at most two write starts; production guards and retry paths are tested separately. | Production permits more retries; no power-loss/filesystem proof, fairness, arbitrary retry count, complete delegated fallback, provider status metadata, or downstream event-consumer model. | + +The production mapping above names primary lifecycle transitions, not every mutation or consumer. Generic store upserts, reconciliation, repair replay, migrations, tool entry points, webview/public API abandonment, provider status updates, and public `TaskCompleted` re-emission remain outside the persisted reducer graph unless explicitly named by a submodel or focused test. For task-local mode, the consumers named under #921/#1623 are a confirmed set, not an exhaustive repository-wide inventory; other mode-sensitive tools must be audited before claiming universal reader isolation. + +CI runs `pnpm lifecycle:model-check` in `.github/workflows/code-qa.yml` after lint and type checking. Extension-host subtask and restart-persistence E2E run separately; a green umbrella command therefore says nothing about an omitted E2E boundary or an unmodeled downstream consumer. + +## Gap audit + +This section is a summary tracker. Issue links are historical provenance rather than specifications. Coverage status uses these evidence classes: + +The [Task lifecycle verification GAP report](./task-lifecycle-gap-report.md) is the authoritative register. It holds the exhaustive repository inventory, the ranked stable burn-down register, the source-based methodology, and the follow-up checklist. This page remains the executable model-suite specification. + +- **Production-backed bounded:** exhaustive only for the declared state space while executing production functions. +- **Abstract bounded:** exhaustive only for model-authored transitions; refinement depends on separate adapter tests. +- **Known-unsafe witness:** CI preserves a reproducible violation and does not claim the property holds. +- **Proxy/partial:** evidence covers a premise, adapter, or representative path, not the full claim. +- **Planned-only:** specifies behavior not enabled in production. +- **Type/static convention:** centralized typing or guidance without repository-wide enforcement. + +| Gap | Invariant | Current evidence | Production/model boundary and runtime impact | Missing work and objective closure criteria | +| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Cross-host completion ownership | A completion may mutate a parent only while that parent authoritatively awaits the same child. | **Known-unsafe witness** plus a production-backed reducer guard. | The reducer rejects stale authoritative input, but disk revalidation checks status legality rather than exact-child ownership. A stale host can orphan the newer child. | Revalidate exact ownership under the disk lock; add deterministic two-store regression coverage; replace the expected witness with a universal bounded invariant. | +| Monotonic detachment | Message persistence must never restore lineage after abandonment clears it. | **Known-unsafe witness** plus a production-backed detach reducer. | A live task rebuilds lineage from stale fields; a later delta can restore parent/root IDs while preserving the interrupted status. | Give lifecycle fields a disk-authoritative write owner or tombstone/generation; prove stale metadata saves cannot alter them; promote the witness to an invariant. | +| Task-local mode consumers | Every mode-sensitive child operation must use the child task's immutable mode, not shared provider/view state. | Write side: **production-backed bounded matrix**. Three confirmed readers: **focused production tests**. Reader checker: **proxy/partial**. | The merged fix covers environment rendering, built-in validation, and custom-tool execution. The pure checker does not execute them, and other provider-mode readers are not exhaustively classified. | Complete the reader inventory, add focused divergent-mode evidence for each required task-local consumer, and enforce a task-local reader boundary before claiming universal isolation. | +| Tool-originated child initialization | Every required child field originating in `new_task` must be task-scoped, durably owned, and equivalent after rehydration. | Argument forwarding has focused tests; durable initial-state refinement is **unmodeled**. | Normal creation uses explicit model-supplied child todos rather than copying the parent, but initial todos demonstrate that some child state is process-local and can disappear. | Inventory all child initialization fields; define durable ownership, deep-copy, precedence, publication, and rehydration contracts with focused and E2E checks (`LIFE-GAP-035`). | +| Tool approval ownership | An interactive edit or settlement may affect only the matching task, action, and tool call. | Single-approval behavior has focused tests; cross-task correlation is **unmodeled and known unsafe by inspection**. | `update_todo_list` uses process-global edit state without task/action identity, allowing delayed or concurrent approval contamination. | Correlate proposal/edit/approval/cancellation by task and action/tool-call ID; reject stale edits and test interleavings (`LIFE-GAP-036`). | +| Tool partial-state isolation | Partial presentation state must be owned by one task and tool call and cleared on every terminal path. | Tool-local tests only; cross-call/task interleavings are **unmodeled**. | Singleton handlers share `lastSeenPartialPath`, so another call can create false or missed path stabilization. | Key state by `(taskId, toolCallId)` or instantiate handlers per call; test interleavings and cleanup (`LIFE-GAP-037`). | +| Tool identity correspondence | Parsed call, durable history, approval, execution, result, pending action, and replay must have one collision-resistant identity. | Duplicate-ID helper tests are **proxy/partial**; end-to-end correspondence is **unmodeled**. | Non-injective sanitization can collapse distinct raw IDs in history while execution still treats them as separate calls. | Reject/disambiguate collisions and prove a one-to-one identity mapping across native/MCP calls and restart (`LIFE-GAP-038`). | +| Serial delegation baseline | Current production permits one awaited active child per parent and resumes the parent only after child release. | Singular ownership is **production-backed bounded**; scheduler/provider ordering is mixed production/abstract. | Reducers and the normal provider path enforce singular ownership, but stale cross-host persistence can still violate the relationship; scheduler capacity is defaulted, not statically fixed. | Close current serial persistence/ordering gaps and ratchet the provider's one-permit baseline. Treat fan-out as separate optional scope. | +| Shared lifecycle status vocabulary | All consumers should derive task status from one exported owner. | **Type/static convention**; the visible interrupted-status symptom is repaired. | Persistence derives its alias from `HistoryItem`, but CLI history adapters still copy the union, allowing future drift. | Export one shared status type, consume it at CLI/persistence boundaries, and rely on typechecking or a static rule to reject copied incompatible vocabulary. | +| Cross-model refinement | No independent checker result may be combined into a stronger end-to-end claim without an executable boundary mapping. | **Explicit limitation** only. | Persistence, provider publication, parser scope, cleanup, and completion durability run as separate state spaces; omitted consumers can violate a premise after another checker passes. | Add production-grounded boundary events and a bounded joint strategy for each genuinely cross-model invariant, or keep claims explicitly local. | +| Completion event consumers | Public completion must not be treated as universally durable beyond the modeled readiness contract. | **Abstract bounded** model plus focused tests and one fresh-host E2E path. | The model abstracts durability and parent reopen; provider status metadata and downstream `TaskCompleted` consumers are outside its state. | Inventory downstream consumers and add refinement checks only for guarantees they require; retain power-loss, filesystem, retry-count, and liveness exclusions. | + +## Historical provenance + +- Cross-host completion ownership: [#1469](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1469). +- Monotonic detachment: [#1021](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1021). +- Task-local mode isolation: [#921](https://github.com/Zoo-Code-Org/Zoo-Code/issues/921), [#1623](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1623), and merged runtime-fix [PR #1625](https://github.com/Zoo-Code-Org/Zoo-Code/pull/1625). +- Fan-out product backlog: [#369](https://github.com/Zoo-Code-Org/Zoo-Code/issues/369) and [#372](https://github.com/Zoo-Code-Org/Zoo-Code/issues/372). +- Shared status vocabulary: [#612](https://github.com/Zoo-Code-Org/Zoo-Code/issues/612). +- Completion visibility history: [#1453](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1453) and [#1279](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1279). +- Cross-instance history preservation: [#920](https://github.com/Zoo-Code-Org/Zoo-Code/issues/920). +- Parser request scoping: [#1468](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1468). ## Extending the model @@ -153,7 +209,7 @@ When production lifecycle behavior changes: 4. Increase depth or task slots only when the new scenario requires it. Keep the state budget explicit and ensure CI completes quickly. 5. Convert any discovered counterexample into a focused production regression test as well as retaining the architectural invariant. -Completion-readiness changes belong in `scripts/check-completion-persistence.ts`; shared-store interleavings belong in `scripts/check-task-store-concurrency.ts`. Do not weaken bounds or remove an invariant merely to make CI pass. If state growth becomes difficult to control, split independent protocols or move the model to TLC/Quint with an implementation trace adapter rather than silently sampling the state space. +Completion-readiness changes belong in `scripts/check-completion-persistence.ts`; shared-store interleavings belong in `scripts/check-task-store-concurrency.ts`. Optional fan-out work belongs in `scripts/check-task-fanout-protocol.ts` and its separately scoped ticket until production transitions exist. Do not weaken bounds or remove an invariant merely to make CI pass. If state growth becomes difficult to control, split independent protocols or move the model to TLC/Quint with an implementation trace adapter rather than silently sampling the state space. Parser request scoping is one such independent bounded submodel within the umbrella suite. Extend `scripts/check-native-tool-call-parser-scoping.ts` and its focused architecture document instead of adding parser state or transitions to `taskLifecycle.ts` or the persisted lifecycle state graph. diff --git a/docs/architecture/task-lifecycle-remediation-blocks.md b/docs/architecture/task-lifecycle-remediation-blocks.md new file mode 100644 index 0000000000..ffbcbb334b --- /dev/null +++ b/docs/architecture/task-lifecycle-remediation-blocks.md @@ -0,0 +1,136 @@ +# Task lifecycle remediation blocks + +## One story point in this report + +One story point (1 SP) is a small, independently reviewable **modeling or documentation increment**, not a time estimate. A 1-SP block owns one bounded behavior or property and must include: + +- an explicit production symbol or boundary mapping; +- one model/checker change when a faithful model boundary exists, otherwise an explicit reason no checker is appropriate; +- focused test or CI evidence references; +- objective acceptance criteria and declared exclusions. + +Completing one block does not close its `LIFE-GAP` unless the parent GAP closure criteria are also satisfied. Blocks may depend on shared primitives or earlier evidence, so story-point size does not imply scheduling independence. + +## Ownership rules + +- Every `LIFE-GAP-001` through `LIFE-GAP-038` has exactly one primary block below. +- A block owns exactly one GAP ID. Dependencies may reference other blocks but do not duplicate ownership. +- Block IDs are stable: `LIFE-BLK-P-`. +- Baseline blocks describe current serial production behavior. Optional fan-out is isolated under `FANOUT-BLK-*` and does not own a baseline `LIFE-GAP`. +- Each block is documentation/formal-model scope. Runtime work named in acceptance criteria belongs in a later implementation PR. + +## P1: Persisted ownership and generation + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------- | +| LIFE-BLK-P1-001 | 001 | Encode authoritative awaited-child revalidation as a model boundary and retain the shortest stale-completion witness. | `TaskHistoryStore.atomicUpdatePair`, `ClineProvider.reopenParentFromDelegation`; shared-store checker; cross-instance tests. | None | Model names lock-time ownership check, witness, bounds, and production test required for promotion. | +| LIFE-BLK-P1-002 | 002 | Specify lifecycle-owned lineage fields versus metadata writes and the stale-save witness. | `Task.saveClineMessages`, `taskMetadata`, `mergeHistoryDelta`; shared-store checker. | P1-001 ownership vocabulary | Field ownership table and monotonic-detachment invariant are explicit; no claim of current safety. | +| LIFE-BLK-P1-012 | 012 | Add attempt-generation state and stale-versus-resumed completion scenarios to the specification. | `PendingTaskAction.actionId`, interruption/resume/completion reducers; lifecycle checker exclusion. | P1-001 | Two generations and acceptance/rejection landmarks are specified with a bounded future checker shape. | +| LIFE-BLK-P1-017 | 017 | Inventory mutable cache read consumers and define immutable read semantics. | `TaskHistoryStore.get/getAll`; store tests. | None | Every direct caller is classified; clone/freeze test criteria and compatibility exclusions are recorded. | +| LIFE-BLK-P1-020 | 020 | Define observable stale-cache and convergence histories. | watcher, `invalidate`, `reconcile`; shared-store landmarks and cross-instance tests. | P1-001 | Missed-watch and explicit-refresh histories have bounded properties and objective convergence evidence. | + +## P2: Durable operation and crash recovery + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------- | +| LIFE-BLK-P2-004 | 004 | Enumerate pair-write interruption points and legal recovered states. | `atomicUpdatePair`; pair-failure landmark/tests. | P1-001 | Every pre/post-write cut has one legal outcome and required fault-injection assertion. | +| LIFE-BLK-P2-005 | 005 | Map delegation create/persist/publish/start cuts and rollback obligations. | `delegateParentAndOpenChild`; provider handoff model/tests. | P1-001, P2-004 | Transition table covers every cut without claiming child/parent atomicity. | +| LIFE-BLK-P2-006 | 006 | Specify completion message/lifecycle commit phases and replay outcomes. | `reopenParentFromDelegation`; completion and shared-store models. | P1-012, P2-004 | Result visibility and lifecycle state are mapped for each injected failure point. | +| LIFE-BLK-P2-021 | 021 | Define store close/drain semantics and post-dispose write exclusion. | `TaskHistoryStore.dispose`, write lock; store tests. | P2-004 recovery vocabulary | A bounded close-state machine and deterministic pending-write test criteria are documented. | +| LIFE-BLK-P2-023 | 023 | Specify deletion unlink failure and reconciliation histories. | `delete/deleteMany`, task directory/checkpoint cleanup; deletion tests. | P2-004 | False-success and resurrection outcomes are explicit with tombstone/retry closure choices. | + +## P3: Schema, path, and vocabulary + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ---------- | ---------------------------------------------------------------------------------------- | +| LIFE-BLK-P3-013 | 013 | Publish the canonical persisted-status owner and copied-union inventory. | `historyItemSchema`, task metadata, Task, CLI/history reader; typecheck/tests. | None | Every copy is listed with replacement/static-ratchet criteria. | +| LIFE-BLK-P3-018 | 018 | Define normal-read validation and quarantine outcomes for malformed history. | `readTaskFile`, reconciliation, shared Zod schema; fixtures. | None | Missing/invalid/legacy records have distinct expected outcomes and test fixtures. | +| LIFE-BLK-P3-019 | 019 | Inventory every task-ID-to-path entry and one shared safe-ID contract. | store paths, imports, deletion, checkpoints; traversal tests. | P3-018 | All path constructors are mapped and separator/traversal acceptance tests are specified. | + +## P4: Request, stream, and tool identity + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | -------------------------- | ------------------------------------------------------------------------------------------- | +| LIFE-BLK-P4-008 | 008 | Add transform-to-parser cases for argument-only deltas and absent indices. | Responses transform, parser APIs/tests. | None | Two-call bounded schedules and expected isolated reconstruction are specified. | +| LIFE-BLK-P4-010 | 010 | Define request-generation ownership for detached usage writes. | Task request/drain paths; delayed-stream tests. | P4-038 identity vocabulary | Old/new generation mutations and allowed accounting-only updates are explicit. | +| LIFE-BLK-P4-024 | 024 | Map parser cleanup on success, abort, provider error, and replacement. | parser scope plus Task request terminal paths. | P4-010 | Every terminal path owns cleanup; late-event exclusions are stated. | +| LIFE-BLK-P4-025 | 025 | Specify listener lifetime for one chunk race and long streams. | `nextChunkWithAbort`; listener-count tests. | None | Both race outcomes remove listeners and a bounded stream cannot accumulate them. | +| LIFE-BLK-P4-026 | 026 | Model a true wall-clock deadline around pending iterator reads. | detached usage drain; fake-timer tests. | P4-010 | Permanently pending `next()` has a terminal deadline transition and no stale mutations. | +| LIFE-BLK-P4-030 | 030 | Define duplicate-start/run-promise identity. | `Task.start/run`, scheduler callback; Task tests. | P4-010 | Repeated starts share the actual settlement and cannot bypass scheduler ownership. | +| LIFE-BLK-P4-037 | 037 | Specify call-scoped partial path state and two-call interleavings. | `BaseTool.lastSeenPartialPath`, editing tool singletons; focused tests. | P4-038, P4-010 | Equal/different path interleavings and sibling-safe cleanup are bounded and reachable. | +| LIFE-BLK-P4-038 | 038 | Define canonical raw-to-durable call identity and collision witnesses. | tool-ID utility, parser, Task history, results, pending actions; duplicate-ID tests. | None | Adversarial IDs preserve or explicitly reject one-to-one call/result/replay correspondence. | + +## P5: Tool-owned task state and queueing + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| LIFE-BLK-P5-003 | 003 | Map every queue consumer to claim/persist/ack or dequeue-before-submit. | `MessageQueueService`, Task queue paths; failure tests. | None | Every consumer is classified and message-retention failure evidence is specified. | +| LIFE-BLK-P5-007 | 007 | Inventory remaining mode-sensitive readers and authoritative task/provider source after the merged three-reader fix. | handoff selector, named production readers `getEnvironmentDetails`, `validateToolUse` call sites in `presentAssistantMessage`, custom tool execution, merged environment/validation/custom-tool tests, delegated reader checker. | None | Confirmed readers are marked production-tested; unclassified readers remain listed; the pure checker is not described as executing downstream readers. | +| LIFE-BLK-P5-031 | 031 | Define intentional versus accidental queue loss across task disposal/restart. | queue service disposal and task lifecycle; E2E boundary. | P5-003 | Product contract, excluded durability, and restart witness are explicit. | +| LIFE-BLK-P5-035 | 035 | Specify durable child initialization precedence using initial todos as witness. | `NewTaskTool`, Task constructor, history/messages, rehydration, UI state. | P2-005 | Omitted, explicit-empty, initial, updated, switched, and restarted cases are mapped. | +| LIFE-BLK-P5-036 | 036 | Model two approval identities and stale/cross-task todo edits. | `approvedTodoList`, webview handler, approval callbacks/tests. | P4-038 | Two-task schedules require task/action/call correlation; current unsafe witness is explicit. | + +## P6: Event and ingress contracts + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------- | +| LIFE-BLK-P6-009 | 009 | Classify lifecycle events as awaited barriers or notifications. | Task/provider/public emitters and listeners; event tests. | P1-012 | Every consequential listener has settlement and rejection semantics. | +| LIFE-BLK-P6-011 | 011 | Inventory `TaskCompleted` consumers and required durable observations. | completion tool, provider status, public API/IPC/telemetry; completion model/tests. | P6-009, P2-006 | Each consumer’s ordering requirement maps to focused evidence or exclusion. | +| LIFE-BLK-P6-022 | 022 | Compare public and webview clear histories. | API eviction versus webview removal; provider tests. | P1-001 | Identical inputs produce an explicit same-or-deliberately-different persisted outcome. | +| LIFE-BLK-P6-027 | 027 | Establish one owner for delegation event emission. | task-level untyped and provider-level listeners; API tests. | P6-009 | Exactly-one source and no duplicate/dead listener are objective acceptance criteria. | +| LIFE-BLK-P6-028 | 028 | Normalize `TaskSpawned` payload semantics in the contract map. | task/provider/public event types and adapters. | P6-027 | Parent/child fields are explicit at each boundary with compatibility requirements. | +| LIFE-BLK-P6-029 | 029 | Document exact predicates behind `taskStatus` and `getRunning`. | Task ask markers, registry abort flags; caller inventory. | None | No caller may infer scheduler admission or persisted status without separate evidence. | +| LIFE-BLK-P6-032 | 032 | Decide supported reachability for webview abandonment. | protocol, handler, UI sender search; host tests. | P6-022 | Add sender evidence or deprecation criteria; no unreachable feature claim remains. | +| LIFE-BLK-P6-033 | 033 | Build a resume-ingress contract matrix. | webview/API/IPC resume adapters; provider/E2E tests. | P1-012, P6-009 | Awaiting, errors, publication, and rehydration results are explicit for each ingress. | + +## P7: Serial baseline and optional fan-out + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------- | +| LIFE-BLK-P7-014 | 014 | Ratchet the current singular-child/one-permit baseline and its cross-host exclusions. | lifecycle reducers/checker, provider scheduler, shared-store witnesses. | P1-001 | Baseline property, bounds, scheduler assumption, and stale-write exceptions are explicit. | + +Optional future fan-out blocks do not own `LIFE-GAP-014` and do not participate in baseline closure: + +| Optional block | Increment | Prerequisites | Acceptance | +| -------------- | ------------------------------------------------------------ | ----------------------------- | ---------------------------------------------------------------------------------- | +| FANOUT-BLK-001 | Map live-parent and two-sibling production boundaries. | LIFE-BLK-P7-014, P1 ownership | No production claim; all missing adapters are named. | +| FANOUT-BLK-002 | Specify reservation, rollback, and permit-release failures. | FANOUT-BLK-001, P2 recovery | Every acquisition/create failure has a legal terminal state. | +| FANOUT-BLK-003 | Specify result writer, explicit routing, and orphan cleanup. | FANOUT-BLK-001, P4 identity | Existing abstract model landmarks map to required production APIs/tests. | +| FANOUT-BLK-004 | Define extension/webview task-scoping E2E matrix. | FANOUT-BLK-001–003 | Focus, messages, profiles, results, cancellation, and orphan behavior are covered. | + +## P8: Verification and traceability platform + +| Block | GAP | 1-SP increment | Production/model/test mapping | Depends on | Acceptance | +| --------------- | --- | ------------------------------------------------------------------- | ----------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------- | +| LIFE-BLK-P8-015 | 015 | Select one cross-model claim and define executable boundary events. | Two relevant checkers plus production adapters. | Owning workstream block | Joint strategy is bounded or the claim remains explicitly local. | +| LIFE-BLK-P8-016 | 016 | Add a machine-readable GAP-to-symbol/test/checker manifest design. | report, scripts, package, workflows. | None | CI validation rules detect missing paths, duplicate ownership, and stale IDs. | +| LIFE-BLK-P8-034 | 034 | Define emitted checker metadata for bounds/actions/landmarks. | all checker scripts and docs. | P8-016 | One schema represents model metadata and docs consume or validate it. | + +## Mechanical coverage check + +The primary tables above map the closed integer range `001..038` exactly once. Reviewers should verify this mechanically before changing the register: + +```sh +rg -o '^\| LIFE-BLK-P[0-9]-[0-9]{3} \|' docs/architecture/task-lifecycle-remediation-blocks.md \ + | sort \ + | uniq -d +``` + +The command must print nothing. It matches only primary table rows, so dependency references and optional `FANOUT-BLK-*` rows are excluded. + +Separately compare block suffixes with the GAP column to detect omissions or mismatches: + +```sh +node -e 'const fs=require("fs");const s=fs.readFileSync("docs/architecture/task-lifecycle-remediation-blocks.md","utf8");const rows=[...s.matchAll(/^\| LIFE-BLK-P\d-(\d{3}) \| (\d{3}) \|/gm)];const gaps=rows.map(r=>r[2]);const want=Array.from({length:38},(_,i)=>String(i+1).padStart(3,"0"));if(rows.length!==38||rows.some(r=>r[1]!==r[2])||want.some(id=>!gaps.includes(id)))process.exit(1)' +``` + +## Block completion template + +- [ ] Stable block and parent GAP IDs are in the PR description. +- [ ] One bounded behavior/property and its exclusions are stated. +- [ ] Production symbols and ownership boundary are linked. +- [ ] Model/checker change is included, or non-applicability is justified. +- [ ] Focused test, E2E, and CI evidence requirements are explicit. +- [ ] Actions/landmarks remain reachable; bounds cannot truncate silently. +- [ ] Completion does not overstate parent GAP closure. +- [ ] Dependencies are satisfied or carried as explicit blockers. diff --git a/package.json b/package.json index 1fd9ddc8fe..1dd8d3d260 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,10 @@ "lint": "turbo lint --log-order grouped --output-logs new-only", "check-types": "turbo check-types --log-order grouped --output-logs new-only", "test": "turbo test --log-order grouped --output-logs new-only", + "test:code-qa-ci": "node --test scripts/code-qa-workflow.test.mjs", "test:mutation-ci": "node --test scripts/stryker-diff.test.mjs", - "lifecycle:model-check": "tsx scripts/check-task-lifecycle.ts && tsx scripts/check-task-store-concurrency.ts && tsx scripts/check-provider-handoff-scheduler.ts && pnpm cleanup-protocol:model-check && pnpm parser-scope:model-check && tsx scripts/check-completion-persistence.ts", + "lifecycle:model-check": "tsx scripts/check-task-lifecycle.ts && tsx scripts/check-task-store-concurrency.ts && tsx scripts/check-provider-handoff-scheduler.ts && pnpm cleanup-protocol:model-check && pnpm parser-scope:model-check && tsx scripts/check-completion-persistence.ts && tsx scripts/check-delegated-mode-readers.ts", + "fanout-protocol:model-check": "tsx scripts/check-task-fanout-protocol.ts", "cleanup-protocol:model-check": "tsx scripts/check-task-cleanup-protocol.ts", "parser-scope:model-check": "node scripts/run-native-tool-call-parser-scoping.mjs", "mcp:integration-check": "tsx scripts/check-mcp-oauth-integration.ts", diff --git a/packages/build/package.json b/packages/build/package.json index 67922d3d09..8668a19207 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -15,6 +15,6 @@ "@roo-code/config-eslint": "workspace:^", "@roo-code/config-typescript": "workspace:^", "@types/node": "22.20.1", - "vitest": "4.1.9" + "vitest": "4.1.11" } } diff --git a/packages/cloud/package.json b/packages/cloud/package.json index 5324832517..612b75afe9 100644 --- a/packages/cloud/package.json +++ b/packages/cloud/package.json @@ -23,6 +23,6 @@ "@types/vscode": "1.100.0", "globals": "16.5.0", "@vitest/coverage-v8": "4.1.9", - "vitest": "4.1.9" + "vitest": "4.1.11" } } diff --git a/packages/core/package.json b/packages/core/package.json index 741a71704a..bcaa1e5c16 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -32,6 +32,6 @@ "@roo-code/config-typescript": "workspace:^", "@types/node": "22.20.1", "@vitest/coverage-v8": "4.1.9", - "vitest": "4.1.9" + "vitest": "4.1.11" } } diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index 6c45195f6c..045e5cb4c2 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -22,6 +22,6 @@ "@types/node": "22.20.1", "@types/vscode": "1.100.0", "@vitest/coverage-v8": "4.1.9", - "vitest": "4.1.9" + "vitest": "4.1.11" } } diff --git a/packages/types/package.json b/packages/types/package.json index a30bba6ffb..dd459ebc3d 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -42,7 +42,7 @@ "globals": "16.5.0", "tsup": "8.5.1", "ajv": "8.20.0", - "vitest": "4.1.9", + "vitest": "4.1.11", "zod-to-json-schema": "3.25.2" } } diff --git a/packages/types/src/__tests__/deepseek-v4-pro.test.ts b/packages/types/src/__tests__/deepseek-v4-pro.test.ts index 78a4befd6b..6fa40d28eb 100644 --- a/packages/types/src/__tests__/deepseek-v4-pro.test.ts +++ b/packages/types/src/__tests__/deepseek-v4-pro.test.ts @@ -10,12 +10,18 @@ describe("DeepSeek V4 Pro 0813 provider catalogs", () => { expect(model?.contextWindow).toBeGreaterThanOrEqual(1_000_000) }) - it("uses peak first-party pricing and unchanged OpenCode Go pricing", () => { + it("uses current peak first-party pricing and unchanged OpenCode Go pricing", () => { + expect(deepSeekModels["deepseek-flash"]).toMatchObject({ + supportsImages: true, + outputPrice: 1.2, + cacheWritesPrice: 0.3, + cacheReadsPrice: 0.006, + }) expect(deepSeekModels["deepseek-v4-flash"]).toMatchObject({ - supportsImages: false, - outputPrice: 1.32, - cacheWritesPrice: 0.44, - cacheReadsPrice: 0.014, + supportsImages: true, + outputPrice: 1.2, + cacheWritesPrice: 0.3, + cacheReadsPrice: 0.006, }) expect(deepSeekModels["deepseek-v4-pro"].supportsImages).toBe(false) expect(deepSeekModels["deepseek-v4-pro"]).toMatchObject({ @@ -42,6 +48,10 @@ describe("DeepSeek V4 Pro 0813 provider catalogs", () => { expect(model.supportsPromptCache).toBe(true) expect(model.contextWindow).toBeGreaterThanOrEqual(1_000_000) expect(model.supportsReasoningEffort).toEqual(["disable", "low", "high", "max"]) + expect(model).toMatchObject({ outputPrice: 1.2, cacheWritesPrice: 0.3, cacheReadsPrice: 0.006 }) + expect(model.description).toContain("Legacy model name") + expect(model).not.toHaveProperty("supportsTemperature") + expect(model).not.toHaveProperty("defaultTemperature") }) // Self-hosted providers retain separate IDs for the preview weights and 0813 checkpoint. diff --git a/packages/types/src/providers/deepseek.ts b/packages/types/src/providers/deepseek.ts index 3e42bbfeec..5cd2e0f21d 100644 --- a/packages/types/src/providers/deepseek.ts +++ b/packages/types/src/providers/deepseek.ts @@ -6,23 +6,38 @@ import type { ModelInfo } from "../model.js" // continuation within the same turn. See: https://api-docs.deepseek.com/guides/thinking_mode export type DeepSeekModelId = keyof typeof deepSeekModels -export const deepSeekDefaultModelId: DeepSeekModelId = "deepseek-v4-flash" +export const deepSeekDefaultModelId: DeepSeekModelId = "deepseek-flash" export const deepSeekModels = { + "deepseek-flash": { + maxTokens: 384_000, + contextWindow: 1_000_000, + supportsImages: true, + supportsPromptCache: true, + supportsReasoningEffort: ["disable", "low", "high", "max"], // Updated 2026-09-10 + preserveReasoning: true, + reasoningEffort: "high", + inputPrice: 0, // the inputs are priced as cache read/write, so `inputPrice` should be 0 + // Static estimates use peak rates; off-peak rates are 50% lower. Effective 2026-09-10. + outputPrice: 1.2, + cacheWritesPrice: 0.3, + cacheReadsPrice: 0.006, + description: `DeepSeek-V4.1-Flash is DeepSeek's fast multimodal model with image understanding. It supports thinking and non-thinking modes, JSON output, tool calls, chat prefix completion (beta), and FIM completion (beta) in non-thinking mode.`, + }, "deepseek-v4-flash": { maxTokens: 384_000, contextWindow: 1_000_000, - supportsImages: false, + supportsImages: true, supportsPromptCache: true, supportsReasoningEffort: ["disable", "low", "high", "max"], // Updated 2026-08-13 preserveReasoning: true, reasoningEffort: "high", inputPrice: 0, // the inputs are priced as cache read/write, so `inputPrice` should be 0 - // Static estimates use peak rates; off-peak rates are 50% lower. Effective 2026-08-16. - outputPrice: 1.32, - cacheWritesPrice: 0.44, - cacheReadsPrice: 0.014, - description: `DeepSeek-V4-Flash is DeepSeek's fast, cost-efficient V4 model. It supports thinking and non-thinking modes, JSON output, tool calls, chat prefix completion (beta), and FIM completion (beta) in non-thinking mode.`, + // This retired ID is billed as the current Flash model. + outputPrice: 1.2, + cacheWritesPrice: 0.3, + cacheReadsPrice: 0.006, + description: `Legacy model name routed to the latest DeepSeek Flash model, which supports image input. Use deepseek-flash for new configurations.`, }, "deepseek-v4-pro": { displayName: "DeepSeek V4 Pro 0813", @@ -49,14 +64,12 @@ export const deepSeekModels = { supportsReasoningEffort: ["disable", "low", "high", "max"], // Updated 2026-08-13 preserveReasoning: true, reasoningEffort: "high", - supportsTemperature: true, - defaultTemperature: 1.0, inputPrice: 0, // the inputs are priced as cache read/write, so `inputPrice` should be 0 - // Static estimates use peak rates; off-peak rates are 50% lower. - outputPrice: 1.32, - cacheWritesPrice: 0.44, - cacheReadsPrice: 0.014, - description: `DeepSeek-V4-Flash-Vision-Exp is DeepSeek's experimental multimodal V4 Flash model with image understanding. It supports thinking and non-thinking modes, JSON output, tool calls, chat prefix completion (beta), and image input through Chat Completions, Responses, and Anthropic-compatible APIs.`, + // This retired ID is billed as the current Flash model. + outputPrice: 1.2, + cacheWritesPrice: 0.3, + cacheReadsPrice: 0.006, + description: `Legacy model name routed to the latest DeepSeek Flash model, which supports image input. Use deepseek-flash for new configurations.`, }, } as const satisfies Record diff --git a/packages/vscode-shim/package.json b/packages/vscode-shim/package.json index 167ec333d1..42b36e5af6 100644 --- a/packages/vscode-shim/package.json +++ b/packages/vscode-shim/package.json @@ -14,7 +14,7 @@ "@roo-code/config-eslint": "workspace:^", "@roo-code/config-typescript": "workspace:^", "@types/node": "22.20.1", - "vitest": "4.1.9" + "vitest": "4.1.11" }, "dependencies": {} } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47f526185f..9b93c1cfe5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,7 +34,7 @@ importers: version: 10.0.0(@types/node@22.20.1) '@stryker-mutator/vitest-runner': specifier: 10.0.0 - version: 10.0.0(@stryker-mutator/core@10.0.0(@types/node@22.20.1))(vitest@4.1.9) + version: 10.0.0(@stryker-mutator/core@10.0.0(@types/node@22.20.1))(vitest@4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0))) '@types/node': specifier: 22.20.1 version: 22.20.1 @@ -137,7 +137,7 @@ importers: version: 18.3.31 '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) ink-testing-library: specifier: 4.0.0 version: 4.0.0(@types/react@18.3.31) @@ -151,14 +151,14 @@ importers: specifier: 4.22.4 version: 4.22.4 vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) apps/vscode-e2e: devDependencies: '@copilotkit/aimock': specifier: 1.35.0 - version: 1.35.0(vitest@4.1.9) + version: 1.35.0(vitest@4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0))) '@playwright/test': specifier: 1.62.1 version: 1.62.1 @@ -208,8 +208,8 @@ importers: specifier: 22.20.1 version: 22.20.1 vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) packages/cloud: dependencies: @@ -237,13 +237,13 @@ importers: version: 1.100.0 '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) globals: specifier: 16.5.0 version: 16.5.0 vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) packages/config-eslint: devDependencies: @@ -309,10 +309,10 @@ importers: version: 22.20.1 '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) packages/ipc: dependencies: @@ -362,10 +362,10 @@ importers: version: 1.100.0 '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) packages/types: dependencies: @@ -395,8 +395,8 @@ importers: specifier: 8.5.1 version: 8.5.1(jiti@2.7.0)(postcss@8.5.15)(tsx@4.22.4)(typescript@5.9.3)(yaml@2.9.0) vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) zod-to-json-schema: specifier: 3.25.2 version: 3.25.2(zod@3.25.76) @@ -413,8 +413,8 @@ importers: specifier: 22.20.1 version: 22.20.1 vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) src: dependencies: @@ -667,7 +667,7 @@ importers: version: 1.100.0 '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) '@vscode/vsce': specifier: 3.9.2 version: 3.9.2 @@ -693,8 +693,8 @@ importers: specifier: 6.0.1 version: 6.0.1 vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) webview-ui: dependencies: @@ -941,10 +941,10 @@ importers: version: 5.2.0(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) '@vitest/coverage-v8': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) '@vitest/ui': specifier: 4.1.9 - version: 4.1.9(vitest@4.1.9) + version: 4.1.9(vitest@4.1.11) babel-plugin-react-compiler: specifier: 1.0.0 version: 1.0.0 @@ -958,8 +958,8 @@ importers: specifier: 8.1.0 version: 8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0) vitest: - specifier: 4.1.9 - version: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + specifier: 4.1.11 + version: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) packages: @@ -3652,11 +3652,11 @@ packages: '@vitest/browser': optional: true - '@vitest/expect@4.1.9': - resolution: {integrity: sha512-vl/rYsUKcBr3SnQn166+XR5ZQcgMx3DQhFWdfli/cWpLnLUmbxZvyrJZotLFUryib+LtArYMSTJ5RbQ57ZqrlA==} + '@vitest/expect@4.1.11': + resolution: {integrity: sha512-VX2x5vNJXET47KAFzwERI+KRMtTTCSWTfSMKsW7JsUsXV4psq++e3DvZpuTDOpHcxytiDs6p2nhVb2tVDiiUYw==} - '@vitest/mocker@4.1.9': - resolution: {integrity: sha512-EVkXzBjrPGM+cK8/ANWgBrkUCfJfb38/EfTSO8h7pWvKkyPkpWxvR7BkD2MyItMF62C97zAEoqdpUixwR/e+Rw==} + '@vitest/mocker@4.1.11': + resolution: {integrity: sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ==} peerDependencies: msw: ^2.4.9 vite: 8.1.0 @@ -3666,23 +3666,29 @@ packages: vite: optional: true + '@vitest/pretty-format@4.1.11': + resolution: {integrity: sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==} + '@vitest/pretty-format@4.1.9': resolution: {integrity: sha512-s0iufns3iIFitdgm+YR7g1whCAaGtXz459VS9/PqyKDEEFgYIhsHOQmXgIgDuYCt7DeQmiZT0Qe2OA2p4ZPu5A==} - '@vitest/runner@4.1.9': - resolution: {integrity: sha512-KXLMDtc7oe70+3mJfGrPUWPesswH+3sTxAMAMl8DG7I8IUQT4XW718dY5ID3vPUcmlu27CcKfY4P3h3I29SLJg==} + '@vitest/runner@4.1.11': + resolution: {integrity: sha512-LztvUgdwMNJMIkj3hQnnxiC2Xy1zNxq928W/xhjCLaNCzqTZOudjwbQf6v9IntZGPw132i2Lq2rgTRZHD3JHNw==} - '@vitest/snapshot@4.1.9': - resolution: {integrity: sha512-Jc7RKGNBo8Z28WYIm0Niej4xdSPByRf6mU58VpHQkd6Zh05rlnA+twjbK5HyeIGHxrzsc3mJgS43uM0CZKzaIA==} + '@vitest/snapshot@4.1.11': + resolution: {integrity: sha512-pN7ikn1ON7h8ee4gIAp4AzyK+zBtJPzVbqOgu5LCEh4VaJVbPQcgYQYJIMGQPXVeJJq1fnfazis7a5pFNPahog==} - '@vitest/spy@4.1.9': - resolution: {integrity: sha512-fHpsS6mIi+PiEW+vcRVOMkX1oSaPKne3VOclSFICPcGOmfKgXPU5iAah+wcNcj2xPrCCmfq99IDGf+EojhhvhA==} + '@vitest/spy@4.1.11': + resolution: {integrity: sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA==} '@vitest/ui@4.1.9': resolution: {integrity: sha512-U/cRvtqfEPj27FI1n9cyUvi4vXXdcLhjJiI+InYKdk8hP4VrS6RXOjGL7rfFaeBc37iRKANsR6eEzIoC7lmgBQ==} peerDependencies: vitest: 4.1.9 + '@vitest/utils@4.1.11': + resolution: {integrity: sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ==} + '@vitest/utils@4.1.9': resolution: {integrity: sha512-A51o8ymO5PpqlWNnBP9ZHPXDIpuMtTLlGSjN7la4US+LJzoUMyhwjA5QXlm39JexgwHKW4Xjs8Z2d3dLCXOeuA==} @@ -8635,20 +8641,20 @@ packages: yaml: optional: true - vitest@4.1.9: - resolution: {integrity: sha512-nE3/LEyc0z87uHYLZebqCUOaJr2hdtuPp7BQ4BosVFnfltxgAvMG08NyrSGlPpOUWvR27c5flSmYFTNr78L9GQ==} + vitest@4.1.11: + resolution: {integrity: sha512-fhACrNXUidIbGSBr5FlbuBkO7VWC1ZyLl0DO4CU2DrQoAPxX84Ysxs+HeGQpii5lZWV1Q4gBZTTu49mF+A6Edw==} engines: {node: ^20.0.0 || ^22.0.0 || >=24.0.0} hasBin: true peerDependencies: '@edge-runtime/vm': '*' '@opentelemetry/api': ^1.9.0 '@types/node': ^20.0.0 || ^22.0.0 || >=24.0.0 - '@vitest/browser-playwright': 4.1.9 - '@vitest/browser-preview': 4.1.9 - '@vitest/browser-webdriverio': 4.1.9 - '@vitest/coverage-istanbul': 4.1.9 - '@vitest/coverage-v8': 4.1.9 - '@vitest/ui': 4.1.9 + '@vitest/browser-playwright': 4.1.11 + '@vitest/browser-preview': 4.1.11 + '@vitest/browser-webdriverio': 4.1.11 + '@vitest/coverage-istanbul': 4.1.11 + '@vitest/coverage-v8': 4.1.11 + '@vitest/ui': 4.1.11 happy-dom: '*' jsdom: '*' vite: 8.1.0 @@ -9811,9 +9817,9 @@ snapshots: '@chevrotain/types@11.1.2': {} - '@copilotkit/aimock@1.35.0(vitest@4.1.9)': + '@copilotkit/aimock@1.35.0(vitest@4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)))': optionalDependencies: - vitest: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + vitest: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) '@csstools/color-helpers@5.0.2': {} @@ -11358,14 +11364,14 @@ snapshots: '@stryker-mutator/util@10.0.0': {} - '@stryker-mutator/vitest-runner@10.0.0(@stryker-mutator/core@10.0.0(@types/node@22.20.1))(vitest@4.1.9)': + '@stryker-mutator/vitest-runner@10.0.0(@stryker-mutator/core@10.0.0(@types/node@22.20.1))(vitest@4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)))': dependencies: '@stryker-mutator/api': 10.0.0 '@stryker-mutator/core': 10.0.0(@types/node@22.20.1) '@stryker-mutator/util': 10.0.0 semver: 7.8.5 tslib: 2.8.1 - vitest: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + vitest: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) '@tailwindcss/node@4.3.2': dependencies: @@ -11924,7 +11930,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@vitest/coverage-v8@4.1.9(vitest@4.1.9)': + '@vitest/coverage-v8@4.1.9(vitest@4.1.11)': dependencies: '@bcoe/v8-coverage': 1.0.2 '@vitest/utils': 4.1.9 @@ -11936,44 +11942,48 @@ snapshots: obug: 2.1.2 std-env: 4.1.0 tinyrainbow: 3.1.0 - vitest: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + vitest: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) - '@vitest/expect@4.1.9': + '@vitest/expect@4.1.11': dependencies: '@standard-schema/spec': 1.1.0 '@types/chai': 5.2.3 - '@vitest/spy': 4.1.9 - '@vitest/utils': 4.1.9 + '@vitest/spy': 4.1.11 + '@vitest/utils': 4.1.11 chai: 6.2.2 tinyrainbow: 3.1.0 - '@vitest/mocker@4.1.9(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0))': + '@vitest/mocker@4.1.11(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0))': dependencies: - '@vitest/spy': 4.1.9 + '@vitest/spy': 4.1.11 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: vite: 8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0) + '@vitest/pretty-format@4.1.11': + dependencies: + tinyrainbow: 3.1.0 + '@vitest/pretty-format@4.1.9': dependencies: tinyrainbow: 3.1.0 - '@vitest/runner@4.1.9': + '@vitest/runner@4.1.11': dependencies: - '@vitest/utils': 4.1.9 + '@vitest/utils': 4.1.11 pathe: 2.0.3 - '@vitest/snapshot@4.1.9': + '@vitest/snapshot@4.1.11': dependencies: - '@vitest/pretty-format': 4.1.9 - '@vitest/utils': 4.1.9 + '@vitest/pretty-format': 4.1.11 + '@vitest/utils': 4.1.11 magic-string: 0.30.21 pathe: 2.0.3 - '@vitest/spy@4.1.9': {} + '@vitest/spy@4.1.11': {} - '@vitest/ui@4.1.9(vitest@4.1.9)': + '@vitest/ui@4.1.9(vitest@4.1.11)': dependencies: '@vitest/utils': 4.1.9 fflate: 0.8.2 @@ -11982,7 +11992,13 @@ snapshots: sirv: 3.0.2 tinyglobby: 0.2.17 tinyrainbow: 3.1.0 - vitest: 4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + vitest: 4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + + '@vitest/utils@4.1.11': + dependencies: + '@vitest/pretty-format': 4.1.11 + convert-source-map: 2.0.0 + tinyrainbow: 3.1.0 '@vitest/utils@4.1.9': dependencies: @@ -17723,15 +17739,15 @@ snapshots: tsx: 4.22.4 yaml: 2.9.0 - vitest@4.1.9(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)): + vitest@4.1.11(@opentelemetry/api@1.9.0)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.9)(@vitest/ui@4.1.9)(jsdom@26.1.0)(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)): dependencies: - '@vitest/expect': 4.1.9 - '@vitest/mocker': 4.1.9(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) - '@vitest/pretty-format': 4.1.9 - '@vitest/runner': 4.1.9 - '@vitest/snapshot': 4.1.9 - '@vitest/spy': 4.1.9 - '@vitest/utils': 4.1.9 + '@vitest/expect': 4.1.11 + '@vitest/mocker': 4.1.11(vite@8.1.0(@types/node@22.20.1)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.22.4)(yaml@2.9.0)) + '@vitest/pretty-format': 4.1.11 + '@vitest/runner': 4.1.11 + '@vitest/snapshot': 4.1.11 + '@vitest/spy': 4.1.11 + '@vitest/utils': 4.1.11 es-module-lexer: 2.1.0 expect-type: 1.3.0 magic-string: 0.30.21 @@ -17748,8 +17764,8 @@ snapshots: optionalDependencies: '@opentelemetry/api': 1.9.0 '@types/node': 22.20.1 - '@vitest/coverage-v8': 4.1.9(vitest@4.1.9) - '@vitest/ui': 4.1.9(vitest@4.1.9) + '@vitest/coverage-v8': 4.1.9(vitest@4.1.11) + '@vitest/ui': 4.1.9(vitest@4.1.11) jsdom: 26.1.0 transitivePeerDependencies: - msw diff --git a/scripts/check-delegated-mode-readers.ts b/scripts/check-delegated-mode-readers.ts new file mode 100644 index 0000000000..bd77de29c1 --- /dev/null +++ b/scripts/check-delegated-mode-readers.ts @@ -0,0 +1,170 @@ +// check-delegated-mode-readers.ts +// +// Refinement check for the delegated-child mode-reader invariant (issue #1623). +// +// check-provider-handoff-scheduler.ts verifies the write side: that +// selectHandoffExecutionContext stores the task-local mode correctly. +// This script verifies the read side: that the mode observable by +// tool-validation readers is the task-local mode, not the shared provider mode. +// +// The VS Code-dependent readers (getEnvironmentDetails, +// presentAssistantMessage) are covered by their vitest regression tests. +// This script covers the pure-TS parts of the invariant chain and proves +// that the two sources of mode are observably different, so any reader +// that uses the wrong source silently produces wrong behavior. +// +// Invariant: for any delegated child task C with taskMode = M, +// toolAllowedForMode(tool, M) ≠ toolAllowedForMode(tool, providerMode) +// whenever M ≠ providerMode and the two modes differ on the tool's group. + +import assert from "node:assert/strict" + +import { DEFAULT_MODES } from "../packages/types/src/mode" + +import { TOOL_GROUPS, ALWAYS_AVAILABLE_TOOLS, TOOL_ALIASES } from "../src/shared/tools" +import { selectHandoffExecutionContext, type TaskExecutionContext } from "../src/core/task/providerHandoff" + +// --------------------------------------------------------------------------- +// Minimal inline mode-allows-tool check. +// Avoids importing src/shared/modes.ts, which pulls in VS Code. +// Only covers built-in modes (no custom modes, no file-regex options). +// That is enough to prove the behavioral divergence this check needs. +// --------------------------------------------------------------------------- + +type ModeConfig = (typeof DEFAULT_MODES)[number] +type GroupEntry = ModeConfig["groups"][number] + +function groupName(entry: GroupEntry): string { + return Array.isArray(entry) ? entry[0] : (entry as string) +} + +function toolAllowedForMode(tool: string, modeSlug: string): boolean { + const resolvedTool = (TOOL_ALIASES as Record)[tool] ?? tool + if ((ALWAYS_AVAILABLE_TOOLS as readonly string[]).includes(resolvedTool)) return true + const mode = DEFAULT_MODES.find((m) => m.slug === modeSlug) + if (!mode) return false + for (const entry of mode.groups) { + const groupTools = (TOOL_GROUPS as Record)[groupName(entry)]?.tools ?? [] + if (groupTools.includes(resolvedTool)) return true + } + return false +} + +// --------------------------------------------------------------------------- +// Scenario: parent in "orchestrator" mode delegates child to "code". +// Regression behavior: both readers used providerMode ("orchestrator"). +// Correct behavior: readers use taskMode ("code"). +// +// orchestrator groups: [] → apply_diff blocked +// code groups: [...edit] → apply_diff allowed +// --------------------------------------------------------------------------- + +const parentCtx: TaskExecutionContext = { + mode: "orchestrator", + apiConfigName: undefined, + apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 3 }, +} + +// 1. Handoff stores the task-local mode, not the parent mode. +const childCtx = selectHandoffExecutionContext(parentCtx, "code", parentCtx.mode, false, undefined) +assert.equal(childCtx.mode, "code", "handoff must store the requested task-local mode") +assert.notEqual(childCtx.mode, parentCtx.mode, "test scenario requires divergent provider and task modes") + +// 2. The two modes produce observably different tool-validation outcomes. +assert.equal(toolAllowedForMode("apply_diff", "orchestrator"), false, "orchestrator has no edit group") +assert.equal(toolAllowedForMode("apply_diff", "code"), true, "code has the edit group") + +// 3. Regression claim: a reader that consumes providerMode rejects apply_diff; +// a reader that consumes taskMode correctly allows it. +const viaProviderMode = toolAllowedForMode("apply_diff", parentCtx.mode) // "orchestrator" — wrong source +const viaTaskMode = toolAllowedForMode("apply_diff", childCtx.mode) // "code" — correct source +assert.equal(viaProviderMode, false, "stale provider mode rejects apply_diff (regression behavior)") +assert.equal(viaTaskMode, true, "task-local mode allows apply_diff (correct behavior)") + +// 4. Additional mode pairs that show the same divergence. +const DIVERGENT_PAIRS: Array<{ + label: string + providerMode: string + taskMode: string + probe: string + blockedInProvider: boolean + allowedInTask: boolean +}> = [ + // orchestrator → code: edit tools blocked at provider level, allowed at task level + { + label: "orchestrator→code apply_diff", + providerMode: "orchestrator", + taskMode: "code", + probe: "apply_diff", + blockedInProvider: true, + allowedInTask: true, + }, + // orchestrator → code: command tools blocked at provider level, allowed at task level + { + label: "orchestrator→code execute_command", + providerMode: "orchestrator", + taskMode: "code", + probe: "execute_command", + blockedInProvider: true, + allowedInTask: true, + }, + // code → ask: edit tools allowed at provider level, blocked at task level + { + label: "code→ask apply_diff", + providerMode: "code", + taskMode: "ask", + probe: "apply_diff", + blockedInProvider: false, + allowedInTask: false, + }, + // ask → code: edit tools blocked at provider level, allowed at task level + { + label: "ask→code write_to_file", + providerMode: "ask", + taskMode: "code", + probe: "write_to_file", + blockedInProvider: true, + allowedInTask: true, + }, +] + +for (const pair of DIVERGENT_PAIRS) { + const ctx = selectHandoffExecutionContext( + { ...parentCtx, mode: pair.providerMode }, + pair.taskMode, + pair.providerMode, + false, + undefined, + ) + assert.equal(ctx.mode, pair.taskMode, `${pair.label}: handoff must store task-local mode`) + assert.equal( + toolAllowedForMode(pair.probe, pair.providerMode), + !pair.blockedInProvider, + `${pair.label}: wrong provider-mode result`, + ) + assert.equal( + toolAllowedForMode(pair.probe, pair.taskMode), + pair.allowedInTask, + `${pair.label}: wrong task-mode result`, + ) + // The two sources disagree, so using the wrong one is always observable. + assert.notEqual( + toolAllowedForMode(pair.probe, pair.providerMode), + toolAllowedForMode(pair.probe, pair.taskMode), + `${pair.label}: provider and task mode must differ on this probe tool`, + ) +} + +// 5. For every built-in mode as a delegation target: selectHandoffExecutionContext +// always stores the requested mode, regardless of parent mode. +for (const mode of DEFAULT_MODES) { + const ctx = selectHandoffExecutionContext(parentCtx, mode.slug, parentCtx.mode, false, undefined) + assert.equal(ctx.mode, mode.slug, `handoff must store ${mode.slug}, not parent mode ${parentCtx.mode}`) +} + +console.log( + `Delegated mode reader check passed: ` + + `regression scenario verified, ` + + `${DIVERGENT_PAIRS.length} divergent-mode pairs checked, ` + + `${DEFAULT_MODES.length}/${DEFAULT_MODES.length} built-in modes verified`, +) diff --git a/scripts/check-provider-handoff-scheduler.ts b/scripts/check-provider-handoff-scheduler.ts index 3fbba11b35..e6c4c29a38 100644 --- a/scripts/check-provider-handoff-scheduler.ts +++ b/scripts/check-provider-handoff-scheduler.ts @@ -147,6 +147,18 @@ for (const scenario of PROFILE_SCENARIOS) { assert.equal(parentContext.apiConfiguration.consecutiveMistakeLimit, 3, `${scenario.name}: parent context mutated`) } +const downstreamConsumerWitness = selectHandoffExecutionContext( + { ...parentContext, mode: "orchestrator" }, + "code", + "orchestrator", + false, +) +assert.equal( + downstreamConsumerWitness.mode, + "code", + "#921/#1623 witness requires task-local and shared provider modes to diverge", +) + const fixed = explore(FIXED_POLICY, false) const counterexamples = LEGACY_POLICIES.map((policy) => { const result = explore(policy, true) @@ -156,7 +168,7 @@ const counterexamples = LEGACY_POLICIES.map((policy) => { }) console.log( - `Provider handoff/scheduler model check passed: ${fixed.states} distinct reachable states, ${PROFILE_SCENARIOS.length}/${PROFILE_SCENARIOS.length} profile scenarios, ${fixed.actions.size}/${EXPECTED_ACTIONS.length} actions, ${fixed.landmarks.size}/${Object.keys(LANDMARKS).length} landmarks, depth <= ${MAX_DEPTH}, states <= ${MAX_STATES}, ${counterexamples.length}/${LEGACY_POLICIES.length} legacy counterexamples`, + `Provider handoff/scheduler model check passed: ${fixed.states} distinct reachable states, ${PROFILE_SCENARIOS.length}/${PROFILE_SCENARIOS.length} profile scenarios, 1/1 downstream shared-mode witness, ${fixed.actions.size}/${EXPECTED_ACTIONS.length} actions, ${fixed.landmarks.size}/${Object.keys(LANDMARKS).length} landmarks, depth <= ${MAX_DEPTH}, states <= ${MAX_STATES}, ${counterexamples.length}/${LEGACY_POLICIES.length} legacy counterexamples`, ) for (const counterexample of counterexamples) { console.log( diff --git a/scripts/check-task-fanout-protocol.ts b/scripts/check-task-fanout-protocol.ts new file mode 100644 index 0000000000..026e3939f8 --- /dev/null +++ b/scripts/check-task-fanout-protocol.ts @@ -0,0 +1,253 @@ +import assert from "node:assert/strict" + +const CHILDREN = ["a", "b"] as const +type Child = (typeof CHILDREN)[number] +type ChildState = "idle" | "running" | "ready" | "delivered" | "cancelled" + +type ModelState = { + parentLive: boolean + children: Record + permitOwners: Child[] + resultWriters: Partial> + deliveries: Child[] + deliveryAfterParentLoss: boolean +} + +type Transition = { name: string; kind: string; next: ModelState } +type TraceStep = { action: string; state: ModelState } + +const MAX_DEPTH = 10 +const MAX_STATES = 500 +const EXPECTED_ACTIONS = ["launch", "finish", "deliver", "lose-parent", "cancel-orphan", "release"] as const +const LANDMARKS = { + "live-parent-with-two-children": (state: ModelState) => + state.parentLive && CHILDREN.every((child) => state.children[child] === "running"), + "out-of-order-results": (state: ModelState) => state.deliveries.join(",") === "b,a", + "single-writer-results": (state: ModelState) => + CHILDREN.every((child) => state.resultWriters[child] === undefined || state.resultWriters[child] === child), + "parent-loss-with-running-child": (state: ModelState) => + !state.parentLive && CHILDREN.some((child) => state.children[child] === "running"), + "orphan-cleanup": (state: ModelState) => + !state.parentLive && + state.permitOwners.length === 0 && + CHILDREN.every((child) => !["running", "ready"].includes(state.children[child])), +} satisfies Record boolean> + +const start = initialState() +const queue: Array<{ state: ModelState; trace: TraceStep[] }> = [ + { state: start, trace: [{ action: "initial", state: start }] }, +] +const visited = new Set([canonical(start)]) +const actions = new Set() +const landmarks = new Set() +const frontier: ModelState[] = [] + +const KNOWN_BAD_STATES: Array<{ name: string; state: ModelState; expected: string }> = [ + { + name: "wrong-result-writer", + state: { + ...initialState(), + children: { a: "ready", b: "idle" }, + permitOwners: ["a"], + resultWriters: { a: "b" }, + }, + expected: "a: result has the wrong writer", + }, + { + name: "early-delivery", + state: { ...initialState(), children: { a: "delivered", b: "idle" }, deliveries: ["a"] }, + expected: "a: result delivered before readiness", + }, + { + name: "duplicate-delivery", + state: { + ...initialState(), + children: { a: "delivered", b: "idle" }, + resultWriters: { a: "a" }, + deliveries: ["a", "a"], + }, + expected: "a: result delivered more than once", + }, + { + name: "post-parent-loss-delivery", + state: { ...initialState(), parentLive: false, deliveryAfterParentLoss: true }, + expected: "result routed after parent loss", + }, + { + name: "scheduler-over-allocation", + state: { ...initialState(), permitOwners: ["a", "b", "a"] }, + expected: "scheduler capacity exceeded", + }, + { + name: "duplicate-permit-owner", + state: { ...initialState(), children: { a: "running", b: "idle" }, permitOwners: ["a", "a"] }, + expected: "duplicate permit owner", + }, + { + name: "active-without-permit", + state: { ...initialState(), children: { a: "running", b: "idle" }, permitOwners: [] }, + expected: "a: active without permit ownership", + }, + { + name: "idle-child-owns-permit", + state: { ...initialState(), permitOwners: ["a"] }, + expected: "a: idle child owns a permit", + }, +] + +for (const unsafe of KNOWN_BAD_STATES) { + assert.ok(invariantViolations(unsafe.state).includes(unsafe.expected), `${unsafe.name}: invariant did not fire`) +} + +for (let index = 0; index < queue.length; index++) { + const node = queue[index]! + for (const [name, predicate] of Object.entries(LANDMARKS)) { + if (predicate(node.state)) landmarks.add(name) + } + const violations = invariantViolations(node.state) + assert.deepEqual(violations, [], formatViolation(violations, node.trace)) + if (node.trace.length - 1 === MAX_DEPTH) { + frontier.push(node.state) + continue + } + + for (const transition of transitions(node.state)) { + actions.add(transition.kind) + const trace = [...node.trace, { action: transition.name, state: transition.next }] + const nextViolations = invariantViolations(transition.next) + assert.deepEqual(nextViolations, [], formatViolation(nextViolations, trace)) + const key = canonical(transition.next) + if (visited.has(key)) continue + visited.add(key) + queue.push({ state: transition.next, trace }) + assert.ok(visited.size <= MAX_STATES, `exceeded ${MAX_STATES}-state budget`) + } +} + +const missingActions = EXPECTED_ACTIONS.filter((action) => !actions.has(action)) +assert.deepEqual(missingActions, [], `unreachable actions: ${missingActions.join(", ")}`) +const missingLandmarks = Object.keys(LANDMARKS).filter((name) => !landmarks.has(name)) +assert.deepEqual(missingLandmarks, [], `unreachable landmarks: ${missingLandmarks.join(", ")}`) +const unseen = frontier.flatMap(transitions).find(({ next }) => !visited.has(canonical(next))) +assert.equal(unseen, undefined, `depth ${MAX_DEPTH} has unseen successor ${unseen?.name}`) + +console.log( + `Task fan-out protocol model check passed: ${visited.size} distinct reachable states, ${actions.size}/${EXPECTED_ACTIONS.length} actions, ${landmarks.size}/${Object.keys(LANDMARKS).length} landmarks, ${KNOWN_BAD_STATES.length}/${KNOWN_BAD_STATES.length} unsafe counterexamples, depth <= ${MAX_DEPTH}, states <= ${MAX_STATES}`, +) + +function transitions(state: ModelState): Transition[] { + const result: Transition[] = [] + for (const child of CHILDREN) { + if (state.parentLive && state.children[child] === "idle" && state.permitOwners.length < 2) { + result.push( + action(`launch(${child})`, "launch", state, (next) => { + next.children[child] = "running" + next.permitOwners.push(child) + }), + ) + } + if (state.children[child] === "running") { + result.push( + action(`finish(${child})`, "finish", state, (next) => { + next.children[child] = "ready" + next.resultWriters[child] = child + }), + ) + } + if (state.parentLive && state.children[child] === "ready" && state.resultWriters[child] === child) { + result.push( + action(`deliver(${child}, parent)`, "deliver", state, (next) => { + next.children[child] = "delivered" + next.deliveries.push(child) + // Record the parent-liveness observed at delivery time so the "result routed + // after parent loss" invariant is coupled to the delivery mechanism, not a flag + // no transition writes. The guard above keeps this false in the correct spec, so + // the model still passes; if a future edit drops the guard, delivery fires with + // !parentLive, this sets the flag, and the invariant catches the regression. + next.deliveryAfterParentLoss ||= !state.parentLive + }), + ) + } + if (!state.parentLive && ["running", "ready"].includes(state.children[child])) { + result.push( + action(`cancel-orphan(${child})`, "cancel-orphan", state, (next) => { + next.children[child] = "cancelled" + }), + ) + } + if (state.permitOwners.includes(child) && ["delivered", "cancelled"].includes(state.children[child])) { + result.push( + action(`release(${child})`, "release", state, (next) => { + next.permitOwners = next.permitOwners.filter((owner) => owner !== child) + }), + ) + } + } + if (state.parentLive && CHILDREN.some((child) => state.children[child] !== "idle")) { + result.push( + action("lose-parent", "lose-parent", state, (next) => { + next.parentLive = false + }), + ) + } + return result +} + +function invariantViolations(state: ModelState): string[] { + const violations: string[] = [] + if (new Set(state.permitOwners).size !== state.permitOwners.length) violations.push("duplicate permit owner") + if (state.permitOwners.length > 2) violations.push("scheduler capacity exceeded") + if (state.deliveryAfterParentLoss) violations.push("result routed after parent loss") + for (const child of CHILDREN) { + const active = ["running", "ready"].includes(state.children[child]) + if (active && !state.permitOwners.includes(child)) violations.push(`${child}: active without permit ownership`) + if (state.children[child] === "idle" && state.permitOwners.includes(child)) { + violations.push(`${child}: idle child owns a permit`) + } + if (state.resultWriters[child] !== undefined && state.resultWriters[child] !== child) { + violations.push(`${child}: result has the wrong writer`) + } + if (state.deliveries.filter((delivered) => delivered === child).length > 1) { + violations.push(`${child}: result delivered more than once`) + } + if (state.children[child] === "delivered" && state.resultWriters[child] !== child) { + violations.push(`${child}: result delivered before readiness`) + } + } + return violations +} + +function initialState(): ModelState { + return { + parentLive: true, + children: { a: "idle", b: "idle" }, + permitOwners: [], + resultWriters: {}, + deliveries: [], + deliveryAfterParentLoss: false, + } +} + +function action(name: string, kind: string, state: ModelState, update: (next: ModelState) => void): Transition { + const next = structuredClone(state) + update(next) + return { name, kind, next } +} + +function canonical(state: ModelState): string { + // resultWriters is built incrementally in finish(), so key insertion order varies by + // interleaving; sort keys so logically identical states dedupe. deliveries stays ordered + // (the out-of-order-results landmark depends on it). + const resultWriters = Object.fromEntries( + (Object.keys(state.resultWriters) as Child[]).sort().map((child) => [child, state.resultWriters[child]]), + ) + return JSON.stringify({ ...state, permitOwners: [...state.permitOwners].sort(), resultWriters }) +} + +function formatViolation(violations: string[], trace: TraceStep[]): string { + return [ + violations.join("; "), + `Bounds: depth=${MAX_DEPTH}, states=${MAX_STATES}`, + ...trace.map((step, index) => `${index}. ${step.action}\n ${canonical(step.state)}`), + ].join("\n") +} diff --git a/scripts/code-qa-workflow.test.mjs b/scripts/code-qa-workflow.test.mjs new file mode 100644 index 0000000000..40ccc66348 --- /dev/null +++ b/scripts/code-qa-workflow.test.mjs @@ -0,0 +1,118 @@ +import assert from "node:assert/strict" +import fs from "node:fs" +import path from "node:path" +import { describe, it } from "node:test" +import { fileURLToPath } from "node:url" + +const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..") +const workflow = fs.readFileSync(path.join(repositoryRoot, ".github/workflows/code-qa.yml"), "utf8") +const extensionTurbo = JSON.parse(fs.readFileSync(path.join(repositoryRoot, "src/turbo.json"), "utf8")) +const coreTurbo = JSON.parse(fs.readFileSync(path.join(repositoryRoot, "packages/core/turbo.json"), "utf8")) + +const workflowStep = (name) => { + const match = workflow.match(new RegExp(`- name: ${name}\\n(?(?:\\s{14,}.*\\n?)*)`)) + assert.ok(match?.groups?.body, `missing workflow step: ${name}`) + return match.groups.body +} + +const parseWorkflowStep = (name) => { + const body = workflowStep(name) + const field = (key) => { + const line = body.split("\n").find((line) => line.trimStart().startsWith(`${key}:`)) + assert.ok(line, `missing ${key} field in workflow step: ${name}`) + return line.slice(line.indexOf(":") + 1).trim() + } + return { if: field("if"), run: field("run") } +} + +describe("platform unit-test workflow", () => { + it("keeps coverage authoritative on Ubuntu and runs equivalent uninstrumented Windows tests", () => { + assert.match(workflow, /name: ubuntu-latest[\s\S]*?collect-coverage: true/) + assert.match(workflow, /name: windows-latest[\s\S]*?collect-coverage: false/) + assert.ok(!workflow.includes("matrix.upload-coverage")) + + assert.deepEqual(parseWorkflowStep("Run extension coverage lanes"), { + if: "matrix.collect-coverage", + run: 'pnpm turbo run test:coverage:api test:coverage:core test:coverage:services test:coverage:misc test:coverage:tree-sitter --filter="zoo-code" --concurrency=2 --log-order grouped --output-logs new-only', + }) + + assert.deepEqual(parseWorkflowStep("Run extension test lanes"), { + if: "${{ !matrix.collect-coverage }}", + run: 'pnpm turbo run test:api test:core test:services test:misc test:tree-sitter --filter="zoo-code" --concurrency=2 --log-order grouped --output-logs new-only', + }) + + for (const [coverageStepName, plainStepName, coverageCommand, plainCommand] of [ + [ + "Run non-extension package coverage", + "Run non-extension package tests", + 'test:coverage --filter="!@roo-code/core" --filter="!zoo-code"', + 'test --filter="!@roo-code/core" --filter="!zoo-code"', + ], + [ + "Run core unit coverage", + "Run core unit tests", + 'test:coverage:unit --filter="@roo-code/core"', + 'test:unit --filter="@roo-code/core"', + ], + [ + "Run core integration coverage", + "Run core integration tests", + 'test:coverage:integration --filter="@roo-code/core"', + 'test:integration --filter="@roo-code/core"', + ], + ]) { + const coverageStep = parseWorkflowStep(coverageStepName) + assert.equal(coverageStep.if, "matrix.collect-coverage") + assert.ok(coverageStep.run.includes(coverageCommand), `missing command in step: ${coverageStepName}`) + + const plainStep = parseWorkflowStep(plainStepName) + assert.equal(plainStep.if, "${{ !matrix.collect-coverage }}") + assert.ok(plainStep.run.includes(plainCommand), `missing command in step: ${plainStepName}`) + assert.ok(!plainStep.run.includes("--coverage"), `${plainStepName} must not collect coverage on Windows`) + } + + assert.ok(!workflowStep("Run extension dist smoke test").includes("if:")) + }) + + it("does not run coverage verification or uploads on Windows", () => { + for (const stepName of [ + "Verify extension coverage contract", + "Verify extension coverage reports", + "Merge extension coverage reports", + "Verify coverage cache inputs", + "Upload non-core coverage to Codecov", + "Upload webview JSDOM coverage to Codecov", + "Upload core unit coverage to Codecov", + "Upload core integration coverage to Codecov", + "Upload coverage reports to GitHub", + ]) { + assert.match(workflowStep(stepName), /if: matrix\.collect-coverage/) + } + }) + + it("keeps plain extension lanes aligned with coverage cache boundaries", () => { + for (const lane of ["api", "core", "services", "misc", "tree-sitter"]) { + const plainTask = extensionTurbo.tasks[`test:${lane}`] + const coverageTask = extensionTurbo.tasks[`test:coverage:${lane}`] + + assert.deepEqual(plainTask.dependsOn, coverageTask.dependsOn) + assert.deepEqual(plainTask.inputs, coverageTask.inputs) + } + }) + + it("keeps plain core tasks aligned with coverage cache boundaries", () => { + for (const lane of ["unit", "integration"]) { + const plainTask = coreTurbo.tasks[`test:${lane}`] + const coverageTask = coreTurbo.tasks[`test:coverage:${lane}`] + + assert.deepEqual(plainTask.dependsOn, coverageTask.dependsOn) + assert.deepEqual(plainTask.inputs, coverageTask.inputs) + } + }) + + it("caps Windows CI extension lanes at two workers per lane to fill the runner vCPUs", () => { + const config = fs.readFileSync(path.join(repositoryRoot, "src/vitest.config.ts"), "utf8") + + assert.match(config, /maxWorkers: isWindowsCI \? 2 : undefined/) + }) +}) diff --git a/scripts/stryker-diff.mjs b/scripts/stryker-diff.mjs index a69d272d75..c1d6b46f4f 100644 --- a/scripts/stryker-diff.mjs +++ b/scripts/stryker-diff.mjs @@ -259,9 +259,19 @@ function git(repoRoot, args) { return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8", maxBuffer: 20 * 1024 * 1024 }) } +// GitHub checks out the synthetic pull request merge commit, but `pull_request.base.sha` is frozen at +// event-creation time. When main advances afterwards, that stale base attributes unrelated upstream +// lines to the pull request. The merge commit's first parent is the base actually merged into. +export function resolvePullRequestBase(repoRoot, baseSha, headSha) { + const parents = git(repoRoot, ["rev-list", "--parents", "-n", "1", headSha]).trim().split(/\s+/).slice(1) + if (parents.length < 2) return baseSha + return parents[0] +} + export function selectFromGit(repoRoot, baseSha, headSha) { validateSha(baseSha, "base SHA") validateSha(headSha, "head SHA") + baseSha = resolvePullRequestBase(repoRoot, baseSha, headSha) const mergeBase = git(repoRoot, ["merge-base", baseSha, headSha]).trim() const nameStatus = git(repoRoot, ["diff", "--name-status", "-z", "--find-renames", `${mergeBase}...${headSha}`]) const entries = parseNameStatus(nameStatus) diff --git a/scripts/stryker-diff.test.mjs b/scripts/stryker-diff.test.mjs index 403cf62d89..f69013b20e 100644 --- a/scripts/stryker-diff.test.mjs +++ b/scripts/stryker-diff.test.mjs @@ -57,6 +57,8 @@ describe("mutation testing workflow", () => { assert.ok(!workflow.includes("ref: ${{ github.event.pull_request.head.sha }}")) assert.ok(workflow.includes("HEAD_SHA: ${{ github.sha }}")) assert.ok(!workflow.includes("HEAD_SHA: ${{ github.event.pull_request.head.sha }}")) + assert.ok(workflow.includes('BASE_SHA="$(git rev-parse "$HEAD_SHA^1")"')) + assert.ok(!workflow.includes("github.event.pull_request.base.sha")) assert.ok(workflow.includes("steps.mutation_report.outputs.artifact-url")) assert.ok(workflow.includes("open the package's mutation.html file")) assert.ok(workflow.includes("Enforce executable-line scope and run advisory mutation testing")) @@ -93,6 +95,86 @@ describe("mutation testing workflow", () => { }) }) +function createSyntheticPullRequestRepository() { + const repository = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-diff-revision-")) + const run = (...args) => execFileSync("git", args, { cwd: repository, encoding: "utf8" }).trim() + const write = (filePath, contents) => { + fs.mkdirSync(path.join(repository, path.dirname(filePath)), { recursive: true }) + fs.writeFileSync(path.join(repository, filePath), contents) + } + + run("init", "--quiet", "--initial-branch", "main") + run("config", "user.email", "gate@example.com") + run("config", "user.name", "Gate") + run("config", "commit.gpgsign", "false") + + write("packages/core/src/unrelated.ts", "export const unrelated = () => 1\n") + write("packages/core/src/feature.ts", "export const feature = () => 1\n") + run("add", ".") + run("commit", "--quiet", "-m", "initial") + const eventBaseSha = run("rev-parse", "HEAD") + + run("checkout", "--quiet", "-b", "pull-request") + write("packages/core/src/feature.ts", "export const feature = () => 2\n") + run("add", ".") + run("commit", "--quiet", "-m", "pull request change") + + // The upstream change lands after the pull_request event recorded its base SHA, which is what + // made the stale event base attribute unrelated main-only lines to the pull request. + run("checkout", "--quiet", "main") + write("packages/core/src/unrelated.ts", "export const unrelated = () => 99\n") + run("add", ".") + run("commit", "--quiet", "-m", "unrelated upstream change") + const upstreamSha = run("rev-parse", "HEAD") + + run("merge", "--quiet", "--no-ff", "-m", "merge pull request", "pull-request") + const mergeSha = run("rev-parse", "HEAD") + + return { repository, eventBaseSha, upstreamSha, mergeSha } +} + +describe("pull request revision selection", () => { + it("excludes unrelated upstream files by diffing from the merge commit's first parent", () => { + const { repository, eventBaseSha, upstreamSha, mergeSha } = createSyntheticPullRequestRepository() + + // A failed assertion must still remove the temporary repository, or a failing run leaks it. + try { + const manifest = selectFromGit(repository, eventBaseSha, mergeSha) + const changedPaths = manifest.packages.flatMap((entry) => entry.files.map((file) => file.path)) + + assert.deepEqual(changedPaths, ["packages/core/src/feature.ts"]) + assert.equal(manifest.baseSha, upstreamSha) + assert.equal(manifest.mergeBase, upstreamSha) + + // Selectors must stay aligned with the checked-out head content. + assert.equal(manifest.headSha, mergeSha) + assert.deepEqual( + manifest.packages.flatMap((entry) => entry.selectors), + ["src/feature.ts:1-1"], + ) + } finally { + fs.rmSync(repository, { recursive: true, force: true }) + } + }) + + it("keeps the supplied base for non-merge heads such as manual runs", () => { + const { repository, eventBaseSha, upstreamSha } = createSyntheticPullRequestRepository() + + try { + const manifest = selectFromGit(repository, eventBaseSha, upstreamSha) + + assert.equal(manifest.baseSha, eventBaseSha) + assert.equal(manifest.mergeBase, eventBaseSha) + assert.deepEqual( + manifest.packages.flatMap((entry) => entry.files.map((file) => file.path)), + ["packages/core/src/unrelated.ts"], + ) + } finally { + fs.rmSync(repository, { recursive: true, force: true }) + } + }) +}) + describe("parseNameStatus", () => { it("parses added, modified, and renamed paths", () => { assert.deepEqual( @@ -444,6 +526,51 @@ describe("selectFromGit", () => { fs.rmSync(repo, { recursive: true, force: true }) } }) + + it("does not charge intervening base-branch changes to the pull request", () => { + const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-stale-base-")) + const runGit = (...args) => execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim() + + try { + runGit("init", "--initial-branch=main") + runGit("config", "user.name", "Mutation Test") + runGit("config", "user.email", "mutation@example.com") + fs.mkdirSync(path.join(repo, "packages/core/src"), { recursive: true }) + fs.writeFileSync(path.join(repo, "packages/core/src/pr.ts"), "export const pr = false\n") + fs.writeFileSync(path.join(repo, "packages/core/src/base.ts"), "export const base = false\n") + runGit("add", ".") + runGit("commit", "-m", "initial") + const staleBaseSha = runGit("rev-parse", "HEAD") + + runGit("checkout", "-b", "feature") + fs.writeFileSync(path.join(repo, "packages/core/src/pr.ts"), "export const pr = true\n") + runGit("commit", "-am", "change pull request") + + runGit("checkout", "main") + fs.writeFileSync(path.join(repo, "packages/core/src/base.ts"), "export const base = true\n") + runGit("commit", "-am", "advance base branch") + const currentBaseSha = runGit("rev-parse", "HEAD") + runGit("merge", "--no-ff", "feature", "-m", "synthetic pull request merge") + const mergeSha = runGit("rev-parse", "HEAD") + const mergeResultBaseSha = runGit("rev-parse", `${mergeSha}^1`) + assert.equal(mergeResultBaseSha, currentBaseSha) + + // A stale base is normalized to the merge's first parent, so the advanced base branch + // file is not charged to the pull request. + assert.deepEqual( + selectFromGit(repo, staleBaseSha, mergeSha).packages[0].files.map(({ path: filePath }) => filePath), + ["packages/core/src/pr.ts"], + ) + assert.deepEqual( + selectFromGit(repo, mergeResultBaseSha, mergeSha).packages[0].files.map( + ({ path: filePath }) => filePath, + ), + ["packages/core/src/pr.ts"], + ) + } finally { + fs.rmSync(repo, { recursive: true, force: true }) + } + }) }) describe("mutation exclusions", () => { diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 978efd867a..4b16bfb62f 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,5 +1,32 @@ # Zoo Code Changelog +## [3.82.2] + +### Patch Changes + +- Prevent unavailable tools from appearing in system prompts (#505 by @DScoNOIZ, #1240 by @JunyongParkDev, PR #1505 by @DaubnerF) +- Fix DeepSeek Flash image input by adding the new deepseek-flash model ID (PR #1618 by @app/zoomote) +- Fix token usage tracking for Grok and xAI-compatible endpoints whose domains contain "x.ai" (#1483 by @BambinoSK, PR #1484 by @BambinoSK) +- Apply the configured reasoning effort consistently across OpenAI-compatible requests (#993 by @Gringo675, PR #1604 by @JunyongParkDev) +- Preserve the configured LiteLLM model ID in the model picker (#1367 by @easonLiangWorldedtech, PR #1368 by @easonLiangWorldedtech) +- Fix delegated subtasks reading the parent mode in environment details and tool validation (#1623 by @edelauna, PR #1625 by @edelauna) +- Add a file version token to the guarded-write path to prevent stale overwrites (PR #1383 by @easonLiangWorldedtech) +- Extract the code-index manager registry for clearer ownership (PR #1622 by @WebMad) +- Route Roomote pull requests through the CodeRabbit review path (PR #1598 by @app/zoomote) +- Make mutation-testing findings advisory instead of blocking (PR #1610 by @app/zoomote) +- Group mutation warnings by source location to remove duplicate warnings (PR #1619 by @app/zoomote) +- Skip mutation testing while pull requests are in draft (PR #1645 by @app/zoomote) +- Scope the mutation diff against the exact merge base so unrelated changes on main stop inflating the scope (PR #1655 by @app/zoomote) +- Model test bundle dependencies in Turbo so caching stays correct (#114 by @edelauna, PR #1611 by @app/zoomote) +- Separate extension unit tests from bundle smoke tests (PR #1614 by @app/zoomote) +- Move extension source coverage to cacheable test lanes (#118 by @edelauna, PR #1620 by @app/zoomote) +- Cache extension coverage by ownership lanes (#115 by @edelauna, PR #1631 by @app/zoomote) +- Keep coverage caches valid when only verification scripts change (PR #1649 by @app/zoomote) +- Union ownership-lane coverage reports before uploading to Codecov (#1647 by @DaubnerF, PR #1650 by @app/zoomote) +- Validate coverage lanes dynamically in the merge queue (PR #1644 by @app/zoomote) +- Stabilize the accessibility contrast audit during theme changes (#1612 by @edelauna, PR #1613 by @app/zoomote) +- Make CodeRabbit completeness checks advisory (PR #1621 by @app/zoomote) + ## [3.82.1] ### Patch Changes diff --git a/src/__tests__/extension.spec.ts b/src/__tests__/extension.spec.ts index bb72d567dd..56ccd52588 100644 --- a/src/__tests__/extension.spec.ts +++ b/src/__tests__/extension.spec.ts @@ -139,9 +139,10 @@ vi.mock("../services/mcp/McpServerManager", () => ({ }, })) -vi.mock("../services/code-index/manager", () => ({ - CodeIndexManager: { - getInstance: vi.fn().mockReturnValue(null), +vi.mock("../services/code-index/code-index-manager-registry", () => ({ + CodeIndexManagerRegistry: { + getOrCreate: vi.fn().mockReturnValue(null), + disposeAll: vi.fn(), }, })) @@ -463,6 +464,7 @@ describe("extension.ts", () => { const { TelemetryService } = await import("@roo-code/telemetry") const { Terminal } = await import("../integrations/terminal/Terminal") const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry") + const { CodeIndexManagerRegistry } = await import("../services/code-index/code-index-manager-registry") vi.mocked(TelemetryService.instance.shutdown).mockRejectedValue(new Error("shutdown failed")) const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile") @@ -474,6 +476,7 @@ describe("extension.ts", () => { expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined) expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1) + expect(CodeIndexManagerRegistry.disposeAll).toHaveBeenCalledTimes(1) setTerminalProfileSpy.mockRestore() }) @@ -486,6 +489,7 @@ describe("extension.ts", () => { const { TelemetryService } = await import("@roo-code/telemetry") const { Terminal } = await import("../integrations/terminal/Terminal") const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry") + const { CodeIndexManagerRegistry } = await import("../services/code-index/code-index-manager-registry") const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile") @@ -509,9 +513,9 @@ describe("extension.ts", () => { expect(mockTelemetryServiceInstance.shutdown).not.toHaveBeenCalled() expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined) expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1) + expect(CodeIndexManagerRegistry.disposeAll).toHaveBeenCalledTimes(1) instanceGetterSpy.mockRestore() - setTerminalProfileSpy.mockRestore() }) }) diff --git a/src/activate/__tests__/registerCommands.spec.ts b/src/activate/__tests__/registerCommands.spec.ts index 67a2b935ec..7088560700 100644 --- a/src/activate/__tests__/registerCommands.spec.ts +++ b/src/activate/__tests__/registerCommands.spec.ts @@ -67,9 +67,9 @@ vi.mock("../../core/config/importExport", () => ({ importSettingsWithFeedback: vi.fn(), })) -vi.mock("../../services/code-index/manager", () => ({ - CodeIndexManager: { - getInstance: vi.fn(), +vi.mock("../../services/code-index/code-index-manager-registry", () => ({ + CodeIndexManagerRegistry: { + getOrCreate: vi.fn(), }, })) diff --git a/src/activate/registerCommands.ts b/src/activate/registerCommands.ts index 692aabfd68..da98be291b 100644 --- a/src/activate/registerCommands.ts +++ b/src/activate/registerCommands.ts @@ -10,7 +10,6 @@ import { ClineProvider } from "../core/webview/ClineProvider" import { ContextProxy } from "../core/config/ContextProxy" import { focusPanel } from "../utils/focusPanel" import { handleNewTask } from "./handleTask" -import { CodeIndexManager } from "../services/code-index/manager" import { importSettingsWithFeedback } from "../core/config/importExport" import { MdmService } from "../services/mdm/MdmService" import { registerRipgrepDiagnosticCommand } from "../services/ripgrep/diagnostic" @@ -227,7 +226,6 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit + ensureModelFetched?(signal?: AbortSignal): Promise /** * Optional context window for context-management / auto-condense when it must differ from diff --git a/src/api/providers/__tests__/deepseek.spec.ts b/src/api/providers/__tests__/deepseek.spec.ts index 2f344d8405..4ab247b131 100644 --- a/src/api/providers/__tests__/deepseek.spec.ts +++ b/src/api/providers/__tests__/deepseek.spec.ts @@ -240,22 +240,22 @@ describe("DeepSeekHandler", () => { expect(model.info).toBeDefined() expect(model.info.maxTokens).toBe(384_000) expect(model.info.contextWindow).toBe(1_000_000) - expect(model.info.supportsImages).toBe(false) + expect(model.info.supportsImages).toBe(true) expect(model.info.supportsPromptCache).toBe(true) // Should be true now expect((model.info as ModelInfo).preserveReasoning).toBe(true) }) - it("should use deepseek-v4-flash as the default model ID for new configs", () => { + it("should use deepseek-flash as the default model ID for new configs", () => { const handlerWithoutModel = new DeepSeekHandler({ ...mockOptions, apiModelId: undefined, }) const model = handlerWithoutModel.getModel() expect(model.id).toBe(deepSeekDefaultModelId) - expect(model.id).toBe("deepseek-v4-flash") + expect(model.id).toBe("deepseek-flash") expect(model.info.maxTokens).toBe(384_000) expect(model.info.contextWindow).toBe(1_000_000) - expect(model.info.supportsImages).toBe(false) + expect(model.info.supportsImages).toBe(true) expect((model.info as ModelInfo).supportsReasoningEffort).toContain("max") }) @@ -290,7 +290,6 @@ describe("DeepSeekHandler", () => { supportsPromptCache: true, preserveReasoning: true, reasoningEffort: "high", - defaultTemperature: 1.0, }) }) @@ -369,41 +368,61 @@ describe("DeepSeekHandler", () => { expect(textChunks[0].text).toBe("Test response") }) - it("should send images and V4 thinking controls to deepseek-v4-flash-vision-exp", async () => { + it.each(["deepseek-flash", "deepseek-v4-flash", "deepseek-v4-flash-vision-exp"] as const)( + "should send images and thinking controls to %s", + async (modelId) => { + const visionHandler = new DeepSeekHandler({ + ...mockOptions, + apiModelId: modelId, + }) + const visionMessages: Anthropic.Messages.MessageParam[] = [ + { + role: "user", + content: [ + { type: "text", text: "Describe this image." }, + { + type: "image", + source: { type: "base64", media_type: "image/png", data: "image-data" }, + }, + ], + }, + ] + + await collectStream(visionHandler.createMessage(systemPrompt, visionMessages)) + + const callArgs = mockCreate.mock.calls[0][0] + expect(callArgs).toMatchObject({ + model: modelId, + thinking: { type: "enabled" }, + reasoning_effort: "high", + max_completion_tokens: 200_000, + }) + expect(callArgs.temperature).toBeUndefined() + expect(callArgs.messages).toContainEqual({ + role: "user", + content: expect.arrayContaining([ + { type: "text", text: expect.stringContaining("Describe this image.") }, + { type: "image_url", image_url: { url: "data:image/png;base64,image-data" } }, + ]), + }) + }, + ) + + it("should use the provider default temperature when reasoning is disabled for the vision alias", async () => { const visionHandler = new DeepSeekHandler({ ...mockOptions, apiModelId: "deepseek-v4-flash-vision-exp", + enableReasoningEffort: false, }) - const visionMessages: Anthropic.Messages.MessageParam[] = [ - { - role: "user", - content: [ - { type: "text", text: "Describe this image." }, - { - type: "image", - source: { type: "base64", media_type: "image/png", data: "image-data" }, - }, - ], - }, - ] - await collectStream(visionHandler.createMessage(systemPrompt, visionMessages)) + await collectStream(visionHandler.createMessage(systemPrompt, messages)) - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs).toMatchObject({ + expect(mockCreate.mock.calls[0][0]).toMatchObject({ model: "deepseek-v4-flash-vision-exp", - thinking: { type: "enabled" }, - reasoning_effort: "high", - max_completion_tokens: 200_000, - }) - expect(callArgs.temperature).toBeUndefined() - expect(callArgs.messages).toContainEqual({ - role: "user", - content: expect.arrayContaining([ - { type: "text", text: expect.stringContaining("Describe this image.") }, - { type: "image_url", image_url: { url: "data:image/png;base64,image-data" } }, - ]), + thinking: { type: "disabled" }, + temperature: 0, }) + expect(mockCreate.mock.calls[0][0].reasoning_effort).toBeUndefined() }) it("should include usage information", async () => { diff --git a/src/api/providers/__tests__/openai.spec.ts b/src/api/providers/__tests__/openai.spec.ts index a3dcbcc0d5..754d57a6cd 100644 --- a/src/api/providers/__tests__/openai.spec.ts +++ b/src/api/providers/__tests__/openai.spec.ts @@ -1252,6 +1252,92 @@ describe("OpenAiHandler", () => { }) }) + describe("Grok xAI false-positive prevention", () => { + it("should NOT detect as Grok xAI when host contains 'x.ai' as a substring but is not x.ai (e.g. box.ai)", () => { + const nonGrokOptions = { + ...mockOptions, + openAiBaseUrl: "https://box.ai/v1", + openAiModelId: "gpt-4o", + } + const handler = new OpenAiHandler(nonGrokOptions) + expect(handler["_isGrokXAI"](nonGrokOptions.openAiBaseUrl)).toBe(false) + }) + + it("should NOT detect as Grok xAI for other domains containing 'x.ai' substring (e.g. fox.ai, max.ai)", () => { + const handler = new OpenAiHandler({ ...mockOptions, openAiBaseUrl: "https://fox.ai/v1" }) + expect(handler["_isGrokXAI"]("https://fox.ai/v1")).toBe(false) + expect(handler["_isGrokXAI"]("https://max.ai/v1")).toBe(false) + }) + + it("should detect as Grok xAI for api.x.ai", () => { + const handler = new OpenAiHandler({ ...mockOptions, openAiBaseUrl: "https://api.x.ai/v1" }) + expect(handler["_isGrokXAI"]("https://api.x.ai/v1")).toBe(true) + }) + + it("should detect as Grok xAI for subdomains of x.ai (e.g. custom.x.ai)", () => { + const handler = new OpenAiHandler({ ...mockOptions, openAiBaseUrl: "https://custom.x.ai/v1" }) + expect(handler["_isGrokXAI"]("https://custom.x.ai/v1")).toBe(true) + }) + + it("should detect as Grok xAI when api.x.ai uses a non-default port", () => { + const handler = new OpenAiHandler({ ...mockOptions, openAiBaseUrl: "https://api.x.ai:8443/v1" }) + expect(handler["_isGrokXAI"]("https://api.x.ai:8443/v1")).toBe(true) + }) + + it("should exclude stream_options when streaming with api.x.ai on a non-default port", async () => { + const portOptions = { + ...mockOptions, + openAiBaseUrl: "https://api.x.ai:8443/v1", + openAiModelId: "grok-1", + } + const handler = new OpenAiHandler(portOptions) + const systemPrompt = "You are a helpful assistant." + const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }] + + const stream = handler.createMessage(systemPrompt, messages) + await stream.next() + + expect(mockCreate).toHaveBeenCalledWith( + expect.objectContaining({ + model: portOptions.openAiModelId, + stream: true, + }), + {}, + ) + + const mockCalls = mockCreate.mock.calls + const lastCall = mockCalls[mockCalls.length - 1] + expect(lastCall[0]).not.toHaveProperty("stream_options") + }) + + it("should include stream_options when using a non-Grok provider whose URL contains 'x.ai' substring", async () => { + const nonGrokOptions = { + ...mockOptions, + openAiBaseUrl: "https://box.ai/v1", + openAiModelId: "gpt-4o", + } + const handler = new OpenAiHandler(nonGrokOptions) + const systemPrompt = "You are a helpful assistant." + const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }] + + const stream = handler.createMessage(systemPrompt, messages) + await stream.next() + + expect(mockCreate).toHaveBeenCalledWith( + expect.objectContaining({ + model: nonGrokOptions.openAiModelId, + stream: true, + }), + {}, + ) + + const mockCalls = mockCreate.mock.calls + const lastCall = mockCalls[mockCalls.length - 1] + expect(lastCall[0]).toHaveProperty("stream_options") + expect(lastCall[0].stream_options).toEqual({ include_usage: true }) + }) + }) + describe("O3 Family Models", () => { const o3Options = { ...mockOptions, @@ -1630,6 +1716,25 @@ describe("OpenAiHandler", () => { { path: "/models/chat/completions" }, ) }) + + it("should exclude stream_options when O3 model uses Grok xAI base URL", async () => { + const handler = new OpenAiHandler({ ...o3Options, openAiBaseUrl: "https://api.x.ai/v1" }) + const stream = handler.createMessage("You are a helpful assistant.", [{ role: "user", content: "Hello!" }]) + await stream.next() + + const lastCall = mockCreate.mock.calls[mockCreate.mock.calls.length - 1] + expect(lastCall[0]).not.toHaveProperty("stream_options") + }) + + it("should include stream_options when O3 model uses non-Grok URL containing 'x.ai' substring", async () => { + const handler = new OpenAiHandler({ ...o3Options, openAiBaseUrl: "https://box.ai/v1" }) + const stream = handler.createMessage("You are a helpful assistant.", [{ role: "user", content: "Hello!" }]) + await stream.next() + + const lastCall = mockCreate.mock.calls[mockCreate.mock.calls.length - 1] + expect(lastCall[0]).toHaveProperty("stream_options") + expect(lastCall[0].stream_options).toEqual({ include_usage: true }) + }) }) }) diff --git a/src/api/providers/__tests__/vscode-lm.spec.ts b/src/api/providers/__tests__/vscode-lm.spec.ts index 423f119f14..a02ec7e642 100644 --- a/src/api/providers/__tests__/vscode-lm.spec.ts +++ b/src/api/providers/__tests__/vscode-lm.spec.ts @@ -16,6 +16,14 @@ vi.mock("vscode", () => { ) {} } + class MockLanguageModelToolResultPart { + type = "tool_result" + constructor( + public callId: string, + public content: unknown[], + ) {} + } + return { workspace: { getConfiguration: vi.fn(() => ({ @@ -53,6 +61,7 @@ vi.mock("vscode", () => { }, LanguageModelTextPart: MockLanguageModelTextPart, LanguageModelToolCallPart: MockLanguageModelToolCallPart, + LanguageModelToolResultPart: MockLanguageModelToolResultPart, lm: { selectChatModels: vi.fn(), }, @@ -60,12 +69,16 @@ vi.mock("vscode", () => { }) import * as vscode from "vscode" -import { VsCodeLmHandler } from "../vscode-lm" +import { VsCodeLmHandler, extractLeakedToolCalls, trailingPartialToolMarkerLength } from "../vscode-lm" import type { ApiHandlerOptions } from "../../../shared/api" import type { Anthropic } from "@anthropic-ai/sdk" import { openAiModelInfoSaneDefaults, vscodeLlmDefaultModelId, vscodeLlmModels } from "@roo-code/types" +import { normalizeToolSchema } from "../../../utils/json-schema" +import { getMcpServerTools } from "../../../core/prompts/tools/native-tools/mcp_server" +import type { McpHub } from "../../../services/mcp/McpHub" import { clearAllMocks } from "../../../test-utils/reset" +import { collectStream } from "../../../test-utils/stream" const mockLanguageModelChat = { id: "test-model", @@ -1077,3 +1090,1226 @@ describe("VsCodeLmHandler", () => { }) }) }) + +describe("leaked tool-call recovery", () => { + // Builders keep the XML fixtures readable and prevent this file's own markup from being + // mistaken for a real tool call. + const invoke = (name: string, body: string) => `${body}` + const param = (name: string, value: string) => `${value}` + const wrap = (body: string) => `${body}` + + describe("extractLeakedToolCalls", () => { + it("recovers a known-tool block and strips it from the leftover text", () => { + const text = `Working on it.\n${wrap(invoke("update_todo_list", param("todos", "[x] one\n[ ] two")))}` + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toEqual([{ name: "update_todo_list", input: { todos: "[x] one\n[ ] two" } }]) + expect(leftoverText).toBe("Working on it.\n") + }) + + it("recovers a wrapped leak preceded by a stray token", () => { + const text = `court\n${wrap(invoke("update_todo_list", param("todos", "[x] done")))}` + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toEqual([{ name: "update_todo_list", input: { todos: "[x] done" } }]) + expect(leftoverText).toBe("court\n") + }) + + it("does not recover a bare invoke block with no function_calls wrapper", () => { + const text = `court\n${invoke("update_todo_list", param("todos", "[x] done"))}` + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover an invoke that follows an already-closed wrapper", () => { + const text = `${wrap("")}\n${invoke("update_todo_list", param("todos", "[x] done"))}` + + const { calls } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + }) + + it("recovers multiple params and strips function-call wrapper tags", () => { + const body = param("mode", "code") + param("message", "go") + const text = `${invoke("new_task", body)}` + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["new_task"])) + + expect(calls).toEqual([{ name: "new_task", input: { mode: "code", message: "go" } }]) + expect(leftoverText).toBe("") + }) + + it("passes through invoke blocks for tools that were not offered", () => { + const text = invoke("some_other_tool", param("x", "1")) + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toEqual([]) + expect(leftoverText).toBe(text) + }) + + it("returns no calls for ordinary text", () => { + const { calls, leftoverText } = extractLeakedToolCalls("just a normal reply", new Set(["update_todo_list"])) + + expect(calls).toEqual([]) + expect(leftoverText).toBe("just a normal reply") + }) + }) + + describe("trailingPartialToolMarkerLength", () => { + it("holds back a split marker prefix at the end of a chunk", () => { + expect(trailingPartialToolMarkerLength("some text { + expect(trailingPartialToolMarkerLength("hello world")).toBe(0) + expect(trailingPartialToolMarkerLength("a < b")).toBe(0) + expect(trailingPartialToolMarkerLength("text ")).toBe(0) + }) + + it("holds back an invoke tag whose name attribute has not arrived", () => { + expect(trailingPartialToolMarkerLength("text { + expect(trailingPartialToolMarkerLength(" { + expect(trailingPartialToolMarkerLength("text <" + "a".repeat(200))).toBe(0) + }) + }) + + describe("quoted markup", () => { + it("does not recover an invoke block inside a fenced code block", () => { + const text = "```\n" + invoke("update_todo_list", param("todos", "[x] one")) + "\n```" + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover an invoke block inside an inline code span", () => { + const text = "avoid `" + invoke("update_todo_list", param("todos", "x")) + "`" + + const { calls } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + }) + + it("does not recover an invoke block quoted in unfenced, backtick-free prose", () => { + const text = "You must never emit " + invoke("update_todo_list", param("todos", "x")) + " directly." + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover a quoted invoke block that ends its line", () => { + // Defect 3: an empty rest-of-line previously made this look like a genuine leak. + const text = "You must never emit " + invoke("update_todo_list", param("todos", "x")) + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover an invoke block inside a tilde fence", () => { + const text = "~~~\n" + invoke("update_todo_list", param("todos", "[x] one")) + "\n~~~" + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover an invoke inside a four-backtick fence containing a three-backtick fence", () => { + // A narrower inner fence must not close the wider outer one, so the invoke stays quoted. + const text = "````\n```\n" + invoke("update_todo_list", param("todos", "[x] one")) + "\n```\n````" + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("does not recover an invoke inside a tilde fence containing a backtick fence line", () => { + const text = "~~~\n```\n" + invoke("update_todo_list", param("todos", "[x] one")) + "\n```\n~~~" + + const { calls, leftoverText } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toHaveLength(0) + expect(leftoverText).toBe(text) + }) + + it("recovers an invoke block that follows a closed code fence", () => { + const text = "```\nexample output\n```\n" + wrap(invoke("update_todo_list", param("todos", "[x] one"))) + + const { calls } = extractLeakedToolCalls(text, new Set(["update_todo_list"])) + + expect(calls).toEqual([{ name: "update_todo_list", input: { todos: "[x] one" } }]) + }) + + it("does not treat doubled angle brackets as trailing prose after stripping", () => { + // Defect 1: a single strip pass turns `<>` into a tag-looking ``, so the + // trailing-text check must strip repeatedly until stable. + const text = wrap(invoke("update_todo_list", param("todos", "x")) + "<