Skip to content

LEARN SL-9: discovery erasure - #148

Open
ViperJuice wants to merge 2 commits into
mainfrom
exec/learn-sl9-erasure
Open

ViperJuice wants to merge 2 commits into
mainfrom
exec/learn-sl9-erasure

Conversation

@ViperJuice

@ViperJuice ViperJuice commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

LEARN SL-9, discovery erasure. This is the plan's lane for #138, #144 and the delete-discovery half of #21 (plans/phase-plan-v1-LEARN.md: SL-9, the row "Deletion propagation" and the list "This plan may not claim").

A finished deletion of a discovery, whether requested or imported, now leaves neither the discovery's recovered metadata nor a notice row naming its items in the store's files. Until the erasure has finished, the deletion answers as delete_task has since SL-2 (#123): with the existing storage failure, the deletion already committed. No schema, contract, doc or other test changes.

What changed, by function

All changes are in src/jevdrill/storage.py.

  • delete_discovery
    • For each discovery of the deleted objective, the same transaction now also deletes:
    • Its existing UPDATE discoveries, which clears seed, result and trace, now also clears request_digest. For an imported discovery that value is canonical_digest(record), and the record includes the domains, so a guessed label could be confirmed against it.
    • After the existing recover_artifacts, it runs PRAGMA wal_checkpoint(TRUNCATE) and reads the result, as delete_task does. If the checkpoint was blocked, it raises the sqlite3.OperationalError that delete_task raises ("deleted content not yet erased; retry the request").
  • import_recovery, the import of deletion records
    • Where a deleted objective is applied, the same two deletions are made for each of the objective's discoveries, and its UPDATE discoveries also clears request_digest.
    • The import's existing closing checkpoint now has its result read. When the bundle carries a discovery deletion record (an objective marked deleted in the bundle), new to this store or not, and a reader blocks the checkpoint, the import raises that same failure instead of returning its count. Its work is committed.
    • Why "carries" and not "newly erased". While a reader blocks the checkpoint, the store cannot tell whether the log still holds the deleted label: a repeat of the same import under the same reader has nothing new to erase, yet the first import's erased rows can still be in the log. So the honest answer is "not finished", as delete_task answers under a reader.
    • A bundle with no discovery deletion record is unchanged and answers as on main, ignoring its checkpoint.

Behaviour change

Both answers stay within CLI version 1. Neither adds a status, code or field.

  • While a reader blocks the checkpoint:
    • delete-discovery answers exit 4 with {"schema_version":"1","status":"storage_failure","code":"infrastructure_failure"}.
    • The recovery command, for an import that applied a discovery deletion record, gives the same answer.
  • The deletion is committed before that answer. Afterwards, nothing of the deleted discovery can be read through storage.
  • The same request, once nothing blocks the checkpoint, finishes the erasure. It then answers as on main:
    • exit 0 and {"schema_version":"1","status":"deleted","work_objective_id":…};
    • for the import, exit 0 and imported with its count.
  • The cost: an ordinary backup that carries a discovery deletion record already applied here, imported while another connection holds a read transaction, now answers with the storage failure where main answers imported. The work is committed, and a repeat succeeds once the reader closes. That is a false "unfinished", which is the safe direction.

The stated cost, as for delete_task: the answer does not itself say that the deletion is committed. A caller learns that from the retry succeeding. No doc sentence says so for delete-discovery or for import.

The control

The tests are in tests/storage/test_discovery_erasure.py. Each assertion is its own test, and the reader is held open by the test itself, not by timing.

How the checks search:

  • The domain label is synthetic and random per test (sl9-synthetic-domain-<uuid4 hex>), so no other discovery, task or catalog entry holds it. It is searched for as bytes in every file under the store's own directory: the database, its write-ahead log, any rollback journal and the artifact files.
  • The byte search skips the -shm file, as SL-2's did. It holds only the log's index, never row content. Closing a descriptor on it would drop the process's SQLite locks on it (POSIX), including the held reader's, and on Windows another connection's locks can refuse the read.
  • The item-identity check searches notice rows, not whole files. It looks at every column of lifecycle_notices and notices for the discovery's content artifact identities and the discovery identity. Whole files are not searched because the plan's non-claim leaves those identities in the decisions and retries of tasks routed with the discovery.
  • An idle connection stays open during every byte check. Otherwise SQLite's checkpoint at the last close would hide a missing checkpoint (shown below).
# Assertion Test id
1 By request: an imported discovery with content items and three notice rows is deleted. After the finished deletion, its label is in no store file, and no notice row names an item. test_1_requested_deletion_erases_metadata_and_notices
2 By import: a store imports the discovery, then its deletion record as another store exports it. The same two checks hold, and still hold after the discovery's own bundle is imported again. test_2_imported_deletion_erases_metadata_and_notices
1, 2 The record's digest: after a finished deletion, canonical_digest(record), computed from the discovery's record with its real label, is in none of the store's files. Shown by request and by import. test_1_and_2_finished_deletion_leaves_no_digest_of_the_discovery_record[request], [import]
1 With the digest cleared, the deleted request is still not new. The original discover request repeated under the same key is refused ("discovery objective deleted"). The same key and digest for another objective are refused as a conflict, rather than handing back the deleted discovery's identity, which is what happens without the fix. The key still has one discoveries row. test_a_repeat_of_a_deleted_discovery_request_under_its_key_is_refused
3 Unfinished, by request: with a second connection holding a read transaction, the deletion raises the storage failure. The label is still on disk, but the metadata row, the notices and the discovery cannot be read through storage. With the reader closed, the same request answers deleted, and the two checks hold. test_3_requested_deletion_is_unfinished_while_a_reader_holds_the_log
3 Unfinished, an import that applied a deletion record: with the checkpoint shown blocked, it raises the storage failure; the deletion is committed as above. The repeat: the same import, once the reader closes, returns 1, and the two checks hold. The 1 counts the bundle's one carried artifact (an ordinary task's), already restored by the first import. Every row of every table is the same before and after the repeat, and there is one artifact row, so nothing is applied twice. test_3_import_applying_a_deletion_record_is_unfinished_while_a_reader_holds_the_log
3 Beside it, an import that applied none: with the checkpoint shown blocked, it returns its count (0) as on main. Shown for another discovery's bundle, and for the deleted discovery's own bundle on a store that holds the deletion; the label and notices do not come back. test_3_import_applying_none_answers_as_on_main_while_a_reader_holds_the_log[another_discovery], [the_deleted_discovery_again]
3 The repeat under the same open reader: the first import raises, and so does the same import repeated while that reader is still open. After the reader closes, the repeat returns 0 and the two checks hold. test_3_import_repeated_under_the_same_reader_is_still_unfinished
3 An ordinary backup (new content plus a discovery deletion record this store already applied), with no reader: it returns 1 (the new content), as on main, and the deleted discovery stays erased. test_3_backup_with_an_applied_deletion_record_answers_imported_with_no_reader
3 The same backup with a blocking reader (the stated cost): it raises with its work committed (the new content is in). After the reader closes, the repeat returns 1 and every table is unchanged. test_3_backup_with_an_applied_deletion_record_is_unfinished_while_a_reader_holds_the_log
3 A store that holds the tombstone but still the discovery's metadata and notices, as main's delete_discovery left them. Importing the tombstone erases them, so with the reader open it raises; after the reader closes, the same import returns 0, and the two checks hold. test_3_import_erasing_what_an_applied_tombstone_left_is_unfinished_while_a_reader_holds_the_log
3 A discovery with only its own row: a reserved request whose seed holds a synthetic value. The new tombstone clears the seed, so with the reader open the import raises and the value is still on disk; after the reader closes, the same import returns 0, and the value is in no store file. test_3_import_newly_tombstoning_a_discovery_is_unfinished_while_a_reader_holds_the_log
4 Through the command line, in a child process: delete-discovery answers (4, storage_failure body) with the reader open, then (0, {"schema_version":"1","status":"deleted","work_objective_id":…}), after which the two checks hold. test_4_delete_discovery_command_answers_a_storage_failure_then_deleted
4 Through the command line, the import: recovery with an encrypted bundle carrying the deletion record answers (4, storage_failure body), then (0, {"schema_version":"1","status":"imported","encrypted_bundle":null,"restored_count":0}). test_4_recovery_import_command_answers_a_storage_failure_then_imported
5 Nothing else goes. These stay exactly as they were: another discovery's metadata row, its notice rows and its stored result, and an ordinary task's notice. Its label is still on disk. Shown both by request and by import. test_5_nothing_else_goes[request], test_5_nothing_else_goes[import]

