Skip to content

feat(#179): pydantic body model for /backfill-age (first write surface) - #182

Merged
jphein merged 1 commit into
mainfrom
feat/backfill-age-pydantic-body
May 29, 2026
Merged

feat(#179): pydantic body model for /backfill-age (first write surface)#182
jphein merged 1 commit into
mainfrom
feat/backfill-age-pydantic-body

Conversation

@jphein

@jphein jphein commented May 29, 2026

Copy link
Copy Markdown
Collaborator

After #180 + #181 migrated all 6 read endpoints to dependency/pydantic canonicalization, /backfill-age is the simplest write surface (4 fields, admin-only, low-traffic). Apply the same pattern as a template for the remaining 4 write surfaces.

Adds BackfillAgeBody with field validator that routes wing through rooms.normalize_wing_filter. All fields optional with safe defaults so the endpoint still accepts an empty POST body.

The request parameter is preserved because the lifespan-cleanup code reads request.app.state.active_mines (subprocess tracking from #138/#139). Pydantic body is added alongside, not replacing.

Tests pass (534). No behavior change beyond moving wing canonicalization from handler-body to parse-time.

After #180 + #181 migrated all 6 read endpoints to dependency/pydantic
canonicalization, /backfill-age is the simplest write surface — 4
body fields, admin-only, low-traffic. Apply the same pattern as a
template for the remaining 4 write surfaces.

Adds BackfillAgeBody to search_models.py with field_validator routing
wing through rooms.normalize_wing_filter. All fields optional with
safe defaults so the endpoint still accepts an empty POST body
(curl -X POST .../backfill-age with no Content-Type).

Refactor signature from
  `async def backfill_age(request, x_api_key)` →
  `async def backfill_age(request, body: BackfillAgeBody = Body(default_factory=...), x_api_key)`

Handler body reads body.wing / body.skip_palace / etc. instead of
body.get("wing") / .get("skip_palace"). The `request` parameter is
preserved because the lifespan-cleanup code reads
request.app.state.active_mines (subprocess tracking from #138/#139).

Tests pass (534). No behavior change beyond moving the wing
canonicalization from handler-body to parse-time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 29, 2026 01:11
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@jphein
jphein merged commit 18d0460 into main May 29, 2026
@jphein
jphein deleted the feat/backfill-age-pydantic-body branch May 29, 2026 01:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

jphein added a commit that referenced this pull request May 29, 2026
Updates HANDOFF.md to reflect the full 39-PR session:
- Adds the wing/room canonicalization sweep (#172-#178)
- Adds the #179 architectural follow-up (#180/#181/#182)
- Updates counts: 39 PRs / 534 tests / 30+ deploys
- Notes that #179 is partially complete: 1/5 write surfaces migrated
  to pydantic (BackfillAgeBody via #182); 4 remain with documented
  per-endpoint empty-wing semantics + suggested order

Also adds a section observing the autonomous-loop discovery pattern
that worked this session — "fix the obvious bug, write a curl probe,
sweep for what else has this shape." Documents that the Stop hook's
literal "ongoing imperative" framing is satisfied when marginal value
per cycle drops below context-thrash cost.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jphein added a commit that referenced this pull request May 29, 2026
…183)

Continues the write-side #179 migration. /silent-save accepts a Stop-
hook diary checkpoint write — same model pattern as BackfillAgeBody
in #182 but with write-side wing semantics: empty wing stays as ""
rather than coercing to "unknown", so the existing daemon warning
("wing is empty — diary entry will have no wing association") still
fires for empty inputs.

Adds SilentSaveBody to search_models.py:
  - entry: required, stripped, non-empty (raises ValueError → 422)
  - wing: optional, normalized if set, empty preserved
  - topic, agent_name, themes, message_count, session_id: pass-through

Refactor signature from
  `silent_save(request, x_api_key)` →
  `silent_save(body: SilentSaveBody, x_api_key)`

Handler body uses body.entry / body.wing / etc. and converts to dict
via body.model_dump() for the existing helpers (_enqueue_pending_write,
_do_silent_save_write) which take the raw payload for rebuild-queue
serialization.

One test update: test_missing_entry_still_rejected_with_400 →
test_missing_entry_still_rejected with 400→422 expectation. Contract
of "entry is required" preserved; HTTP code surface shifted to
pydantic's standard for missing-required-field (matches #181's
SearchHybridBody fusion_mode change).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jphein added a commit that referenced this pull request May 29, 2026
Fourth write-surface #179 migration. /memory is the primary write
endpoint and has the most elaborate room-error contract (structured
detail with valid_rooms + hint).

Adds MemoryBody to search_models.py:
  - content: optional, defaults "" (preserves pre-#179 permissive
    behavior — body.get("content", ""))
  - wing: empty → "unknown" then normalize_wing_slug (matches the
    inline default)
  - room: empty → "discoveries" (spec's catch-all), then validated
    via the shared rooms.validate_room_or_raise which raises 400
    with the existing structured detail (error / valid_rooms / hint)

Empty-wing semantics per write surface now form a complete matrix
established across #179 / #182 / #183 / #184 / this PR:

  /memory       → "unknown"        (this PR)
  /silent-save  → ""  + warning    (#183 SilentSaveBody)
  /mine         → "general"        (#184 MineBody)
  /backfill-age → None (filter)    (#182 BackfillAgeBody)

The signature change removes the `request: Request` parameter since
/memory has no need for request.app.state — the only other write
surface keeping Request is /mine, which uses app.state.active_mines
for subprocess tracking (#138/#139).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jphein added a commit that referenced this pull request May 29, 2026
#188)

Fifth and final write surface for #179. The watcher isn't an HTTP
endpoint so it can't take a pydantic body — but the same architectural
goal applies: canonicalize wing at the *input* boundary so all
downstream code can trust the WatchTarget is canonical.

Pre-#179: parse_watch_dirs ran ``normalize_wing_name`` only on
path-derived wings (when env entry was bare ``path`` with no
``=wing``). Explicit ``path=Wing_Name`` env entries were passed through
verbatim, and a defensive ``_normalize_wing_slug`` ran later in
_internal_mine before subprocess spawn.

Post-#179: parse_watch_dirs normalizes both branches (path-derived AND
explicit) through normalize_wing_name. WatchTargets always carry
canonical slugs. The use-time normalize in _internal_mine drops to a
comment explaining the new invariant.

Test added: ``Palace_Daemon`` and ``palace_daemon`` env entries
produce identical WatchTarget.wing values ("palace_daemon"). Was the
shape of the pre-#175/#178 bug class — mixed-case writes paired with
canonical reads producing empty result sets.

This closes the wing-canonicalization migration that began with #172.
All 11 wing/room-accepting sites in palace-daemon now canonicalize at
the input boundary:

Read side (#180):
  GET /search, GET /list, GET /search/fast — FastAPI Depends()
Write body (#181, #182, #183, #184, #186, #187):
  POST /search/keyword, POST /search/hybrid, POST /search/age-fused,
  POST /backfill-age, POST /silent-save, POST /mine, POST /memory —
  pydantic body models in search_models.py
Internal env (this PR):
  PALACE_WATCH_DIRS via watcher.parse_watch_dirs

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants