Skip to content

di.util.cfg: one implementation of every config coercion - #152

Merged
DI-Dexter merged 11 commits into
DataIntellectTech:mainfrom
DI-Dexter:di-util-cfg-coercions
Nov 6, 2026
Merged

DI-Dexter merged 11 commits into
DataIntellectTech:mainfrom
DI-Dexter:di-util-cfg-coercions

Conversation

@DI-Dexter

@DI-Dexter DI-Dexter commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #150. Every config coercion helper in di.* now has one implementation, in di.util.cfg. Modules bind them at load time, the same way #150 does.

Eleven commits:

  1. f4b714e – move the identical copies. No behaviour change.
  2. b53bf2d – merge the copies that had diverged. This changes behaviour on purpose; see below.
  3. e22a0f5 – fix astimespan for reals. A real (1.5e) is cast to float before scaling. q rounds a real multiplied by a timespan to a whole number first, so 1.5e seconds gave 2s and 0.1e hours gave 0.
  4. 886a0af – bump each module's VERSION once for the PR. Every module is one minor version above main; for example di.util.cfg goes 0.1.0 → 0.2.0.
  5. a51d69f – address the review. The runtimes range check, heartbeat moved onto astimespan, and the misplaced comments.
  6. c0cad98 – refuse bare digits on a timespan override. See "Command line" below.
  7. 35d8404 – the follow-ups. Errors name the setting, tosym merges into assym, infinity stays infinite, hdb uses the shared datahome, and an empty runtimes logs an error.
  8. 8f842a0 – widen the di.clienttracking idle and retain test sleeps to 3s. A WSL2 clock step of about -645ms every 32s cut the 1.5s sleeps below the 1s limits.
  9. 74c3f55 – di.timer: disable a job whose next run falls outside its period. See section 3.
  10. 9f0b9f4 – di.timer: fix mode 5. See section 3.
  11. 01f195b – keep to one VERSION bump per module after the follow-ups.

If you have already reviewed the earlier commits, read 5 onwards.

Rebased onto main after #151, so the first four hashes changed; their content did not.

1. Identical copies moved

Helper Copies Modules
tosym (now assym) 3 chainedtp, segmentedtp, tickerlogreplay
aslist 3 gateway, rdb, wdb
assym 3 gateway, rdb, wdb
astoklist 2 gateway, wdb
astz (now assym) 2 tickerplant, idb

astz is replaced by assym. The tickerplant copy has the same source. idb's `$(),x gives the same result on every input tried, including a char atom and an empty string.

2. Behaviour changes

