Skip to content

Feature rediscovery - #138

Merged
alowrydi merged 9 commits into
mainfrom
feature-rediscovery
Oct 2, 2026
Merged

alowrydi merged 9 commits into
mainfrom
feature-rediscovery

Conversation

@alowrydi

Copy link
Copy Markdown
Collaborator

Adds di.torq.proc.discovery (0.1.0), a one-to-one port of TorQ's discovery service, plus the client-side machinery di.torq.servers (0.3.0 → 0.4.0) needed to support it - identity exchange on connect (getdetails/addhw/addw), connection-retry to a discovery service (retrydiscovery/autodiscovery), and the register/query surface (register, querydiscovery, registerfromdiscovery). Settings config moves to a generic, config-driven dict rather than individual hardcoded values, which is what let the missing legacy settings (discoveryregister, connectionsfromdiscovery, retain, autoclean, debug, etc.) land cleanly.

Behaviour change for every process using di.torq.servers: connections now default to coming from discovery rather than process.csv directly; retry intervals default to 5 minutes (was 10s); startup no longer self-excludes the caller's own row, matching legacy.

Includes a fix to waitfortype so it can reach a discovery service that comes up mid-wait, and a comment/doc trim to what-not-why across both touched modules.

alowrydi and others added 5 commits September 25, 2026 14:34
di.torq.proc.discovery 0.1.0 repackages TorQ code/processes/discovery.q line for line
(register, getservices, subs, the startup addw pass and autodiscovery push, .z.pc prune),
publishing register/getservices at their legacy root names.

di.torq.servers 0.3.0 -> 0.4.0 ports the client half of the protocol from
code/handlers/trackservers.q at its legacy root names (.servers.*, .dotz.liveh*): addw,
removerows, cleanup, retrydiscovery, autodiscovery, querydiscovery, registerfromdiscovery,
addprocs, procupdate, startup and friends, with SERVERS (now carrying attributes) and the
trackservers settings as root .servers.* globals. Exported API unchanged. servers.md lists
each ported line, the conversions, what was not ported, and the behaviour changes.

di.torq: discovery registered as a built-in; legacy STARTUP ported (torq.q l.673) so the hdb
registers with discovery as legacy's does; settings/default.q carries legacy default.q's
.servers values, settings/discovery.q legacy's discovery settings, settings/hdb.q startup:1b.

Note: legacy defaults route every process's connections through discovery - a stack with no
discovery process no longer dials process.csv peers directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Legacy TorQ timer modes 0/1/2 schedule the next run from the scheduled start, the actual start and
the finish (code/common/timer.q l.8-11); di.timer's 1h/2h/3h mean the same, so legacy mode n is
di.timer mode n+1. d04d8d4 ported legacy's .timer.repeat (default mode 2, from finish) as di mode 2
(from actual start) for the discoveryretry and serversretry jobs. Both now use mode 3.

The servers suite gains a row asserting mode 3 for both jobs; it fails against d04d8d4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… up during the wait

With connections taken from discovery (the builtin default), a process started before discovery
registers only a dead discovery row. waitfortype polled retry[], which skips discovery rows and
never re-queries, so the rdb, wdb and feed each waited out tpwaittimeout (30s) and aborted init,
left running but uninitialised. Reproduced on TorqX-POC with discovery1 last in process.csv.

Each poll now calls startup ()!() (reconnect discovery, register, take the rows it names) and
keeps retry[]. The servers suite gains a discovery stub that comes up after startup; the
waitfortype row fails against 3c67d3c and passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
servers.q: the header, registered, init, opencon, timer, startup and waitfortype comments cut to
one line each. servers.md: intro and init prose condensed; the .z.pc registration and
conventions sections dropped (the conversions list covers the first); tests section listed.
Test helper headers cut to one line. Comment and doc changes only; the servers (43),
discovery (30) and di.torq (56) suites pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
discoveryregister and connectionsfromdiscovery default to 0b, so a process dials its
process.csv peers directly unless the app turns discovery on. debug defaults to 0b.
default.q regrouped into discovery, connections and server-record blocks with aligned
one-line comments. servers.md updated to match. The di.torq suite gains a row asserting the
cascaded defaults for a non-discovery proctype; it fails on the previous default.q.

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

Copy link
Copy Markdown

DIReview Summary

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

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

Could not be posted inline

  • WARNING di/torq/servers/servers.q:329 — waitfortype now calls startup ()!() inside the poll loop (line 329). startup with an empty dict uses .z.m.processcsv as the process-file path (line 204: pf:$[processcsv in key config;configprocesscsv;.z.m.processcsv]). If .z.m.processcsv is "" (the default set in init when processcsv is absent from deps, line 60), readprocesscsv will attempt to open an empty string as a file path and throw. This means waitfortype will throw on any process where processcsv was not supplied to init, including any process that was not given a processcsv config key. Fix: guard the startup call so it is only made when a non-empty processcsv is known, or document that waitfortype requires processcsv to have been set.

