Tasks: Next-Command Latency — Durable Fix + Perf-Gate Migration

Mission: next-latency-durable-fix-01M14RM3 | Branch: perf/next-latency-durable-fix Plan: plan.md | Spec: spec.md | Squad map: research/post-spec-squad-findings.md

4 work packages. Durable fix = two independent runtime levers (WP01 imports, WP02 charter-freshness cache), then the off-PR statistical guard (WP03) and the blocking-gate retirement (WP04).

Subtask Index

IDDescriptionWPParallel
T001Profile baseline next import graph; find query-path-unreachable importsWP01
T002Defer eager model imports in next_cmd.py to function scopeWP01
T003Lazy command registration in _build_app (secondary)WP01
T004test_next_import_footprint.py — assert trimmed footprintWP01
T005test_next_output_preservation.py — byte-identical (no-charter)WP01
T006freshness/cache.py — composite content key + entry + fail-closed IOWP02[P]
T007Wire cache into compute_freshness (skip parse on hit)WP02
T008Verdict serialize round-trips exactly; gitignore cache dirWP02
T009test_freshness_cache.py — 6 contract guarantees incl. DRG-graph invalidationWP02
T010Charter-path byte-identical assertion (NFR-004)WP02
T011test_next_cold_start_performance.py — subprocess benchmark.pedanticWP03
T012Verify env-gated collection semantics (perf leg)WP03
T013Seed post-fix next baseline JSONWP03
T014Document missing-baseline pass + update_baseline pathWP03
T015Remove the latency step from ci-quality.yml; keep smokeWP04
T016Delete check_nfr_003_latency.py; clear dangling refsWP04
T017Drop absolute ceiling from nfr-003-baseline.json; add noteWP04
T018Guard test: no wall-clock ceiling on blocking path; smoke retainedWP04

The [P] marker indicates parallelism, not status. Completion is event-sourced via spec-kitty agent tasks mark-status.

Dependency Graph

WP01 (import trim) ─┐
                    ├─→ WP03 (benchmark + POST-fix baseline) ─→ WP04 (retire blocking gate)
WP02 (charter cache) ┘
  • WP01 and WP02 are independent subsystems (next_cmd.py/__init__.py vs charter_runtime/freshness/) → parallel (Wave 1).
  • WP03 depends on WP01 + WP02 (baseline must reflect post-fix latency).
  • WP04 depends on WP03 (no guard gap: replacement exists before the blocking gate is removed).

Work Packages

WP01 — Import-graph trim on the next read path (Priority: P1)

  • Goal: Defer eager pydantic model imports on the read-only next query path (FR-001, NFR-001, NFR-004).
  • Independent test: -X importtime shows a lighter graph; test_next_import_footprint.py + test_next_output_preservation.py pass.
  • Subtasks: T001, T002, T003, T004, T005 · Deps: none · Prompt: tasks/WP01-import-graph-trim.md
  • Risk: deferred import still needed on the path just moves cost; circular imports.

WP02 — Charter-freshness content-hash cache (Priority: P1)

  • Goal: Cache the charter freshness verdict; skip the 1588-line ruamel parse on a hit (FR-002, NFR-002, NFR-004, C-005).
  • Independent test: profiled cache hit skips the parse; test_freshness_cache.py proves all 6 contract guarantees incl. DRG-graph invalidation + fail-closed.
  • Subtasks: T006, T007, T008, T009, T010 · Deps: none · Prompt: tasks/WP02-charter-freshness-cache.md
  • Risk: ELEVATED — caches a governance verdict; stale "fresh" is a correctness regression. Pre-merge adversarial review pass required.

WP03 — next cold-start performance benchmark + seeded baseline (Priority: P2)

  • Goal: Subprocess-based @pytest.mark.performance next benchmark on performance.yml; seed post-fix baseline (FR-003, FR-006).
  • Independent test: env-gated collection; passes under SPEC_KITTY_RUN_PERFORMANCE=1; committed baseline exists.
  • Subtasks: T011, T012, T013, T014 · Deps: WP01, WP02 · Prompt: tasks/WP03-perf-benchmark-baseline.md
  • Risk: in-process vs subprocess confusion; auto-calibration CI-time balloon.

WP04 — Retire the blocking NFR-003 latency gate (Priority: P2)

  • Goal: Remove the blocking latency step; keep the structural smoke; delete the script + absolute ceiling (FR-004, FR-005, NFR-003, C-001).
  • Independent test: quality-gate.needs has no wall-clock ceiling; smoke retained; script gone.
  • Subtasks: T015, T016, T017, T018 · Deps: WP03 · Prompt: tasks/WP04-retire-blocking-gate.md
  • Risk: accidentally removing the structural smoke (C-001); dangling script references.

MVP

WP01 + WP02 (the durable fix) is the value core; WP03 guards it; WP04 delivers the contributor-facing unblock (US2).