From 8d548af59f130546996ace21f6f0b99e49989785 Mon Sep 17 00:00:00 2001 From: Dexter Date: Thu, 29 Oct 2026 14:02:13 +0800 Subject: [PATCH 1/7] di.compression: stamp a VERSION The module shipped without one, so depcheck reports any module declaring a dependency on it as "has no VERSION file" and fails the pre-load version graph. di.torq.proc.compression needs to declare that dependency. 0.1.0 - a first stamp for the module as it stands, not a behaviour change. Co-Authored-By: Claude Opus 5 --- di/compression/VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 di/compression/VERSION diff --git a/di/compression/VERSION b/di/compression/VERSION new file mode 100644 index 00000000..6e8bf73a --- /dev/null +++ b/di/compression/VERSION @@ -0,0 +1 @@ +0.1.0 From 1a6c36a3b1d7bfcfba94444481ff5125f873abea Mon Sep 17 00:00:00 2001 From: Dexter Date: Thu, 29 Oct 2026 14:02:13 +0800 Subject: [PATCH 2/7] di.torq.proc.compression: one-shot hdb compression process type Ports TorQ's code/processes/compression.q and config/settings/compression.q. The compression engine itself was already ported as di.compression; this is the process wrapper around it - config resolution, hdb path validation and the one-shot lifecycle - plus the framework settings tier and an entry in di.torq's built-in proctype registry, without which the proctype cannot start at all. The pass runs from di.torq's runhook as .compression.run[], not from init: init must not exit, since torqx.sh owns the process lifecycle. Keeping the pass in its own .compression.compressnow[] leaves it re-triggerable over IPC without terminating the process - the same split di.torq's sample loader uses. A hdbpath that does not exist is refused at init. Without that the partition traverse returns nothing and the run reports success having compressed zero columns, which reads exactly like a correct no-op. Documents one inherited divergence, not changed here: di.compression's loadcsv traps its own checkcsv, so an invalid algorithm is logged and the run continues, where TorQ lets it throw and abort. The suite asserts the current behaviour so that changing it fails deliberately. Tests build a real two-partition hdb and assert with -21! that the configured column is compressed and an unconfigured one is not. Co-Authored-By: Claude Opus 5 --- di/torq/proc/compression/VERSION | 1 + di/torq/proc/compression/compression.md | 118 ++++++++++++++++++++++++ di/torq/proc/compression/compression.q | 90 ++++++++++++++++++ di/torq/proc/compression/deps.toml | 3 + di/torq/proc/compression/init.q | 5 + di/torq/proc/compression/test.csv | 34 +++++++ di/torq/proc/compression/test.q | 65 +++++++++++++ di/torq/settings/compression.q | 7 ++ di/torq/torq.q | 2 +- 9 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 di/torq/proc/compression/VERSION create mode 100644 di/torq/proc/compression/compression.md create mode 100644 di/torq/proc/compression/compression.q create mode 100644 di/torq/proc/compression/deps.toml create mode 100644 di/torq/proc/compression/init.q create mode 100644 di/torq/proc/compression/test.csv create mode 100644 di/torq/proc/compression/test.q create mode 100644 di/torq/settings/compression.q diff --git a/di/torq/proc/compression/VERSION b/di/torq/proc/compression/VERSION new file mode 100644 index 00000000..6e8bf73a --- /dev/null +++ b/di/torq/proc/compression/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/di/torq/proc/compression/compression.md b/di/torq/proc/compression/compression.md new file mode 100644 index 00000000..ecad314b --- /dev/null +++ b/di/torq/proc/compression/compression.md @@ -0,0 +1,118 @@ +# di.torq.proc.compression + +A one-shot process type that compresses an existing hdb. It walks the partitions up to a maximum +age and rewrites every column named in a compression config csv, using the algorithm, block size +and level that csv gives it. + +Ported from TorQ's `code/processes/compression.q` and `config/settings/compression.q`. + +The compression itself is **not** here — it lives in `di.compression`, which was ported +separately. This module is the process wrapper: config resolution, validation, and the one-shot +run/exit lifecycle. + +## Dependencies + +| | | +|---|---| +`log` | injected by di.torq, required | +`di.compression` | the compression engine, `use`d directly | + +## Config + +Defaults ship in `di/torq/settings/compression.q`; an app overrides them per proctype or +procname, or on the command line. + +| setting | default | meaning | +|---|---|---| +`csvpath` | `:appconfig/compressionconfig.csv` | the compression config csv. Resolved under `TORQXAPPHOME` — it is config, not data | +`hdbpath` | `:hdb` | hdb root to compress. Resolved under `TORQXDATAHOME`, falling back to `TORQXAPPHOME` | +`maxage` | `365` | only scan partitions this many days old or newer | +`exitonfinish` | `1b` | exit the process when the pass completes | + +### Migrating from TorQ + +| TorQ | here | +|---|---| +`.cmp.inputcsv` | `csvpath` — renamed to match `di.compression`'s own `compressmaxage[hdbpath;csvpath;maxage]` parameter | +`.cmp.hdbpath` | `hdbpath` | +`.cmp.maxage` | `maxage` | +`.cmp.exitonfinish` | `exitonfinish` | + +TorQ's settings file also switched off `.usage`, `.clients`, `.servers` and `.hb`. Here those are +ordinary settings sections, so an app turns them off in its own `compression.toml` if it wants +them off — the framework tier does not force it. + +## The compression csv + +Unchanged from TorQ, and read by `di.compression`, not by this module: + +``` +table,minage,column,calgo,cblocksize,clevel +trade,0,price,2,17,5 +``` + +`calgo` is kdb's algorithm number (0 none, 1 ipc, 2 gzip, 3 snappy on 3.4+), `cblocksize` the +power-of-two block size 12–19, `clevel` 0–9. + +## Behaviour + +The pass runs from di.torq's post-init hook as `.compression.run[]`, **not** from `init`. + +- `init` must not exit — `torqx.sh` owns the process lifecycle, and exiting from inside `init` + would fight it. This is the same reasoning `di.torq.proc.housekeeping` gives for declining to + port legacy's one-shot mode. +- keeping the pass in its own function leaves it re-triggerable by hand or over IPC as + `.compression.compressnow[]`, without killing the session. + +Both names are published at real root names, because `use`-loading this module compiles it into a +private namespace where neither the runhook nor an IPC caller could reach them. + +### `process.csv` + +A batch job with no listening port: + +``` +host,port,proctype,procname,startwithall +localhost,0,compression,compression1,1 +``` + +### A bad hdb path is fatal + +`init` refuses a `hdbpath` that does not exist. Without that check the partition traverse simply +returns nothing and the run reports success having compressed zero columns — which reads exactly +like a correctly-configured no-op. + +## Known divergence: an invalid csv does not abort the run + +`di.compression.loadcsv` traps its own `checkcsv` and returns, logging an error: + +```q +res:.[checkcsv;(loadedcsv;string inputcsv);{.z.m.logerr[...];:0b}]; +if[res~0b;:(::)]; +``` + +TorQ's `loadcsv` calls `checkcsv[compressioncsv]` **untrapped**, so an invalid algorithm, block +size or level throws and aborts the run. + +So a misconfigured csv here is logged and skipped, and the pass continues with whatever config +was previously loaded — or none. The process still exits 0. This divergence predates this module +(it came in with `di.compression` itself) and is **not** changed here; it is recorded so that an +operator reading a successful compression log knows to check for an error line above it. The test +suite asserts the current behaviour rather than TorQ's, so changing it will fail a test +deliberately. + +## Testing + +```q +k4unit:use`di.k4unit +k4unit.moduletest`di.torq.proc.compression +``` + +The suite builds a real two-partition hdb under `/tmp`, compresses it, and asserts with `-21!` +that the configured column is compressed in both partitions while an unconfigured one is not. +It uses 200,000 rows per partition on purpose: kdb will not compress a file smaller than its +block size, so a token few rows would leave the test asserting on a no-op indistinguishable from +a failure. + +`run[]` is deliberately never called by the tests — with the default `exitonfinish` it would +terminate the test process. diff --git a/di/torq/proc/compression/compression.q b/di/torq/proc/compression/compression.q new file mode 100644 index 00000000..ff467b44 --- /dev/null +++ b/di/torq/proc/compression/compression.q @@ -0,0 +1,90 @@ +/ di.torq.proc.compression - one-shot hdb compression process type. Walks an hdb's partitions up +/ to a maximum age and rewrites each column named in a compression config csv using the algorithm, +/ block size and level that csv gives it. Ported from TorQ/code/processes/compression.q. +/ --- +/ The compression itself lives in di.compression; this module is only the process wrapper around +/ it - config resolution, validation of the hdb path, and the one-shot run/exit lifecycle. +/ --- +/ Lifecycle: the pass runs from di.torq's post-init runhook as .compression.run[], NOT from init. +/ init must not exit - torqx.sh owns this process's lifecycle, and exiting from inside init would +/ fight it (the same reason di.torq.proc.housekeeping declined to port legacy's one-shot mode). +/ Keeping the pass in its own named function also leaves it re-triggerable by hand or over IPC as +/ .compression.compressnow[] without killing the session. Same split di.torq's sample loader uses. + +/ has init run? probes .z.m.log, which has no load-time default - only init ever sets it - via a +/ trap rather than a `in key .z.m` test, so it cannot be confused by how module state is shaped. +initialised:{[] @[{.z.m.log;1b};::;{[e] 0b}]} + +/ an exported function that touches injected deps or config refuses to run before init wired them, +/ so a pre-init call says what the real mistake was instead of dying on an unset .z.m.hdbpath. +requireinit:{[ctx] + if[not initialised[]; + '"di.torq.proc.compression: ",string[ctx],": init must be called before any other function"]; + } + +/ config arrives from a .q settings file (typed) or a .toml one (string/long), so coerce both. +/ Same shape as di.permissions' own helpers. +asbool:{[x] $[-1h=type x;x;10h=abs type x;first "B"$(),x;-7h=type x;0<>x;0b]} +aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]} + +/ base dirs: code/config under TORQXAPPHOME, runtime data under TORQXDATAHOME falling back to it +apphome:{getenv[`TORQXAPPHOME]} +datahome:{$[count h:getenv[`TORQXDATAHOME];h;getenv[`TORQXAPPHOME]]} + +/ resolve a possibly-relative path setting to an absolute path string under base. Same body as +/ di.torq.proc.wdb's resolvedir - accepts a `.q` settings symbol (`:x) or a colon-less `.toml` +/ string ("x") and normalises both. +resolvedir:{[base;dir] + dir:$[10h=abs type dir;dir;string dir]; + dir:$[(0 algo, block, level) +hdbpath:`:hdb / hdb root to compress, under TORQXDATAHOME +maxage:365 / only scan partitions this many days old or newer +exitonfinish:1b / exit when the pass completes diff --git a/di/torq/torq.q b/di/torq/torq.q index 44e93d88..a7fb74c2 100644 --- a/di/torq/torq.q +++ b/di/torq/torq.q @@ -4,7 +4,7 @@ / same init[config;deps] calling convention. / built-in process type registry: proctype -> di.* module name -builtin:`hdb`tickerplant`rdb`wdb`sort`gateway`idb`segmentedtp`chainedtp`housekeeping`sortworker`discovery`tickerlogreplay`segmentedchainedtp!`di.torq.proc.hdb`di.torq.proc.tickerplant`di.torq.proc.rdb`di.torq.proc.wdb`di.torq.proc.wdb`di.torq.proc.gateway`di.torq.proc.idb`di.torq.proc.segmentedtp`di.torq.proc.chainedtp`di.torq.proc.housekeeping`di.torq.proc.wdb`di.torq.proc.discovery`di.torq.proc.tickerlogreplay`di.torq.proc.segmentedtp +builtin:`hdb`tickerplant`rdb`wdb`sort`gateway`idb`segmentedtp`chainedtp`housekeeping`sortworker`discovery`tickerlogreplay`segmentedchainedtp`compression!`di.torq.proc.hdb`di.torq.proc.tickerplant`di.torq.proc.rdb`di.torq.proc.wdb`di.torq.proc.wdb`di.torq.proc.gateway`di.torq.proc.idb`di.torq.proc.segmentedtp`di.torq.proc.chainedtp`di.torq.proc.housekeeping`di.torq.proc.wdb`di.torq.proc.discovery`di.torq.proc.tickerlogreplay`di.torq.proc.segmentedtp`di.torq.proc.compression reqenv:{[e] v:getenv e; From d952772bba8ebb1fce775104219cbd0560164c7b Mon Sep 17 00:00:00 2001 From: Dexter Date: Mon, 2 Nov 2026 13:51:45 +0800 Subject: [PATCH 3/7] di.torq.proc.compression: address review on #149 1. Trim comments to concise what-only, matching #148's repo-wide pass. 47 comment lines -> 13. The rationale already lives in compression.md. 2. Derive the test fixture's partitions from .z.D. They were fixed at 2026.01.01/02, so from 2027.01.02 they fall outside the maxage window and the compression assertions would have started failing. 3. Ship maxage 30, not 365. TorQ's code default is 365 but its config/settings/compression.q sets 30, so a stock TorQ process scans 30 days - 365 was a parity miss. Recorded in "Migrating from TorQ". 4. Actually assert the code defaults. The comments claimed the tests checked them; nothing did. Both are now asserted from the init log after an init that supplies neither. Also: - add a partition outside the maxage window and assert it is left alone - csvpath's unreachable code default used TORQXAPPCONFIG while the shipped setting resolves under TORQXAPPHOME; both now use TORQXAPPHOME - compression.md's process.csv example had startwithall=1, which would rewrite the hdb on every stack start - torq.md's two proctype lists did not mention compression - the toml test rows recompressed already-compressed files and passed native types, so the string branches never ran; the fixture is rebuilt first and maxage/exitonfinish are passed as text Four suites green; the process still boots and exits on the POC stack. Co-Authored-By: Claude Opus 5 --- di/torq/proc/compression/compression.md | 6 +-- di/torq/proc/compression/compression.q | 57 +++++++------------------ di/torq/proc/compression/test.csv | 39 ++++++++++------- di/torq/proc/compression/test.q | 43 ++++++++++--------- di/torq/settings/compression.q | 5 +-- di/torq/torq.md | 6 +-- 6 files changed, 70 insertions(+), 86 deletions(-) diff --git a/di/torq/proc/compression/compression.md b/di/torq/proc/compression/compression.md index ecad314b..085acd84 100644 --- a/di/torq/proc/compression/compression.md +++ b/di/torq/proc/compression/compression.md @@ -26,7 +26,7 @@ procname, or on the command line. |---|---|---| `csvpath` | `:appconfig/compressionconfig.csv` | the compression config csv. Resolved under `TORQXAPPHOME` — it is config, not data | `hdbpath` | `:hdb` | hdb root to compress. Resolved under `TORQXDATAHOME`, falling back to `TORQXAPPHOME` | -`maxage` | `365` | only scan partitions this many days old or newer | +`maxage` | `30` | only scan partitions this many days old or newer | `exitonfinish` | `1b` | exit the process when the pass completes | ### Migrating from TorQ @@ -35,7 +35,7 @@ procname, or on the command line. |---|---| `.cmp.inputcsv` | `csvpath` — renamed to match `di.compression`'s own `compressmaxage[hdbpath;csvpath;maxage]` parameter | `.cmp.hdbpath` | `hdbpath` | -`.cmp.maxage` | `maxage` | +`.cmp.maxage` | `maxage` — ships `30`, as TorQ's settings file does (its code default of 365 is overridden there) | `.cmp.exitonfinish` | `exitonfinish` | TorQ's settings file also switched off `.usage`, `.clients`, `.servers` and `.hb`. Here those are @@ -73,7 +73,7 @@ A batch job with no listening port: ``` host,port,proctype,procname,startwithall -localhost,0,compression,compression1,1 +localhost,0,compression,compression1,0 ``` ### A bad hdb path is fatal diff --git a/di/torq/proc/compression/compression.q b/di/torq/proc/compression/compression.q index ff467b44..babd0f9d 100644 --- a/di/torq/proc/compression/compression.q +++ b/di/torq/proc/compression/compression.q @@ -1,48 +1,30 @@ -/ di.torq.proc.compression - one-shot hdb compression process type. Walks an hdb's partitions up -/ to a maximum age and rewrites each column named in a compression config csv using the algorithm, -/ block size and level that csv gives it. Ported from TorQ/code/processes/compression.q. -/ --- -/ The compression itself lives in di.compression; this module is only the process wrapper around -/ it - config resolution, validation of the hdb path, and the one-shot run/exit lifecycle. -/ --- -/ Lifecycle: the pass runs from di.torq's post-init runhook as .compression.run[], NOT from init. -/ init must not exit - torqx.sh owns this process's lifecycle, and exiting from inside init would -/ fight it (the same reason di.torq.proc.housekeeping declined to port legacy's one-shot mode). -/ Keeping the pass in its own named function also leaves it re-triggerable by hand or over IPC as -/ .compression.compressnow[] without killing the session. Same split di.torq's sample loader uses. +/ one-shot hdb compression process type - compresses an hdb once at startup, then exits -/ has init run? probes .z.m.log, which has no load-time default - only init ever sets it - via a -/ trap rather than a `in key .z.m` test, so it cannot be confused by how module state is shaped. +/ has init run? initialised:{[] @[{.z.m.log;1b};::;{[e] 0b}]} -/ an exported function that touches injected deps or config refuses to run before init wired them, -/ so a pre-init call says what the real mistake was instead of dying on an unset .z.m.hdbpath. +/ refuse an exported call before init has wired the deps and config requireinit:{[ctx] if[not initialised[]; '"di.torq.proc.compression: ",string[ctx],": init must be called before any other function"]; } -/ config arrives from a .q settings file (typed) or a .toml one (string/long), so coerce both. -/ Same shape as di.permissions' own helpers. +/ coerce a config value that may arrive typed (.q) or as text (.toml) asbool:{[x] $[-1h=type x;x;10h=abs type x;first "B"$(),x;-7h=type x;0<>x;0b]} aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]} -/ base dirs: code/config under TORQXAPPHOME, runtime data under TORQXDATAHOME falling back to it +/ code and config under TORQXAPPHOME, runtime data under TORQXDATAHOME apphome:{getenv[`TORQXAPPHOME]} datahome:{$[count h:getenv[`TORQXDATAHOME];h;getenv[`TORQXAPPHOME]]} -/ resolve a possibly-relative path setting to an absolute path string under base. Same body as -/ di.torq.proc.wdb's resolvedir - accepts a `.q` settings symbol (`:x) or a colon-less `.toml` -/ string ("x") and normalises both. +/ resolve a possibly-relative path setting to an absolute path string under base resolvedir:{[base;dir] dir:$[10h=abs type dir;dir;string dir]; dir:$[(0 algo, block, level) hdbpath:`:hdb / hdb root to compress, under TORQXDATAHOME -maxage:365 / only scan partitions this many days old or newer +maxage:30 / only scan partitions this many days old or newer exitonfinish:1b / exit when the pass completes diff --git a/di/torq/torq.md b/di/torq/torq.md index 76527af3..44f6d918 100644 --- a/di/torq/torq.md +++ b/di/torq/torq.md @@ -86,13 +86,13 @@ expects. ### Process-type dispatch A built-in registry maps proctype → module name, `` `x → `di.torq.proc.x `` for each of `hdb`, -`tickerplant`, `rdb`, `wdb`, `gateway`, `idb`, `segmentedtp`, `chainedtp`, `housekeeping`, `discovery` -and `tickerlogreplay`; `segmentedchainedtp` also maps to `di.torq.proc.segmentedtp` and resolves the +`tickerplant`, `rdb`, `wdb`, `gateway`, `idb`, `segmentedtp`, `chainedtp`, `housekeeping`, `discovery`, +`tickerlogreplay` and `compression`; `segmentedchainedtp` also maps to `di.torq.proc.segmentedtp` and resolves the `segmentedtp` settings tier (builtin and app root alike); its chained behaviour comes from the instance's own settings, e.g. `sctp1.toml`, as any other per-instance distinction does: ```q -builtin:`hdb`tickerplant`rdb`wdb`gateway`idb`segmentedtp`chainedtp`housekeeping`discovery`tickerlogreplay`segmentedchainedtp!`di.torq.proc.hdb`di.torq.proc.tickerplant ... +builtin:`hdb`tickerplant`rdb`wdb`gateway`idb`segmentedtp`chainedtp`housekeeping`discovery`tickerlogreplay`segmentedchainedtp`compression!`di.torq.proc.hdb`di.torq.proc.tickerplant ... ``` If `proctype` is in `builtin`, `startbuiltin` `use`-loads that module and calls its From f180f553c6eb1b8d4e8080730a0180f900d2baf0 Mon Sep 17 00:00:00 2001 From: Dexter Date: Mon, 2 Nov 2026 14:01:38 +0800 Subject: [PATCH 4/7] address the remaining review items on #149 6. Ship a default compression csv (di/torq/compressionconfig.csv, the same default,10,default,1,16,0 TorQ ships) and fall back to it when the app has none. Previously an app without its own csv failed. 8. asbool read only "1" as true, so a quoted exitonfinish = "true" in a toml silently meant false. It now accepts true/false/1/0 in any case and throws on anything else rather than guessing. Fixed in di.permissions too, where the same copy meant a quoted enabled = "true" would have left access control off with no warning. 10. init resolved and assigned module state before validating the hdb path, so a failed init left initialised[] true and compressnow died on an unset .z.m.cmp. Everything is resolved into locals and validated first. 12. A pass that logged errors exited 0, which for a scheduled batch job reads as success. The injected error logger is now counted and run exits 1 if the pass logged any. errorcount is exported. 14. di/torq VERSION 0.5.0 -> 0.6.0, since the built-in registry gained a proctype. di.permissions 0.1.0 -> 0.2.0 for the asbool change. Tests cover the framework-csv fallback, the bad-boolean refusal, the error count, and the toml path now passes "true"/"false" as text rather than native types, so the string branches actually run. Six suites green; the POC stack starts clean and still enforces permissions. Co-Authored-By: Claude Opus 5 --- di/permissions/VERSION | 2 +- di/permissions/permissions.q | 10 +++- di/torq/VERSION | 2 +- di/torq/compressionconfig.csv | 2 + di/torq/proc/compression/compression.q | 65 +++++++++++++++++++------- di/torq/proc/compression/init.q | 2 +- di/torq/proc/compression/test.csv | 6 +++ di/torq/proc/compression/test.q | 8 +++- 8 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 di/torq/compressionconfig.csv diff --git a/di/permissions/VERSION b/di/permissions/VERSION index 6e8bf73a..0ea3a944 100644 --- a/di/permissions/VERSION +++ b/di/permissions/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/di/permissions/permissions.q b/di/permissions/permissions.q index adee9ad0..2ef53dde 100644 --- a/di/permissions/permissions.q +++ b/di/permissions/permissions.q @@ -14,7 +14,15 @@ / is permitted rather than refused. / config coercion - a .toml tier gives strings, a .q tier gives typed values -asbool:{[x] $[-1h=type x;x;10h=abs type x;first "B"$(),x;-7h=type x;0<>x;0b]}; +asbool:{[x] + if[-1h=type x;:x]; + if[-7h=type x;:0<>x]; + if[10h<>abs type x;:0b]; + s:`$lower (),x; + $[s in `1`true;1b; + s in `0`false;0b; + '"di.permissions: cannot read \"",(string s),"\" as a boolean - use true or false"] + }; aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]}; / wildcard/superuser marker for functions and data diff --git a/di/torq/VERSION b/di/torq/VERSION index 79a2734b..a918a2aa 100644 --- a/di/torq/VERSION +++ b/di/torq/VERSION @@ -1 +1 @@ -0.5.0 \ No newline at end of file +0.6.0 diff --git a/di/torq/compressionconfig.csv b/di/torq/compressionconfig.csv new file mode 100644 index 00000000..0efc5573 --- /dev/null +++ b/di/torq/compressionconfig.csv @@ -0,0 +1,2 @@ +table,minage,column,calgo,cblocksize,clevel +default,10,default,1,16,0 diff --git a/di/torq/proc/compression/compression.q b/di/torq/proc/compression/compression.q index babd0f9d..c1ad1e7d 100644 --- a/di/torq/proc/compression/compression.q +++ b/di/torq/proc/compression/compression.q @@ -10,7 +10,16 @@ requireinit:{[ctx] } / coerce a config value that may arrive typed (.q) or as text (.toml) -asbool:{[x] $[-1h=type x;x;10h=abs type x;first "B"$(),x;-7h=type x;0<>x;0b]} +asbool:{[x] + if[-1h=type x;:x]; + if[-7h=type x;:0<>x]; + if[10h<>abs type x;:0b]; + s:`$lower (),x; + $[s in `1`true;1b; + s in `0`false;0b; + '"di.torq.proc.compression: cannot read \"",(string s),"\" as a boolean - use true or false"] + } + aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]} / code and config under TORQXAPPHOME, runtime data under TORQXDATAHOME @@ -24,42 +33,66 @@ resolvedir:{[base;dir] $[dir like "/*";dir;base,"/",dir] } +/ the app's compression csv if it exists, else the one this framework ships +resolvecsv:{[config] + p:hsym `$resolvedir[apphome[];$[`csvpath in key config;config`csvpath;"appconfig/compressionconfig.csv"]]; + $[count key p;p;hsym `$getenv[`TORQXHOME],"/di/torq/compressionconfig.csv"] + } + +/ count errors logged during a pass, so run can exit non-zero +counterrors:{[logdep] + logdep,enlist[`error]!enlist {[f;c;m] .z.m.errors+:1; f[c;m]}[logdep`error] + } + / run one compression pass - re-triggerable, does not exit compressnow:{[] requireinit[`compressnow]; + .z.m.errors:0; .z.m.log[`info][`compression;"compressing ",(string .z.m.hdbpath)," using ",string .z.m.csvpath]; (.z.m.cmp`compressmaxage)[.z.m.hdbpath;.z.m.csvpath;.z.m.maxage]; .z.m.log[`info][`compression;"finished compression"]; } -/ di.torq's post-init hook - compress, then exit unless told to stay up +/ di.torq's post-init hook - compress, then exit unless told to stay up. +/ a pass that logged errors exits non-zero, so a scheduler does not read it as success. run:{[] compressnow[]; - if[.z.m.exitonfinish; - .z.m.log[`info][`compression;"exitonfinish set, exiting"]; - exit 0]; + if[not .z.m.exitonfinish;:()]; + if[.z.m.errors>0; + .z.m.log[`warn][`compression;"exiting 1 - ",(string .z.m.errors)," error(s) during compression"]; + exit 1]; + .z.m.log[`info][`compression;"exitonfinish set, exiting"]; + exit 0; } / di.compression's post-compression summary table getstatstab:{[] requireinit[`getstatstab]; (.z.m.cmp`getstatstab)[]} +/ how many errors the last pass logged +errorcount:{[] requireinit[`errorcount]; .z.m.errors} + init:{[config;deps] - / wire deps, resolve config, load di.compression and publish the IPC surface + / resolve and validate first, so a failed init leaves no half-set state if[not `log in key deps;'"di.torq.proc.compression: log dependency is required - see di.util.log"]; - .z.m.log:deps`log; - .z.m.hdbpath:hsym `$resolvedir[datahome[];$[`hdbpath in key config;config`hdbpath;"hdb"]]; - .z.m.csvpath:hsym `$resolvedir[apphome[];$[`csvpath in key config;config`csvpath;"appconfig/compressionconfig.csv"]]; + lg:deps`log; + hp:hsym `$resolvedir[datahome[];$[`hdbpath in key config;config`hdbpath;"hdb"]]; + cp:resolvecsv config; / defaults must agree with di/torq/settings/compression.q - test.csv asserts both halves - .z.m.maxage:$[`maxage in key config;aslong config`maxage;30]; - .z.m.exitonfinish:$[`exitonfinish in key config;asbool config`exitonfinish;1b]; + ma:$[`maxage in key config;aslong config`maxage;30]; + eof:$[`exitonfinish in key config;asbool config`exitonfinish;1b]; / a bad hdb path otherwise compresses nothing and reports success - if[not count key .z.m.hdbpath; - .z.m.log[`error][`compression;e:"invalid hdb path ",string .z.m.hdbpath];'e]; + if[not count key hp;lg[`error][`compression;e:"invalid hdb path ",string hp];'e]; + .z.m.errors:0; + .z.m.log:counterrors lg; + .z.m.hdbpath:hp; + .z.m.csvpath:cp; + .z.m.maxage:ma; + .z.m.exitonfinish:eof; .z.m.cmp:use`di.compression; - (.z.m.cmp`init)[enlist[`log]!enlist deps`log]; + (.z.m.cmp`init)[enlist[`log]!enlist .z.m.log]; / root names, so di.torq's runhook and IPC callers can reach them set[`.compression.run;run]; set[`.compression.compressnow;compressnow]; - .z.m.log[`info][`init;"initialised, hdbpath=",(string .z.m.hdbpath),", csvpath=",(string .z.m.csvpath), - ", maxage=",(string .z.m.maxage),", exitonfinish=",string .z.m.exitonfinish]; + .z.m.log[`info][`init;"initialised, hdbpath=",(string hp),", csvpath=",(string cp), + ", maxage=",(string ma),", exitonfinish=",string eof]; } diff --git a/di/torq/proc/compression/init.q b/di/torq/proc/compression/init.q index 37242c14..0632bbb3 100644 --- a/di/torq/proc/compression/init.q +++ b/di/torq/proc/compression/init.q @@ -2,4 +2,4 @@ version:first read0`:::VERSION -export:([init;compressnow;getstatstab;version]) +export:([init;compressnow;getstatstab;errorcount;version]) diff --git a/di/torq/proc/compression/test.csv b/di/torq/proc/compression/test.csv index 73040dd7..0452b4c9 100644 --- a/di/torq/proc/compression/test.csv +++ b/di/torq/proc/compression/test.csv @@ -32,10 +32,16 @@ run,0,0,q,setupfixture[],1,, run,0,0,q,cmp[`init][tomlcfg[];mockdeps[]],1,,init accepts the string values a .toml settings file delivers run,0,0,q,cmp[`compressnow][],1,,and compresses with them true,0,0,q,compressed[PARTS 0;`price],1,,the string-valued maxage was coerced and the pass ran +fail,0,0,q,cmp[`init][badboolcfg[];mockdeps[]],1,,a boolean setting that is neither true/false nor 1/0 must error rather than silently read as false + +run,0,0,q,cmp[`init][nocsvcfg[];mockdeps[]],1,,an app with no compression csv falls back to the one the framework ships +true,0,0,q,initlog[] like "*di/torq/compressionconfig.csv*",1,,and the init log names it run,0,0,q,writebadalgocsv[],1,,swap in a csv naming an unsupported algorithm +run,0,0,q,cmp[`init][basecfg[];mockdeps[]],1,,point back at the fixture csv - the previous row inited against the framework one run,0,0,q,resetcalls[],1,,clear the captured log run,0,0,q,cmp[`compressnow][],1,,an invalid algorithm is logged and skipped rather than thrown - see compression.md true,0,0,q,0 Date: Mon, 2 Nov 2026 14:43:20 +0800 Subject: [PATCH 5/7] error on any type asbool cannot read Carries the same fix made on #150 into the two copies this branch still owns, so #149 does not ship a known silent-false. DIReview raised it against di.util.cfg: a value that is not a boolean, long or string fell through the type guard to 0b. The symbol case it named is not the worst one: asbool 1i -> 0b an int 1 read as FALSE asbool 1h -> 0b asbool `true -> 0b asbool (::) -> 0b In di.permissions that meant a .q settings tier writing enabled:1i left access control off with no warning. Numeric atoms are now accepted, nonzero being true; every other type errors, naming the type. Both copies are superseded by di.util.cfg once #150 and this merge. Three suites green; the POC stack starts clean and still enforces. Co-Authored-By: Claude Opus 5 --- di/permissions/permissions.q | 13 +++++++------ di/torq/proc/compression/compression.q | 13 +++++++------ di/torq/proc/compression/test.csv | 1 + di/torq/proc/compression/test.q | 3 +++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/di/permissions/permissions.q b/di/permissions/permissions.q index 2ef53dde..e454ca07 100644 --- a/di/permissions/permissions.q +++ b/di/permissions/permissions.q @@ -16,12 +16,13 @@ / config coercion - a .toml tier gives strings, a .q tier gives typed values asbool:{[x] if[-1h=type x;:x]; - if[-7h=type x;:0<>x]; - if[10h<>abs type x;:0b]; - s:`$lower (),x; - $[s in `1`true;1b; - s in `0`false;0b; - '"di.permissions: cannot read \"",(string s),"\" as a boolean - use true or false"] + if[type[x] in -5 -6 -7 -9h;:0<>x]; + if[10h=abs type x; + s:`$lower (),x; + :$[s in `1`true;1b; + s in `0`false;0b; + '"di.permissions: cannot read \"",(string s),"\" as a boolean - use true or false"]]; + '"di.permissions: cannot read a value of type ",(string type x)," as a boolean - use true or false" }; aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]}; diff --git a/di/torq/proc/compression/compression.q b/di/torq/proc/compression/compression.q index c1ad1e7d..75582038 100644 --- a/di/torq/proc/compression/compression.q +++ b/di/torq/proc/compression/compression.q @@ -12,12 +12,13 @@ requireinit:{[ctx] / coerce a config value that may arrive typed (.q) or as text (.toml) asbool:{[x] if[-1h=type x;:x]; - if[-7h=type x;:0<>x]; - if[10h<>abs type x;:0b]; - s:`$lower (),x; - $[s in `1`true;1b; - s in `0`false;0b; - '"di.torq.proc.compression: cannot read \"",(string s),"\" as a boolean - use true or false"] + if[type[x] in -5 -6 -7 -9h;:0<>x]; + if[10h=abs type x; + s:`$lower (),x; + :$[s in `1`true;1b; + s in `0`false;0b; + '"di.torq.proc.compression: cannot read \"",(string s),"\" as a boolean - use true or false"]]; + '"di.torq.proc.compression: cannot read a value of type ",(string type x)," as a boolean - use true or false" } aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]} diff --git a/di/torq/proc/compression/test.csv b/di/torq/proc/compression/test.csv index 0452b4c9..9fcb47f0 100644 --- a/di/torq/proc/compression/test.csv +++ b/di/torq/proc/compression/test.csv @@ -33,6 +33,7 @@ run,0,0,q,cmp[`init][tomlcfg[];mockdeps[]],1,,init accepts the string values a . run,0,0,q,cmp[`compressnow][],1,,and compresses with them true,0,0,q,compressed[PARTS 0;`price],1,,the string-valued maxage was coerced and the pass ran fail,0,0,q,cmp[`init][badboolcfg[];mockdeps[]],1,,a boolean setting that is neither true/false nor 1/0 must error rather than silently read as false +fail,0,0,q,cmp[`init][symboolcfg[];mockdeps[]],1,,a symbol must error too - it used to fall through the type guard and read as false run,0,0,q,cmp[`init][nocsvcfg[];mockdeps[]],1,,an app with no compression csv falls back to the one the framework ships true,0,0,q,initlog[] like "*di/torq/compressionconfig.csv*",1,,and the init log names it diff --git a/di/torq/proc/compression/test.q b/di/torq/proc/compression/test.q index ec10f8ae..79965969 100644 --- a/di/torq/proc/compression/test.q +++ b/di/torq/proc/compression/test.q @@ -70,5 +70,8 @@ tomlcfg:{[] `csvpath`hdbpath`maxage`exitonfinish!(FIXTUREDIR,"/appconfig/compres / a boolean setting that is neither true/false nor 1/0 badboolcfg:{[] `csvpath`hdbpath`exitonfinish!(`$":",FIXTUREDIR,"/appconfig/compressionconfig.csv";`$":",FIXTUREDIR,"/hdb";"yes")} +/ a boolean setting given as a symbol, which used to read as a silent false +symboolcfg:{[] `csvpath`hdbpath`exitonfinish!(`$":",FIXTUREDIR,"/appconfig/compressionconfig.csv";`$":",FIXTUREDIR,"/hdb";`true)} + / a csvpath that does not exist, so resolvecsv falls back to the framework's shipped csv nocsvcfg:{[] `csvpath`hdbpath`exitonfinish!(`:no/such/compressionconfig.csv;`$":",FIXTUREDIR,"/hdb";0b)} From a649bf9c265547f90180410152ee3fa72d0410da Mon Sep 17 00:00:00 2001 From: Dexter Date: Mon, 2 Nov 2026 14:46:48 +0800 Subject: [PATCH 6/7] accept every numeric atom, not an arbitrary five Carries the #150 follow-up into the two copies this branch owns: the type list now covers -4h..-9h rather than omitting real (-8h) while accepting float, and uses (type x) to match the form used elsewhere. Co-Authored-By: Claude Opus 5 --- di/permissions/permissions.q | 2 +- di/torq/proc/compression/compression.q | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/di/permissions/permissions.q b/di/permissions/permissions.q index e454ca07..0f32f987 100644 --- a/di/permissions/permissions.q +++ b/di/permissions/permissions.q @@ -16,7 +16,7 @@ / config coercion - a .toml tier gives strings, a .q tier gives typed values asbool:{[x] if[-1h=type x;:x]; - if[type[x] in -5 -6 -7 -9h;:0<>x]; + if[(type x) in -4 -5 -6 -7 -8 -9h;:0<>x]; if[10h=abs type x; s:`$lower (),x; :$[s in `1`true;1b; diff --git a/di/torq/proc/compression/compression.q b/di/torq/proc/compression/compression.q index 75582038..7c10dbcc 100644 --- a/di/torq/proc/compression/compression.q +++ b/di/torq/proc/compression/compression.q @@ -12,7 +12,7 @@ requireinit:{[ctx] / coerce a config value that may arrive typed (.q) or as text (.toml) asbool:{[x] if[-1h=type x;:x]; - if[type[x] in -5 -6 -7 -9h;:0<>x]; + if[(type x) in -4 -5 -6 -7 -8 -9h;:0<>x]; if[10h=abs type x; s:`$lower (),x; :$[s in `1`true;1b; From 9a90c3b57b2e0456b2bdff6489cc6241adbd8aab Mon Sep 17 00:00:00 2001 From: Dexter Date: Tue, 3 Nov 2026 12:58:50 +0800 Subject: [PATCH 7/7] aslong: error on unparseable values; tidy comments A malformed maxage compressed nothing and exited 0; a malformed maxsize refused every query. aslong now errors, as wdb's tolong does. Co-Authored-By: Claude Opus 5.5 --- di/permissions/permissions.q | 6 +++++- di/permissions/test.csv | 1 + di/permissions/test.q | 3 +++ di/torq/proc/compression/compression.q | 21 +++++++++++--------- di/torq/proc/compression/test.csv | 1 + di/torq/proc/compression/test.q | 27 +++++++++++++------------- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/di/permissions/permissions.q b/di/permissions/permissions.q index 0f32f987..6157f700 100644 --- a/di/permissions/permissions.q +++ b/di/permissions/permissions.q @@ -24,7 +24,11 @@ asbool:{[x] '"di.permissions: cannot read \"",(string s),"\" as a boolean - use true or false"]]; '"di.permissions: cannot read a value of type ",(string type x)," as a boolean - use true or false" }; -aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]}; +aslong:{[x] + r:$[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]; + if[null r;'"di.permissions: cannot read \"",$[10h=abs type x;(),x;-3!x],"\" as a whole number"]; + r + }; / wildcard/superuser marker for functions and data ALL:`$"*"; diff --git a/di/permissions/test.csv b/di/permissions/test.csv index 920e8516..266efae1 100644 --- a/di/permissions/test.csv +++ b/di/permissions/test.csv @@ -81,6 +81,7 @@ true,0,0,q,`name`public`descrip`params`return~cols pm[`getapimeta][],1,,getapime true,0,0,q,all pm[`getapimeta][][`name] in key pm,1,,every documented name is an exported function comment,0,0,q,,1,,--- a dispatched payload q elides when stringified (di.asyncdispatch's shape) --- +fail,0,0,q,pm[`init][badmaxsizecfg[];mockdeps[]],1,,a maxsize that does not parse must error rather than refuse every result run,0,0,q,pm[`init][cfg[1b];mockdeps[]],1,,re-init with the defaults true,0,0,q,"runsok[`alice;elidedpayload[]]",1,,lamq's tokenizer must not signal on an elided function source true,0,0,q,"`.gw.addserverresult~first pm[`requ][`alice;elidedpayload[]]",1,,and the payload runs - it reports the result callback diff --git a/di/permissions/test.q b/di/permissions/test.q index 875f0274..1206e127 100644 --- a/di/permissions/test.q +++ b/di/permissions/test.q @@ -19,6 +19,9 @@ badlog:{[] enlist[`log]!enlist `info`warn!({[c;m]};{[c;m]})} cfg:{[e] (enlist`enabled)!enlist e} cfgwith:{[k;v] (`enabled`maxsize`runmode`permissivemode!(1b;200000000;1b;0b)),(enlist k)!enlist v} +/ a maxsize that does not parse +badmaxsizecfg:{[] cfgwith[`maxsize;"2e8x"]} + / which events got an exec owner execevents:{[] asc exec event from reg where phase=`exec} pcregistered:{[] 0