Breaks and their results

Each break was applied to a scratch copy of the source, never to this branch, and the file was run serially there.

Break Fails (of 18)
request_digest kept on both paths both digest cases (in route.db), and the repeat-under-its-key case
request_digest kept by delete_discovery only the digest case by request, and the repeat-under-its-key case
request_digest kept by the import only the digest case by import
No checkpoint in delete_discovery (the PRAGMA removed) 1 at its own label check (['route.db']), the digest case by request, 3-request (did not raise), 4-request ((0, deleted) instead of (4, …))
The metadata row left by delete_discovery 1, 3-request, 4-request, 5-request (guard), and 3-none for the deleted discovery again (label on disk)
The notices left by delete_discovery 1, 3-request and 4-request, each on notice rows naming the items
The import path left unfixed 2, 3-record, 3-residue, 3-leftover, 4-import and 5-import (guard)
OR 1: a fix that deletes every discovery's metadata 5-request and 5-import
A trigger on "something new was erased" (the previous revision's storage.py) 3-residue (the repeat under the same reader answered 0) and the backup with a reader; also the three B1 cases, since that file predates the digest fix
No checkpoint check in the import (main's behaviour) 3-record, 3-residue, the backup with a reader, 3-leftover, 3-fresh and 4-import. Neither "as on main" test fails, nor does the backup with no reader.
The import's check firing on every import both "applied none" tests
The check firing whenever the store holds the tombstone 3-none for the deleted discovery again

Also run:

  • delete_discovery's answer check removed but its checkpoint kept: 3-request and 4-request fail, and 1 passes. That is correct, since the checkpoint still erases the label: test 1 guards erasure, not the answer.
  • the import's metadata only left (2, 3-record, 3-residue, 3-leftover, 4-import and 5-import fail); the import's notices only left (the same, less 5-import); a fix that deletes every notice in the scope (both 5s fail);
  • main's storage.py: 17 of 18 fail; only the import of another discovery's bundle passes;
  • the no-checkpoint break with test 1's idle connection also removed: test 1 passes. This is why every byte check keeps that connection open.

What the pinned host integration does with the unfinished answer

The pin is Consiliency/agent-harness at 85b29c76ecfb8cf5a94523e7da84edc44dcd250f, under phase-loop-runtime/src/phase_loop_runtime/.

  • JevDrill.delete_objective (jevdrill_adapter.py:285-293) runs these steps in order:
    1. it writes the host's own objective tombstone (self.queue.delete_objective, :289, which commits in jevdrill_queue.py:142-147);
    2. it delivers notices (:291-292);
    3. it returns self.transport.call("delete-discovery", …) (:293).
  • JevDrillTransport.call checks the exit code before reading the body. Any exit code other than 0 or 3 raises OSError("JEV Drill CLI failed") (jevdrill_adapter.py:167-168), so exit 4 raises there and the body is never parsed.
  • Even a parsed body must equal {"schema_version": "1", "status": "deleted", "work_objective_id": …} exactly, or the call raises ValueError("Invalid deletion acknowledgment") (:179-182).
  • So the unfinished answer reaches the host's caller as an OSError from delete_objective, never as a finished deletion. There is no retry in the adapter.
  • The host's tombstone stays committed, and its write also removed the objective's bindings. Later work on the objective is refused:
    • discovery, by discover_objective (:255-257);
    • routing and launch of a linked task, by _check_discovery (:273-274).
  • The harness's own test shows this sequence: phase-loop-runtime/tests/test_jevdrill_discovery.py:246-255 raises OSError from delete-discovery and asserts objective_deleted is still true.
  • The host integration has no recovery command (jevdrill_adapter.py:102-110), so the import's answer does not reach it.

The plan's non-claim, in plain words

Deleting a discovery does not remove its identities from the records of tasks that were routed with it: their routing decisions, their retries, and notices copied into those decisions. Nor does it remove request text those tasks supplied. Those records go when their task is deleted. The item-identity check therefore looks at notice rows only.

Unit and ROUTE counts

These are expected counts. Replace them with the job figures when the jobs report.

Run Linux macOS Windows
Unit, main before (Windows: 8 skipped, before #142 merges) 1,647 passed 1,647 passed 1,639 passed
Unit, this branch 1,665 passed 1,665 passed 1,657 passed
Delta +18 +18 +18
ROUTE, before and after 1,235 1,235 1,234
  • The 18 new tests are fifteen functions, three of them parametrized twice. None is skipped on any platform.
  • The new file is not in ROUTE's test collection: scripts/verify_route_phase.py names its storage test files one by one, and this one is not among them. ROUTE's lint and format steps do cover tests/storage.
  • The plan's LEARN deliverable command already names this file. The LEARN verifier's expected-test lists are SL-4's and SL-5's.

What is not shown

  • The HOST conformance set does not run in unit CI. Whether the pinned host integration's delete-discovery path still passes is not shown until the next host.yml run. Its handling of exit 4 is shown above by reading the code and its own test at the pin, not by a run against this branch.
  • A bundle with no discovery deletion record still ignores its checkpoint. That is what remains of Storage: check the WAL checkpoint result after deletion #21: an import that applies only task deletion records can still answer imported while its erasure is unfinished.
  • Each row of discovery_content_artifacts holds a digest that someone with the original content and access to the store can match. The table stays so that deleted content cannot be staged again.
    • A row is (scope, discovery identity, artifact identity), one per content item. The artifact identity is a digest of the scope, the discovery identity (the item's task), the kind and the content's digest.
    • stage_artifact reads the table to refuse staging a deleted discovery's content again.
    • An issue opens at merge, covering this table and the next item.
  • maintenance_control's cursor can keep a deleted item's identity after a paused run. This was already listed in SL-2's limits, and it goes on the same issue.
  • The byte search skips the -shm file, as SL-2's did, for the reason given under the control.
  • SQLite's temporary and statement-journal files go to the system's temporary directory, not the store's, and the byte search does not cover them.
  • The control's store has no task routed with the discovery. It shows the label gone where it lives today, in the recovered metadata. Analysis evidence derived from linked tasks is purged by the existing path and is not re-tested here.
  • What else a finished deletion still leaves in the store, outside the property:
    • the discovery's row: its identity, objective, scope and request key (recovery:<identity> for an imported discovery, the host's idempotency key for a requested one), with its seed emptied and its request digest, result and trace cleared;
    • the objective's tombstone;
    • the discovery's tasks row, not marked deleted, so an export lists the discovery identity as a live task;
    • the records under the plan's non-claim.
  • Local runs were Linux only. The new file, tests/storage, tests/privacy and tests/maintenance (799 passed), plus ruff check, ruff format --check and mypy src/jevdrill. The tests in tests/application, tests/cli and tests/experiments that call these paths were not run locally; unit CI runs them.

CI at 7a2fb111e, read per job. Each run adds 18 to its base:

Base Linux macOS Windows
Branch, on f6ed67854 1,647 → 1,665 1,647 → 1,665 1,639 → 1,657 passed, 8 skipped
Merge ref, on main with #142 1,650 → 1,668 1,650 → 1,668 1,643 → 1,661 passed, 7 skipped

ROUTE, read from the verification receipts: 1,235 / 1,235 / 1,234, unchanged, with 0 failures.

🤖 Generated with Claude Code

After a discovery's deletion, by request or by an imported deletion record,
its recovered metadata row and the notice rows naming its items are
deleted in the same transaction, and the deletion answers as finished
only once its closing checkpoint completes; while a reader blocks it, it
answers with the existing storage failure, committed, and a repeat
finishes it, as delete_task does since SL-2. An import whose bundle
carries a discovery deletion record checks its closing checkpoint the
same way; an import without one is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T00:37:35.690869Z 7251e80 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

An imported discovery's request digest is a digest of its record, domains
included, so after a deletion it could confirm a guessed label. Both
deletion paths now clear it. State the discovery_content_artifacts and
maintenance cursor limits and where SQLite's temporary files go.

Co-Authored-By: Claude Opus 5.5 <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.

1 participant