Skip to content

Sweep and purge primary objects per org (multi startup still refused) - #198

Merged
Yoshiofthewire merged 1 commit into
masterfrom
feat/tenancy-object-runtime
Nov 25, 2026
Merged

Yoshiofthewire merged 1 commit into
masterfrom
feat/tenancy-object-runtime

Conversation

@Yoshiofthewire

Copy link
Copy Markdown
Member

In one line: Multi mode now has a primary-object blob GC and an org purge that erases the org's object-storage prefix; neither is bound to startup, which stays refused.

What changed

  • storage.RunObjectGC sweeps unreferenced blobs per (org_id, digest), at most 100 a pass, serving orgs only. Identical ciphertext in another org is never touched.
  • Each sweep takes the blob's session lock (storage.BlobLockName), re-checks, commits the row deletes, then deletes every version of the object. A failed delete leaves an object with no row, never a row with no object.
  • The purge takes a PurgeObjects step, refuses before deleting anything when there is none, deletes orgs/<org_id>/ after the rows and marks the tombstone purged only if that worked.
  • The replica schedule adapter carries the purge step. The startup wiring stays unbuilt.

Review this

  • internal/storage/object_gc.go: orgUnreferenced and sweepObject. A predicate that ignores the org, or a delete that runs before the commit, loses another org's data or leaves a row pointing at a missing object.
  • internal/storage/purge.go PurgeOrg: purged is marked only after the prefix delete succeeds.
  • Safe to skip: doc updates and test-call signature changes.

Checked: full local suites on SQLite, FIPS and PostgreSQL 17, plus build/vet/gofmt/govulncheck/docs/no-binaries (details below). Four mutations (org-blind candidates, no re-check under lock, object delete before commit, purge without the prefix step) each fail their test.
Not checked: web/e2e/Docker image (no web or image input changed; CI runs them). No real provider: tests use the real shared client over the local TLS S3 fixture.
Decided for you: the purge's object step is a function value (PurgeObjects), so the row-only purge tests in internal/storage need no S3 fixture. The real Objects.Purge is tested in internal/blobstore.
You need to: nothing. The late-PUT fence is the stacked PR on top of this one.

Detail

Spec: new "PR 5b-3 as built" section in docs/superpowers/specs/2026-11-23-tenancy-design.md. Contracts updated in AGENTS.md, internal/blobstore/AGENTS.md and DESIGN.md.

Tests (PostgreSQL, real ky-primitives/s3 client over TLS): TestObjectGCSweepsOnlyTheUnreferencedOrgsCopy, TestObjectGCWaitsForTheBlobLockAndRechecks, TestObjectGCDeleteFailureLeavesNoRowPointingAtAMissingObject, TestObjectGCWaitsWhileTheOrgIsStoppedAndRefusesSingleMode, TestPurgeDeletesOnlyTheDeletedOrgsPrefix. On both backends: TestPurgeRefusesWithoutObjectsAndKeepsTheOrgUnpurged.

Local full run (Major, Go 1.27.3, shared lock with a 6 GiB cap, own postgres:17-alpine container removed by a trap):

head 8fbddb82dca995f9c878bac7f7ccd030a6b7c8c1
PASS build, vet, gofmt
PASS race       go test -race -count=1 -p 2 ./... (SQLite)
PASS fips       GODEBUG=fips140=on, same suite
PASS postgres   CI postgres package list + TestPostgresRestore/TestStaffUserCommand (PG 17)
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) compares home_region with one region setting. It becomes a membership test against the recorded cell list, and object keys gain the cell prefix in blobstore.OrgPrefix.

🤖 Generated with Claude Code

RunObjectGC is the multi-mode blob sweep: per (org_id, digest), under the
blob session lock, rows commit before the object delete. The purge now
deletes the org's object prefix and marks the tombstone purged only after
that succeeds. Startup stays refused; binding comes with enablement.

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

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

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-198, 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

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

@Yoshiofthewire
Yoshiofthewire merged commit 9ef1d6f into master Nov 25, 2026
14 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/tenancy-object-runtime branch November 25, 2026 00:16
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