Commit Graph

15 Commits

Author SHA1 Message Date
anonsaber 26e916b79d docs: bump test/anchor baseline to match the backend-label round
Sync the stated-as-current gate numbers that the previous feature commit
(88f0923) shifted, per the same-round rule:

- Test baseline 104 -> 105 passed / 0 failed / 4 ignored across the
  authoritative (charter §6.1) and deferring docs (design §Phase 0,
  opengaps access-control, HANDOFF-push-401), with retest date 2026-10-14.
  The new test `setup_status_reports_backend_label` is a normal (non-ignored)
  test, so the ignored set is unchanged.
- opengaps anchor count 72 -> 49, matching what `run_all.sh` ANCHOR AUDIT now
  reports (the design.md main.rs line-anchors were converted to symbol refs).
- AGENTS version baseline 3b36fe3 -> 88f0923 (gate-holder merged this batch;
  88f0923 is the gate-green commit of the round). Charter Code Baseline
  `fc686ab` left as-is — line-number anchor semantics were not bulk-reverified
  this round, so claiming otherwise would overstate (§7.4).

GATE-DOCS 6/6 clean (49 line-refs, 0 errors); GATE-P0 stood at 105/0/4.
2026-10-14 02:46:17 +08:00
anonsaber 88f0923e6c feat(status): report per-instance backend label so probes can identify the origin
`/api/status` now echoes a `backend` field alongside `version`. The baked
`BUILD_VERSION` is identical across every instance built from the same image bath,
so it answers "did this deploy land?" but not "which origin answered?" when a
probe goes through the Cloudflare Worker load balancer (`ARCH-LB-WORKER`) — and the
Worker's `x-lb-backend` header is unreliable (it is silently dropped when the
response headers are immutable, e.g. cross-origin without CORS). Having the backend
self-report in the body removes that dependency entirely.

The value is a per-instance observability label read once at startup from
`BACKEND_ID` (falling back to `HOSTNAME`, which container runtimes set their
selves). It is not a connection secret and is never persisted (`C-REDIS-ONLY-STATE`).
`null` means neither env var was set — two such instances are indistinguishable by
this field by design.

Wiring keeps handlers off the environment (matching the `debug_surface_requested`
rationale: env is process-global and reading it inside a handler races tests):
`main` reads it once and threads `backend_id` through the router builders into
`AppState::backend_id`.

Also replaces the drift-prone `src/main.rs:<line>` anchors in design.md /
design.zh-CN.md with symbol references (`std::env::var` key names,
`LlmClient::with_runtime`), per the symbol-not-line rule; the insert had already
shifted them.

Tests: `setup_status_reports_backend_label` asserts the label round-trips into the
body. GATE-P0 105 passed / 0 failed / 4 ignored; GATE-DOCS 6/6 clean.
2026-10-14 02:28:06 +08:00
anonsaber 3b36fe30ba fix(push): rate-limiter no longer blocks verification; sync stale docs
P1 (src/notify.rs): in jmap_push, move remember_push_subscription and
set_push_subscription_status BEFORE the push-verify rate limiter. The limiter
now gates only the outbound PushSubscription/verify JMAP API call
(claim_dedup == true -> call it; false -> skip), and the 429 branch is removed
entirely. A retry within the 30s window still records the key, so RFC 8620 §7.2
verification (the callback response) is never rejected by the limiter.

Test (src/notify.rs): jmap_push_requires_verification_code case 4 expected
SERVICE_UNAVAILABLE (503) -- pre-TTL=0 behaviour when remember failed. With
TTL=0 (commit 7331cb7) remember always succeeds and the hybrid payload
(verificationCode + accountId + emailId) falls through to event enqueue ->
NO_CONTENT (204). Expectation updated; comment added.

Comments: src/domain.rs drops phantom 'teloxide' (crate never imported);
src/config.rs SPLIT-EVAL reason corrected to real 1119-line size.

