Skip to content

Request-scoped session exposes no post-commit hook, so module caches refresh against uncommitted state #268

Description

@antosubash

Found while reviewing geowiki_public_website's map module (modules/geowiki_map/geowiki_map/service.py).

The module keeps a process-global cache of CSP origins derived from its table (the CSP middleware reads it on every response, so it cannot query per request). Writes refresh that cache — but the only points a module can hook are before commit: after flush(), the transaction can still fail or roll back, leaving cache and database diverged until the next successful write or a restart.

Concrete failure: a layer delete whose commit fails still removes that layer's origin from every response's Content-Security-Policy — the overlay goes dark site-wide with only console evidence. The create-side mirror pollutes the CSP with a host that was never committed.

What would fix it: a supported post-commit callback on the request-scoped session (e.g. session.on_commit(fn) or an event the hosting layer fires after a successful commit), so modules can refresh derived caches only from committed state.

Workaround today is refreshing after flush and accepting the divergence window, which is what geowiki does — noted in review rather than patched, since the correct fix lives here.

Activity

  1. added
    bugSomething isn't working
    pi-readyApproved for the headless Pi worker
    pi-workingThe headless Pi worker is implementing this issue
    and removed
    pi-readyApproved for the headless Pi worker
    on Aug 21, 2026
  2. antosubash commented on Aug 21, 2026

    @antosubash
    OwnerAuthor

    🤖 Claimed. I am creating an isolated worktree from origin/main and starting implementation.

  3. added
    pi-pr-openThe headless Pi worker opened a draft pull request
    and removed
    pi-workingThe headless Pi worker is implementing this issue
    on Aug 21, 2026
  4. antosubash commented on Aug 21, 2026

    @antosubash
    OwnerAuthor

    ✅ Draft pull request opened: #278

    Summary

    • Added RequestSession.on_commit(callback) supporting sync and async callbacks.
    • Callbacks run only after successful commits; rollback/read-only/failed commits discard them.
    • Callback failures are logged without affecting committed responses or later callbacks.
    • Exported the new session/callback types and documented usage.

    Changed areas

    • DB session/finalization runtime
    • Framework DB public API
    • Session documentation and changelog
    • Transaction/session tests

    Verification

    • uv run pytest framework/db/tests — 69 passed
    • Ruff format/check — passed
    • uv run ty check ... — passed
    • uv run python scripts/check_file_size.py — passed
    • git diff --check — passed

    Visual evidence: none required.

    Risks/blockers: none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpi-pr-openThe headless Pi worker opened a draft pull request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions