Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,14 @@ jobs:
# env lines + deletion-ledger volume, the TC-2346 operation-retry warning codes, the TC-2917
# storage-headroom event in the Vector config, the TC-1491 artifact read limit env line, the TC-3554
# DstackKmsEpoch epoch-0 pins opened from root_wrap, no key-recovery sidecar, the TC-287 retention
# sweeper env line, the TC-1791 delegated SQL caveats env line and the TC-1491 SQL size-cap and
# free-disk env lines (raw 46287bc3…; e5f1c356… / d1d2ef49… before the TC-1491 caps,
# sweeper env line, the TC-1791 delegated SQL caveats env line, the TC-1491 SQL size-cap and
# free-disk env lines and the TC-3739 node_request DB timing fields in the Vector config
# (raw 02d90755…; c6d05e1e… / 46287bc3… before TC-3739, e5f1c356… / d1d2ef49… before the TC-1491 caps,
# e1cf031b… / f4f51e75… before TC-1791, 6a577c6d… / 272f43b8… before TC-287,
# 70c71aa0… / 8e602959… with the sidecar, 417719648a0c… / d6af7a70… before TC-3554,
# 5419a6fb… before TC-1491, d703d69b… before TC-2917, 298ea356… before TC-2346,
# 192dfb7e… before TC-1777), its single node digest normalized to 64 zeros.
n0_template_hash = 'c6d05e1e4d8c15c384c7b3a86e8a8f9e3560d17efbb9b0236b9e724f1dfe8f46'
n0_template_hash = 'cc219eb5a05deda365a9683b6c6dc407eb872cb77d9f3954a819d1805ddd2249'
node_pin = re.compile(rb'(?m)^ image: ghcr\.io/tinycloudlabs/tinycloud-node@sha256:([0-9a-f]{64})$')
def n0_template(raw):
pins = list(node_pin.finditer(raw))
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]
### Changes
- A delegated SQL `/invoke` makes fewer PostgreSQL round trips. It checks the identity cutover fence and resolves the database identity once instead of twice, and it reads the statements profile from the delegation chain that authorization already loaded instead of walking the chain again in its own read-only transaction (`BEGIN`, `SET TRANSACTION READ ONLY`, two `SELECT`s per chain level, `ROLLBACK`). A warm `SELECT 1` through a 1-hop delegation goes from 16 to 9 sequential statements, through a 2-hop delegation from 18 to 9, and a cold one from 18 or 20 to 11. Answers, refusals and error messages are unchanged. Details: TC-3739.
- Production compose: the log shipper keeps the per-request database accounting the node already logs on each `node_request` line: `pool_wait_ms` and `query_time_ms` (numbers, 0 to 86,400,000) and `query_count` (an integer), on requests that answered below 400 only. Before, the shipper dropped them. A value of the wrong type or out of range is dropped and the event still ships. The vendored log schema moves to canonical revision `29ee97f9…`. The log budget's representative request event grows to 551 bytes; the capped 4xx and 5xx classes carry none of the fields, and the capped daily volume is unchanged. Config only, no migration; the N0 compose template hash is now `cc219eb5…` (raw `02d90755…`). Details: TC-3739.
- `POST /delegate` and `POST /revoke` refuse a validly signed request that has no standing, or is outside its signed time window, before taking any lock. Before, it took the guards of the delegation chain it cited, queued for the write order of the spaces it named and, on PostgreSQL, held a pooled connection in an open transaction until it was refused. Now it is refused at once:
- a delegation whose issuer has no applicable authority for its requested capabilities;
- a revocation by someone who may not revoke its target, or of a target that is not stored;
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dstack-postgres.yaml

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,9 @@ Before any CVM mutation the workflow requires:

