# Prospective daily spam hiding

This workflow marks and hides unused registrations while retaining all account data. It is separate from the immutable fixed Oct8 spam cohort. It never permanently purges accounts or cancels billing. These commands document an operator interface; they do not authorize production changes by themselves.

## Eligibility and trustworthy authentication history

The rule means registered at least 172800 elapsed seconds ago and NEVER successfully logged in. The inclusive threshold is an elapsed-time calculation across DST, not two calendar dates or idle time since a previous login. No email-verification transition is assumed: registration currently activates the account and sends its generated password.

Pre-instrumentation successful API use may lose its key evidence after key deletion. Historical NULL login/activity/token fields cannot prove NEVER. Only companies and their sole raw-owned main user registered at or after the immutable `evidence_since` boundary can qualify. Before preparing that boundary, independently verify the exact deployed authentication release and supported API/reset/web/remembered/MCP paths, config/opcode caches, long-lived workers and any in-flight old authentication execution. Capture an offset-qualified timestamp after that verification. A CLI deployment attestation is not proof that a Git SHA actually ran. Never backdate the boundary to admit unknown historical registrations. A genuine first eligible pilot requires at least 48 elapsed hours after this boundary.

The sender-mode migration can overwrite prior mode choices without changing timestamps. Independently attest that the exact sender-mode migration is applied and the current registration model/database defaults agree, then capture the actual `MAX(companies.id)` across all companies in a complete fresh read-only snapshot. Preserve the source, migration ledger, execution context and snapshot evidence. Prepare this exact value as immutable `sender_baseline_after_id`; every ID at or below it is excluded with `sender_mode_history_unknown`, including registrations after the authentication boundary and future-dated existing rows. This is an additional exclusion: preserve the original authentication boundary unchanged. Never lower/reset the floor, erase an old policy, or fabricate timestamps/accounts to admit existing rows. Production attestation must use the actual maximum, never the synthetic-test floor 0.

This attestation relies on verified supported registration/default execution and ordinary monotonically allocated IDs. Qualify in-flight old registration/migration execution before the snapshot. It is not proof against later arbitrary SQL, explicit-ID insertion/reuse, resurrection or another bulk mode rewrite. Relevant later source/default/data changes require stop and independent review; a matching source hash alone cannot repair erased history. New higher IDs still require all existing age, authentication, ownership and legitimacy evidence; a genuine eligible pilot may consequently be later than 48 hours after the original authentication boundary.

Policy schema version 2 rejects persisted old-version, absent/malformed/inconsistent attestations without upgrading or arming them. Both apply modes default disabled; `sender_baseline_after_id` and `evidence_since` default NULL. The runtime policy lives in `storage/app/daily-spam`; configuration-cache contents cannot enable it. Preparation records the exact authentication release SHA and the sender-history floor together and cannot rewrite either boundary. The floor is a strict integer from 0 through 999999999; missing values never fall back to zero. Missing or malformed policy, schema, timestamps or evidence fails closed. SQL DATETIME values must be exact nonnull `YYYY-MM-DD HH:MM:SS` values in the configured storage timezone; impossible dates, DST gaps, repeated fall-back hours, offsets and normalization are rejected. The boundary uses a valid ISO calendar timestamp with an explicit offset in the range -14:00 to +14:00.

Eligibility requires active/nondeleted free-package company, exactly one raw-owned active/nondeleted main user, ordinary registration role and unchanged registration baseline. Extra users (including soft-deleted), foreign overrides/main users, any successful login/activity, any nonnull remember token (including empty), reset/API/SMTP/MCP/security/history/manual/protected evidence, billing identity and retained business use are exclusions. Sender evidence must be the exact unchanged default sender, with no custom/suffixed/deleted/additional sender or custom automatic-reply settings. Exactly one unchanged, unread owned registration welcome notice must match the current template and registration timestamps; other or additional notices block. All other conservative audit/history exclusions remain. Missing evidence is ineligible, never silently assumed absent.

Every application revalidates company and child evidence with current locking reads after acquiring the company lock, and rereads runtime policy/kill state after waiting. Authentication success and daily marking use the shared company lock. Ordinary reports are snapshots, not authorization or full backups.

## Review, pilot and enable gates

All policy/journal commands, scheduled marking and restoration must use the same verified operating-system account as Nuhet's PHP-FPM application. Journal directories are private mode 0700. On this host, verify the FPM and cron user is `www-data` and execute operator commands as `sudo -u www-data php artisan ...` through the approved SSH sudo transport. Do not prepare state as `nuhetftp` or root and then change ownership or broaden permissions as a workaround. Verify the production storage mount supports the required sync/lock/rename operations and is writable by that application user before creating any runtime state. Read-only reports must also have access to that user's journal. These checks preserve the existing host/service authorization; they do not grant account or permission changes.

