Skip to content

feat: add pre-recon cache for incremental analysis#227

Open
jvinolas wants to merge 7 commits intoKeygraphHQ:mainfrom
jvinolas:feature/prerecon-cache
Open

feat: add pre-recon cache for incremental analysis#227
jvinolas wants to merge 7 commits intoKeygraphHQ:mainfrom
jvinolas:feature/prerecon-cache

Conversation

@jvinolas
Copy link

@jvinolas jvinolas commented Mar 9, 2026

Disclaimer

We are using it to test the same code that evolves with new features and bugfixes, so we found interesting to avoid the long pre-recon phase and just update with diff. I used claude and build and we are using it, but feel free to discard it and instead take this as an improvement request issue if you prefer.

Summary

  • Add pre-recon cache service that detects source code changes via git
    commit tracking
  • When source is unchanged, skip pre-recon entirely; when changed, run a
    lightweight delta agent that updates the previous analysis based on the
    git diff
  • Graceful fallback to full pre-recon when cache is missing, corrupt, or
    diff generation fails

Changes

  • src/services/prerecon-cache.ts — Cache service with
    checkPrereconCache() and savePrereconCache()
  • src/session-manager.tsPRE_RECON_DELTA_AGENT definition (separate
    from ALL_AGENTS to avoid breaking resume)
  • src/temporal/activities.ts — Cache check, save, and delta agent
    activities
  • src/temporal/workflows.ts — Phase 1 cache-aware logic (skip / delta /
    full)
  • src/services/agent-execution.ts — Optional AgentDefinition override
    for delta execution
  • prompts/pre-recon-delta.txt — Delta agent prompt template

How it works

  1. Before pre-recon, checkPrereconCacheActivity reads
    .prerecon-cache.json from the repo's deliverables directory
  2. Compares the cached commit hash against current HEAD:
    • Same commit → skip pre-recon entirely
    • Different commit → write git diff to disk, run delta agent with
      previous analysis + diff context
    • No cache / invalid → run full pre-recon
  3. After successful analysis, savePrereconCacheActivity writes the
    source commit hash (captured before agent execution to avoid checkpoint
    commit interference)

Test plan

  • Run scan on a repo with no cache → full pre-recon runs, cache saved
  • Re-run same scan without code changes → pre-recon skipped
  • Pull new commits, re-run → delta agent runs with diff context
  • Corrupt/delete cache file → graceful fallback to full pre-recon
  • Verify resume still works correctly (pre-recon-delta not in
    ALL_AGENTS)

vinolas added 7 commits March 9, 2026 01:44
- Fix delta agent execution: use PRE_RECON_DELTA_AGENT definition
  instead of invalid 'pre-recon-delta' AgentName lookup
- Strip large payloads from Temporal event history: return lightweight
  CacheAction instead of CacheCheckResult with 170KB+ strings
- Fix cache saving wrong commit hash: capture source HEAD before agent
  execution (which creates checkpoint commits that change HEAD)
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.

2 participants