- the main compose, with its one node digest replaced by 64 zeros, to hash
to the reviewed N0 template
**`c6d05e1e4d8c15c384c7b3a86e8a8f9e3560d17efbb9b0236b9e724f1dfe8f46`**
(raw `46287bc31dc09649b0679bacfe611ee24ad5ced5c51cd7909821dee895c1f6d2` normalized). Before the TC-1491 `TINYCLOUD_STORAGE__SQL__MAX_DATABASE_BYTES` / `MIN_FREE_BYTES` env lines the template was `e5f1c356d68fe9dfac3d1f93109ded95108a8def42984b4bbeab1a29c5ee05ea`
**`cc219eb5a05deda365a9683b6c6dc407eb872cb77d9f3954a819d1805ddd2249`**
(raw `02d907552b74066b0d49f1088cc0b7ba9ca3e842eb9c1444b3cd778474498eb9` normalized). Before the TC-3739 `node_request` DB timing fields (`pool_wait_ms`, `query_time_ms`, `query_count`) in the Vector config the template was `c6d05e1e4d8c15c384c7b3a86e8a8f9e3560d17efbb9b0236b9e724f1dfe8f46`
(raw `46287bc31dc09649b0679bacfe611ee24ad5ced5c51cd7909821dee895c1f6d2` normalized); before the TC-1491 `TINYCLOUD_STORAGE__SQL__MAX_DATABASE_BYTES` / `MIN_FREE_BYTES` env lines the template was `e5f1c356d68fe9dfac3d1f93109ded95108a8def42984b4bbeab1a29c5ee05ea`
(raw `d1d2ef49f3c69c802b9a1e26a48488aae6f370fe5205d3d2d709cdb4cfa907d5` normalized); before the TC-1791 `TINYCLOUD_SQL__DELEGATED_CAVEATS_ENFORCED` env line the template was `e1cf031b7f042ed006e625fd8e7026a6ca4a2dd636dd0f567b60a7f0ad32570e`
(raw `f4f51e75076f21c7bd05e93e24d08ffe7290e2f9567fe1ed4daca7ec0e9ad7a5` normalized); before the TC-287 `TINYCLOUD_RETENTION__ENABLED` env line the template was `6a577c6dc138b456b4ff514564fe7aeb17c8fa94c85335db75719f2e30e57ea7`
(raw `272f43b8d969478388c57f089cf352db1eadb1b8e8cf73b3fe09f3bb34b1f468` normalized). With the TC-3554 key-recovery sidecar (1.26.14), before the node opened its root from `root_wrap`, the template was `70c71aa0acb7ebe157a1c1fac3e30fb3536b7cc21ba51d4013f905599c22ea4f`
Expand Down Expand Up @@ -860,8 +861,8 @@ gh workflow run docker.yml -R TinyCloudLabs/tinycloud-node --ref main \

The served/OCI identity remains **1.20.6-dstack / e18578ff9162986ddd813259c60f73866e3e60d1**.
With the template lock on main this redeploys exactly main's raw compose
`46287bc31dc09649b0679bacfe611ee24ad5ced5c51cd7909821dee895c1f6d2`
(the 1.21.0 compose `d95bfb70…` with the TC-1274, TC-1317, TC-1482, `current_kv_c_index_*`, `db_failure_5xx`, the 4xx and 5xx caps, `errors_dropped`, TC-2346 `db_operation_retried` / `db_operation_retry_skipped_slow` and TC-2917 `node_storage_headroom` Vector config, the optional TC-1482 `NODE_STATS_READ_TOKEN` env line, the TC-950 pool of 10, the TC-1777 `NAMED_KEYS_V1` gate env lines with the `deletion-ledger` volume, the TC-1491 artifact read limit env line, the TC-3554 `TINYCLOUD_KEYS__TYPE: DstackKmsEpoch` pins with no key-recovery sidecar, the TC-287 `TINYCLOUD_RETENTION__ENABLED: "true"` env line, the TC-1791 `TINYCLOUD_SQL__DELEGATED_CAVEATS_ENFORCED: "true"` env line and the TC-1491 `TINYCLOUD_STORAGE__SQL__MAX_DATABASE_BYTES: "320 MiB"` / `MIN_FREE_BYTES: "1 GiB"` env lines), whatever digest
`02d907552b74066b0d49f1088cc0b7ba9ca3e842eb9c1444b3cd778474498eb9`
(the 1.21.0 compose `d95bfb70…` with the TC-1274, TC-1317, TC-1482, `current_kv_c_index_*`, `db_failure_5xx`, the 4xx and 5xx caps, `errors_dropped`, TC-2346 `db_operation_retried` / `db_operation_retry_skipped_slow`, TC-2917 `node_storage_headroom` and TC-3739 `node_request` DB timing Vector config, the optional TC-1482 `NODE_STATS_READ_TOKEN` env line, the TC-950 pool of 10, the TC-1777 `NAMED_KEYS_V1` gate env lines with the `deletion-ledger` volume, the TC-1491 artifact read limit env line, the TC-3554 `TINYCLOUD_KEYS__TYPE: DstackKmsEpoch` pins with no key-recovery sidecar, the TC-287 `TINYCLOUD_RETENTION__ENABLED: "true"` env line, the TC-1791 `TINYCLOUD_SQL__DELEGATED_CAVEATS_ENFORCED: "true"` env line and the TC-1491 `TINYCLOUD_STORAGE__SQL__MAX_DATABASE_BYTES: "320 MiB"` / `MIN_FREE_BYTES: "1 GiB"` env lines), whatever digest
main's template currently pins. **Since TC-3554 only 1.26.15 or later boots
on this compose, and only once the database holds the `root_wrap` blob:**
1.26.14 needs the sidecar this compose lacks,
Expand Down
18 changes: 14 additions & 4 deletions log-shipper/budget.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const CAPPED_ALLOCATION_BYTES = 600_000_000;
*/
export const CAPPED_CLASSES = Object.freeze({
db_failure_5xx: Object.freeze({ capPerMinute: 10, representative: 'dbFailure' }),
node_request_5xx: Object.freeze({ capPerMinute: 10, representative: 'node' }),
node_request_5xx: Object.freeze({ capPerMinute: 10, representative: 'nodeCapped' }),
ingress_request_5xx: Object.freeze({ capPerMinute: 10, representative: 'ingress' }),
node_request_4xx: Object.freeze({ capPerMinute: 3, representative: 'node' }),
node_request_4xx: Object.freeze({ capPerMinute: 3, representative: 'nodeCapped' }),
ingress_request_4xx: Object.freeze({ capPerMinute: 3, representative: 'ingress' }),
});