1. Deploy the independently accepted authentication prerequisite and verify its execution boundary; deploy accepted daily code with runtime disabled. Do not rebuild config cache as part of this workflow.
2. Under a separately approved operation, prepare the captured boundary and exact deployed auth SHA: `php artisan DailySpamAccounts --prepare-evidence-since=<ISO-with-offset> --auth-release-sha=<40hex> --sender-baseline-after-id=<attested-MAX-company-ID>`. Both attestations are immutable.
3. Obtain a complete fresh bounded audit, reconcile pagination/exact IDs/reasons/hash and review genuine prospective eligibility. Default `php artisan DailySpamAccounts --limit=50 --after-id=0 --maximum-id=<fixed-bound>` reports up to 500 rows per page. `--ids=<exact-comma-separated-IDs>` reports every requested ID including missing accounts.
4. Capture and verify the full retained database, files, statistics, outside-account and access/sending BEFORE footprint. Source/classification hashes are not that backup or recovery procedure.
5. Explicit `--arm-pilot` allows only manual apply. Apply 1-10 exact reviewed IDs once using `php artisan DailySpamAccounts --apply --ids=<IDs> --run-id=<new-identity>`. Verify retained footprint, deletion clock, marker, access/sending refusal and outside isolation after the genuine pilot. Stop at the first failed or uncertain operation. Do not automatically retry.
6. `php artisan DailySpamAccounts --enable-pilot=<completed-manual-run>` requires every pilot ID durably marked, 1-10 exact IDs, completed receipt, settled journal, matching immutable authentication boundary, sender-history floor and the current source/policy fingerprint. It enables scheduled mode and closes manual mode. Any relevant code/template/protected-ID contract change invalidates scheduling and requires review and a new matching pilot. There is no automatic enable or backfill.

Reports and run receipts expose the exact sender-history floor, which also participates in the immutable eligibility fingerprint. Reports include exact eligible IDs, reasons, source/policy hash, per-row classification hash and report hash. Verify actual deployed source before using the receipt. Genuine eligible pilot and enable remain future operator gates until satisfied; tests or synthetic timestamps do not establish production readiness.

The validated effective `storage_timezone` is reported explicitly and included in the immutable eligibility fingerprint; changing the application timezone invalidates an old pilot or enabled schedule and requires review plus a new matching pilot.

## Bounded schedule and stop flag

The scheduler calls `DailySpamAccounts --scheduled` daily at 03:20 using scheduler `withoutOverlapping`; the internal filesystem lease remains authoritative. Each run examines at most 500 candidate rows and plans/marks at most 10 IDs. A fixed UTC-day run identity with a completed receipt (including empty runs) prevents repeat applications that day. The cursor advances only through examined IDs up to the cap and wraps to zero at the end, revisiting young/excluded/backlog rows later. One execution does not drain an arbitrary backlog.

`php artisan DailySpamAccounts --disable` publishes a durable stop-only flag using its independent short lock, without waiting for the global run lease. Running batches reread it before later IDs and after company-lock waits. An already executing transaction may finish; later IDs stop. Explicit arm/enable clears the flag while holding global then stop lock; disable holds only stop lock. A failed stop/enable write is a blocker to investigate, never a successful transition.

## Durable journal, uncertainty and recovery

Lock order is global filesystem lease, fresh company row, then user/child evidence. All participants must use the same shared Linux storage root; the lease is not a distributed lock across independent host filesystems. Arbitrary external SQL and unsupported writers do not acquire the application lock.

`pending.json` is durably published before the started `runs/<run-id>.json` receipt or database mutation. Each marked ID first receives durable `companies/<id>.json` intent. Checked marking stores abandoned marker, automatic provenance, frozen status and the actual deletion timestamp under the company transaction. Outcomes are durably recorded before completion. The completed run receipt is published before cursor advancement and pending removal. Per-company provenance conservatively blocks future automatic marking, including uncertain or rolled-back intent.

The writer rejects symlinks/invalid documents, creates directory entries iteratively with checked parent fsync before using each entry (including existing entries left after failed sync), flushes and fsyncs exclusive temporary files, atomically renames, fsyncs containing Linux directories and freshly verifies exact bytes by hash. A crash, I/O error, unfinished receipt or pending run stops later runs and replay. There is no automatic replay/reconciliation command. Preserve exact journal/DB/footprint evidence; reconcile each planned ID and uncertain outcome against fresh state and the separately verified targeted recovery procedure before another apply. Never erase/reconstruct a journal to bypass uncertainty. Receipt completion plus a lingering pending flag still requires review.

Local interruption tests exercise real Linux flock, actual file publication/readback, a killed owned lease holder and a blocked publish directory. These do not prove power-loss durability, ENOSPC behavior or deployed-storage semantics. Local disposable MariaDB REPEATABLE READ tests prove supported lock coordination and current reads across distinct connections, not the production server configuration or every authentication HTTP path. Production storage/database verification and the actual deployed-auth boundary remain required.

## Restoration and retention

Normal company lists omit abandoned markers. The superadmin review surface lists retained and manually marked accounts with grouped search and shows restore only for retained deleted markers. Existing outer admin authorization rejects role4 users with 401; non-superadmin admins reach the controller and receive 403. Guests require login. POST restoration requires CSRF and a fresh still-deleted+abandoned predicate under the shared lock; a changed account returns 409.

`CompanyRetention::restore` obtains the same global lease before the company lock. The fresh optional predicate runs before journal or lifecycle writes. Daily provenance receives durable automatic-marking protection before restoration. Successful restoration clears `deleted_at` and all abandoned marker fields and activates the account while preserving users/business/files/statistics/queues. Failed DB restoration leaves conservative protection; rejected predicates do not add provenance. Ordinary non-daily restores create no company provenance. Restoration does not erase pending uncertainty or reverse prior billing/cancellation effects.

Retention begins at actual persisted `deleted_at`; repeated marking never resets it. Data remains retained for at least 12 calendar months. Exact calendar anniversary remains retained; eventual permanent cleanup requires strictly later than the clamped anniversary and every existing independent purge/rehearsal/recovery gate in [account-deletion-retention.md](account-deletion-retention.md). This daily workflow never schedules permanent cleanup.
