CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 6 · Lesson 35/45

    Diagnosing Compaction Failures: What Was Discarded and How to Fix the Prompt

    Given a long running agent task that has been compacted and is now exhibiting downstream coherence failures, identify which category of information was incorrectly discarded during compaction and select the compaction prompt revision that preserves that category without significantly increasing the token cost of the summarized context.

    13 min read
    2.2% of exam
    9 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Name the categories of information a compaction summary must keep for a long-running agent to stay coherent, and the categories it can safely drop
    • Map a post-compaction coherence failure (repeated tool calls, contradictions, constraint violations, wrong identifiers, early completion) to the category that was lost
    • Choose the compaction prompt revision that restores the lost category with a short, targeted instruction instead of a large increase in summary size
    • Use the full session transcript and trace token data to check that a revision brings back fidelity without a large rise in cost

    Key concept

    Category-targeted compaction — Compaction swaps an agent's long history for a summary, so every coherence failure afterwards comes from a category of information the summary left out. The fix is to name that category in the compaction prompt and ask for it in a compact, structured form. Keeping more of everything is the wrong fix.

    1.What compaction acts on, and why it can break an agent

    A long-running agent builds up history with every turn. Its session state is the conversation so far: what the user asked, every tool call, every tool result, and the agent's reasoning between them. When that history gets close to the context-window limit, the harness summarizes it and the agent continues from the summary. From then on the agent can only use what the summary kept. If a fact was left out, the agent has no way to know it ever existed.

    A generic summarizer keeps the story and drops the bookkeeping. It tends to write a few fluent sentences about what the agent was doing and leave out the details later steps rely on: the exact table name the user said not to touch, the ID of the job already launched, the approach tried and rejected at step 14, the three sub-tasks still open. Databricks describes a similar step for long-term memory, where an agent or application distills durable facts out of a session. Compaction faces the same choice inside a single task: what is worth keeping? The basic example below shows the default behavior. A one-line summarization template with no guidance about what matters.

    A basic summarization prompt from the MLflow prompt-versioning docs. Nothing in it tells the summarizer which kinds of information must survive, which is the usual root cause of compaction failures.python
    prompt_v1 = mlflow.genai.register_prompt(
        name=PROMPT_NAME,
        template="Summarize this text: {{content}}",
        commit_message="v1: Basic summarization prompt"
    )

    A compaction summary has two kinds of content. The must-keep set: (1) the goal and hard constraints, (2) decisions and their short rationale, including rejected alternatives, (3) completed actions with their identifiers, especially actions with side effects, (4) the specific facts pulled from tool outputs, such as IDs, values, paths and error messages, and (5) open items still to do. The safe-to-drop set: superseded reasoning, raw tool output whose useful facts are already extracted, and the step-by-step detail of finished sub-tasks.

    Checkpoint 1 of 5· Check yourself

    In the Databricks description of agent session state, what does the conversation history being compacted actually contain?

    Sources12

    2.Reading the symptom: which category was discarded?

    Compaction failures show up later. The summary looks reasonable, and the agent goes wrong several steps afterwards. To diagnose one, work backwards: look at what the agent did wrong, then ask which piece of information would have stopped it. Each must-keep category has its own symptom, and exam scenarios are written so that only one category fits.

    A fifth pattern is the agent saying it is finished while sub-tasks are still open. That points to lost open items. The summary described completed work well but never listed what was left. Two other patterns can look similar but don't count as compaction failures: an agent that was already inconsistent before compaction, and an error that comes from a bad tool response. Before you blame compaction, confirm that the failure first appears after the compaction boundary.

    Checkpoint 2 of 5· Exam question

    A data-engineering agent has been running for over an hour, executing many diagnostic SQL queries against a Delta table to find the source of a null-value bug. A compaction event condenses the growing history into a narrative summary ("agent investigated several possible causes of the null values"). Immediately after, the agent reruns two diagnostic queries it had already executed and already had results for. Which category of information was incorrectly discarded, and which compaction prompt revision fixes this without materially increasing summary length?

    Sources34

    3.Selecting the revision: preserve the category, not the volume

    Once you know which category was lost, the second half of the objective is choosing the fix. Answer options tend to fall into two groups. Broad options keep more of everything: keep the last N turns verbatim, keep all tool outputs, raise the summary length cap, compact less often. Each might restore the missing fact, but by inflating the summarized context, which defeats the purpose of compacting. Targeted options add one specific instruction for the lost category and ask for it in a terse, structured format.

    Databricks has no dedicated compaction setting to learn here. This is prompt design. The closest Databricks pattern is the system-prompt guidance for managed agent memory, which tells the agent what to keep and what to drop when it writes durable memory. Its rules carry over to compaction prompts. When something changes, replace the old version instead of keeping both. Write each entry so it stands on its own out of context. Leave out the agent's own suggestions or guesses, passing chatter, secrets, and anything scoped to this chat. The MLflow prompt-versioning example shows the same move in a general summarizer: its improved version adds explicit guidance such as "Include ALL core facts and key findings" instead of simply allowing a longer output.

    Applied to each category, a good revision is one short clause. For lost progress state: "List every completed tool action with side effects as one line: action, target, returned ID." For lost constraints: "Restate the user's original goal and hard constraints verbatim at the top." For lost facts: "Keep exact identifiers, values and paths extracted from tool outputs; drop the raw output." For lost open items: "End with a checklist of unfinished sub-tasks." Each one adds a few lines to the summary and does not bring the transcript back. Some also let the summarizer drop more raw output, which partly pays for the new lines.

    Checkpoint 3 of 5· Check yourself

    After a compaction, an agent mixes a decision the user revised mid-task with the original version. Which compaction prompt revision best matches Databricks' guidance on handling information that changes?

    Checkpoint 4 of 5· Exam question

    While configuring a Genie space, an agent is explicitly told by the user to exclude the deprecated table "sales_2019_legacy" from the space. Several turns later, a compaction step summarizes the session as "configured Genie space with the relevant sales tables." On the next turn, the agent adds "sales_2019_legacy" back into the space's table list. Which category of information was incorrectly discarded during compaction?

    Sources56

    4.Confirming the fix: fidelity restored, cost contained

    A diagnosis is only a guess until you check it against evidence. On Databricks, two kinds of evidence are available. First, compaction changes what the model sees, but the full session record can still be kept. Managed agent sessions let you rebuild full context, including tool calls and reasoning, from the stored history. Compare the compacted summary with that transcript to confirm the missing category really was in the original and really is gone from the summary. Second, MLflow Tracing records token usage and cost for every step. You can measure how many tokens the revised summary adds and confirm the increase is small.

    Last, rerun the failing scenario with the revised prompt. The original symptom should be gone: no repeated call, no contradiction, constraints followed. Summary size should stay about the same. If the symptom remains, the diagnosis may have been wrong. Go back to the transcript and check whether a different category was lost. Long conversations that hit token limits are a recognized problem area on Databricks, so this check-and-compare loop is part of normal work, not a one-off fix.

    Checkpoint 5 of 5· Exam question

    Early in a session, a user tells an agent, "Only write results to the dev catalog, never to prod." Many turns later, after a compaction event summarizes the conversation as "agent has been writing pipeline outputs to Unity Catalog tables," the agent writes its next output directly to a table in the production catalog. Which category of information was incorrectly discarded during compaction?

    Sources789

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.The right fix for post-compaction forgetting is to compact less often or keep more raw history in context.Why is that wrong?

      Compaction exists so the model is not overwhelmed as context grows. Keeping more raw history gives up that purpose and raises token cost. The objective rewards a targeted instruction that preserves only the lost category.

      Covered in Selecting the revision: preserve the category, not the volume

    2. 2.When an agent repeats tool calls after compaction, the fix is to add iteration limits or timeouts.Why is that wrong?

      Iteration limits are a general guard against runaway loops. They stop the damage but don't restore the lost record of completed actions. The cause, a summary missing completed actions and their IDs, has to be fixed in the compaction prompt.

      Covered in Reading the symptom: which category was discarded?

    3. 3.For completeness, a compaction summary should keep both the original and the revised version of a decision.Why is that wrong?

      Keeping superseded information next to current information is what causes contradictions after compaction. The current version should replace the old one, with at most a one-line note of what was rejected.

      Covered in Selecting the revision: preserve the category, not the volume

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “the ordered transcript of messages, tool calls, and results”
      ↩︎ What compaction acts on, and why it can break an agent
      “an agent (or your application) distills the durable facts out of it and writes them to memory”
      ↩︎ What compaction acts on, and why it can break an agent
    2. 2.
      “As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
      ↩︎ What compaction acts on, and why it can break an agent
      “As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
      ↩︎ Key concept
      “trimming older parts of the conversation so the model does not become overwhelmed as the context grows”
      ↩︎ Exam trap 1
    3. 3.
      “Must guard against repeated or incorrect tool calls”
      ↩︎ Reading the symptom: which category was discarded?
      “Infinite loops can occur in any tool-calling scenario, so set iteration limits or timeouts.”
      ↩︎ Exam trap 2
    4. 5.
      “update or replace it rather than keeping both”
      ↩︎ Selecting the revision: preserve the category, not the volume
      “Write each memory so it stands on its own out of context”
      ↩︎ Selecting the revision: preserve the category, not the volume
      “your own suggestions or guesses, passing chatter, secrets, or anything scoped to this chat”
      ↩︎ Selecting the revision: preserve the category, not the volume
      “update or replace it rather than keeping both”
      ↩︎ Exam trap 3
    5. 7.
      “Reconstruct full context (including tool calls and reasoning) on a follow-up message.”
      ↩︎ Confirming the fix: fidelity restored, cost contained
    6. 8.
      “Tracing records the inputs, outputs, latency, token usage, and cost of every intermediate step”
      ↩︎ Confirming the fix: fidelity restored, cost contained

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.