Expand All @@ -43,6 +43,13 @@ const correlation = {
request_id: 'ffffffff-ffff-8fff-bfff-ffffffffffff', request_id_replaced: true,
account_hash: 'f'.repeat(64), space_hash: 'f'.repeat(64),
};
// Worst-valid per-request DB accounting (TC-3739): two long round-trippable fractional timings and the widest
// attempt count. The shipper copies them onto node_request lines with status below 400 only, so they count against
// the request allocation and never against the capped classes.
const dbAccounting = {
pool_wait_ms: 0.0000010000000000000002, query_time_ms: 0.0000010000000000000002,
query_count: schema.fields.query_count.max,
};
const request = {
method: longest(schema.fields.method.values), route: longest(schema.fields.route.values),
status: schema.fields.status.max,
Expand All @@ -55,12 +62,15 @@ const request = {
* space_hash); the ingress log carries none. db_hash is emitted by the F6 typed events only. The node's 5xx
* diagnostic (dbFailure) ships individually, one event per failing request: it is not an aggregated code. The
* shipper's dropped-count event (errorsDropped) is emitted by the shipper itself, one per capped class per window. The
* disk headroom event (storageHeadroom, TC-2917) ships once per local store every 5 minutes.
* disk headroom event (storageHeadroom, TC-2917) ships once per local store every 5 minutes. `node` is the request
* allocation's node line (status below 400, so it also carries the TC-3739 DB accounting); `nodeCapped` is the
* capped classes' node line (status 400 and above), which the shipper never gives DB accounting.
* Bytes below are exact for these records, not a proven Vector float-serializer
* upper bound or a fixed event-size guard. Actual ingestion/billing can differ.
*/
export const representativeEvents = Object.freeze({
node: Object.freeze({ ...common, event: 'node_request', svc: 'api', ...request, latency_us: schema.fields.latency_us.max, ...correlation }),
node: Object.freeze({ ...common, event: 'node_request', svc: 'api', ...request, status: 399, latency_us: schema.fields.latency_us.max, ...correlation, ...dbAccounting }),
nodeCapped: Object.freeze({ ...common, event: 'node_request', svc: 'api', ...request, latency_us: schema.fields.latency_us.max, ...correlation }),
ingress: Object.freeze({ ...common, event: 'ingress_request', svc: 'ingress', ...request, request_time_seconds: 0.0000010000000000000002 }),
diagnostic: Object.freeze({ level: 'warn', ts: common.ts, event: 'node_warning', svc: 'api', event_code: longest(aggregatedCodes), event_count: schema.fields.event_count.max }),
dbFailure: Object.freeze({
Expand Down
22 changes: 20 additions & 2 deletions log-shipper/budget.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ test('request representatives use the schema longest route and method; only node
assert.ok(representativeEvents.ingress.request_time_seconds >= 0 && representativeEvents.ingress.request_time_seconds <= 86400);
});

// test-ruling: TC-3739 log-shipper/budget.test.mjs new test only (2026-11-22)
test('DB accounting sizes only the status < 400 node line; the capped node line is the same record without it', () => {
const dbKeys = ['pool_wait_ms', 'query_time_ms', 'query_count'];
const { node, nodeCapped } = representativeEvents;
assert.ok(node.status < 400 && nodeCapped.status >= 400);
for (const key of dbKeys) {
assert.equal(Object.hasOwn(node, key), true);
assert.equal(Object.hasOwn(nodeCapped, key), false);
const field = nodeSchema.fields[key];
assert.ok(node[key] >= field.min && node[key] <= field.max);
}
assert.equal(node.query_count, nodeSchema.fields.query_count.max);
const strip = ({ status, pool_wait_ms, query_time_ms, query_count, ...rest }) => rest;
assert.deepEqual(strip(node), strip(nodeCapped));
assert.ok(serializedEventBytes(node) > serializedEventBytes(nodeCapped));
});

test('exact serialized bytes account for newlines or singleton JSON array overhead', () => {
for (const row of Object.values(representativeEvents)) {
assert.equal(serializedEventBytes(row, 'ndjson'), Buffer.byteLength(`${JSON.stringify(row)}\n`));
Expand Down Expand Up @@ -122,9 +139,10 @@ test('capped classes: worst case is cap x worst-valid bytes x 43,200 minutes plu
const budget = calculateBudget({ requestsPerMinute: 0, framing });
const bytes = name => serializedEventBytes(representativeEvents[name], framing);
assert.equal(budget.cappedClasses.db_failure_5xx.bytes30Days, CAPPED_CLASSES.db_failure_5xx.capPerMinute * bytes('dbFailure') * 43200);
assert.equal(budget.cappedClasses.node_request_5xx.bytes30Days, CAPPED_CLASSES.node_request_5xx.capPerMinute * bytes('node') * 43200);
// test-ruling: TC-3739 log-shipper/budget.test.mjs capped node classes size from nodeCapped (status >= 400, no DB accounting), not node (2026-11-22)
assert.equal(budget.cappedClasses.node_request_5xx.bytes30Days, CAPPED_CLASSES.node_request_5xx.capPerMinute * bytes('nodeCapped') * 43200);
assert.equal(budget.cappedClasses.ingress_request_5xx.bytes30Days, CAPPED_CLASSES.ingress_request_5xx.capPerMinute * bytes('ingress') * 43200);
assert.equal(budget.cappedClasses.node_request_4xx.bytes30Days, CAPPED_CLASSES.node_request_4xx.capPerMinute * bytes('node') * 43200);
assert.equal(budget.cappedClasses.node_request_4xx.bytes30Days, CAPPED_CLASSES.node_request_4xx.capPerMinute * bytes('nodeCapped') * 43200);
assert.equal(budget.cappedClasses.ingress_request_4xx.bytes30Days, CAPPED_CLASSES.ingress_request_4xx.capPerMinute * bytes('ingress') * 43200);
assert.equal(budget.droppedCountBytes30Days, 5 * bytes('errorsDropped') * 43200);
assert.equal(budget.cappedReserveBytes30Days, budget.cappedEventBytes30Days + budget.droppedCountBytes30Days);
Expand Down
4 changes: 2 additions & 2 deletions log-shipper/canonical.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repo": "samgbafa/tinycloud-dev",
"revision": "4fc32a2f9a24526b8fae6329a04f54230753c8c8",
"revision": "29ee97f9ed7581dccb93b35cc4640d47ca75658e",
"path": "ops/logging/fields.json",
"sha256": "38dae8e0ce7794d9e626cab30b2b2ab205fce3498588e14b541d6e506e8c0ca4"
"sha256": "100f5294f831c3663c2b2b3acec8606e21029cef405dd45b20ae5d9abc5fc0b6"
}
8 changes: 8 additions & 0 deletions log-shipper/cases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export const vectorTests = [
...[['account_hash', `${goodHash}TC959_SYNTHETIC`], ['account_hash', `TC959_SYNTHETIC${goodHash}`], ['space_hash', `${goodSpace}0`], ['space_hash', `0${goodSpace}`], ['space_hash', `${goodSpace}\n`], ['space_hash', `${goodSpace}${goodSpace}`]].map(([key, value], i) => correlated(`${key} #${i}: with a valid 64-hex digest embedded in a longer string is dropped (${value.length} chars)`, envelope(nodeRequest({ [key]: value })), `.event == "node_request" && !exists(.${key})`)),
correlated('a diagnostic cannot carry correlation fields', envelope({ timestamp, level: 'WARN', target: 'tinycloud::runtime', fields: { message: 'invalid link bind address; LAN listener not started', request_id: goodId, account_hash: goodHash, space_hash: goodHash } }), '.event == "node_warning" && !exists(.request_id) && !exists(.account_hash) && !exists(.space_hash)'),
correlated('ingress rows never carry correlation fields', envelope(ingressRequest({ request_id: goodId, account_hash: goodHash, space_hash: goodHash }), 'tinycloud-ingress'), '.event == "ingress_request" && !exists(.request_id) && !exists(.account_hash) && !exists(.space_hash)'),
// test-ruling: TC-3739 log-shipper/cases.mjs new cases only (2026-11-22)
check('node request DB accounting ships as numbers within bounds', envelope(nodeRequest({ pool_wait_ms: 0.004, query_time_ms: 12.5, query_count: 9 })), '.event == "node_request" && .pool_wait_ms == 0.004 && .query_time_ms == 12.5 && .query_count == 9'),
check('integral DB timings and the schema maxima still ship', envelope(nodeRequest({ pool_wait_ms: 0, query_time_ms: 86400000, query_count: 9007199254740991 })), '.event == "node_request" && .pool_wait_ms == 0.0 && .query_time_ms == 86400000.0 && .query_count == 9007199254740991'),
check('out-of-bounds or mistyped DB accounting is dropped but the request ships', envelope(nodeRequest({ pool_wait_ms: -0.5, query_time_ms: '12.5', query_count: 1.5 })), '.event == "node_request" && .route == "/invoke" && !exists(.pool_wait_ms) && !exists(.query_time_ms) && !exists(.query_count)'),
check('DB timings above the canonical maximum are dropped', envelope(nodeRequest({ pool_wait_ms: 86400000.5, query_time_ms: 1e12, query_count: -1 })), '.event == "node_request" && !exists(.pool_wait_ms) && !exists(.query_time_ms) && !exists(.query_count)'),
...[399, 400, 404, 499, 500, 503, 599].map(status => check(`DB accounting ships on status ${status} only below 400`, envelope(nodeRequest({ status, pool_wait_ms: 0.004, query_time_ms: 12.5, query_count: 9 })), status < 400
? `.event == "node_request" && .status == ${status} && .pool_wait_ms == 0.004 && .query_time_ms == 12.5 && .query_count == 9`
: `.event == "node_request" && .status == ${status} && !exists(.pool_wait_ms) && !exists(.query_time_ms) && !exists(.query_count)`)),
check('known warning strips all free text', envelope({ timestamp, level: 'WARN', target: 'tinycloud::runtime', fields: { message: 'invalid link bind address; LAN listener not started', err: canary, bind: canary } }), '.event == "node_warning" && .event_code == "link_bind_invalid" && .event_count == 1'),
check('unmatched warning becomes typed unclassified', envelope({ timestamp, level: 'WARN', target: 'tinycloud::tunnel::connection', fields: { message: canary, remote: canary } }), '.event == "node_warning" && .event_code == "unclassified" && .event_count == 1'),
check('application error remains typed without error value', envelope({ timestamp, level: 'ERROR', target: 'tinycloud::share_email', fields: { message: 'native share KV put failed', failure: canary } }), '.event == "node_error" && .event_code == "share_native_kv_put_failed" && .event_count == 1'),
Expand Down
Loading
Loading