Memory Governance for Long Conversations Under Compute Constraints

    Long conversations are not unlimited history pasted back into the model. On a shared inference cluster, request cost tracks input tokens, output tokens, concurrency, and residency time. This article separates context limits, session retention, and quotas, then describes layered memory, checkpoints, degradation, and metrics so identity and progress survive when inactive long sessions are dropped.

    Long conversations are not an endless concatenation of history resent to the model. On a shared inference cluster, the cost of one request is roughly tied to input tokens, output tokens, concurrency, and how long the request stays resident. A light Q&A pattern—a dozen turns a day, hundreds to a few thousand tokens each—barely touches a quota. Uses that keep project material, study notes, or hundreds of thousands of words of plot and persona in the same session inflate a single prefill and the key-value cache to a scale a cluster cannot absorb for free. Quota policy therefore tends to cut “very long and inactive” sessions before it cuts short question-and-answer traffic.

    Why limits show up as “the old window stopped working”

    Capacity signals usually fall into three kinds. Treat them separately so they are not collapsed into “the server is flaky.”

    1. Context ceiling. The history plus system prompt that one request may carry is capped at a fixed window, on the order of tens of thousands of words. Anything beyond that window is not magically remembered. The system truncates, errors, or silently forgets.
    2. Session keep-alive. A long session with no new messages for several days no longer keeps server-side state. That is usually reclaiming conversation storage, cache, and indexes, not the model suddenly losing language ability.
    3. Call rate or daily quota. The interactive entry point is capped per user or per application. Once the cap is hit, the caller sees busy or quota exhausted. A metered programming interface on a separate resource pool may still work, because its cost can be measured and isolated.

    A site-wide stall is more often a regional failure or a model-version switch. If only the free interactive endpoint is constrained and the metered interface is healthy, the pattern looks more like resource pooling and priority scheduling. If the product only says “busy,” the caller should still handle four error classes separately: timeout, rate limit, context too long, and session expired.

    Heavy use does not really depend on “one chat box”

    Companion chat, long outlines, and a private knowledge base all look like an oversized transcript. Their constraints are not the same.

    • Identity and style. System prompts, persona, taboos, and speaking habits must stay stable. They belong in a short, versioned instruction layer, not scattered through hundreds of thousands of words of small talk.
    • Relationship and progress. Recent agreements, open items, and key facts need high-priority recall. Structured state fits better than hoping the model will retrieve them from the full text.
    • Raw archive. Complete chats, notes, and outlines are archives. They belong in object storage and retrieval, with fragments fetched on demand, not replayed in full on every turn.

    If archive, state, and persona are bound to a single session identifier, and the server drops that identifier after a number of inactive days, the application looks like “memory wiped.” For a writer that is a lost outline. For a companion setting it is a broken relationship context. The root cause is that state was never externalized.

    Capacity model: estimate before you argue about experience

    A simplified estimate helps with planning. The figures are orders of magnitude only, not any platform’s billing rules.

    Let average user input per turn be U tokens and the model reply A tokens. Keep the last K turns verbatim, plus system prompt S, structured state M, and retrieved fragments R. One request’s input is about:

    S + M + R + K × (U + A)

    As K grows linearly, prefill cost grows roughly linearly or worse, because attention cost rises with sequence length. Daily cost is also multiplied by turns and concurrent users. If a free pool shares the same accelerators with a metered pool, long-context users crowd out latency for short requests. A reasonable split is:

    • Give the free interactive pool a smaller window, shorter keep-alive, and a stricter daily quota.
    • Bill the metered pool by tokens and concurrency, allow a longer window, and still set a hard cap.
    • On overflow, return an explicit error code that says to shorten context or switch to asynchronous batch processing, rather than queue without limit.

    Memory layers

    Split the input of one generation into four layers and define an eviction order.

    1. Instruction layer. Role, format, and safety boundaries stay inside a fixed budget. Changes go through a version number.
    2. State layer. Structured fields hold progress: current chapter, open questions, relationship stage, user preferences. Each turn updates only the delta. Do not write a whole inner monologue back into state.
    3. Retrieval layer. Chunk historical messages and notes, then index them by vectors or keywords. Recall a limited set of fragments for the current user question, and attach source turn numbers so they can be checked.
    4. Verbatim sliding window. Keep only the last few turns word for word so tone stays continuous. Older text stays out of the prompt unless retrieval hits it.

    Evict in this order: drop verbatim text outside the window first, then reduce retrieved items, and touch state and instructions last. Persona and key facts are then not the first things cut just because small talk got long.

    The assembly sketch below is control flow only. It does not match any vendor API:

    1. def build_prompt(store, session_id, user_text, budgets):
    2. instruction = store.load_instruction(session_id)
    3. state = store.load_state(session_id)
    4. hits = store.search(session_id, user_text, top_k=budgets["retrieve_k"])
    5. window = store.recent_turns(session_id, n=budgets["window_n"])
    6. prompt = assemble(instruction, state, hits, window, user_text)
    7. while token_len(prompt) > budgets["max_input"]:
    8. if window:
    9. window = window[1:]
    10. elif hits:
    11. hits = hits[:-1]
    12. else:
    13. raise ContextBudgetExceeded("state or instruction too large")
    14. prompt = assemble(instruction, state, hits, window, user_text)
    15. return prompt

    Summaries, checkpoints, and migration

    Inactive cleanup is not the scary part. Missing checkpoints are. Run this on the application side on a schedule, instead of trying to repair the session after the server deletes it.

    • Rolling summary. Every fixed number of turns or tokens, write a short “confirmed facts” block into the state layer and record the start and end turns it covers. The user must be able to spot-check the summary so the model does not quietly rewrite the setting.
    • Checkpoint object. Export the session in an open format—per-turn text or a common interchange format—together with the state snapshot, instruction version, and summary, into object storage. Export should be repeatable and verifiable.
    • New session. Initialize from the instruction version, the latest state, and the latest summary. Do not paste the entire history. The old window is only an archive retrieval source.
    • Conflicts. If a summary disagrees with the source text, the numbered source fragment wins, and that summary segment is rolled back.

    Companion and creative sessions are highly sensitive to “forgotten identity,” because a wrong state is amplified by later turns. State updates should use an allowlist and a confirmation policy. High-impact fields—forms of address, relationship stage, published canon—should not change because of one casual sentence unless the user explicitly confirms.

    Quotas, isolation, and degradation

    Interactive endpoints for end users and metered endpoints for programs should isolate queues, caches, and limits. Otherwise long requests drag down short ones. Fix the degradation order and encode it in the client:

    1. Shorten the sliding window and the number of retrieved items; keep the state layer.
    2. Switch to read-only archive plus short replies, and pause automatic long-form writing.
    3. Ask the user to export and start a new session.
    4. Retry on the metered channel and show this request’s input size so quota is not burned silently.

    The client should persist recent messages locally. Server keep-alive is only an acceleration. It is not the only copy. When the daily quota is hit, user input still sitting in the send queue should also land locally so a refresh does not lose it.

    Observability

    Without metrics you cannot tell whether a limit is reasonable. At minimum record: input tokens, output tokens, retrieval hit count, state-field size, session idle time, share of rate-limit errors, and success rate of session rebuilds. If users immediately write another oversized input after a rebuild, the product is still encouraging pile-up in a single window. Split archive and progress out of the chat product instead of simply enlarging the free window.

    Order of practice

    Externalize archive and state before you chase a longer context. The steps are: export the existing long session; extract persona into a versioned instruction; collapse key facts into a small state; chunk and index history; replace full concatenation with a sliding window plus retrieval; checkpoint idle sessions with summaries; degrade by error type. Then, even if the server no longer keeps an oversized conversation past its keep-alive period, the application can still restore identity, progress, and the memories that are actually needed, and spend compute on the context the current turn requires.