A deleted gift keeps its row, and a user message ref still resolves to it
by owner and msg_id. The paid upgrade path checked only Converted and
UniqueGiftID, so an upgrade of a deleted, upgradable gift ran until the
upgrade_msg_id write found no aggregate row and failed with an internal
error. The transaction rolled back, but the client got INTERNAL instead
of STARGIFT_INVALID.
The upgrade form now refuses a deleted gift before issuing a payment
form, and the upgrade transaction re-checks the lifecycle under the row
lock. TestStarGiftDeleteBlocksLaterUpgradePostgres pins that no Stars
are charged and nothing is minted.
docs/collectible-gifts.md described tmp_password as unsupported; main
issues account.getTmpPassword grants and serves exact Layer 225-231 via
payments.getStarGiftWithdrawalUrlLegacy with SRP.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TestStarGiftDeleteRefreshesCollectionHashPostgres reproduces the stale-hash bug
and guards the fix; TestStarGiftDeleteRefusesIrreversibleGiftsPostgres covers the
limited, auction, convertible and prepaid refusals. Both are in the CI Postgres
job list.
A gift that was upgraded into a collectible (NFT) is refused with
STARGIFT_INVALID: destroying a collectible is a different operation with its
own financial rules, so this method must never burn one. The store no longer
touches unique_star_gifts and the listing/offer/withdrawal guards are gone
with it.
The delete itself is unchanged: the saved gift row survives for the audit
trail, the gift moves to lifecycle_status='deleted', it leaves every
collection and disappears from the profile projections.
Covered by TestStarGiftDeleteRefusesUpgradedGiftPostgres, which upgrades a
gift and asserts the delete is refused and the gift stays active.
Layer 232 added payments.deleteStarGift#3cdaf8aa stargift:InputSavedStarGift
= Bool. The owner removes a received gift from the profile.
The saved gift row survives: upgrade commands, offers and transfers reference
it, so the delete is a lifecycle transition. The new 'deleted' state lives in
migration 20261017010003_star_gift_deleted_state; read paths only project
lifecycle_status='active', so the gift leaves the profile, the account rating
signal and the saved-gift lists at once. A gift that was upgraded into a
collectible also burns that collectible, so it can neither be listed nor
exported afterwards, and it is dropped from every collection.
Refused states (STARGIFT_INVALID): converted, exported, burned, already
deleted, listed for resale, under a pending purchase offer or under a pending
withdrawal request. Only the caller may delete their own gift; channel gifts
are a channel asset (STARGIFT_OWNER_INVALID) and bots are refused
(BOT_METHOD_INVALID).
getGaslessInfo returned a vector of updates, which does not encode: the schema
declares `= Updates`, a bare type, so every call published INTERNAL. The client
called it 42 times in the few minutes after the previous deploy, so this was
its own log flood. Now it returns an Updates with no entries, which encodes and
still claims nothing about running a gasless relay.
CI ran only on main, grammy, admin and on pull requests. A branch push ran
nothing, so breakage sat invisible on the branch until a PR was opened against
it -- which is the moment you least want to find out. Every branch push now
runs the workflow; tags are excluded because they are not branch state.
The wallet keys in appConfig are hand-built fragments concatenated into the
served document, so a missing comma cannot fail the build -- it produces JSON
the client silently discards, taking the wallet limits, the gasless copy and
ton_usd_rate with it while every request still returns 200 and the Money tab
still opens. The new test parses the served bytes and pins the wallet keys to
the values production ships, so a USD amount that stops rendering can be told
apart from a rate the client chose to ignore. They currently match exactly,
which is why the missing fiat display is not a config problem.
Co-Authored-By: Claude Fable 5.5 (1M context) <noreply@anthropic.com>
The previous commit moved the wallet off the read-only rootfs and onto the
/var/lib/telesrv volume, which fixed the container, but created the
directory with -m 0750 alongside the other four data paths. NewFileStore
refuses to open a state directory that is group- or world-accessible, so
the server exited at boot with
open wallet state directory: wallet state directory must have mode 0700
0700 is the only mode it accepts: it checks Perm()&0077 == 0, so 0750 is
rejected exactly as 0755 would be. That is not a bad default to paper over
either -- the directory holds one 0600 JSON per account plus the
AES-256-GCM master key, so a group-readable state directory is a real
disclosure, and the check is the right one.
Install it in its own RUN at 0700 instead of sharing the 0750 line. The
smoke test now asserts the mode on the mounted volume at runtime rather
than trusting the image build, because that is the check that actually
gates the boot, and it is checked against the server container explicitly
rather than whatever $container_id the hardening loop happened to leave
behind.
Co-Authored-By: Claude Fable 5.5 (1M context) <noreply@anthropic.com>
The in-app wallet is enabled by default with a relative default,
data/wallet. That is fine bare-metal, where the working directory is
writable, and fatal in the container: the rootfs is read_only and only
/var/lib/telesrv is a volume, so boot died on
open wallet state directory: mkdir data: read-only file system
before the server ever reached its listener, and the whole stack failed to
come up. Every other data path telesrv writes to already has this pin --
blobs, blob-staging, maptiles, livestream, the RSA key, the donation wallet
key -- and the wallet was the only one missing, which is why nothing caught
it: the pattern was there to copy and the new path did not copy it.
Pin both wallet variables next to the volume, and pre-create the directory
in the image alongside the other four so a fresh named volume inherits the
right ownership instead of depending on runtime mkdir.
The CI compose assertion now checks that both wallet paths resolve under
/var/lib/telesrv, so the next data path that forgets its pin fails the
build instead of a deployment.
Co-Authored-By: Claude Fable 5.5 (1M context) <noreply@anthropic.com>
The route and permission tables in docs/admin-panel-api.{en,ru}.md had
drifted a long way out of date and nothing noticed: permissions.tsx
exported a dozen section rights the tables never mentioned, the SPA table
listed routes that no longer existed, and several pages and their rights
were missing entirely. They are generated from nav.ts, permissions.tsx and
security.go now, so editing the source and rerunning is the only way they
move -- and CI runs --check so they cannot rot unnoticed again.
The generator also documents what the panel does now, since the rules it
follows were only ever in the diff: the sidebar, the tab bars and the
route table are three views of one declaration in nav.ts, a sibling page
is a tab rather than a second sidebar row, a right outside
assignablePermissions() cannot be granted to a named operator, and the
//go:embed web/dist bundle has to be rebuilt and committed or a src change
does not ship. AGENTS.md and both API docs carry that, plus a section on
adding a page in the order that avoids repeating this drift.
docs/giftfetch.md is new, and local-setup.md points at it. Official
Star-gifts are only reachable with an authorized user session, which is the
part that actually stops people: the fetch is written up around the QR
login, the snapshot layout, the validation it performs, and the fact that
a .session file is a live account credential and belongs outside the
repository.
One fix to the generator itself. It read nav.ts's tab arrays with a
non-greedy (?P<tabs>.*?)\]\s*\}, which stops at the first ] followed by a
} -- the closing bracket of a tab's own aliases: [...] -- so the messages
section parsed to zero tabs and dropped out of the table with no error
where all the others were fine. The tabs array is now read by bracket
matching, and a section that parses to zero tabs raises instead of
vanishing, because a silently missing section is exactly the failure this
commit exists to stop.
Bot API sendGift spends the bot's Stars wallet (bot_stars_balances), so
crediting the recipient on conversion would let any gift cash the bot's
spend out into a personal balance. Zero convert_stars at purchase for
BuyerIsBot, refuse conversion server-side (backstop is the sender's
users.is_bot flag, independent of data state) and migrate already-sent,
unconverted bot gifts to convert_stars = 0. Human buyers keep the
catalog convert price.
Operators had no supported way to move a deployment or to recover one. This
adds cmd/gramsrv-backup, which captures the PostgreSQL databases, the media and
key tree, Redis and the configuration into a single verifiable bundle, and
restores it on another host.
backup / restore / verify, with MANIFEST.json recording the source commit, the
schema version and exact row counts, and SHA256SUMS in sha256sum(1) format.
Components are captured independently (server, grammystore) since each has its
own database and usually its own container; pg_dump and redis-cli can come from
the host or from docker exec.
Portability is the point of the dump format:
- plain SQL rather than the custom format, so any psql can replay it and the
client need not match the server
- --clean --if-exists so a bundle can be replayed over a populated database
- --no-owner --no-privileges, and no --create, so the target role and database
name are not baked into the artifact
- restored with ON_ERROR_STOP=1 and --single-transaction, so a failure cannot
leave a half-applied schema
- \restrict, \unrestrict and SET transaction_timeout are stripped on the way
in; they are PostgreSQL 17 specific and break older clients and servers
- the target major version is checked before the restore starts
Freezing (--freeze-units, --freeze-containers) is optional because pg_dump is
already MVCC-consistent; it exists so the media tree is byte consistent, and
everything stopped is restarted from a defer even when the capture fails.
Verification re-hashes every artifact, decompresses it, walks tar members, and
cross-checks file_blobs against the media tree, reporting missing and corrupt
objects. check-media.sh runs the live form of that check.
Also included: shell and PowerShell wrappers, a migration runbook in
docs/backup-restore.md, and internal/doclint, which fails the build when tracked
markdown leaks a key, a token or a credential so documentation stays safe to
publish.
Bring the grammy-branch grammystore work onto main: a full PostgreSQL
rewrite of the Telegram store bot, real-number mode with gramsrv
account binding, plus the admin API lookup the bot depends on. Also
wires the new endpoint into telesrv, CI, deployment and docs.
grammystore bot (cmd/bots/grammystore):
- migrate from SQLite (BOT_DB_PATH) to PostgreSQL: db/init.sql schema,
DATABASE_HOST-based config assembly, persistent upserts and tests
- new bot modes: "random" (generate free numbers) and "real" (users
bind their real Telegram phone); phone-share keyboard flow with
cancel, transient toasts and auto-deleted service messages
- real-mode number lifecycle: +888 purchases replace the account phone
on gramsrv (set-phone sync) and unbind the personal number; replaced
numbers return to the pool; a second anonymous number request is
refused; number picking guards free generation
- OTP login-code delivery routed to the chat bound to the verified
phone, per-recipient language; stopped for replaced numbers
- admin panel: exact lookups, admin can bind any number to any
Telegram account, Telegram-native ticket replies (button and
reply-to-notification), constant visible button menu after admin
actions, broadcast/stars/premium/promo/giveaway/referral/bonus
flows, payment and refund tracking against gramsrv
- gramsrv client (gramsrv.js) grows resolveUserByPhone; fetch-my-ID
flow resolves a bound phone to the server user id with graceful
error handling
- SOCKS5 proxy support for Telegram API (socks5h://), proxy tests
- Docker/GHCR image, docker-compose files and dev compose, .env
documentation, per-branch translation pairs kept in sync
gramsrv admin API and telesrv:
- POST /v1/accounts/resolve-by-phone (authenticated, read-only, no
CommandMeta): canonicalize the phone and resolve it to a user id via
the new admin.UserLookup dependency; wired in cmd/telesrv with the
user store; admin service method, server handler and tests
CI and deployment:
- bot test job runs under GitHub Actions with an ephemeral
PostgreSQL 16 service and DB-config env vars; grammystore
container build workflow
- scripts/install.sh: build telesrv server and admin panel, create
systemd units (gramsrv, gramsrv-admin), configure PostgreSQL/Redis
via docker compose
- admin panel API reference (docs/admin-panel-api.{ru,en}.md) documents
the new resolve-by-phone endpoint
Verified on the merged tree: go build ./... clean; grammystore bot test
suite 68/68 against local PostgreSQL.
Ignore inactive collectible supply for ordinary imports; preserve existing issuance caps and remaining stock under the purchase lock. Reject cap or sales-mode changes on an existing gift identity.
Add focused PostgreSQL inventory/ledger CI, revision and purchase regression tests, and Debit Stars session/CSRF coverage. Rebuild Admin assets and document the inventory contract.
Preserve passwordless development Redis defaults and align explicit empty process password overrides with Compose. Document and test psql password rotation against authenticated TCP connections, retain existing volume data, and run the integration gate in CI.