Setting helper Before Now
Timespans (totimespan including heartbeat's copy, wdb astimespan, housekeeping astimespans) The three helpers disagreed. "30" was 30 hours in totimespan ("N"$) but 30 seconds in wdb's. Housekeeping read a bare number as nanoseconds. Junk text gave 0Nn. astimespan[unit;x]. A bare number, or bare digits as text, counts in unit (`second, `minute or `hour). Unreadable input errors.
tosym (chainedtp, segmentedtp, tickerlogreplay) A number passed through unchanged. Uses assym, so a number throws.
tolong (idb, wdb) idb returned 0N on a bad value; wdb threw. Both use aslong, which throws (wdb's behaviour).
Booleans (wdb tobool, asbool) wdb read junk such as "ture" as 0b and threw on a symbol. asbool rejected yes/no. asbool 0N was 1b. One asbool. It accepts true/false, yes/no, t/f, y/n and 1/0 in any case. Anything else errors, including a null number.
astimespan[`second;30]          / 0D00:00:30
astimespan[`second;"30"]        / 0D00:00:30 - was 30 hours via totimespan
astimespan[`hour;2]             / 0D02:00:00
astimespan[`second;"0D00:05"]   / text containing D or : is read as a timespan
astimespan[`second;"junk"]      / error - was 0Nn
astimespan[`second;0W]          / 0Wn - infinity stays infinite, as in TorQ
astimespan[`second;1e300]       / error - too big for a timespan

An asbool, aslong or astimespan error reading a setting now names it: setting retry: di.util.cfg: cannot read "junk" as a timespan.

Unit at each call site:

  • Seconds: retry, discoveryretry, pubinterval, eodwaittime, checksubscriptionperiod, rolltimeoffset, heartbeatpublishinterval and heartbeatcheckinterval. The module docs already describe all of these in seconds, so a bare number reads as before.

  • Housekeeping runtimes is a time of day, so it has its own rules:

    Value Result
    "0200 1430", "02:00 14:30" 02:00 and 14:30, unchanged (text still goes through "N"$)
    2 02:00 (was 2 ns)
    30, -1, "30", "junk" error (anything outside 0–24 hours)
    "" error
    an empty list no jobs, and now logs an error, as TorQ does

Command line: -retry 30 on a timespan-typed setting is now refused and logged, and the old value stays. "N"$"30" is 30 hours, which is never what an interval means. Use 00:00:30 or 0D00:00:30. This differs from TorQ, which accepts it as 30 hours. A string-typed setting from .toml keeps the text, so astimespan reads it in the module's unit.

di.permissions and di.torq.proc.compression now use the shared asbool/aslong in place of their own copies. compression also uses the shared path helpers. di.permissions gains a deps.toml. di.torq.proc.hdb uses the shared datahome and also gains one.

Who is affected: a setting that relied on the old meaning:

  • bare digits as text for a timespan;
  • a bare number for housekeeping runtimes, or a runtimes value outside 0–24 hours;
  • bare digits on the command line for a timespan-typed setting;
  • an unrecognised boolean word;
  • a number in a setting that went through tosym.

None of the shipped di/torq/settings or TorqX-POC settings do any of these. They all use explicit timespans and booleans.

3. di.timer

  • Period check. TorQ's timer disables a job whose next run falls outside its start and end times, so a period of 0Wn runs once. di.timer only checked the end time, and .z.p+0Wn wraps to 1734, so the job ran on every tick. It now checks both ends. An infinite, null or negative period runs once and is disabled; normal periods are unchanged.
  • Mode 5. Every mode 5 job threw a type error, because xbar was given a minute as its bar size. It now schedules as timer.md describes. A period under a minute is rejected when the job is added, as it would otherwise run once and silently stop.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

✅ No new findings at 30333f3.

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

@DI-Dexter DI-Dexter changed the title di.util.cfg: fold in the remaining identical coercion helpers di.util.cfg: one implementation of every config coercion Nov 4, 2026
Comment thread di/util/cfg/cfg.q
if[null r;'"di.util.cfg: cannot read \"",$[10h=abs type x;(),x;-3!x],"\" as a whole number"];
r
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

spanunits is defined at module load time as a plain dict literal with timespan values. If di.util.cfg is loaded in a use context, this top-level assignment executes once. The dict key lookup spanunits unit for a missing key returns the default value for the value type — for a timespan dict, the default is 0Nn. null 0Nn is 1b in q, so the guard if[null u:…] correctly catches an unknown unit. This is fine per the Known q facts (null of a typed null is 1b).

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

Suggestions

  • di/util/cfg/cfg.q:46 — For a float/real input (-8h or -9h type), the branch (type x) in -5 -6 -7 -8 -9h matches and computes `timespan$u*x. For example astimespan[second;1.5]: uis0D00:00:01(a timespan, 1 000 000 000 ns), andxis1.5f. In q, timespan * floatis not guaranteed to be defined — multiplying a timespan atom by a float may yield a float, not a timespan, and then ``timespan$ `` of a float casts nanoseconds, not the intended seconds. The test tsfloat asserts `0D00:00:01.5~(cfg`astimespan)[`second;1.5]` which would be 1 500 000 000 ns — if `0D00:00:01 * 1.5` in q yields `1500000000` (a long, due to integer*float=float truncated?) this could silently give the wrong result. This depends on q's arithmetic between timespan and float, which is UNVERIFIED.

Comment thread di/util/cfg/cfg.q Outdated
x:$[-11h=type x;string x;x];
r:$[-16h=type x;x;
(type x) in -17 -18 -19h;`timespan$x;
(type x) in -5 -6 -7h;u*x;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The branch for types -5 -6 -7h (short, int, long) now returns u*x (a raw numeric product, e.g. a long or int) instead of a timespan. Previously, \timespan$uxwas applied to all five numeric types uniformly, converting the product to a timespan. The new code omits the`timespan$cast for the integer types, so callers receive a raw integer/long rather than a 0Nn-or-timespan value, breaking the contract ofastimespan. The fix is `timespan$uxfor the-5 -6 -7h` branch (the same cast that was there before, now separated from real/float).

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

@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.

Right direction, and the mechanical part checks out. A few things before merge.

Verified

  • Merged with #153 on current main: same results as main in every suite except the two that grew, di.util.cfg (62/62) and di.torq (100/100). Suites that fall short do so identically on main.
  • TorqX-POC on the merged tree: every process started reports depcheck 0 failures.
  • Probed astimespan/asbool/aslong directly. Real and float arithmetic is correct and integer inputs return a timespan, so DIReview's warnings on u*x don't apply. assym matches idb's old astz on every input I tried.
  • Every module that uses di.util.cfg declares it at 0.2.0. Shipped framework and POC settings use explicit timespans and booleans.

Please fix before merge

  • Housekeeping runtimes regression. runtimes = "0200 1430" used to give 02:00 and 14:30. It now gives 8D08:00 and 59D14:00 with no error, so the job would first fire days or weeks out. The PR's "who is affected" list doesn't cover this form. astimespans should reject anything outside 0-24 hours, which also catches runtimes = 30.
  • heartbeat still has its own totimespan. #151 landed after this branched and adds the old copy at heartbeat.q:20, so "30" is still 30 hours there and junk is 0Nn. Please rebase and use astimespan[second;…]`.
  • Comments now sit above the wrong code. The cfg block went between an existing comment and the line it describes:
    • gateway.q: "di.dataaccess partition coverage…" (belongs to buildpartitions)
    • segmentedtp.q: "di.eodtime settings from an [eodtime] section…" (eodconfig)
    • tickerlogreplay.q: "log the error and exit" (ex)
    • subscriptions.q: "registry of active subscriptions" (SUBSCRIPTIONS)
  • Dead check in subscriptions.q. if[null p;…] can't fire now that astimespan errors. Remove it.
  • No call-site test for runtimes. housekeeping/test.csv is unchanged. Add rows for a bare number as an hour and for the out-of-range rejection.

Nits, fine as a follow-up

  • Errors name the value but not the setting (cannot read "ture" as a boolean), where the old messages said "rolltimeoffset must be a timespan". With this many settings, the name would help.
  • astimespan[second;0W]overflows to-0D00:00:01, while the text "0W"gives0Wn`. The old copies did the same multiplication, so this isn't new.
  • hdb's datahome is still an identical copy, and tosym/assym do the same job for text and symbols.
  • Unrelated blank-line removals in tickerlogreplay.q, a double blank line in idb.q, and astz:cfgassymcould just beassym`.
  • compression test.q:68's comment still says "neither true/false nor 1/0", and some test comments explain history ("it used to…").

DI-Dexter and others added 5 commits November 5, 2026 11:40
Moves totimespan, tosym, aslist, assym and astoklist (and astz, now bound to assym) into
di.util.cfg - 18 copies across 10 modules, behaviour unchanged. Diverged helpers
(tolong, tobool, the timespan trio) are left for their own PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
astimespan[unit;x] replaces the three timespan helpers that disagreed on what a bare
number means; wdb, idb, permissions and compression now use the shared asbool/aslong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
timespan*real rounds the real first, so 1.5e seconds gave 2s and 0.1e hours gave 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
di.util.cfg goes 0.1.0 -> 0.2.0, and the seven modules bumped twice drop back one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eat, misplaced comments

runtimes text is read as a time of day again and anything outside 0-24 hours errors. heartbeat
moves onto astimespan, and comments stranded by the cfg block go back above their code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DI-Dexter
DI-Dexter force-pushed the di-util-cfg-coercions branch from b7d4225 to a51d69f Compare November 5, 2026 03:52
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

Could not be posted inline

  • WARNING di/torq/heartbeat/heartbeat.q:47 — The parameter name hb in storeheartbeat:{[hb] ...} shadows the module-level table hb. Inside the function, .z.m.hb is written using a upsert that reads hb (the parameter), so .z.m.hb:.z.m.hb upsert ... is fine. However, if any other reference to the bare name hb inside the body intended the module table rather than the argument, it would silently read the argument instead. More practically, this violates the project style guide's naming conventions (parameters should not collide with module globals) and is a latent maintenance hazard. Rename the parameter — e.g. rows — to avoid the collision.
  • CRITICAL di/torq/heartbeat/heartbeat.q:57 — checkheartbeat writes warn and err calls but never updates .z.m.hb with the new status values — stats is a local table that is discarded after the two select calls. Processes that enter warning or error will be re-flagged on every subsequent check call (the not warning / not error filter will never activate because .z.m.hb is only updated inside warn/err, which only run for newly-flagged rows, but the status field that drives the filter comes from stats which is recomputed fresh each time). The intent is clearly to persist the computed status back into .z.m.hb so the warn/err predicates work on cumulative state. Fix: after computing stats, do .z.m.hb:.z.m.hb upsert select sym,procname,warning,error from stats (or equivalent) so the warning/error flags survive across calls — noting that warn and err already set the flag fields on .z.m.hb by key-filtered update, so the actual missing step is persisting stats before calling those helpers, or relying entirely on warn/err to persist.
  • WARNING di/torq/heartbeat/heartbeat.q:119 — When subenabled is true, upd is wrapped unconditionally outside the registered guard (lines 119–122 come after if[registered;:()]). This means a second init call with subenabled:1b will wrap upd and .servers.connectcustom again, accumulating nested wrappers. The doc says a second init must not rewrap, but the guard at line 112 (if[registered;:()]) returns early before the wrap only for the jobs/handlers block — the if[subenabled;...] block at line 119 is outside that early return and therefore runs on every call. Move the if[subenabled;...] block inside the not registered section, or add a separate subenabled-registered flag.

Suggestions

  • di/util/cfg/cfg.q:44 — astimespan handles a float/real (types -8h/-9h) by computing `timespan$u*`float$x. The intermediate `float$x is then multiplied by the unit timespan (a long). Multiplying a timespan (long nanoseconds) by a float gives a float, then casting that float to timespan truncates rather than rounds, which is unexpected for values like 1.5 seconds (expected 0D00:00:01.500000000). The test tsreal at test.q line 39 asserts 0D00:00:01.5~(cfg\astimespan)[`second;1.5e], and the existing test for tsfloat(a float -9h) passes, so this may happen to work, but the type ofu*float$x depends on q's arithmetic rules for timespanfloat. Verify the cast path is \timespan$`long$u`float$x` or equivalent integer arithmetic to guarantee nanosecond precision.

"N"$"30" is 30 hours, so -retry 30 on a timespan-typed setting is now logged and skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/torq/config/config.q
@@ -86,6 +86,9 @@ parsefailed:{[t;raw;vals]
any null vals];
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

barenumber accepts strings like "-." (all characters are in .Q.n,".-") which are not valid numbers. For example, ".." or "-" or "." would be flagged as bare numbers and rejected for timespan settings, even though "N"$ would not parse them as hours (they would fail with a parse error caught by parsefailed). The check incorrectly blocks values that would already fail parsefailed with a clearer message. To fix, anchor the pattern more tightly: e.g. require the first char to be a digit or -, at most one ., etc., or check not null "F"$x instead of a character-set membership test.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

DI-Dexter and others added 5 commits November 5, 2026 14:05
…erflow

Coercion errors name the setting, tosym folds into assym, hdb uses the shared datahome, and an
empty runtimes logs an error as TorQ does. Infinity stays infinite, as in TorQ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A WSL2 clock step of about -645ms every 32s cut the 1.5s sleeps below the 1s limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As TorQ's timer does. An infinite period wrapped into the past and ran on every tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xbar needs a numeric bar size, not a minute. A mode 5 period under a minute is now rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The follow-ups were bumped on top of the PR's own bumps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
.z.m.jobcsv:resolvepath[apphome[];config`jobcsv];
/ defaults match di/torq/settings/housekeeping.q
.z.m.runtimes:$[`runtimes in key config;astimespans config`runtimes;enlist 0D02:00:00];
.z.m.runtimes:$[`runtimes in key config;named[`runtimes;astimespans;config`runtimes];enlist 0D02:00:00];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

An empty runtimes list is now only logged as an error (log[error]) rather than throwing — execution continues and .z.m.runtimesis set to(). If the downstream code that schedules jobs iterates over .z.m.runtimesit will simply schedule nothing, which may be a silent misconfiguration. The testrtnone(line 136 in test.csv) explicitly expectsrtnone[]to succeed (i.e.initdoes not throw), confirming this is intentional. But the oldastimespans did throw on an empty string (rtempty) — an empty *list* (`` timespan$() ``) is now accepted silently. If a misconfigured TOML produces an empty list, the housekeeping process will start, log an error, and run no jobs — operators may not notice. This is a design choice rather than a code defect, but note that the error is logged and not raised, so monitoring must rely on log scanning.

@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

Suggestions

  • di/util/cfg/cfg.q:41 — The scale function returns 0Nn (null timespan) when the float magnitude exceeds 9.2e18, but the caller astimespan only checks if[null r;…] to detect errors — and 0Nn is null, so this path correctly triggers the error. However, when the input x is a float (-9h) the type check t in -8 -9h is true and the code falls through to $[t in -8 -9h;\timespan$f;ux]. But f is computed as `` (float$u)float$x ``, so for a float input like 1e20(testtsfloatover) the overflow check 9.2e18<abs ffires and0Nnis returned — that path is fine. The subtle problem is the sign handling for negative-infinity detection:if[inf=abs x;:$[x<0;-0Wn;0Wn]]computesinfas the infinity for the *input type*, but then compares it withabs x. For a float negative infinity (-0w), abs -0wis0wandinffor-9his0w, so 0w=0wis1b — correct. For a long negative infinity (-0W), abs -0Wis0Wandinffor-7his0W— correct. Howeverinf for short (-5h) is 0Wh, and 0Wh=abs -0Whrequires comparing a short to a short — this appears correct. The issue is that for integer types-5 -6 -7h, infis computed as an integer infinity, but the comparisoninf=abs xperforms a typed equality. Ifxis-6h(int),infis0Wi, and abs -0Wiis0Wi, so 0Wi=0Wiis1b— correct. This path appears sound. The real gap is that a **null** numeric input (e.g.0Nwhich is-7h) reaches the -5 -6 -7 -8 -9hbranch ofastimespanand entersscale: inffor-7his0W; abs 0N(null long) is0N, and 0W=0Nis0b(not null, not infinity), so it falls through tof:(float$u)*float$0Nwhich is0n(float null), then9.2e18<abs 0nis0b, and the result is `` timespan$0n `` which is 0Nn. The caller then fires the error on null, so a null long is correctly rejected. This all works. No actionable bug found in this logic.
  • di/util/cfg/cfg.q:56 — The text-infinity path in astimespan — $[any ((),x) in "D:";"N"$(),x;scale[u;"F"$(),x]] — passes the float-cast result to scale, but "F"$"0W" is 0w (float infinity). Inside scale, the type t of 0w is -9h, so inf is set to 0w. Then inf=abs 0w is 0w=0w which is 1b, so the function returns 0Wn. The test tstextinf expects 0Wn and this works. However "F"$"0Wn" (the text of a typed timespan infinity) is 0w — also fine since -16h branch would have caught a typed timespan before reaching here. The real problem is "F"$"1e20" — this produces 1e20, abs 1e20 is 1e20, inf is 0w, 0w=1e20 is 0b, so it falls through to f:(float$u)*float$1e20 = 1e20*1.0 = 1e20, then 9.2e18<1e20 is 1b, so scale returns 0Nn. The caller sees null and errors. The test tsfloatover expects a fail — this works. But "F"$x on a non-numeric char string like "junk" returns 0n (null float). scale receives 0n: inf is 0w, 0w=abs 0n — abs 0n is 0n, 0w=0n is 0b, falls through; f = u * 0n = 0n; 9.2e18 < abs 0n is 0b; result is `timespan$0n = 0Nn. The outer null r check then errors. So "junk" as text still errors, just via a different null path. No actual broken behaviour — removing.

@alowrydi
alowrydi self-requested a review November 5, 2026 11:41

@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, all the items from my last review are addressed. Approving.

Checked

  • runtimes: astimespans rejects anything outside 0-24 hours, a bare number is an hour, "0200 1430" still works, and an empty string errors. The new housekeeping rows cover each case.
  • heartbeat now uses astimespan, with tests for digits as text and a number.
  • The four misplaced comments are back above the right code, the dead if[null p;…] check is gone, and the history-style test comments are removed.
  • Errors name the setting, tosym is merged into assym, hdb uses the shared datahome, and 0W stays infinite.
  • di.timer: the new period check matches TorQ's within (periodstart;periodend) rule. The mode 5 fix is right, and the tests cover the interval, an exact boundary, rollover to the next day, a past start and the under-a-minute rejection.
  • Merges cleanly into current main.

@DI-Dexter
DI-Dexter merged commit 2647306 into DataIntellectTech:main Nov 6, 2026
alowrydi added a commit that referenced this pull request Nov 6, 2026
Resolve the segmentedtp VERSION conflict with #152 as 0.3.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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