From 949f58a05431f9c54526459ffb462e84b12c46b0 Mon Sep 17 00:00:00 2001 From: parththakkar106 Date: Sun, 30 Aug 2026 18:43:29 +0530 Subject: [PATCH] Sweep the last three uses of the columns SP8 dropped `seed_demo.py` still passed `index=0` to `models.Action`, which raises `TypeError` now that the attribute is gone. Every call site inside `app/` was updated when the column went, but the seed script sits outside the package and was missed. `bundle.settle` wrote `memory_cursor` and `summary_cursor`, which are no longer mapped, so the assignments only set transient Python attributes. The version 2 branch existed solely to make those assignments, and it ran two queries per cursor to do it, so it goes. `settle` now returns early when the bundle carries anchors. The `db` parameter is unused after that. Also move the comment about deleted memories next to the `db.delete(branch)` it describes. Splitting the router package left it after the `finally`, where it read as attached to nothing. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01YFQY6WgaE3JaX3dXkxLynV --- backend/app/bundle.py | 33 ++++++++-------------- backend/app/routers/adventures/branches.py | 9 ++---- backend/seed_demo.py | 2 +- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/backend/app/bundle.py b/backend/app/bundle.py index 1ba222f..5f368af 100644 --- a/backend/app/bundle.py +++ b/backend/app/bundle.py @@ -587,31 +587,22 @@ def _write_anchors( cursor.anchor(adventure, ids[branch] if branch is not None else None, depth) -def settle(db: Session, adventure: models.Adventure, story: dict) -> None: - """Aligns the two coordinate systems, once the nodes exist. +def settle(adventure: models.Adventure, story: dict) -> None: + """Resolves a version 1 bundle's counts into anchors, once the nodes exist. - The anchors and the legacy counts describe the same boundary in different - terms, and each version of the bundle carries one of them. A version 1 file - carries the count, so the anchor is found by counting that far along the - story. A version 2 file carries the anchor, so the count is read back from - it. The legacy columns are written either way, because a rolled-back build - reads them. + A version 1 file records how far the memories and the summary have read as + a count, so the anchor is found by counting that far along the story. A + version 2 file carries the anchor itself, which `_write_anchors` has + already stored, so there is nothing left to do. - The caller runs this after the flush, because both directions need the - actions to be queryable. + The caller runs this after the flush, because counting needs the actions to + be queryable. """ positions = story["positions"] + if positions is None: + return for cursor in cursors.ALL: - if positions is not None: - setattr(adventure, f"{cursor.name}_cursor", positions[cursor.name]) - cursors.anchor_at_position(adventure, cursor, positions[cursor.name]) - else: - setattr( - adventure, f"{cursor.name}_cursor", - cursors.position_of(adventure, cursor.depth(db, adventure)), - ) - - + cursors.anchor_at_position(adventure, cursor, positions[cursor.name]) def materialize( @@ -673,7 +664,7 @@ def materialize( write(db, adventure, story) db.flush() db.expire(adventure, ["actions"]) - settle(db, adventure, story) + settle(adventure, story) return adventure # ------------------------------------------------------------------ reading diff --git a/backend/app/routers/adventures/branches.py b/backend/app/routers/adventures/branches.py index 086715c..a09f73a 100644 --- a/backend/app/routers/adventures/branches.py +++ b/backend/app/routers/adventures/branches.py @@ -190,18 +190,15 @@ def delete_branch( stored_branch, _ = cursor.stored(adventure) if stored_branch in doomed: cursor.clear(adventure) + # The deleted branch's memories are deleted with it, and their cached + # vectors drop out of the catalogue on the next read, so no + # invalidation call is needed. See the note on the `memorybank` cache. db.delete(branch) adventure.updated_at = models.utcnow() db.commit() finally: turns._active_turns.discard(adventure_id) - - # The deleted branch's memories are deleted with it, and their cached - # vectors drop out of the catalogue on the next read, so no invalidation - # call is needed. See the note on the `memorybank` cache. - - def _branch_subtree( db: Session, adventure: models.Adventure, root: models.Branch ) -> set[int]: diff --git a/backend/seed_demo.py b/backend/seed_demo.py index 0d6a6dd..0266406 100644 --- a/backend/seed_demo.py +++ b/backend/seed_demo.py @@ -252,7 +252,7 @@ try: for position, s in enumerate(SCRIPTS): db.add(models.AdventureScript(adventure_id=adventure.id, position=position, **s)) opening = models.Action( - adventure_id=adventure.id, index=0, type="start", text=scenario.prompt + adventure_id=adventure.id, type="start", text=scenario.prompt ) # Through the same door create_adventure uses, so the seeded adventure has a # story tree like every other one.