yau-plant-assistant/db
Claude 0c0bd0ef6d Stop a bulk re-ingest resurrecting withdrawn documents
ingest_file() inserted every chunk with superseded = FALSE, so replacing a
document's chunks reset its withdrawal. One `ai-ingest --all` made every
superseded revision citable again - including the old revision of a procedure -
silently, and only after a bulk run, so a supersede survived exactly until the
next full ingest.

  - ingest_file() reads the existing state with superseded_state() before the
    delete and carries it through the insert. A withdrawn document is
    re-ingested as withdrawn, and logs that it did so.
  - --all skips withdrawn documents, so a bulk run does not spend an embeddings
    call on a document that will not be cited either way. --include-superseded
    overrides it; the chunks still come back withdrawn.
  - --restore DOC_NUMBER REVISION is the counterpart to --supersede, refusing
    while another revision of the same document is live. Without it the
    conservative default would be a dead end - mark_superseded() only ever sets
    TRUE, so there was no way back.
  - Rule 5 in the module docstring, beside the other four.

Corrects a claim in the Phase 9 design: 16.10 said moving the withdrawn file
out of /datadisk/ai-docs "is not tidying" because otherwise --all resurrects it.
That was true when written and is not now. The guard belongs in the ingest code,
because a rule that depends on somebody remembering to move a file is not a
rule. The move stays as archival housekeeping and is documented as such in
16.10, db/005_doc_actions.sql and README.md.

Phase 3's gate gains the proof: supersede a revision, run --all again, ask the
question that used to cite it.

Not executed anywhere - no Postgres or Docker on this machine.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 13:50:34 +10:00
..
seed Scaffold the WRPS plant operations assistant repository 2026-08-20 13:56:32 +10:00
001_schema.sql Scaffold the WRPS plant operations assistant repository 2026-08-20 13:56:32 +10:00
002_fixtures.sql Close two Phase 1 gate failures found on lin001 2026-08-20 15:02:51 +10:00
003_roles.sql Give ingestion a role that can write 2026-08-21 13:45:20 +10:00
004_doc_uploads.sql Give ingestion a role that can write 2026-08-21 13:45:20 +10:00
005_doc_actions.sql Stop a bulk re-ingest resurrecting withdrawn documents 2026-08-21 13:50:34 +10:00
006_doc_pool.sql Design Phase 9 - operator document management 2026-08-21 13:17:38 +10:00