Skip to content

fix(insights): stop dead historical paths from anti-selecting resume candidates - #3057

Merged
Sinity merged 1 commit into
masterfrom
feature/gpt-pro/perf04-resume
Jul 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/gpt-pro/perf04-resume

Conversation

@Sinity

@Sinity Sinity commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Repairs resume-candidate file-overlap scoring so that historical paths which no longer resolve under the current checkout layout (after a refactor/rename) no longer poison exact-path Jaccard, while still not counting still-dead paths in the union denominator. Adds an offline hit@1/hit@3/MRR ranking evaluator with a versioned, lineage-grounded fixture.

Problem

Bead polylogue-v1vo found, from a live-archive analysis, that resume ranking's file-overlap component computes lexical exact-path Jaccard over raw file_paths_touched. On the live archive, 43% of historical file touches no longer exist under the current repo layout (e.g. storage/repository.py -> storage/repository/__init__.py), so a session that is a true refactor ancestor of the caller's current work scores near-zero overlap and gets anti-selected below unrelated sessions. Additionally, a candidate with extra dead paths in its touch set gets a larger union denominator than an otherwise-identical candidate, so it scores lower purely for having more (dead) history recorded — the opposite of what should happen.

Solution

  • polylogue/insights/resume.py: adds a per-ranking-call _PathResolutionContext that resolves the caller's repo root once and caches filesystem existence checks. Candidate paths are partitioned into resolvable (exact current-checkout match, or file-to-package correction when a missing foo.py resolves to foo/__init__.py) vs. dead. Dead candidate paths are matched one-to-one against not-yet-matched recent caller files by deepest-prefix, root-rejecting parent-directory continuity (_directory_overlap_pairs). The Jaccard denominator becomes caller identities ∪ resolvable candidate identities — still-dead paths never enter the union. Falls back to the previous lexical behavior when no valid repo root is available.
  • Result is exposed additively via ResumeCandidate.overlap_basis (exact / dir / dead_excluded); score_breakdown.file_overlap keeps its existing float contract and the 0.25 weight is unchanged.
  • Threaded through consumers: Polylogue.resume_brief (optional repo_path/recent_files), MCP get_resume_brief, CLI continue --candidates (JSON + terminal), and the SessionStart context preamble (via a typed ContextPreambleOverlapBasis projection crossing the surface boundary through model_dump/model_validate, not a direct insights import).
  • RESUME_BRIEF_MATERIALIZER_VERSION bumped 1 -> 2 (additive optional field).
  • No schema/migration touched; no stored profile rewritten — adaptation happens at query time only.
  • devtools/resume_ranking_eval.py + tests/data/resume-ranking-eval-v1.json: durable offline evaluator comparing legacy vs refactor-aware scoring over lineage-derived ground truth (no hand-authored relevance labels).

This patch originated as an externally-generated (GPT Pro) packet against bead polylogue-v1vo. It was independently re-verified against current master in this session (not merely re-run per its own claimed HANDOFF/TESTS docs) before being committed here.

