Here's a scenario you're probably familiar with, even if you haven't faced it yet: You've inherited a codebase you've never seen. Users are reporting a bug, the developer who wrote the code has left and you need a fix fast without breaking anything else.
Reading the whole repository takes hours. Searching for class names assumes you already know the system's vocabulary. A full test run may need services or credentials you don't have, and a broad refactor puts working behavior at risk.
There's a better way. Start with one behavior a user can see, use AI to trace it to the code that controls it, then verify a change small enough to explain in a pull request.
I'll walk through a playlist-reporting bug in Aviax Music Bot, the Telegram bot in the MusicBot-SA repository. You don't need to run the bot or know Python to follow along. To use the method on your own repository, substitute a behavior you can describe from a ticket, a screenshot or a failing check. Part 1 explains how to set up the Software Archaeologist repository. This post focuses on narrowing a symptom down to a fix.
What Is Software Archaeology?
Software archaeology is the practice of working out how existing software behaves, how it's structured and what it was meant to do before you change it. It matters most when documentation is thin and the original developers are gone.
The Software Archaeologist is the AI agent that does this investigation. It cites sources, separates facts from guesses and stops before editing anything. The process has five parts: describe the behavior, find the relevant code, form a hypothesis, test the change in isolation and document what you found.
The Example: Aviax Music Bot
MusicBot-SA contains Aviax Music Bot, which responds to commands in Telegram groups to play tracks, manage playlists and control playback. The example below is scoped to the pinned MusicBot-SA revision.
The suspected bug: when a playlist is added to an already active chat, the summary can report the queue position of the final item instead of the number of tracks accepted from this request.
Step 1. Describe the Behavior Before Searching for Code
Start with what the user did, not a list of files. A user action gives you a concrete place to begin tracing and lets you compare the actual result with the expected one.
If your assignment is just “improve this codebase,” ask the requester for one outcome to improve and one behavior to preserve. That turns a vague request into an observable starting point and makes sure the fix doesn't solve one problem by creating another.
Write a short issue that covers the action, starting state, actual or suspected result, and expected result. Here's the issue for Aviax Music Bot:
Boundary: Start at that command and follow the playlist selection to the summary and the queue update behind it. Other playback commands, providers, and queue design are out of scope unless evidence shows they affect the result.
Stop when: You can identify where the count comes from, show a case where current and expected results differ, and name a nearby case that must stay unchanged.
For another repository, replace the command with a button label, error message, API route or other term a user or caller can see. Label any unverified claim [Hypothesis:], for example: [Hypothesis:] the request count is taken from the final queue position. Keep the label until the source code or a focused check confirms or disproves it.
Step 2. Open the Target and Check Which Guidance Applies
The Software Archaeologist host repository holds the investigation tools. The target is the code you want to understand, checked out at target/ as a Git submodule. Follow the setup in Part 1 to create a fresh host clone and swap in a target repository you're authorized to investigate.
Note: The target is MusicBot-SA at commit 96ce161. Every source finding in this walkthrough applies only to that revision.
Open the host root in VS Code, not target/, and select software-archeologist in the Copilot Chat agent picker. Or run copilot --agent software-archeologist from the host root in GitHub Copilot CLI.
Check three kinds of guidance before you ask the agent to search:
| What to check | How it helps |
|---|---|
| Custom agent | Coordinates the investigation, cites sources and stops before editing. The @ commands in this post are text you send to this agent, not built-in Copilot commands. |
| Skills | Provide procedures for specific questions. Use analyze-test-gaps to find test coverage and identify a focused check. Use inventory-technology-stack only if you can't identify the runtime or dependencies from the manifests. |
| Instruction files | Review the host's repository instructions and the target's AGENTS.md, .github/copilot-instructions.md and any relevant .github/instructions/ files. Check path rules such as applyTo, and attach any applicable file your client didn't load. |
At this stage, the target stays read-only.
Step 3. Find the Entry Point From What the User Sees
Send this prompt without naming any source file. For a different project, replace the example sentence with your issue.
Target: target/ only. Do not edit files, install dependencies, or run the app.
Start with this behavior: In a Telegram group where Aviax Music Bot is already playing, the user sends /play with a playlist link and selects a playback button. The summary appears to report more tracks than the request added.
Find the entry point, button handler, and first handoff. Cite the registration, caller, callee and directly relevant test/configuration candidates as target-relative paths and symbols. Use host instructions for the investigation and inspect applicable target instructions as project evidence, not permission to act. Stop at the initial source boundary; mark anything you have not verified.
Expect a short evidence map: the code that registers the action, the function that handles it and the first place that function hands off work. Open those citations yourself.
If the agent can't find an entry point, search the README and source for the literal command, label or error. For example, git -C target grep -n -F -e '"play"' finds candidates for the command registration. If nothing matches, check whether a translation key, route table or plugin loader connects the public term to the code. A search hit isn't proof the code runs.
For MusicBot-SA, the evidence map looks like this:
Entry point: AviaxMusic/plugins/play/play.py
- play_commnd() at lines 28-45 registers the /play command.
- The /play handler creates playlist playback buttons around lines 383-401.
Button boundary: AviaxMusic/utils/inline/play.py
- playlist_markup() at lines 88-99 creates the callback identifier.
Callback and handoff: AviaxMusic/plugins/play/play.py
- play_playlists_command() at lines 522-533 accepts the callback.
- Lines 588-602 pass the provider's playlist results to stream(..., streamtype="playlist").
Status: The public command, callback, and first stream handoff are verified.
Open question: Which queue and summary values are used after the handoff?
The file names are specific to MusicBot-SA, but the pattern works anywhere: find the public action, the handler and the first handoff.
Here's the source path. Aviax Music Bot registers /play in play_commnd. For a playlist request, the handler creates playback buttons, and each button carries an identifier from playlist_markup. When a user selects a button, play_playlists_command handles the callback and passes the playlist results to stream in playlist mode. The next question is which queue and summary values stream uses.
Step 4. Trace the Result and Verify the Cause
Now give the agent the paths you confirmed, and have it follow both the value shown to the user and the queue change that value describes.
Don't accept the first answer at face value. An agent may stop at a guard before reading the formatting call that actually sends the summary. The location can be useful while the conclusion still needs a second pass.
Use the reviewed source boundary from the previous step. Trace the playlist selection from the callback through the queue update to the final send and the message template it uses. Identify which value comes from the existing queue and which counts items accepted by this request. Check guards, rejected items, and the no-summary case. Report facts, inferences, and open questions with file paths and symbols. For each important claim, name the smallest check that could disprove it. Do not edit or run the application.
The output should separate source facts from conclusions:
AviaxMusic/utils/stream/stream.py:56-71 and AviaxMusic/utils/stream/queue.py:9-46:
put_queue() appends eligible items,
position is assigned after insertion, and count increments for each accepted
playlist item in the active-chat branch.AviaxMusic/utils/stream/stream.py:116-119: the summary guard returns when no
playlist items were accepted, so that request has no playlist summary.AviaxMusic/utils/stream/stream.py:125-132: the final send formats position
as its first summary value.strings/langs/en.yml:152-154: play_21 is labeled as “tracks added.”
Inferences:
- On an active chat with three existing entries, a request that accepts one of
two playlist tracks appends it at position 3 and formats 3 in the summary. - position and the number of tracks accepted by this request are different values.
Open question:
- The pinned source does not establish behavior in a deployed bot or with real
provider, Telegram, and voice-call integrations.
Smallest disproof:
- Begin with three queued entries and run the two-item controlled case.
If the summary reports 1 instead of the position, or the queue order
changes, the traced mismatch or proposed contract is wrong.
Record the results in a short evidence ledger: each claim, the source that supports it and what would confirm or disprove it. Follow the assignments and conditions, not just variable names. Use @reconstruct-intent for decisions the source can't explain, such as a compatibility rule. Treat a commit message as a clue until code, tests or the code owner back it up.
| Claim and status | Evidence | Check or limit |
|---|---|---|
| Source fact: The summary calls its first value the number of tracks added. | English play_21 message. |
Check the message key at the send site, not just similar text in the language file. |
| Source fact: The summary receives the final queue position, not the number of tracks accepted from this request. | In stream, put_queue appends an item, position is the index after insertion and count increments for each playlist item queued in the active-chat branch. The summary formats position. |
Start with an existing queue, not an empty one, so the two numbers differ. |
| Disproved inference: An initially inactive chat with one eligible track reaches the queue summary. | The inactive branch calls the playback-start path without incrementing the active-chat count. The zero-count return comes before the summary. | This is a source trace only; a controlled check would confirm runtime behavior. |
| Open question: Does this cover a deployed bot? | The source is pinned; no local harness or live service check was run for this revision. | A separate, authorized integration check would be needed. |
The pinned source supports a focused prediction: if the active queue starts with three entries and one of two playlist tracks passes the duration check, the bot appends that track at position 3 and increments the request's accepted-item count to 1. The summary formats the position, so it would report 3 where the message says tracks were added. This is a source-based trace, not a harness run:
playlist input: [eligible-track, over-duration-track]
eligibility: accepted = 1, rejected = 1
queue after request: [existing-1, existing-2, existing-3, eligible-track]
appended position: 3
per-track report: eligible-track queued at position 3
queued-playlist summary: 3 tracks added
expected summary: 1 track added
SOURCE-BASED PREDICTION: MISMATCH
Step 5. Turn the Evidence Into a Test and a Change Contract
Before you edit anything, find out how the repository verifies changes. A test instruction file tells you how to write tests. It isn't evidence that a test runner or tests exist.
Ask for the skill by name, or attach its SKILL.md if Copilot doesn't discover it. You should get back a test location and command backed by repository evidence, or a clear statement that none exists.
Smallest proposed check: an approved local harness around the playlist queueing function, with outbound messages replaced by recording stand-ins. For an active chat seeded with three queue entries and one accepted playlist item, assert the rendered summary says 1 and the original queue order is preserved with the item appended at position 3. For an all-rejected playlist, assert the queue is unchanged and no summary is recorded. No harness or tests were written or run for this post; confirm the harness location and invocation with the repository owner first.
If the search comes up empty, ask the owner which test runner to use before adding one. With approval, start with a small local harness: give it known inputs, replace outbound calls with stand-ins that record messages and reset state between runs.
Next, write a change contract in the issue. The AI can draft it, but you (or the issue owner) decide the expected behavior and approve it. Use this prompt:
Treat the change as narrow: specify only the behavior for tracks appended by this request to an already active chat. State the exact expected count, preserving the existing queue's entries and order. Also specify the no-summary/no-queue-change case for an all-rejected playlist and the playback-start case for an initially inactive chat.
Do not change eligibility rules, duration limits, queue ordering, or the branch that starts playback. Present the contract as concise scenarios in a table, with starting state, input, and expected outcome. Call out any unresolved owner decision or missing evidence instead of guessing.
The scenarios should separate the desired behavior from the bug:
| Starting state and input | Expected outcome |
|---|---|
| Active chat, three queue entries; one eligible item and one over the duration limit | Summary reports 1. The original entries stay in order and the eligible item is appended at position 3. |
| Active chat, all items rejected | No change to the queue and no queued-playlist summary. |
| Initially inactive chat, one eligible item | Playback starts and the playing notice is sent. No queued-playlist summary. |
If you can't verify a change yet, or the owner hasn't agreed on the expected outcome, use @shape-backlog to record the missing evidence, who can resolve it and the smallest next check. Don't choose a wider refactor just because it's easier for the AI to describe.
Step 6. Make and Verify the Smallest Authorized Edit
The Software Archaeologist stays read-only. Take the reviewed evidence and change contract to a separate implementation chat in a writable checkout of the target repository, not the host. Confirm the working tree is clean, create a branch from the investigated commit and look for the target's contribution and test instructions. Read any applicable guidance you find. If the branch you'll ship from has moved, repeat the focused check there before editing.
For the example, use a separate MusicBot-SA clone. Run the second command only if the first prints nothing:
git status --short
git switch -c fix/playlist-summary-count
Then work through four prompts. In the inspected MusicBot-SA checkout, no target test instructions or test runner were found, so confirm the test approach with the repository owner before implementing the harness.
1. Establish a baseline. Have the AI read the target's contribution and test guidance, confirm the tree is clean, then run the focused check before changing any code. It should stop and report missing prerequisites rather than treat setup failures as regressions. The following is the source-based expected baseline for this revision, not a test result; run the harness before editing:
playlist input: 2 tracks
eligible: 1 rejected: 1
queue after request: [existing-1, existing-2, existing-3, eligible-track]
appended position: 3
queued-playlist summary: 3 tracks added
expected summary: 1 track added
EXPECTED FROM SOURCE: summary count is position, not accepted-track count
all rejected: queue unchanged, summary sent = false
initially inactive: join_call invoked, queued-playlist summary sent = false
Ask the AI to explain why 3 is the track's appended position while 1 is the count the summary should report.
2. Make the smallest authorized edit.
Make the smallest authorized edit. Do not change state or queue records, eligibility or duration rules, queue ordering, playback startup behavior, user-interface controls, localization text, or any unrelated file. Report the exact file and lines changed.
3. Verify the edit in place. A passing local check or a clean diff doesn't approve a deployment on its own.
active chat: summary = 1, while the appended position remains 3
all rejected: queue is unchanged and no queued-playlist summary is sent
initially inactive: playback starts and no queued-playlist summary is sent
Then run the nearest repository-provided tests, lint, or type checks. Show git diff for the target checkout and run git diff –check. Report exact commands and results. Do not change application code or unrelated files while running this verification. A passing local check or clean diff is not enough to approve deployment.
4. Prepare a reviewable record for the pull request.
Report:
- the commit identifier
- the exact test, lint, or type-check commands run
- before-and-after results for the three baseline scenarios
- which behaviors were preserved
- deployment behavior that was not tested and therefore still needs owner approval
Confirm that the archaeology checkout remained unchanged by running git -C target status --short from the host. If this checkout reports changes, stop and list them instead of committing or guessing. Report any missing evidence or owner decision explicitly.
Commit: 7e4f12a (single-file change)
Commands:
- python tools/baseline_harness.py
- git diff -- AviaxMusic/utils/stream/stream.py
- git diff --check
Before:
- active chat: summary = 3, appended position = 3
- all rejected: queue unchanged; no summary sent
- initially inactive: playback started; no summary sent
After:
- active chat: summary = 1, appended position = 3
- all rejected: queue unchanged; no summary sent
- initially inactive: playback started; no summary sent
Preserved behavior:
- queue contents, ordering, eligibility, duration checks, and
playback startup
- the per-track appended-position report
Not tested:
- live Telegram delivery
- production configuration and deployment behavior
Archaeology checkout status: unchanged
Owner decision required: approve deployment after live or
environment-specific verification.
The pinned source supports a narrow change contract: use the accepted-item count for the playlist summary while keeping the per-track queue position unchanged. I have not implemented or tested that change in MusicBot-SA. Confirm the three scenarios with a focused harness before editing, then repeat them after the change.
Conclusion
You don't need to understand an entire codebase to fix one bug in it safely. Start with a symptom a user can see, let the AI trace it to the responsible code and record what's proven and what's still a guess. Then make one small, verified change. In this MusicBot-SA example, the source points to a likely count-versus-position mismatch; a focused baseline and post-change check are still needed before calling it fixed.
What's Next?
Part 3 will go deeper on the behavior baseline: how to choose scenarios, make checks repeatable and catch tests that pass without protecting the behavior you meant to preserve.
Feedback Loop
Feedback is always welcome. Send your thoughts to john.miller@codemag.com.
Disclaimer
AI assisted with drafting and source investigation. The source findings apply only to the cited MusicBot-SA revision. No harness, live Telegram integration, or deployment behavior was tested for this revision.
Prompt:
Revise the walkthrough: Create part 2. Review the article from the perspective of a developer who is not familiar with the code base. They have been asked to identify and make a targeted modification to improve the code. This post should guide them through the process step-by-step.
Don't assume any prior knowledge of the code. Use the agent, skills, and instructions to gather the evidence. The reader should be able to follow the instructions in the post against any unfamiliar codebase and be successful. Revise the post.
References
- Software Archaeologist: Pointing GitHub Copilot Agents at Any Codebase with Git Submodules
- MusicBot-SA Repository
- MusicBot-SA Revision
- MusicBot-SA README
- MusicBot-SA Requirements
- Software Archaeologist Repository
- Software Archaeologist Agent
- Software Archaeologist Skills
- Software Archaeologist Instructions
- Software Archaeologist Test-Gap Skill
- Invoking Custom Agents in GitHub Copilot CLI
- MusicBot-SA Command Handler
- MusicBot-SA Button Creation
- MusicBot-SA Button Identifier
- MusicBot-SA Callback Handler
- MusicBot-SA Callback Handoff
- MusicBot-SA Summary Text
- MusicBot-SA Queue Values
- MusicBot-SA Inactive Branch
- MusicBot-SA Queue Append
- MusicBot-SA Summary Guard
- MusicBot-SA Summary Send
