Skip to content

Fence late object PUTs out of org purge and GC (multi startup still refused) - #199

Merged
Yoshiofthewire merged 3 commits into
masterfrom
feat/tenancy-late-put-fence
Nov 25, 2026
Merged

Yoshiofthewire merged 3 commits into
masterfrom
feat/tenancy-late-put-fence

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: A write that reaches object storage after an org's purge, or after GC deleted a blob, can no longer outlive the erasure. The purge waits out a 20-minute late-PUT window before it reports the org purged, and an age-gated orphan sweep removes the rest. Builds on #198 (merged). Multi startup is still refused.

What changed

  • Every object PUT (Objects.Put/PutPart) is bounded by a 5-minute deadline from entry.
  • The purge records a fence in database time, together with its org_purge_started audit, on the first run only. It deletes rows and the org prefix on every run, but marks the tombstone purged only on a run that started its prefix delete at least LatePutWindow (20 min: deadline plus SigV4's 15-minute request age) after the fence.
  • SweepOrphanObjects, run at the end of RunObjectGC, deletes a serving org's blob with no row, or an upload's parts with no pending session, once the provider says it is over an hour old. The re-check runs under the blob or upload session lock. Unknown age (zero LastModified) never deletes.
  • The ky-primitives pin moves from chore(deps): bump golang.org/x/crypto from 0.57.0 to 0.58.0 in the go group #77 (79823f9) to the chore(deps): bump the npm-build group in /web with 2 updates #78 merge (b55ca6d) for provider modification times (s3 only; no other package changed).
  • The spec records this as the selected late-PUT resolution: a time fence, no ledger.
  • Each orphan deletion re-reads that the org serves, with the claim, under its session lock. The purge re-reads deleted before the prefix delete and when marking (Guide finding, fixed in ed3735b).

Review this

  • internal/storage/purge.go PurgeOrg/purgeFence: waited must be computed before the prefix delete, and from database time. If either is wrong, a late PUT survives a purge reported complete.
  • internal/blobstore/objects.go putDeadline/LatePutWindow: the window is only as sound as its premise. A provider that commits a PUT more than 20 minutes after the client signed it breaks it. Unproven on a real provider.
  • internal/storage/object_gc.go SweepOrphanObjects/dropOrphan: deleting a claimed object loses data, so check the in-lock claim query.
  • Safe to skip: the test fixture's Last-Modified plumbing and the doc edits.

Checked: full suites on SQLite, FIPS and PostgreSQL 17, plus build/vet/gofmt/tidy/govulncheck/docs/no-binaries (details below). Mutations each fail their test: no window check, no put deadline, no age check, no claim re-check, no pending-upload check, no serving re-check, and either purge status re-read. Full checks were re-run at ed3735b (results in the PR comment).
Not checked: a real provider's request-age and late-commit behaviour, and provider/database clock skew past a few minutes; both are provider qualification. Web/e2e/image: no inputs changed.
Decided for you: a time fence instead of a durable operation ledger, because it needs no new table. The org_purge_started audit is now written once per purge instead of on every resumed run, so the 20-minute wait does not write one row a minute. The orphan age is the spec's hour, which is longer than the window.
You need to: nothing for this PR. Provider qualification of the window stays open before any readiness claim.

Detail

New tests (PostgreSQL, real shared client over the TLS fixture):

  • TestLatePutAfterPurgeIsErasedBeforeTheOrgIsMarkedPurged: the fixture holds a PUT at the provider, the client's deadline expires, and the purge runs. Then the provider stores the PUT, so it lands after the prefix delete. The test requires the org to stay unpurged inside the window and the run after the window to leave no orgs/org_b/ key.
  • TestOrphanSweepDeletesOnlyOldUnclaimedObjects: young, unknown-age, claimed, pending-upload and stopped-org objects stay; an old unclaimed blob and an abandoned upload's parts go.
  • Existing purge tests (both backends) now end the window by backdating purge_fence:<org> and assert a single started audit.

Mutation runs (kjob, PG 17 on K hosts):

none              ok
no-window         FAIL TestLatePutAfterPurge...: org marked purged inside the late-PUT window
no-deadline       FAIL TestLatePutAfterPurge... (10-second guard)
no-age            FAIL TestOrphanSweep...: swept=3
no-claim-check    FAIL TestOrphanSweep...
no-pending-check  FAIL TestOrphanSweep...

Full checks:

head 72f3a6476b87a5cbd3894e25206e7e34b25f9bb9
PASS race       go test -race -count=1 -p 2 ./... (SQLite)   kjob k82, Go 1.27.4
PASS fips       GODEBUG=fips140=on, same suite               kjob fell back to Major (all K busy), under the lock
PASS build, vet, gofmt                                       kjob k81
PASS tidy       go mod tidy leaves go.mod/go.sum unchanged (Major)
PASS postgres   CI postgres package list (PG 17, own container, Major)
PASS postgres-restore  TestPostgresRestore/TestStaffUserCommand
PASS fuzz       FuzzConfigLoad 200000x
PASS govulncheck, strong-crypto compose, no-binaries
PASS docs       mdbook build docs + check-links.py: 287 local links and fragments

Cells (C5): the cell list and refusal belong to the enablement PR. storage.OrgServes (internal/storage/orgs.go) becomes a test against the recorded cell list. The purge fence and the orphan sweep need no change; the orphan sweep lists only serving orgs, so it follows that change by itself. blobstore.OrgPrefix gains the cell prefix.

🤖 Generated with Claude Code

Yoshiofthewire and others added 2 commits November 24, 2026 18:51
A PUT admitted before an org's deletion can still be stored after the
purge erased its prefix. Every object PUT is now bounded from entry, and
the purge marks the org purged only after a prefix delete at least
LatePutWindow past its database-time fence. An age-gated orphan sweep,
run by object GC under the blob and upload locks, removes late PUTs
after GC or erasure. The shared client pin moves to the #78 merge for
provider modification times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kynotes-server-199, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

…nt org state

The orphan sweep decided from an org query read before the listing, so an
org stopped meanwhile could lose objects. Each deletion now re-reads that
the org serves, with the claim, in a short transaction under its session
lock. The purge re-reads the status before the prefix delete and requires
deleted when it marks the tombstone. The purge batch hook now runs after
each commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Fixed in ed3735b. The reported gap was real. The same pattern (a decision based on org state read earlier) also existed in the purge, so that is fixed too.

  • Orphan sweep: dropOrphan (internal/storage/object_gc.go) now admits each blob and upload-part deletion in a short transaction on the session-lock connection. It re-reads both OrgServes and the claim. Because that transaction takes N3, it serialises with the org poll's status write. No object I/O runs under N3.
  • Purge: PurgeOrg re-reads status='deleted' before the prefix delete. The batches can take a while, and a run can wait out the late-PUT window. Marking the tombstone purged now requires status='deleted' in the same transaction. GC's sweepObject already rechecks OrgServes inside its row transaction, so it is unchanged.
  • Tests: TestOrphanSweepKeepsObjectsOfAnOrgStoppedDuringTheListing suspends the org from inside the provider listing and asserts nothing is deleted. TestPurgeRereadsTheStatusBeforeThePrefixAndTheMark covers both purge rereads. The purge batch hook now runs after each commit, which is what lets that test change the status between batches on SQLite.
  • Mutations (PostgreSQL 17): each fails without its fix. Without the serving recheck the sweep deletes 2 objects; without the pre-prefix reread the prefix is deleted; without the mark recheck the org is marked purged.
  • Full checks at ed3735b: all pass. Race and FIPS suites (SQLite), the PostgreSQL CI package list on my own container on Major (every K host was busy), vet/gofmt/fuzz, tidy, govulncheck, docs (287 links), strong-crypto compose and no-binaries.

Remaining gap (judgment, not tested): a suspension that commits after an admitted deletion's transaction cannot stop that one delete. That is the same ordering GC already has: the decision is made while the org serves.

@Yoshiofthewire
Yoshiofthewire merged commit fc5b878 into master Nov 25, 2026
14 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/tenancy-late-put-fence branch November 25, 2026 04:20
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