Verification

  • devtools test tests/unit/core/test_resume.py tests/unit/devtools/test_resume_ranking_eval.py tests/unit/mcp/test_contract_evidence.py tests/unit/mcp/test_compose_context_preamble.py tests/unit/mcp/test_server_surfaces.py tests/unit/cli/test_continue_absorption.py → 154 passed in 23.06s.
  • Anti-vacuity: neutered _directory_overlap_pairs to unconditionally return () (disabling directory recovery), reran the core/evaluator tests → 5 failed, 13 passed, including test_resume_candidates_recover_100_percent_dead_session_by_directory (assert 0.0 > 0) and the evaluator's own partition invariant (recovered=0 vs expected 254/430). Reverted the neutering and confirmed the file is byte-identical to the pre-mutation patched state (diff clean) before rerunning → 18 passed in 11.14s.
  • devtools render all --check → exit 0, no out of sync lines (grepped the full log per the repo's documented gotcha).
  • uv run --frozen mypy on all 9 changed production/evaluator modules → Success: no issues found in 9 source files.
  • devtools test tests/unit/mcp/test_tool_declarations.py tests/unit/mcp/test_tool_discovery.py tests/unit/mcp/test_server_surfaces.py tests/unit/mcp/test_query_tool_schema_derivation.py tests/unit/cli/test_cli_output_schemas.py → 1 failed, 206 passed. The one failure (test_target_algebra_preserves_semantic_dimensions_without_self_authorizing, an 8-vs-9 TARGET_RESOURCES count assertion) is pre-existing drift unrelated to this patch — confirmed by diffing polylogue/mcp/declarations/registry.py against origin/master, which shows only a get_resume_brief tool-description string change, nothing touching TARGET_RESOURCES.
  • uv run --frozen python -m devtools.resume_ranking_eval reproduces the claimed fixture metrics exactly: overall hit@1 20.0% -> 100.0%, MRR 0.390 -> 1.000; seeded 1,000-path evidence sample 57.0% -> 82.4% usable, 254/430 (59.1%) dead-path directory recovery.
  • git push ran the pre-push devtools verify --quick gate: all 16 steps passed (ruff format/check, mypy, render all, topology/layering/closure-matrix, schema roundtrip, manifests, ci-workflows, doc-commands, docs-coverage, test-infra-currency, test-clock-hygiene, pytest-timeout-overrides, degrade-loudly).

Not run: replay against the live 4,264-session/27,785-touch archive (unavailable in this environment — the 57% -> 82% improvement is a seeded/fixture reproduction of the bead's reported proportions, not an independent live-corpus rerun); full non-quick devtools verify --all.

Ref polylogue-v1vo

Summary by CodeRabbit

  • New Features

    • Resume candidates and briefs now include transparent file-overlap explanations, including exact matches, directory matches, and excluded obsolete paths.
    • Resume brief APIs and tools accept repository path and recent-file context for more informative results.
    • Candidate-ranking CLI output displays overlap details alongside scores.
    • Added an offline evaluator for measuring ranking quality and evidence recovery.
  • Bug Fixes

    • Improved ranking recovery for renamed, relocated, and historical files while reducing false directory matches.
    • Added validation when recent-file context is supplied without a repository path.
  • Tests

    • Expanded coverage for ranking accuracy, overlap explanations, API contracts, and evaluation metrics.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6690f62c-8c05-4d45-badc-1ec329961a42

📥 Commits

Reviewing files that changed from the base of the PR and between ef83732 and 6aa8131.

⛔ Files ignored due to path filters (1)
  • docs/generated/mcp-equivalence.json is excluded by !**/generated/**
📒 Files selected for processing (17)
  • devtools/resume_ranking_eval.py
  • polylogue/api/archive.py
  • polylogue/cli/query_verbs.py
  • polylogue/context/preamble.py
  • polylogue/insights/resume.py
  • polylogue/mcp/declarations/registry.py
  • polylogue/mcp/server_insight_tools.py
  • polylogue/mcp/server_prompts.py
  • polylogue/surfaces/payloads.py
  • tests/data/resume-ranking-eval-v1.json
  • tests/data/witnesses/mcp-tool-schemas.json
  • tests/unit/cli/test_continue_absorption.py
  • tests/unit/core/test_resume.py
  • tests/unit/devtools/test_resume_ranking_eval.py
  • tests/unit/mcp/test_compose_context_preamble.py
  • tests/unit/mcp/test_contract_evidence.py
  • tests/unit/mcp/test_server_surfaces.py

📝 Walkthrough

Walkthrough

Resume ranking now resolves path overlap with structured provenance, carries that evidence through resume briefs, MCP payloads, prompts, and CLI output, and adds a fixture-driven evaluator comparing legacy and refactor-aware ranking metrics.

Changes

Resume overlap ranking

Layer / File(s) Summary
Path overlap scoring and candidate ranking
polylogue/insights/resume.py, tests/unit/core/test_resume.py
Path resolution distinguishes live, recoverable dead, and excluded paths; candidate scores now include structured exact, directory, and dead-excluded overlap evidence.
Resume brief overlap materialization
polylogue/insights/resume.py, polylogue/api/archive.py
build_resume_brief and resume_brief accept repository context and recent files, compute overlap for matching profiles, and expose the resulting basis.
MCP and CLI overlap surfaces
polylogue/surfaces/payloads.py, polylogue/context/preamble.py, polylogue/mcp/*, polylogue/cli/query_verbs.py, tests/unit/{mcp,cli}/*
Overlap basis is serialized in context payloads and MCP responses, forwarded through prompts and schemas, and rendered in terminal candidate output.
Fixture-driven ranking evaluation
devtools/resume_ranking_eval.py, tests/data/resume-ranking-eval-v1.json, tests/unit/devtools/test_resume_ranking_eval.py
A versioned evaluator compares ranking metrics and evidence recovery for legacy and refactor-aware scoring, with human-readable and JSON CLI reports.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MCP_get_resume_brief
  participant build_resume_brief
  participant SessionProfileInsights
  participant PathOverlapScorer
  Client->>MCP_get_resume_brief: provide session_id, repo_path, recent_files
  MCP_get_resume_brief->>build_resume_brief: forward repository context
  build_resume_brief->>SessionProfileInsights: load matching profile insights
  build_resume_brief->>PathOverlapScorer: score candidate paths against recent files
  PathOverlapScorer-->>build_resume_brief: score and overlap_basis
  build_resume_brief-->>MCP_get_resume_brief: ResumeBrief with overlap_basis
  MCP_get_resume_brief-->>Client: serialized resume brief
Loading

Possibly related PRs

  • Sinity/polylogue#1559: Both changes modify resume-brief materialization and how profile insight data is sourced.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/gpt-pro/perf04-resume

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f35f3d719

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/insights/resume.py Resolved
Comment thread polylogue/insights/resume.py Resolved
Comment thread polylogue/insights/resume.py Resolved
…candidates

Problem: resume-candidate ranking scores file overlap via exact-path
Jaccard over raw historical file_paths_touched. Bead polylogue-v1vo found
that on the live archive 43% of historical file touches no longer exist
under the current layout after repo refactors (e.g. storage/repository.py
-> storage/repository/__init__.py), so a session that is a true refactor
ancestor scores near zero overlap while unrelated sessions with fresher
but shallower touches rank higher. Extra dead paths in a candidate's
touch set also deflate its Jaccard denominator relative to an otherwise
identical candidate with fewer historical paths.

What changed: polylogue/insights/resume.py adds a per-ranking-call
_PathResolutionContext that resolves the caller's repo root once and
caches filesystem existence checks. Candidate paths are partitioned into
resolvable (exact current-checkout match, or file-to-package correction
for a missing foo.py when foo/__init__.py exists) versus dead. Dead
candidate paths are then matched against not-yet-matched recent files by
one-to-one, deepest-prefix, root-rejecting parent-directory continuity.
The Jaccard denominator is corrected to caller-identities union
resolvable-candidate-identities, so still-dead paths no longer enter the
union and no longer deflate the score. The result is exposed additively
as ResumeCandidate.overlap_basis (exact / dir / dead_excluded) without
changing score_breakdown.file_overlap's existing float contract or the
0.25 file-overlap weight. When no valid repo root is available the
scorer falls back to the previous lexical behavior.

Consumers threaded through: Polylogue.resume_brief gained optional
repo_path/recent_files; MCP get_resume_brief and get_resume_brief's tool
description; CLI `continue --candidates` JSON/terminal output; the
SessionStart context preamble (via a typed ContextPreambleOverlapBasis
projection, crossing the surface boundary through model_dump/
model_validate rather than importing the insight model directly).
RESUME_BRIEF_MATERIALIZER_VERSION bumped 1 -> 2 for the added optional
field. No schema/migration touched; no stored profile is rewritten;
adaptation happens at query time only.

Adds devtools/resume_ranking_eval.py, a durable offline hit@1/hit@3/MRR
evaluator over a versioned, lineage-grounded fixture
(tests/data/resume-ranking-eval-v1.json) comparing legacy vs
refactor-aware scoring. On the fixture: overall hit@1 20% -> 100%, MRR
0.390 -> 1.000; a seeded 1,000-path evidence sample reproduces the
bead's reported proportions at 57.0% -> 82.4% usable evidence (254/430
dead paths directory-recovered). This is a seeded/fixture reproduction,
not a rerun against the live 4,264-session archive, which was not
available in this environment.

This patch originated as an externally-generated (GPT Pro) packet
against bead polylogue-v1vo. It was independently re-verified on current
master before commit: full diff read line-by-line, an anti-vacuity
mutation (neutering _directory_overlap_pairs to return () ) confirmed 5
tests genuinely fail including the eval harness's own partition
invariant, then reverted and confirmed byte-identical to the patched
state; devtools test passed 154/154 plus the facade route test;
devtools render all --check passed with no "out of sync" surfaces;
strict mypy passed on all 9 changed production/evaluator modules; a
broader MCP/CLI contract run reproduced 206 passed / 1 pre-existing
unrelated failure (test_target_algebra_preserves_semantic_dimensions_
without_self_authorizing, an 8-vs-9 TARGET_RESOURCES count mismatch this
patch's registry.py diff does not touch).

Ref polylogue-v1vo

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01XR2eyvDxV5xr4qmbmbwyrL
@Sinity
Sinity force-pushed the feature/gpt-pro/perf04-resume branch from 4f35f3d to 6aa8131 Compare July 18, 2026 02:57
@Sinity
Sinity merged commit 38faf99 into master Jul 18, 2026
1 of 3 checks passed
@Sinity
Sinity deleted the feature/gpt-pro/perf04-resume branch July 18, 2026 02:58
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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