Skip to content

Course · Pi · Context

Context

Yesterday closed clean: fetch_feed in stash/feeds.py (stash is the course’s running example, a small FastAPI feed reader) now reads namespaced Atom entries and pulls each link from the <link> element instead of an attribute that never existed, tests/test_feeds.py passes, and the full suite is green for the first time since you inherited stash. Committed.

The course so far also left you a skill that outranks the fix: you can print the literal prompt and watch the window fill, turn by turn, down to the string. That skill has a boundary, and this chapter walks you into it on purpose - a window you can read is still a window that fills.

Here’s the problem this chapter takes up, and everything else in it bends around: the session outlives the window. Something must be dropped, and you pick what. stash isn’t a one-sitting job - it’s a week of real work, spread across mornings you didn’t plan for and at least one job long enough to fill the window outright. Reading the meter was last chapter’s win. Staying in charge of what happens when the meter runs out is this one’s.

Nothing here is exotic - a handful of session commands, one file convention, and the judgment of when to reach for each. To keep that judgment concrete, the three lessons follow a single thread of stash work rather than listing features in the abstract.

Two fixes shipped and the loop holds no surprises. The next stretch of real work looks like this:

  • This morning, you resume yesterday’s session - the one that ended green - and pick the thread back up without re-explaining a thing. That habit is cheaper than it looks, and the first lesson measures exactly how much.
  • Then the fixed code hands you the next bug. POST /feeds/{feed_id}/sync works properly for the first time, so you re-sync a feed that’s already stored - and every article gets saved a second time. Nothing behind db.save_article in stash/db.py stops a duplicate: no UNIQUE constraint, no check. There are two legitimate fixes, a schema-level one and an app-level one, and neither is obviously cheaper. You fork the session and try both, one per branch, then keep one and say why.
  • The fix you keep commits you to a cleanup - migrate the duplicated rows already sitting in stash.db, then re-sync every stored feed, twice, to prove nothing doubles again. That job runs long enough to fill the window, Pi compacts the session in the middle of it, and you learn exactly what survives that and what doesn’t.
  • By the end of the week, one more inherited oddity surfaces: the friend’s root SYSTEM.md holds five real engineering conventions - sqlite3 from the standard library, httpx and never requests, pytest, pydantic models in stash/models.py, normalized feed dates - and it sits at a path Pi never reads. Every session this week started blind to rules the friend wrote down. You write them once, where Pi loads them before you say a word.

Each lesson leaves you with the problem the next one solves. Read them in order and it’s a story; drop into one from search and it still stands on its own.

By the end you’ll treat Pi’s context window the way you treat memory in any long-running program - a resource you watch, spend on purpose, and reclaim before it runs out. And you’ll be able to answer, with numbers you checked yourself, the three cost questions this chapter is organized around: what a session file costs you, what compaction’s defaults cost you, and what writing your rules down costs you.

Those answers share one shape - something in the window, paid for by someone - and by the close of this chapter most of that someone is you.

Start where the week does - picking up yesterday’s session, and forking today’s real decision.