Docs (EN+ZH pairs, same round -- AGENTS 6.5/7.2):
- reference.* : ratelimit:push-verify row -> jmap_push, suppress-not-429;
  drop 429 error row; src/{index,lb}.js -> cloudflare-worker/src/*.
- design.*   : section 419 rate-limit scope; baseline 93 -> 104 (2026-10-13).
- charter.*  : secrecy 0.10 -> 0.8 (matches Cargo.lock); baseline 93 -> 104.
- opengaps.* : baseline 94 -> 104.
- HANDOFF-push-401.md : test baseline 99 -> 104 (never true; red test fixed).
- AGENTS.md  : fill version-baseline placeholder; surviving-anchor count
  17 -> 21 (verified: opengaps 8 + retired 9 + design 4).
- .env.example : src/main.rs:40 line-anchor -> symbol reference.

GATE-P0 (docker rust:1-slim-bookworm): fmt/check/clippy/test -> 104 passed / 0 failed / 4 ignored.
GATE-DOCS (scripts/docs_check/run_all.sh): 6/6 clean (704 path-refs, 55 anchors, 459 sec-refs).
2026-10-13 22:43:29 +08:00
anonsaber 7331cb7d31 fix(push): verification key should never expire (TTL 0)
User feedback: any finite TTL causes push to silently stop working
eventually. Stalwart does not re-verify (RFC 8620 §7.2 sends the
verification request once at subscription creation). The key is
explicitly deleted by forget_push_subscription when the subscription
is retired, so no TTL is needed.

Changes:
- PUSH_SUBSCRIPTION_SECONDS: WEEK → 0 (never expires)
- remember_push_subscription: ttl_seconds=0 → SET without EX (Redis)
  / expiry=i64::MAX (MemoryState)
- ttl_contract_is_pinned test: assert 0
- docs: reference/opengaps/design updated to 'never expires'
2026-10-12 23:57:24 +08:00
anonsaber d452f95485 fix(push): PUSH_SUBSCRIPTION_SECONDS 300→WEEK (604800)
Root cause of push notifications failing while cron works:
- Stalwart sends the verification request (RFC 8620 §7.2) once at
  subscription creation; event pushes (§7.3) arrive without
  verificationCode and rely on dedup_exists("push:subscription:{id}")
  to confirm prior verification.
- TTL was 300s (5 min): key expired → every event push 401'd.
- Cron path bypasses this key entirely (polls /changes directly),
  which is why cron-delivered emails still arrived.

Fix: align with PUSH_REGISTRATION_SECONDS (1 week). Stalwart does not
re-verify; the key must survive restarts and any gap between
subscription creation and events.

Also fixes: removed fictional push:subscription-code:{code} from
opengaps TTL table (no such key exists in code); corrected
reference.md caller from register_push→jmap_push verification path;
fixed 前→EX typo in reference.zh-CN.md; design.md updated with
fifth 'why' bullet and historical context.
2026-10-12 23:42:28 +08:00
anonsaber 21e91765d0 feat(reconcile): filter initial baseline to 7-day unread emails
New mailbox onboarding no longer floods Telegram with the entire
mailbox history.  The initial baseline walk (ReconcileCursor::Walk,
any position) now passes an EmailQueryFilter to list_emails_page that
bounds Email/query to messages received within the last 7 days and
not yet seen ($seen keyword, RFC 8621 §4.1.2).

- EmailQueryFilter { received_after: Option<i64>, unread_only: bool }
  in src/domain/jmap.rs (backend-agnostic domain type).
- StalwartJmap::fetch_email_page builds a compound Filter::and from
  the filter conditions (after + not_keyword "$seen").
- walk_baseline computes the 7-day cutoff once and passes it to
  every page fetch, so resumed walks stay filtered.
- Replay(state) path returns early and never calls list_emails_page,
  so /changes incremental is unaffected.
- const INITIAL_BASELINE_WINDOW_DAYS: u64 = 7.
- New test first_reconcile_filters_the_initial_baseline_to_recent_unread
  pins the filter on every Walk page and the cursor transition to Replay.
- 3 doc anchors re-anchored (worker.rs:227→241, client.rs:485→513 ×2).

GATE-P0: 104 passed / 0 failed / 4 ignored.
2026-10-12 22:08:51 +08:00
anonsaber 1bdda7c471 fix: reconcile lock robustness — TTL 300s→60s, heartbeat 90s→30s, renewal interval 10s
- state.rs: RECONCILE_LOCK_SECONDS 300→60, RECONCILE_HEARTBEAT_SECONDS 90→30,
  new RECONCILE_HEARTBEAT_INTERVAL_SECONDS=10; ttl_contract_is_pinned asserts
  interval*2 <= TTL < 60 and interval < LOCK
- notify.rs: heartbeat sleep uses ttl::RECONCILE_HEARTBEAT_INTERVAL_SECONDS
- docs: 7 files updated (reference/charter/opengaps/design × en+zh + index.js
  comments); retired.md/opengaps.md anchor line numbers shifted for state.rs
  (+9) and notify.rs (+3); notify.rs:1484-1485 range trimmed to avoid blank
- GATE-DOCS 6/6, cargo fmt/clippy/test clean (103/0/4)
2026-10-12 22:03:11 +08:00
anonsaber 77bb253cc0 docs: clean remaining deployment.md refs in design docs
Replace 9 residual deployment.md references in design.md (EN) with
correct targets (charter §8, reference §3/§9, README §3.0/§3.10,
cloudflare-worker/README). Mirror all changes in design.zh-CN.md.
GATE-DOCS 6/6 PASS.
2026-10-10 19:06:40 +08:00
anonsaber 7aedcd4145 docs: merge deployment.md into README, delete deployment files
- Move operational content (env var reference, multi-instance prerequisites,
  troubleshooting, cron-drain, CF Dashboard Git integration, BACKEND_ORIGINS_JSON
  format, security checklist) into README and README.zh-CN
- Delete docs/deployment.md and docs/deployment.zh-CN.md
- Update 5 validator DOCS lists to remove deployment entries
- Update charter §7 doc boundary table, AGENTS §2.5 line-anchor exception
- Fix cross-doc references in design/reference/opengaps/retired/worker READMEs
- Fix cron-drain.sh header comment reference (deployment.md §6.3 → README §3.10)
- GATE-DOCS 6/6 PASS (55 anchors / 441 sec-refs / 699 path-refs, 0 errors)
2026-10-10 18:53:43 +08:00
anonsaber 29178cb093 docs: fold quickstart into README, rename gateway→load balancer
Two changes requested by the user:

1. Fold the hand-holding quickstart tutorial into README §3 (both
   languages). Delete docs/quickstart.md and docs/quickstart.zh-CN.md.
   Remove them from all 5 validator DOCS lists, README §6 doc index,
   and charter §7 boundary table. The tutorial now lives as
   README §3.0–§3.11: prerequisites, create Telegram bot, find chat id,
   get JMAP credentials, run backend, sign in, fill config, register
   callbacks, enable processing, verify, schedule drain, troubleshoot.

2. Replace 'gateway'/'网关' with 'load balancer'/'负载均衡器' across
   all markdown (README, docs/, AGENTS.md, cloudflare-worker/README).
   Also fix 4 markdown anchor links whose heading slugs changed.
   Also fix charter §8 '18 safe routes' → '19' (was missed in the
   earlier reference.md fix).

GATE-DOCS 6/6 PASS (71 anchors, 727 path-refs, 455 sec-refs).
2026-10-08 21:35:14 +08:00
anonsaber 2089a95b79 docs: drop the SPA-footer deploy proof and reanchor notify.rs refs
Four spots told the operator to read the SPA footer to confirm a
deploy landed. The footer no longer renders a version, so restating
that would send an operator looking at a control that no longer
exists. Point them at /api/status instead; the version field itself is
unchanged.

The previous commit inserted 500+ lines into notify.rs, moving
register_push and register_telegram_webhook. Reanchor the two
deployment.md line refs; the other seven refs in that file are before
the insertion point and are unchanged.

Document the new retire-on-change contract in reference.md.
2026-10-01 11:18:07 +08:00
anonsaber af89a17f7f feat(auth): extend admin session to 30 minutes 2026-10-01 09:19:49 +08:00
anonsaber 2752069eb3 docs: fix Chinese technical terminology 2026-10-01 03:33:42 +08:00
anonsaber e4a0a4b7db docs: translate Chinese document headings 2026-10-01 03:21:57 +08:00
anonsaber 7a27f7ff00 docs: add bilingual guides and callback setup in SPA 2026-10-01 02:36:03 +08:00