Suggestions

  • di/torq/servers/servers.q:108 — addnthawc uses isalive before it is defined when checkhandle is false. The line if[checkhandle and not isalive:.dotz.liveh W;'"invalid handle"]; assigns isalive as a side-effect of the not expression. When checkhandle is 0b, q's short-circuit evaluation means the right-hand side is never evaluated, so isalive is never set. The subsequent use $[isalive;.z.p;0Np] in the insert line will throw 'isalive. Fix: assign isalive:.dotz.liveh W; on its own line before the guard.
  • di/torq/servers/servers.q:159 — addprocs applies an lj (line 159: .servers.SERVERS lj 3!select procname,proctype,hpup,attributes from connectiontab where not ([]procname;proctype;hpup) in select procname,proctype,hpup from .servers.SERVERS) using the wrong where clause: the where not ... in ... condition selects rows from connectiontab that are NOT already in .servers.SERVERS, so these are new rows that have no existing counterpart to join onto — the lj updates nothing. The intent (from the comment "maybe there are updated attributes") is to update attributes for rows that ARE already present. The condition should be where ([]procname;proctype;hpup) in select procname,proctype,hpup from .servers.SERVERS (without the not). This is a direct port of what appears to be the same logic bug present in the legacy code.
  • di/torq/proc/discovery/discovery.q:13 — The register function is published at root via set[register;register]ininit, making it callable as `` ..register `` from peers. However, the function body unconditionally calls .z.m.subs and `.z.m.loginfo` (via the `.z.pc` handler and `init` wiring), which are only valid after `init` has run. If a peer calls `register` before `init` completes (e.g. a race during startup since `.servers.startup` at line 28 dials peers and they may immediately call back), `.z.m.subs` and `.z.m.loginfo` are uninitialised. The `set` calls for `register`/`getservices` (lines 29–30) should be placed after the `addw`/`autodiscovery` lines and after `.z.m.subs` is initialised, to close the window.

Comment thread di/torq/servers/servers.q Outdated
registered:0b;

/ trackservers.q l.13-28: flat config key -> (.servers global;trackservers default)
settings:`connections`discoveryregister`connectionsfromdiscovery`subscribetodiscovery`discoveryretry`tracknontorqprocess`hopentimeout`retry`retain`autoclean`debug`startup`discovery!(

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.

PR 139 has enabled in the dictionary do we need it here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's needed. It's TorQ's own setting (trackservers.q l.12, gating both retry timers at l.387), and 0.4.0 left it out. It's added here (55caea0).

Comment thread di/torq/servers/test.q Outdated

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.

should this also use the same qbin as spawnq below?
system QBIN," ",args," -p ",string[port]," -q </dev/null >/dev/null 2>&1 &";

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.

actually looks like all the QBIN are defined differently in the test, might be minor but maybe they can be standardised

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, and it was more than style. spawnpeer was the only fixture running $QHOME/bin/q rather than the binary actually running, so a QHOME pointing at a different install would have tested the wrong q. It now uses QBIN, defined once.

- settings gains `enabled` -> .servers.enabled (1b), gating the discoveryretry
  and serversretry timer jobs (trackservers.q l.12, l.387). Lines are
  byte-identical to di.torq.servers 0.5.0, so feature-chainedtp inherits them.
- test.csv: enabled defaults to 1b.
- test.q: spawnpeer runs QBIN (the running q binary) instead of $QHOME/bin/q;
  QBIN is defined once in the fixture block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/torq/servers/test.q Resolved
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

di.torq.servers converts retry and discoveryretry from a timespan, a "0D00:00:10" string or a
number of seconds. TOML has no timespan type, so these settings can now live in .toml files.
New test rows fail on the previous code.

The di.torq.servers half of c95ce2f from feature-torqx-poc-demo; the chainedtp half lives on
feature-chainedtp.

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/torq/servers/servers.q:35 — The totimespan branch for strings uses "N"$(),x — appending x (already a string) to an empty list () produces a mixed list, not a char vector. The "N"$ cast requires a char vector (e.g. "N"$"0D00:00:10"). The correct form is "N"$x directly (since 10h=abs type x already confirms x is a char vector/atom string). Wrapping with (), will cause a type error at runtime when a string is supplied.

This reverts commit f6788a9. Nothing in this repo sets retry or
discoveryretry as a string or number, and it is outside this PR's scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/torq/servers/servers.q Resolved
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

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

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

@@ -0,0 +1,21 @@
/ Bespoke config for the discovery service - legacy TorQ config/settings/discovery.q (flat keys)
/ list of connections to make at start up

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.

does enabled need to be added here? i see PR 139 has it in default.q

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

enabled:0b, for clarity rather than function. retry and discoveryretry are already 0 here, so this has no effect either way, but it makes the file self-documenting the same way the other settings already are.

@alowrydi
alowrydi merged commit 3297abf into main Oct 2, 2026
alowrydi added a commit that referenced this pull request Oct 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alowrydi
alowrydi deleted the feature-rediscovery branch October 16, 2026 13:16
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