Skip to content

perf(draft-cache): order the draft prompt static -> project-stable -> task-specific - #622

Merged
unohee merged 1 commit into
mainfrom
perf/draft-prompt-order-clean
Sep 10, 2026
Merged

perf(draft-cache): order the draft prompt static -> project-stable -> task-specific#622
unohee merged 1 commit into
mainfrom
perf/draft-prompt-order-clean

Conversation

@unohee

@unohee unohee commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • buildDraftPrompt emitted static intro -> Task (title/description) -> ... -> Codebase State/peer issues (project-stable) -> Output Format. The per-task title/description opened the prompt, so nothing after it could ever be shared across different tasks drafted against the same project.
  • Reordered to: static intro -> Codebase State + peer issues (project-stable, hoisted) -> Task -> Operator Feedback -> Impact Analysis -> File Health -> Output Format.
  • Part of the standing 80%-draft-cache goal. Two prior fixes this session (fingerprint self-invalidation, in-session hard-gate retry) already merged/deployed and moved the measured rate from ~66-68% to a ~74-76% plateau; the finishValidator fix was confirmed working at the per-call level (0.3% -> 96.2% at the previously-reset position) but didn't move the aggregate much, pointing at genuine per-task cold starts as the remaining cost this PR targets.
  • Layer-2 review caught a real defect in the first draft: "File Health" looked project-stable but is actually seeded from impactAnalysis.directModules (this task's own affected files) — fixed by keeping it in the task-specific section next to Impact Analysis, with a new test exercising the real code path the round-1 test's synthetic fixture couldn't reach. Round 2 clean apart from a comment-wording nit (addressed).

Test plan

  • New tests: two different tasks share a long common prefix (peer issues before Task); File Health stays in the task-specific section with real impact-analysis data — both mutation-verified
  • npx tsc --noEmit / lint (0 new warnings) / build / full vitest suite green
  • Layer-2 independent review, 2 rounds — round 1 found a real defect (fixed in this PR), round 2 clean
  • Deploy to vela and measure the draft stage cache rate (part of the standing 80%-cache goal)

🤖 Generated with Claude Code

… task-specific (AGT-4300)

buildDraftPrompt emitted, in order: static intro -> Task (title/
description) -> Operator Feedback -> Codebase State -> Impact Analysis
-> File Health -> peer issues -> Output Format. Every task drafted
against the same project during one scheduling pass shares Codebase
State (project stats) and peer issues, but the per-task title/
description opened the prompt, so nothing after it could ever be a
shared prefix across different tasks -- AGT-4286 measured only the
~378-token static template and concluded "nothing to hoist" without
noticing this.

Reordered to: static intro -> Codebase State -> peer issues (both
project-stable) -> Task -> Operator Feedback -> Impact Analysis ->
File Health -> Output Format.

Layer-2 review caught a real defect in the first draft: File Health
looked project-stable but collectCodebaseState() actually seeds it
from impactAnalysis.directModules (THIS task's affected files,
keyword-matched against its title/description), only falling back to
project-wide high-risk entities when fewer than 3 files matched --
hoisting it ahead of Task would not have delivered the claimed benefit
in the common case, and the round-1 test's synthetic project path
happened to always produce a null impactAnalysis, hiding the gap.
Fixed by leaving File Health in the task-specific section next to
Impact Analysis (the data it actually shares), and added a test that
mocks a real ImpactAnalysis + registry fileBrief to exercise the branch
the round-1 test structurally could not reach. Round-2 re-review
confirmed the fix and flagged only a documentation nit (peer issues are
"nearly" identical across tasks, not byte-identical -- production
excludes each task's own record from its own list), addressed in
comments.

TSC=0, LINT=0 (0 new warnings), BUILD=0, full vitest suite green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@unohee
unohee merged commit 9f6d804 into main Sep 10, 2026
7 checks passed
@unohee
unohee deleted the perf/draft-prompt-order-clean branch September 10, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant