Skip to content

Self-scan context pack: per-issue "read file:X-Y" pointers from the master DB for churn workers #5521

Open

Description

@squid-protocol

Why

A cost audit of nyx's churn workers (2026-10-18, 16 worker sessions, 10 merged PRs at ~$2/PR) found:

  • Workers get only the issue number and title. Each one finds the code itself, taking 5-14 grep/sed -n requests before its first edit. Orientation accounts for ~45% of worker spend, though most of that is the fixed ~40k-token starting context that every request re-reads.
  • Whole-file reads are the main trap. gitgalaxy/core/detector.py is ~135k tokens, and seven files are over 60k tokens each. The golden-master JSON fixtures run up to 606k lines.
  • The self-scan already has what is needed to point a worker straight at the code, but nothing turns it into a per-issue slice:
    • The master DB's function_data has start_line, loc, complexity, fan-in/fan-out and token_mass.
    • fcall_data holds the resolved call graph and edge_data the import edges.
    • file_data has token_mass, churn and blast radius.
    • The existing LLM brief (_llm.md) is ~137 KB (~34k tokens), too big to inject.

What

Add a tool, e.g. tests/tools/context_pack.py <issue> [--db docs/self_scan/gitgalaxy_master.db] [--max-tokens 3000]. Given an issue, it would:

  1. Pull out the paths, file names, function, class and symbol names, and backticked identifiers named in the issue body and title (gh issue view --json title,body).
  2. Resolve them against the master DB (file_data, function_data, class_data). Fuzzy-match bare names and rank matches by how often they are mentioned.
  3. For each hit, emit path:start-end (from start_line + loc), complexity and token size. Add one hop of callers and callees from fcall_data, each with its own path:start-end, and import fan-in from edge_data.
  4. Flag large files (token_mass > 8k, as dev_agent_firewall does) with "read only the named ranges".
  5. Print a Markdown block capped at about 1-3k tokens that a worker brief can include verbatim. If nothing resolves, print nothing; never pad.

Freshness: keep one DB per origin/main commit (tests/tools/self_scan.py already does delta mode, ~6-8 s; a full scan is ~1.5 min). Run the pack before the worker launches, so a stale DB is off by at most the commits since the last refresh. Line ranges are hints and the worker still reads the code.

Integration (separate PR in squid-protocol/promoter-bot): churn worker runs the tool and adds its output to prompt.md under "Where to look". That is a few lines once the tool exists.

Related cleanups found during the audit

  • CLAUDE.md:103 points agents at docs/gitgalaxy_architecture_brief.md. That file moved to the generated branch, so a local checkout has nothing there.
  • docs/agents/self-scan-orientation.md says the DB "has no line numbers". That is stale: function_data.start_line is populated.
  • Delta-mode briefs written into worker worktrees (e.g. churn-5464_galaxy_llm.md) report "0 analyzed artifact(s), 0 LOC". Either fix them or stop writing them.

Acceptance

Activity

  1. added
    enhancement
    scope:infra
    on Oct 18, 2026
  2. squid-protocol commented on Oct 19, 2026

    @squid-protocol
    OwnerAuthor

    Churn run 5521-20261019T0924Z (host nyx) ended without a PR. Nothing to do: slice 1 had already merged in #5532. The remaining slices are noted on the issue, which stays open.

    🤖 Generated with Claude Code

  3. squid-protocol commented on Oct 23, 2026

    @squid-protocol
    OwnerAuthor

    #6145 merged: a partial slice of [c:530ba3ea] "context_pack.py produces a pack of 3k tokens or less for at least 5 recent closed churn issues, and for each one the pack names the file(s) the merged PR actually changed. Show the hit rate in the P"; left: 17/24 (71%) hit rate shown above; the criterion asks that each of >=5 issues name the changed files, which holds for a minority (e.g. #5736, #4707, #5168) and not for all. (promoter-bot)

  4. squid-protocol commented on Oct 23, 2026

    @squid-protocol
    OwnerAuthor

    #6145 merged: a partial slice of [c:8c9805b3] "Follow-up issue or PR filed on promoter-bot to wire it into churn worker."; left: promoter-bot wiring not filed (worker may not file issues); listed as a remaining slice. (promoter-bot)

  5. squid-protocol commented on Oct 24, 2026

    @squid-protocol
    OwnerAuthor

    #6533 merged: a partial slice of [c:8c9805b3] "Follow-up issue or PR filed on promoter-bot to wire it into churn worker."; left: the promoter-bot issue/PR itself is still to be filed; workers may not file issues or edit other repos. (promoter-bot)

  6. squid-protocol commented on Oct 25, 2026

    @squid-protocol
    OwnerAuthor

    Churn run 5521-20261025T2331Z (host nyx) ended without a PR. No gitgalaxy change; remaining item is promoter-bot wiring of context_pack.py into churn worker (outside worker scope, owner/tick side). Other 4 boxes ticked.

  7. added
    priority: low
    and removed on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementperformancepriority: lowscope:infra

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions