Skip to content

di.torq.proc.compression: one-shot hdb compression process type - #149

Merged
DI-Dexter merged 7 commits into
DataIntellectTech:mainfrom
DI-Dexter:di-compression-proc
Nov 4, 2026
Merged

DI-Dexter merged 7 commits into
DataIntellectTech:mainfrom
DI-Dexter:di-compression-proc

Conversation

@DI-Dexter

@DI-Dexter DI-Dexter commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Ports TorQ's code/processes/compression.q and config/settings/compression.q.

The compression engine was already ported as di.compression (#82). This adds the missing half: the process type that drives it, so compression can actually be started as a TorqX process.

What's here

di/torq/proc/compression/ the process module — config resolution, hdb validation, one-shot lifecycle
di/torq/settings/compression.q framework defaults (csvpath, hdbpath, maxage, exitonfinish)
di/torq/torq.q one entry in the built-in proctype registry — without it the proctype cannot start at all
di/compression/VERSION the module shipped without one, so depcheck rejects any dependency declared on it

Design notes

The pass runs from runhook as .compression.run[], not from init. init must not exit — torqx.sh owns the process lifecycle. Keeping the work in .compression.compressnow[] leaves it re-triggerable over IPC without terminating the process. Same split di.torq's sample loader uses.

A hdbpath that does not exist is refused at init. Without that check the partition traverse returns nothing and the run reports success having compressed zero columns — indistinguishable from a correct no-op.

DI-Dexter and others added 2 commits October 30, 2026 15:04
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 0 warning(s) | 1 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/torq/proc/compression/compression.q:75 — The variable e is used before it is defined on the same line. The expression e:"invalid hdb path ",string .z.m.hdbpath assigns and then uses e in 'e, but e is referenced inside the if[...] list before the assignment executes — specifically, .z.m.log[error][compression;e:...] will log e and assign it in one statement, then 'e throws it. However, if key .z.m.hdbpath throws (e.g. because the path is malformed in a way key can't handle), neither log nor throw runs and the error is uncaught. More concretely: e is a local only within this lambda-less init function body, so it leaks as a global if q's scoping treats it that way. The real issue is the unprotected key .z.m.hdbpath call — wrap it: @[{not count key x};.z.m.hdbpath;{1b}] so a bad path string that errors in key is still caught.

@DI-Dexter
DI-Dexter requested a review from alowrydi October 30, 2026 09:12

@alowrydi alowrydi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the suite (21/21) and smoke-tested against the TorqX-POC stack: one-shot lifecycle, root publishing for runhook, and the hdb-path check all behave. Compressed a real 26-partition hdb (338MB saved, data verified readable after).

What's good

  • Faithful port: the four settings map one-to-one to TorQ (inputcsv is renamed csvpath), and the invalid-hdb-path check matches TorQ's.
  • The lifecycle is right: the exit lives in run, which runhook calls after the full init, and compressnow stays re-triggerable over IPC without killing the process.
  • Registry entry, root-published .compression.run/.compression.compressnow, and the di.compression VERSION stamp (so depcheck stops rejecting it) are all in place.
  • The test builds a real two-partition hdb and checks with -21! that the configured column is compressed and an unconfigured one isn't - and the 200k-row reasoning (kdb won't compress below block size) is exactly the trap a lazier test would fall into.
  • compression.md is clear, and the inherited csv-validation divergence is documented rather than hidden.
  • Real-data run worked end to end: compressed, verified readable, and the process exited cleanly.

Nothing structural needs reworking. The four blocking items below are quick, mostly mechanical edits (trim comments, fix fixture dates, settle one default, add one assertion). I'd expect to approve once 1-4 are addressed.

Blocking

  • 1. Comments are too long. Many of them explain why the code is written the way it is, and some point at TorQ or other modules. Trim each to a short line saying what the code does - the explanations already live in compression.md. Biggest ones: the 13-line header at the top of compression.q, "Ported from TorQ" (l.3), "Legacy TorQ exits here too" (l.53-55), and the comment in test.csv row 31. This is the new comment rule in style.md (#148).
  • 2. Test fails from 2027.01.02. Fixture partitions are fixed at 2026.01.01 2026.01.02 with maxage 365, and di.compression keeps age within (compressage;maxage). Reproduced by ageing the fixture: the 366-day partition stays uncompressed, so row 19 fails. Derive the dates from .z.D.
  • 3. maxage default is 365; TorQ ships 30. TorQ's code default is 365, but config/settings/compression.q:12 sets 30, so a stock TorQ process scans 30 days. Is 365 intended? If not, use 30; if so, say so in "Migrating from TorQ".
  • 4. Code defaults are never asserted. compression.q:73-75 says "the tests assert both halves" and rows 11-12 say "asserted below", but row 14 is a run - nothing checks maxage/exitonfinish after init[nodefaultscfg[]]. Assert them (e.g. from the captured init log line) or drop the claim.

Should fix

  • 5. Doc example has startwithall=1 (compression.md:76) - torqx.sh start all would then rewrite the hdb on every stack start. Should be 0, as the POC row is.
  • 7. csvpath roots disagree. The code default uses TORQXAPPCONFIG/compressionconfig.csv; the shipped setting :appconfig/compressionconfig.csv resolves under TORQXAPPHOME. Since the setting always applies, TORQXAPPCONFIG is ignored.
  • 8. toml rows prove nothing, and asbool mis-parses "true". Rows 26-27 recompress already-compressed files (every file skipped), and tomlcfg passes maxage/exitonfinish natively, so the string branches of aslong/asbool never run. Those branches have a bug: "B"$"true" is 0b (only "1" parses true), so exitonfinish = "true" quoted in a toml silently disables exit. Rebuild the fixture first, pass "365"/"0"/"1", and either accept "true" or reject non-0/1 strings. asbool is a copy of the one in di.permissions (permissions.q:17), so a quoted "true" for enabled there would silently leave access control off - worth its own ticket.
  • 9. No maxage-exclusion test. No fixture partition is ever outside the window - add one and assert it is left alone.
  • 11. torq.md l.89-90 and l.95 list the builtin proctypes without compression.

Your call

  • 6. No default compression csv. TorQ ships config/compressionconfig.csv (default,10,default,1,16,0) and resolves app-then-framework via .proc.getconfigfile; here an app without one fails. di.torq.config exports getconfigfile. (housekeeping also builds its csv path by hand, so this is a consistency question, not a regression in this PR.)
  • 10. Failed init leaves state half set. .z.m.log/.z.m.hdbpath are assigned before the hdb check, so after a bad-path init initialised[] is true and compressnow dies on .z.m.cmp instead of the init message. Validate, then assign. Low impact: torqx_init exits 3 on any init error, so this state is only reachable if a caller catches the failure.
  • 12. Bad csv exits 0. Confirmed live: two ERROR lines, nothing compressed, exit code 0. For a scheduled batch job that is a silent success. Fixable in this wrapper without touching di.compression: count calls through the injected error logger and have run exit 1 if any.
  • 13. apphome/datahome/resolvedir now exist in three process modules; asbool/aslong copy di.permissions - backlog candidate.
  • 14. di/torq/VERSION stays 0.5.0 though the registry gained a proctype - is a bump expected?

The DIReview suggestion to trap key .z.m.hdbpath isn't needed: key on a missing path returns ().

TorqX-POC (#6, already merged)

  • On POC main, start compression1 fails until this merges - the builtin isn't on kdbx main.
  • compression1.toml has no .q twin; every other settings file has one since #7.
  • deps.toml declares neither di.torq.proc.compression nor di.compression.
  • The toml NOTE blames block size, but the shipped 2015.01.07 partition is excluded by maxage = 365 first, and its columns (largest about 4 KB) are below the 2^17 block size anyway. On a stack that has run EODs, the recent partitions are in range and do get compressed.

DI-Dexter and others added 2 commits November 2, 2026 13:51
1. Trim comments to concise what-only, matching DataIntellectTech#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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

✅ No new findings at f180f55.

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Carries the same fix made on DataIntellectTech#150 into the two copies this branch still
owns, so DataIntellectTech#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
DataIntellectTech#150 and this merge.

Three suites green; the POC stack starts clean and still enforces.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 0 warning(s) | 1 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/permissions/permissions.q:20 — The type list -5 -6 -7 -9h omits short int (-5h) and real (-8h) numeric atom types that the old code accepted implicitly via numeric comparison. More importantly, it includes -9h (float/real), but excludes -8h (real atom). If a real atom (1.0e) is passed, neither the numeric branch nor the string branch will match and it will fall through to the final error — a behaviour change from the original which accepted any numeric type via 0<>x. Review whether all numeric atom types (-4h through -9h, excluding -1h which is bool) should be included, or document the intentional narrowing.

Carries the DataIntellectTech#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 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 0 warning(s) | 1 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/permissions/permissions.q:19 — Adding -4h (byte atom) to the numeric-coercion branch is reasonable, but adding -8h (date atom) is almost certainly wrong. A date value like 2024.01.01 has type -14h, not -8h; -8h is a 32-bit real (float) atom. If the intent was to cover the real/float type it should be noted explicitly; if it was to cover date it is the wrong type code. Confirm the intended type set — including -8h means a real-valued config flag like 1.5e will be coerced (0<>1.5e → 1b) while a date (type -14h) still won't be. The same issue appears at di/torq/proc/compression/compression.q line 15.

@DI-Dexter

DI-Dexter commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi Aaron, thanks, really useful review. All 14 items are addressed.

#149 has 1–12 and 14. Some things to note: maxage now ships 30 rather than 365, matching TorQ's config/settings/compression.q, so a stock deploy scans 30 days; and the fixture dates derive from .z.D, since the hardcoded ones would have started failing on 2027-01-02.

#150 is item 13: a new di.util.cfg module with one copy of apphome, datahome, resolvedir, asbool and aslong. rdb, tickerplant, wdb and housekeeping bind it at load time, so call sites are unchanged. di.torq.proc.hdb is left alone since its resolvedir takes one argument and has different semantics, so it isn't a duplicate.

di.permissions and di.torq.proc.compression still carry their own copies. They're modified on the #149 branch and would conflict, so they fold in via a follow-up PR once both #149 and #150 have merged. That's the asbool/aslong/path-helper duplication.

There's more of this than item 13 covered: totimespan is in five modules, tosym/aslist/assym in three each, all identical. A few others (astz, tolong, tobool vs asbool, and the timespan trio) have genuinely diverged, including a seconds-vs-nanoseconds difference. I'd rather land #150 first and do those as a follow-up, since the divergent ones need decisions rather than a move.

TorqX-POC #8 covers the POC notes. It must merge after #149 since its deps.toml declares the compression modules, and I've checked every process fails at startup naming them if it goes first.

Order: #149 before POC #8, since its deps.toml declares the compression modules. #150 is independent. The fold-in needs both #149 and #150; the wider conversion cleanup needs only #150, so those two can land in either order.

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 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 0 warning(s) | 1 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/permissions/permissions.q:28 — The null check uses 10h=abs type x to decide whether to format the bad value as a string, but x has already been consumed by the $[...] expression stored in r — the type-test is re-evaluated on the original x, which is correct. However, the error branch for a non-string, non-long input (the final "j"$x arm) will produce 0N when x is, e.g., a float or a symbol that doesn't cast cleanly. For a symbol input, 10h=abs type x is false, so the error message uses -3!x — but -3! on a symbol returns a string like `foo, which is fine. The real gap is that "j"$ on a symbol atom signals a type error ('type) before null r can be tested, so the if[null r;...] guard is never reached for symbol inputs — the cast itself throws. This means the null guard only fires for numeric types that cast to 0N (e.g. a float 0n), not for un-castable types. This is inconsistent with the stated intent and with asbool's behaviour. The same issue exists in di/torq/proc/compression/compression.q line 24.

@alowrydi
alowrydi self-requested a review November 3, 2026 12:19

@alowrydi alowrydi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Dexter, I checked all 14 against the new code and ran it. Approving.

Verified

  • Suites green with TORQXHOME unset: di.torq.proc.compression 35/35, di.permissions 58/58, di.torq 93/93, di.compression 73/73. Also green merged with #150 on current main.
  • Ran compression1 live via POC #8 against a scratch hdb: good csv exits 0 (price compressed, cond not), bad csv exits 1 ("2 error(s) during compression"), bad hdb path exits 3.
  • 1–4: comments say what the code does, fixture dates come from .z.D, maxage ships 30, code defaults are asserted from the init log.
  • 5, 7, 9, 11: startwithall is 0 in the doc, csv path is under TORQXAPPHOME, the out-of-window partition is asserted untouched, torq.md lists compression.
  • 8: asbool takes true/false/1/0 in any case and errors on anything else, in di.permissions too. The toml rows pass text, so the string branches run.
  • 6, 10, 12, 14: default csv fallback, validate before setting state, run exits 1 on logged errors, versions bumped.
  • 13: split out to #150.

Merge order: #149 and #150 can go in either order, then POC #8 after #149.

@DI-Dexter
DI-Dexter merged commit 3e4ccfe into DataIntellectTech:main Nov 4, 2026
DI-Dexter added a commit that referenced this pull request Nov 4, 2026
* di.util.cfg: one implementation of the shared config helpers

apphome, datahome and resolvedir were copied byte-for-byte into
di.torq.proc.rdb, .tickerplant, .wdb and .housekeeping (which named its
copy resolvepath). asbool and aslong are duplicated the same way. Raised
in review on #149.

Adds di.util.cfg holding one copy of each, and binds it in the four
modules at load time so call sites are unchanged:

  cfg:use`di.util.cfg;
  apphome:cfg`apphome;
  datahome:cfg`datahome;
  resolvedir:cfg`resolvedir;

Two things found while consolidating:

- resolvedir signalled 'type on a single-character relative path. "x" is
  a char ATOM, so `like` was applied to an atom rather than a string. All
  five copies had it. Fixed with (), and covered by a test.
- asbool read only "1" as true, so a quoted setting of "true" meant false.
  It now takes true/false/1/0 in any case and errors otherwise.

NOT folded in here: di.permissions and di.torq.proc.compression also carry
copies, but both are changed on the #149 branch and would conflict. They
follow once that merges. di.torq.proc.hdb has its own single-argument
resolvedir with different semantics - left alone deliberately.

Seven suites green; the POC stack starts clean with data flowing.

* di.util.cfg: error on any type asbool cannot read

DIReview on #150 noted a symbol fell through the type guard to a silent
0b, contradicting the doc. Correct, and the symbol is not the worst case:

  asbool 1i    -> 0b      an int 1 read as FALSE
  asbool 1h    -> 0b
  asbool 1f    -> 0b
  asbool `true -> 0b
  asbool (::)  -> 0b

So a .q settings tier writing enabled:1i disabled the thing it was
enabling, silently - the same class of bug as the quoted "true" already
fixed here, and likelier to be hit.

Numeric atoms (short/int/long/float) are now accepted, nonzero being
true. Every other type errors, naming the type. Tested across all of them.

* di.util.cfg: accept every numeric atom, not an arbitrary five

DIReview on #150: the type list included float (-9h) but not real (-8h),
which is an arbitrary gap, and type[x] was inconsistent with the (type x)
form used elsewhere in the file. Both fixed - the list is now -4h..-9h,
every numeric atom, with nonzero true.

The review's premise is not right, for the record: the original did NOT
accept any numeric via 0<>x. Measured, it took long alone -

  orig 1   -> 1b
  orig 1i  -> 0b
  orig 1h  -> 0b
  orig 1f  -> 0b
  orig 1e  -> 0b

so int, short, float and real were all silent falses. This widens
acceptance rather than narrowing it; the only values that now error are
ones that previously returned a silent 0b.

* di.util.cfg: cover byte in the asbool tests

DIReview on #150: -4h is in the numeric guard and the doc says "byte
through float", but no test exercised a byte. Keeping -4h deliberately -
excluding it would reintroduce the arbitrary gap this list was widened to
remove - so the test is what was missing.

* di.util.cfg: aslong errors on unparseable values; tidy comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants