@vibelord/lanes 1.7.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +1 -1
- package/payload/lanes/VERSION +1 -1
- package/payload/lanes/bin/lanes +97 -17
- package/payload/lanes/bin/lanes-site-serve +15 -0
- package/payload/lanes/bin-rs/BINARIES.json +5 -0
- package/payload/lanes/container/lane-mcp +105 -5
- package/payload/lanes/container/lane_core.py +110 -0
- package/payload/lanes/container/throttle-pulse +159 -14
- package/payload/lanes/docs/ARCHITECTURE.md +108 -11
- package/payload/lanes/docs/DESIGN.md +10 -8
- package/payload/lanes/docs/INSTALL.md +1 -1
- package/payload/lanes/docs/RUNBOOK.md +297 -5
- package/payload/lanes/docs/USERGUIDE.md +11 -6
- package/payload/lanes/install/host-install.sh +14 -3
- package/payload/lanes/libexec/adopt.py +325 -0
- package/payload/lanes/libexec/cutover.py +656 -0
- package/payload/lanes/libexec/docsd.py +12 -8
- package/payload/lanes/libexec/doctor_lanes2.py +213 -0
- package/payload/lanes/libexec/economy_poll.py +87 -2
- package/payload/lanes/libexec/lanes_lib.py +465 -2
- package/payload/lanes/libexec/native.sh +38 -0
- package/payload/lanes/libexec/native_bin.py +668 -0
- package/payload/lanes/libexec/shadow.py +1311 -0
- package/payload/lanes/libexec/sidebar.py +252 -30
- package/payload/lanes/libexec/sidebar_status.py +373 -25
- package/payload/lanes/libexec/statusd.py +67 -3
- package/payload/lanes/libexec/tokens.py +99 -131
- package/payload/lanes/libexec/tokens.sh +1 -1
- package/payload/lanes/libexec/update.py +48 -5
- package/payload/lanes/libexec/users.py +282 -0
- package/payload/lanes/site/README.md +9 -0
- package/payload/lanes/site/conformance.py +280 -0
- package/payload/lanes/site/protocol.py +368 -0
- package/payload/lanes/site/server.py +314 -0
- package/payload/lanes/tokens/README.md +156 -0
- package/payload/lanes/tokens/generate.py +930 -0
- package/payload/lanes/tokens/generated/parity.v1.tsv +489 -0
- package/payload/lanes/tokens/generated/tokens.resolved.json +835 -0
- package/payload/lanes/tokens/tokens.v1.json +763 -0
- package/payload/lanes/tokens/tokens.v1.schema.json +143 -0
- package/payload/lanes/web/README.md +132 -4
- package/payload/lanes/web/directory.css +95 -0
- package/payload/lanes/web/directory.js +951 -0
- package/payload/lanes/web/generated/README.md +107 -0
- package/payload/lanes/web/generated/lanes2_protocol.d.mts +1162 -0
- package/payload/lanes/web/generated/lanes2_protocol.mjs +2333 -0
- package/payload/lanes/web/mobile.js +17 -21
- package/payload/lanes/web/tokens.css +137 -0
- package/payload/manifest.json +7 -4
|
@@ -612,11 +612,16 @@ def refresh_containers(names):
|
|
|
612
612
|
previous = read_json(STATE / 'containers.json', {}) or {}
|
|
613
613
|
info = {}
|
|
614
614
|
names = sorted(set(names))
|
|
615
|
+
guests = _guest_routes([n for n in names if IDENT.match(n)]) # H1: a guest's containers are not docker's here
|
|
615
616
|
try: # ONE docker spawn for every container; an invalid name stays that name's error, not the batch's
|
|
616
|
-
answers, failure = containers_info([n for n in names if IDENT.match(n)]), None
|
|
617
|
+
answers, failure = containers_info([n for n in names if IDENT.match(n) and n not in guests]), None
|
|
617
618
|
except (LanesError, subprocess.SubprocessError, ValueError) as error:
|
|
618
619
|
answers, failure = {}, error
|
|
619
620
|
for name in names:
|
|
621
|
+
if name in guests: # no local init: its typed actions and reads go through lanes-site/1 (write_route)
|
|
622
|
+
info[name] = {'pid': 0, 'home': '', 'running': False, 'transport': guests[name], 'container': name}
|
|
623
|
+
atomic_write_if_changed(STATE / 'containers' / f'{name}.pid', '0\n')
|
|
624
|
+
continue
|
|
620
625
|
try:
|
|
621
626
|
if not IDENT.match(name):
|
|
622
627
|
raise LanesError(f'Invalid container name: {name}')
|
|
@@ -651,6 +656,9 @@ def host_path(info, container_path):
|
|
|
651
656
|
raise LanesError(f'Unsafe registry path: {container_path}')
|
|
652
657
|
if not (container_path + '/').startswith(CONTAINER_HOME + '/'):
|
|
653
658
|
raise LanesError(f'Registry outside the home volume: {container_path}')
|
|
659
|
+
if info.get('transport', TRANSPORT_LOCAL) != TRANSPORT_LOCAL:
|
|
660
|
+
raise LanesError(f"{container_path}: container {info.get('container')} runs behind {info['transport']}, "
|
|
661
|
+
'whose files are not readable from this host (lanes-site/1 v1 serves no file reads)')
|
|
654
662
|
if not info.get('home'):
|
|
655
663
|
raise LanesError('Container home volume unknown')
|
|
656
664
|
return Path(info['home']) / container_path[len(CONTAINER_HOME) + 1:]
|
|
@@ -854,7 +862,10 @@ def tmux_probe(info, socket_name, args, timeout=5):
|
|
|
854
862
|
'timeout' no answer in time — on a busy host this says NOTHING about the server
|
|
855
863
|
'error' any other failure; text = tmux's stderr
|
|
856
864
|
Only ok/noserver are observations. A caller that turns timeout/error into "gone" reports an overloaded host
|
|
857
|
-
as lost lanes.
|
|
865
|
+
as lost lanes. A container behind a guest (refresh_containers stamped its `transport`) is asked through
|
|
866
|
+
lanes-site/1 (guest_probe: read verbs only)."""
|
|
867
|
+
if isinstance(info, dict) and info.get('transport', TRANSPORT_LOCAL) != TRANSPORT_LOCAL:
|
|
868
|
+
return guest_probe(info, socket_name, args, timeout)
|
|
858
869
|
if not info.get('pid'):
|
|
859
870
|
return 'noserver', ''
|
|
860
871
|
path = tmux_socket(info, socket_name)
|
|
@@ -895,6 +906,451 @@ def tmux_query(info, socket_name, args, timeout=5):
|
|
|
895
906
|
return text if outcome == 'ok' else None
|
|
896
907
|
|
|
897
908
|
|
|
909
|
+
# ------------------------------------------------------- transport (lanes-site/1 federation seam, plan row H1)
|
|
910
|
+
# Every container is reached through ONE transport, named per board in catalog.json (`"transport"`, DM-LANES-CATALOG,
|
|
911
|
+
# DM-LANES-SITE-ADAPTER): "local" (the default: the container runs on this docker host, reached through
|
|
912
|
+
# /proc/<init>/root and `docker exec`, as before) or "guest:<ssh alias>" (it runs on a guest that serves lanes-site/1 —
|
|
913
|
+
# site/protocol.py, site/server.py — behind a forced-command key; one long-lived `ssh -T` per guest and process).
|
|
914
|
+
# A board's bad transport costs that board only (catalog_transports): build_registry reports it as the board's error
|
|
915
|
+
# and `lanes doctor` prints it; every other board keeps its route. A `guest:` board builds no lanes on this host before
|
|
916
|
+
# its aggregator duty runs (Lanes2 W20): build_registry refuses it `aggregator_absent` (its previous lanes kept, stale),
|
|
917
|
+
# and statusd never reads a guest-stamped container as down (probe_server: nobody knows). refresh_containers stamps a
|
|
918
|
+
# guest's containers `{"transport": "guest:<alias>", "container": <name>}` instead of asking docker about them, and the
|
|
919
|
+
# hooked functions keep their signatures (BEY-6912): tmux_probe/tmux_query send a read verb of a stamped container as
|
|
920
|
+
# `tmux_read` and refuse any other verb there (the one write is `tmux_write`, through lane_write); host_path says a
|
|
921
|
+
# stamped container's files are not readable from here. A typed action asks write_route: for a container with no local
|
|
922
|
+
# init and no guest transport it asks tmux_probe — looked up at call time, so a runtime hook that reaches the container
|
|
923
|
+
# (O-3 part 0) keeps typing — and only when that answers `noserver` is it "not typed: no write transport for
|
|
924
|
+
# <container>" (AR §7.5, BEY-6899): on stderr with a non-zero exit, in the journal and in `lanes doctor`.
|
|
925
|
+
TRANSPORT_LOCAL = 'local'
|
|
926
|
+
TRANSPORT_PROBE = 'tmux_probe' # a route, never a catalog value: no init here, no guest transport, tmux_probe answered
|
|
927
|
+
GUEST_PREFIX = 'guest:'
|
|
928
|
+
NO_WRITE_TRANSPORT = 'no write transport for'
|
|
929
|
+
AGGREGATOR_ABSENT = 'aggregator_absent'
|
|
930
|
+
SITE_SSH_OPTIONS = ('-T', '-o', 'BatchMode=yes', '-o', 'ServerAliveInterval=10', '-o', 'ConnectTimeout=5')
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
class SiteError(LanesError):
|
|
934
|
+
"""A lanes-site/1 refusal (`code` one of site/protocol.py ERRORS) or `no_answer` (no reply within the deadline,
|
|
935
|
+
the connection ended or could not start: a NoAnswer on a write is never resent)."""
|
|
936
|
+
|
|
937
|
+
def __init__(self, code, human):
|
|
938
|
+
super().__init__(f'{human} ({code})')
|
|
939
|
+
self.code, self.human = code, human
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
def site_protocol():
|
|
943
|
+
"""site/protocol.py as a module (one instance per process, like lane_core())."""
|
|
944
|
+
module = sys.modules.get('lanes_site_protocol')
|
|
945
|
+
if module is None:
|
|
946
|
+
import importlib.util
|
|
947
|
+
spec = importlib.util.spec_from_file_location('lanes_site_protocol', str(REPO / 'site' / 'protocol.py'))
|
|
948
|
+
module = importlib.util.module_from_spec(spec)
|
|
949
|
+
spec.loader.exec_module(module)
|
|
950
|
+
sys.modules['lanes_site_protocol'] = module
|
|
951
|
+
return module
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
def parse_transport(value, where='catalog.json'):
|
|
955
|
+
"""'local' or 'guest:<ssh alias>' (an alias of letters, digits and . _ -, at most 63) -> the value; LanesError
|
|
956
|
+
naming `where` otherwise."""
|
|
957
|
+
if value == TRANSPORT_LOCAL:
|
|
958
|
+
return value
|
|
959
|
+
if isinstance(value, str) and value.startswith(GUEST_PREFIX) and \
|
|
960
|
+
site_protocol().ALIAS.match(value[len(GUEST_PREFIX):]):
|
|
961
|
+
return value
|
|
962
|
+
raise LanesError(f'{where}: transport {value!r} is not "local" or "guest:<ssh alias>"')
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
def catalog_transports(site=None, manifests=None):
|
|
966
|
+
"""Every catalog board's transport, scoped per board -> {'routes': {container: transport}, 'boards': {board: why},
|
|
967
|
+
'containers': {container: why}}. A board's optional `transport` (absent = local) names the transport of every
|
|
968
|
+
container its manifest's repositories name (`host`). A board whose transport is invalid, or that puts a container
|
|
969
|
+
behind another transport than a second board does, gets its error in 'boards' (build_registry makes it the board's
|
|
970
|
+
error) and each such container its own in 'containers' (write_route says why nothing is typed); every other board
|
|
971
|
+
and container keeps its route. A board whose manifest cannot be read names no container here (build_registry
|
|
972
|
+
reports that). `manifests` {board: manifest} spares the reads build_registry made already. Raises only when
|
|
973
|
+
catalog.json itself cannot be read."""
|
|
974
|
+
site = read_site_json(workspaces_dir() / 'catalog.json') if site is None else site
|
|
975
|
+
boards, named = {}, {}
|
|
976
|
+
for workspace in site.get('workspaces') or []:
|
|
977
|
+
board = workspace.get('id') if isinstance(workspace, dict) else None
|
|
978
|
+
if not isinstance(board, str):
|
|
979
|
+
continue
|
|
980
|
+
try:
|
|
981
|
+
spec = parse_transport(workspace.get('transport', TRANSPORT_LOCAL), f'board {board}')
|
|
982
|
+
except LanesError as error:
|
|
983
|
+
spec, boards[board] = None, str(error)
|
|
984
|
+
try:
|
|
985
|
+
manifest = (manifests or {}).get(board) or read_site_json(workspaces_dir() / workspace['manifest'])
|
|
986
|
+
except (LanesError, OSError, ValueError, KeyError, TypeError):
|
|
987
|
+
continue
|
|
988
|
+
for repo in manifest.get('repositories') or []:
|
|
989
|
+
host = repo.get('host') if isinstance(repo, dict) else None
|
|
990
|
+
if isinstance(host, str) and host:
|
|
991
|
+
named.setdefault(host, []).append((board, spec))
|
|
992
|
+
routes, containers = {}, {}
|
|
993
|
+
for host, entries in sorted(named.items()):
|
|
994
|
+
invalid = [board for board, spec in entries if spec is None]
|
|
995
|
+
specs = sorted({spec for _board, spec in entries if spec is not None})
|
|
996
|
+
if invalid:
|
|
997
|
+
containers[host] = f'catalog.json {boards[invalid[0]]}'
|
|
998
|
+
elif len(specs) > 1:
|
|
999
|
+
text = f'catalog.json puts container {host} behind ' + ' and '.join(
|
|
1000
|
+
f'{spec} (board {board})' for board, spec in entries)
|
|
1001
|
+
containers[host] = text
|
|
1002
|
+
for board, _spec in entries:
|
|
1003
|
+
boards.setdefault(board, text)
|
|
1004
|
+
else:
|
|
1005
|
+
routes[host] = specs[0]
|
|
1006
|
+
return {'routes': routes, 'boards': boards, 'containers': containers}
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
def _catalog():
|
|
1010
|
+
"""catalog_transports(), or no route at all when catalog.json cannot be read (build_registry refuses then)."""
|
|
1011
|
+
try:
|
|
1012
|
+
return catalog_transports()
|
|
1013
|
+
except (LanesError, OSError, ValueError, KeyError, TypeError, AttributeError):
|
|
1014
|
+
return {'routes': {}, 'boards': {}, 'containers': {}}
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
def container_transports(site=None):
|
|
1018
|
+
"""{container: transport} of every container whose boards agree on a valid transport (catalog_transports)."""
|
|
1019
|
+
return catalog_transports(site)['routes']
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
def transport_of(container):
|
|
1023
|
+
"""The transport catalog.json names for `container`: 'local' unless its boards put it behind a guest."""
|
|
1024
|
+
return _catalog()['routes'].get(container, TRANSPORT_LOCAL)
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
def _guest_routes(names):
|
|
1028
|
+
"""{name: 'guest:<alias>'} of the `names` a catalog board puts behind a guest."""
|
|
1029
|
+
routes = _catalog()['routes']
|
|
1030
|
+
return {name: routes[name] for name in names if routes.get(name, TRANSPORT_LOCAL) != TRANSPORT_LOCAL}
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
def board_refusal(workspace, transports):
|
|
1034
|
+
"""Why build_registry builds no lanes for catalog board `workspace` on this host, or None: its transport is invalid
|
|
1035
|
+
or conflicts with another board's (catalog_transports), or it is a `guest:` board, which only an aggregator
|
|
1036
|
+
builds — `aggregator_absent` until that duty runs (Lanes2 W20, AR §7.5)."""
|
|
1037
|
+
board = workspace.get('id')
|
|
1038
|
+
if board in transports['boards']:
|
|
1039
|
+
return f"catalog.json {transports['boards'][board]}"
|
|
1040
|
+
transport = workspace.get('transport', TRANSPORT_LOCAL)
|
|
1041
|
+
if isinstance(transport, str) and transport.startswith(GUEST_PREFIX):
|
|
1042
|
+
return (f'{AGGREGATOR_ABSENT}: board {board} is behind {transport}; this host builds no lanes for a guest '
|
|
1043
|
+
'board before its aggregator duty runs (Lanes2 W20): its previous lanes are kept, stale '
|
|
1044
|
+
'(lanes/docs/RUNBOOK.md "Federation")')
|
|
1045
|
+
return None
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
def _route(container, info):
|
|
1049
|
+
"""(route, None) with route 'local' or 'guest:<alias>' — the stamp, else a local init, else the catalog — or
|
|
1050
|
+
(None, why) when the catalog cannot give `container` a transport (an invalid or conflicting board)."""
|
|
1051
|
+
if info.get('transport', TRANSPORT_LOCAL) != TRANSPORT_LOCAL:
|
|
1052
|
+
return info['transport'], None
|
|
1053
|
+
if info.get('pid'): # its init runs here: local, without reading the catalog
|
|
1054
|
+
return TRANSPORT_LOCAL, None
|
|
1055
|
+
catalog = _catalog()
|
|
1056
|
+
if container in catalog['containers']:
|
|
1057
|
+
return None, f"{NO_WRITE_TRANSPORT} {container} ({catalog['containers'][container]})"
|
|
1058
|
+
return catalog['routes'].get(container, TRANSPORT_LOCAL), None
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
def _untypable(container, info):
|
|
1062
|
+
"""Why nothing reaches a local `container` whose tmux_probe answered `noserver` with no init of it running here."""
|
|
1063
|
+
if info.get('pid'):
|
|
1064
|
+
return f"{NO_WRITE_TRANSPORT} {container} (its recorded init pid {info['pid']} does not run on this host)"
|
|
1065
|
+
if info.get('home') and not info.get('error'):
|
|
1066
|
+
return f'container {container} is not running'
|
|
1067
|
+
detail = (f"docker gave no answer about it: {info['error']}" if info.get('error') else
|
|
1068
|
+
'docker has no such container on this host, catalog.json names no "transport" for its board, and '
|
|
1069
|
+
'tmux_probe reaches no server there')
|
|
1070
|
+
return f'{NO_WRITE_TRANSPORT} {container} ({detail})'
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
def write_route(container, info=None, socket=None):
|
|
1074
|
+
"""How a typed action reaches `container` -> (route, None): 'local' (its init runs on this host), 'guest:<alias>',
|
|
1075
|
+
or TRANSPORT_PROBE ('tmux_probe': no init here and no guest transport, but tmux_probe — looked up at call time, so a
|
|
1076
|
+
runtime hook replaces it — answered `list-sessions` on the lane's `socket`: typing goes through it) — else
|
|
1077
|
+
(None, why). AR §7.5: a container with no local pid is `no write transport for <name> (…)` only once tmux_probe
|
|
1078
|
+
answered `noserver` (or no `socket` was given to ask), `container <name> is not running` for a local container
|
|
1079
|
+
docker knows stopped, and an answer that is no answer (timeout, error) is not typed but says so."""
|
|
1080
|
+
info = info if isinstance(info, dict) else {}
|
|
1081
|
+
route, why = _route(container, info)
|
|
1082
|
+
if route != TRANSPORT_LOCAL or info.get('pid'):
|
|
1083
|
+
return route, why
|
|
1084
|
+
if socket:
|
|
1085
|
+
outcome, detail = tmux_probe(info, socket, ['list-sessions', '-F', '#{session_name}'])
|
|
1086
|
+
if outcome == 'ok':
|
|
1087
|
+
return TRANSPORT_PROBE, None
|
|
1088
|
+
if outcome != 'noserver':
|
|
1089
|
+
return None, f'tmux_probe gave no answer about {container} ({outcome}{": " + detail if detail else ""})'
|
|
1090
|
+
return None, _untypable(container, info)
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
def no_write_transport(why):
|
|
1094
|
+
"""True when a write_route `why` is the no-write-transport kind (not a stopped container, not a slow answer)."""
|
|
1095
|
+
return isinstance(why, str) and why.startswith(NO_WRITE_TRANSPORT)
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
def site_ssh_argv(alias):
|
|
1099
|
+
"""The one ssh client of a guest's site channel: no pty, no prompt, keepalives; the guest's forced command picks
|
|
1100
|
+
what runs, so no remote command is sent."""
|
|
1101
|
+
if not site_protocol().ALIAS.match(str(alias or '')):
|
|
1102
|
+
raise LanesError(f'invalid ssh alias {alias!r}')
|
|
1103
|
+
return ['ssh', *SITE_SSH_OPTIONS, alias]
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
class SiteClient:
|
|
1107
|
+
"""One lanes-site/1 connection: `argv` (default `site_ssh_argv(alias)`) started on first use, `hello` first, then
|
|
1108
|
+
one request at a time with a deadline. A reply that does not come in time, a frame that is not one, or a channel
|
|
1109
|
+
that ends closes the connection (SiteError no_answer); the next call starts a new one. Never resends a request."""
|
|
1110
|
+
|
|
1111
|
+
def __init__(self, alias, argv=None, env=None):
|
|
1112
|
+
self.alias, self.argv, self.env = alias, argv, env
|
|
1113
|
+
self.child = self.reader = self.errors = None
|
|
1114
|
+
self.next_id, self.hello = 0, None
|
|
1115
|
+
|
|
1116
|
+
def _start(self):
|
|
1117
|
+
P = site_protocol()
|
|
1118
|
+
self.errors = tempfile.TemporaryFile()
|
|
1119
|
+
try:
|
|
1120
|
+
self.child = subprocess.Popen(self.argv or site_ssh_argv(self.alias), stdin=subprocess.PIPE,
|
|
1121
|
+
stdout=subprocess.PIPE, stderr=self.errors, env=self.env)
|
|
1122
|
+
except OSError as error:
|
|
1123
|
+
self.close()
|
|
1124
|
+
raise SiteError('no_answer', f'{GUEST_PREFIX}{self.alias}: cannot start ({error.strerror or error})') from None
|
|
1125
|
+
self.reader, self.next_id = P.FrameReader(self.child.stdout.fileno()), 0
|
|
1126
|
+
try:
|
|
1127
|
+
self.hello = self._request('hello', {'client': f'lanes/{tree_version(REPO) or "unknown"}',
|
|
1128
|
+
'proto': P.PROTO}, P.DEADLINE_S, {'lanes_site': P.PROTO})
|
|
1129
|
+
except SiteError:
|
|
1130
|
+
self.close()
|
|
1131
|
+
raise
|
|
1132
|
+
if self.hello.get('lanes_site') != P.PROTO:
|
|
1133
|
+
self.close()
|
|
1134
|
+
raise SiteError('version_unsupported', f'{GUEST_PREFIX}{self.alias} serves lanes-site/'
|
|
1135
|
+
f'{self.hello.get("lanes_site")}, this host speaks {P.PROTO}')
|
|
1136
|
+
|
|
1137
|
+
def _stderr_tail(self):
|
|
1138
|
+
try:
|
|
1139
|
+
self.errors.seek(0)
|
|
1140
|
+
text = self.errors.read()[-300:].decode('utf-8', 'replace').strip()
|
|
1141
|
+
except (OSError, ValueError, AttributeError):
|
|
1142
|
+
return ''
|
|
1143
|
+
return f': {text.splitlines()[-1]}' if text else ''
|
|
1144
|
+
|
|
1145
|
+
def _request(self, op, args, timeout, extra=None):
|
|
1146
|
+
P = site_protocol()
|
|
1147
|
+
request_id, self.next_id = self.next_id, self.next_id + 1
|
|
1148
|
+
try:
|
|
1149
|
+
P.write_frame(self.child.stdin.fileno(), dict({'id': request_id, 'op': op, 'args': args}, **(extra or {})))
|
|
1150
|
+
except (OSError, ValueError) as error:
|
|
1151
|
+
tail = self._stderr_tail()
|
|
1152
|
+
self.close()
|
|
1153
|
+
raise SiteError('no_answer', f'{GUEST_PREFIX}{self.alias}: {op} not sent ({error}){tail}') from None
|
|
1154
|
+
deadline = time.monotonic() + timeout
|
|
1155
|
+
while True:
|
|
1156
|
+
try:
|
|
1157
|
+
reply = self.reader.read(max(0.0, deadline - time.monotonic()))
|
|
1158
|
+
except TimeoutError:
|
|
1159
|
+
self.close()
|
|
1160
|
+
raise SiteError('no_answer', f'{GUEST_PREFIX}{self.alias}: no answer to {op} within {timeout:g} s') \
|
|
1161
|
+
from None
|
|
1162
|
+
except P.ProtocolError as error:
|
|
1163
|
+
self.close()
|
|
1164
|
+
raise SiteError('no_answer', f'{GUEST_PREFIX}{self.alias}: {error.human}') from None
|
|
1165
|
+
if reply is None:
|
|
1166
|
+
tail = self._stderr_tail()
|
|
1167
|
+
self.close()
|
|
1168
|
+
raise SiteError('no_answer', f'{GUEST_PREFIX}{self.alias}: the channel ended{tail}')
|
|
1169
|
+
if reply.get('id') != request_id:
|
|
1170
|
+
continue # the late reply to a request this client already gave up on
|
|
1171
|
+
if isinstance(reply.get('err'), dict):
|
|
1172
|
+
raise SiteError(str(reply['err'].get('code') or 'internal'), str(reply['err'].get('human') or ''))
|
|
1173
|
+
if not isinstance(reply.get('ok'), dict):
|
|
1174
|
+
raise SiteError('frame_invalid', f'{GUEST_PREFIX}{self.alias}: a reply without ok or err')
|
|
1175
|
+
return reply['ok']
|
|
1176
|
+
|
|
1177
|
+
def call(self, op, args=None, timeout=None):
|
|
1178
|
+
"""The `ok` object of one request, else SiteError (the guest's code, or no_answer). A mutating op (protocol
|
|
1179
|
+
MUTATING) carries a fresh `intent` id unless the caller gave one: the guest echoes it, and an owner fence
|
|
1180
|
+
(W17) resolves a NoAnswer by it — never by resending."""
|
|
1181
|
+
P = site_protocol()
|
|
1182
|
+
args = dict(args or {})
|
|
1183
|
+
if op in P.MUTATING and 'intent' not in args:
|
|
1184
|
+
args['intent'] = secrets.token_hex(16)
|
|
1185
|
+
if self.child is None or self.child.poll() is not None:
|
|
1186
|
+
self.close()
|
|
1187
|
+
self._start()
|
|
1188
|
+
return self._request(op, args, P.DEADLINE_S if timeout is None else timeout)
|
|
1189
|
+
|
|
1190
|
+
def close(self):
|
|
1191
|
+
child, self.child, self.reader = self.child, None, None
|
|
1192
|
+
if child is not None:
|
|
1193
|
+
for stream in (child.stdin, child.stdout):
|
|
1194
|
+
try:
|
|
1195
|
+
stream.close()
|
|
1196
|
+
except OSError:
|
|
1197
|
+
pass
|
|
1198
|
+
try:
|
|
1199
|
+
child.terminate()
|
|
1200
|
+
child.wait(timeout=2)
|
|
1201
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
1202
|
+
try:
|
|
1203
|
+
child.kill()
|
|
1204
|
+
except OSError:
|
|
1205
|
+
pass
|
|
1206
|
+
if self.errors is not None:
|
|
1207
|
+
self.errors.close()
|
|
1208
|
+
self.errors = None
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
_SITE_CLIENTS = {}
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
def site_client(alias):
|
|
1215
|
+
"""This process's one SiteClient of a guest alias (started on its first call)."""
|
|
1216
|
+
client = _SITE_CLIENTS.get(alias)
|
|
1217
|
+
if client is None:
|
|
1218
|
+
client = _SITE_CLIENTS[alias] = SiteClient(alias)
|
|
1219
|
+
return client
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
def _guest_alias(route):
|
|
1223
|
+
return route[len(GUEST_PREFIX):]
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
def guest_probe(info, socket_name, args, timeout=5):
|
|
1227
|
+
"""tmux_probe of a container behind a guest: a read verb (site/protocol.py check_tmux_read) as `tmux_read`, its
|
|
1228
|
+
outcome as tmux_probe's; any other verb is refused here, unsent ('error'): the one write is lane_write's scoped
|
|
1229
|
+
`tmux_write`. A guest that gives no answer is 'timeout' — nothing about the server."""
|
|
1230
|
+
P, route = site_protocol(), info.get('transport')
|
|
1231
|
+
try:
|
|
1232
|
+
words = P.check_tmux_read(list(args))
|
|
1233
|
+
except P.ProtocolError as error:
|
|
1234
|
+
return 'error', f'not sent to {route}: {error.human} (a write goes through tmux_write)'
|
|
1235
|
+
try:
|
|
1236
|
+
answer = site_client(_guest_alias(route)).call(
|
|
1237
|
+
'tmux_read', {'container': info.get('container'), 'socket': socket_name, 'args': words}, timeout + 1)
|
|
1238
|
+
except SiteError as error:
|
|
1239
|
+
return ('timeout' if error.code == 'no_answer' else 'error'), error.human
|
|
1240
|
+
outcome, text = answer.get('outcome'), answer.get('text')
|
|
1241
|
+
if outcome not in ('ok', 'noserver', 'timeout', 'error'):
|
|
1242
|
+
return 'error', f'{route}: tmux_read answered no outcome'
|
|
1243
|
+
return outcome, text if isinstance(text, str) else ''
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
def lane_write(lane, info, text, enter=False):
|
|
1247
|
+
"""Type `text` (and, with `enter`, an Enter as a second client lane_core.ENTER_DELAY s later) into the active pane
|
|
1248
|
+
of a tmux lane through its container's transport -> (outcome, detail): 'typed', 'typed-no-enter', 'failed' (not
|
|
1249
|
+
typed), 'no_transport' (not typed: no write transport, AR §7.5), 'unknown' (the guest gave no answer: whether it
|
|
1250
|
+
was typed is not known, and it is not resent). Local — a container whose init runs here, or one with no init here
|
|
1251
|
+
and no guest transport — through tmux_probe send-keys, as `lanes upload --paste` always typed: tmux_probe is looked
|
|
1252
|
+
up at call time, so a runtime hook that reaches the container keeps typing, and only its `noserver` (with no init
|
|
1253
|
+
of the container running here) is `no_transport`. Guest: the guest's `tmux_write`, which takes the lane's dispatch
|
|
1254
|
+
lock there."""
|
|
1255
|
+
tmux = lane.get('tmux') if isinstance(lane.get('tmux'), dict) else {}
|
|
1256
|
+
if lane.get('holder') != 'tmux' or not tmux.get('socket') or not tmux.get('session'):
|
|
1257
|
+
return 'failed', 'not typed: not a tmux lane'
|
|
1258
|
+
container, info = lane.get('container') or '', info if isinstance(info, dict) else {}
|
|
1259
|
+
route, why = _route(container, info)
|
|
1260
|
+
if route is None:
|
|
1261
|
+
return 'no_transport', f'not typed: {why}'
|
|
1262
|
+
if route == TRANSPORT_LOCAL:
|
|
1263
|
+
target = f"={tmux['session']}:"
|
|
1264
|
+
literal = text[:-1] + '\\;' if text.endswith(';') else text # = lane_core.tmux_text, without loading it
|
|
1265
|
+
outcome, detail = tmux_probe(info, tmux['socket'], ['send-keys', '-t', target, '-l', '--', literal])
|
|
1266
|
+
if outcome == 'noserver' and not os.path.exists(f"{proc_root()}/{info.get('pid')}"):
|
|
1267
|
+
why = _untypable(container, info)
|
|
1268
|
+
return ('no_transport' if no_write_transport(why) else 'failed'), f'not typed: {why}'
|
|
1269
|
+
if outcome != 'ok':
|
|
1270
|
+
return 'failed', f'not typed: tmux did not take it ({outcome}{": " + detail if detail else ""})'
|
|
1271
|
+
if not enter:
|
|
1272
|
+
return 'typed', 'typed'
|
|
1273
|
+
names_pause(lane_core().ENTER_DELAY)
|
|
1274
|
+
outcome, _detail = tmux_probe(info, tmux['socket'], ['send-keys', '-t', target, 'Enter'])
|
|
1275
|
+
return ('typed', 'typed') if outcome == 'ok' else ('typed-no-enter', f'typed without its Enter (tmux {outcome})')
|
|
1276
|
+
try:
|
|
1277
|
+
answer = site_client(_guest_alias(route)).call('tmux_write', {'lane': lane.get('id'), 'text': text,
|
|
1278
|
+
'enter': bool(enter)},
|
|
1279
|
+
site_protocol().WRITE_DEADLINE_S)
|
|
1280
|
+
except SiteError as error:
|
|
1281
|
+
if error.code == 'no_answer':
|
|
1282
|
+
return 'unknown', f'not known whether it was typed: {error.human}; not resent'
|
|
1283
|
+
return 'failed', f'not typed: {route} refused it: {error.human} ({error.code})'
|
|
1284
|
+
if enter and not answer.get('enter'):
|
|
1285
|
+
return 'typed-no-enter', f'typed through {route} without its Enter'
|
|
1286
|
+
return 'typed', f'typed through {route}'
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
def names_refusal(lane, info):
|
|
1290
|
+
"""Why `/rename` (or any typed action whose recipient check reads the container's own files: `lanes names sync
|
|
1291
|
+
--write`, `lanes message`) cannot reach `lane` from this host at all -> 'not typed…', or None when it can or when
|
|
1292
|
+
only "not now" stands in the way (a stopped container stays a deferral). No write transport (BEY-6899); a guest
|
|
1293
|
+
route (lanes-site/1 v1 carries no rename: its recipient check reads that guest container's Claude session files,
|
|
1294
|
+
so `lanes names sync --write` runs on the guest; BEY-6899 keeps the rd-control witness open); a tmux_probe-only
|
|
1295
|
+
route (no init here: the same files are not readable from this host)."""
|
|
1296
|
+
container = lane.get('container') or ''
|
|
1297
|
+
route, why = write_route(container, info, (lane.get('tmux') or {}).get('socket'))
|
|
1298
|
+
if route is None:
|
|
1299
|
+
return f'not typed: {why}' if no_write_transport(why) else None
|
|
1300
|
+
if route == TRANSPORT_PROBE:
|
|
1301
|
+
return (f'not typed: container {container} has no init on this host (tmux_probe reaches it, a runtime hook); '
|
|
1302
|
+
'the recipient check reads its Claude session files, which are not readable from here')
|
|
1303
|
+
if route != TRANSPORT_LOCAL:
|
|
1304
|
+
return (f"not typed here: {lane.get('id')} runs behind {route}; lanes-site/1 v1 carries no rename (the "
|
|
1305
|
+
"recipient check reads that guest's Claude session files): run `lanes names sync --write` on the guest")
|
|
1306
|
+
return None
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
def transport_report(registry, containers, greet=True):
|
|
1310
|
+
"""`lanes doctor`'s transport lines -> [(ok, label, detail)]: per container a registry tmux lane names, a ✗ when it
|
|
1311
|
+
has no write transport (write_route, with tmux_probe asked on one of its lanes' sockets) and a ✓ when only
|
|
1312
|
+
tmux_probe reaches it (a runtime hook: typing works, the recipient checks of renames and messages do not); with
|
|
1313
|
+
`greet`, per guest a catalog board names (guest boards build no lanes here before the aggregator, so the catalog,
|
|
1314
|
+
not the registry, names them) whether it answers lanes-site/1 (`hello`, then `boards.list`). Nothing when every
|
|
1315
|
+
container is local and reachable and no board names a guest."""
|
|
1316
|
+
sockets = {}
|
|
1317
|
+
for workspace in (registry or {}).get('workspaces') or []:
|
|
1318
|
+
for lane in workspace.get('lanes') or []:
|
|
1319
|
+
tmux = lane.get('tmux') if isinstance(lane.get('tmux'), dict) else {}
|
|
1320
|
+
if lane.get('holder') == 'tmux' and lane.get('container') and tmux.get('socket'):
|
|
1321
|
+
sockets.setdefault(lane['container'], tmux['socket'])
|
|
1322
|
+
lines = []
|
|
1323
|
+
for name, socket in sorted(sockets.items()):
|
|
1324
|
+
route, why = write_route(name, (containers or {}).get(name), socket)
|
|
1325
|
+
if route is None and no_write_transport(why):
|
|
1326
|
+
lines.append((False, f'write transport for {name}',
|
|
1327
|
+
f'not typed: {why} — upload --paste, lanes message, names sync, statusd\'s inbox drain and '
|
|
1328
|
+
'auto-rename type nothing into its lanes; name its board\'s "transport" in catalog.json '
|
|
1329
|
+
'(guest:<ssh alias>, lanes-site/1: lanes/docs/RUNBOOK.md "Federation")'))
|
|
1330
|
+
elif route == TRANSPORT_PROBE:
|
|
1331
|
+
lines.append((True, f'write transport for {name}', 'tmux_probe reaches it with no init on this host (a '
|
|
1332
|
+
'runtime hook): typed; names sync and lanes message refuse (their recipient checks read its '
|
|
1333
|
+
'files)'))
|
|
1334
|
+
if not greet:
|
|
1335
|
+
return lines
|
|
1336
|
+
guests = {}
|
|
1337
|
+
for name, route in sorted(_catalog()['routes'].items()):
|
|
1338
|
+
if route != TRANSPORT_LOCAL:
|
|
1339
|
+
guests.setdefault(route, []).append(name)
|
|
1340
|
+
for route, names in sorted(guests.items()):
|
|
1341
|
+
client = site_client(_guest_alias(route))
|
|
1342
|
+
try:
|
|
1343
|
+
boards = client.call('boards.list').get('boards') or []
|
|
1344
|
+
lines.append((True, f'{route} answers lanes-site/1',
|
|
1345
|
+
f"{len(boards)} boards; serves {', '.join(names)} (its boards build no lanes here before "
|
|
1346
|
+
'the aggregator, Lanes2 W20)'))
|
|
1347
|
+
except LanesError as error:
|
|
1348
|
+
lines.append((False, f'{route} answers lanes-site/1', f"{error} — {', '.join(names)}"))
|
|
1349
|
+
finally:
|
|
1350
|
+
client.close()
|
|
1351
|
+
return lines
|
|
1352
|
+
|
|
1353
|
+
|
|
898
1354
|
# -------------------------------------------------------------------- health
|
|
899
1355
|
# Host pressure from PLAIN FILES only — no subprocess: this is read exactly when spawning is what hurts.
|
|
900
1356
|
|
|
@@ -1702,6 +2158,9 @@ def rename_claude(lane, address, info):
|
|
|
1702
2158
|
client `lane_core.ENTER_DELAY` seconds later (DEF-1803) if the process is still the same. Never reads anything but
|
|
1703
2159
|
the `<pid>.json` session files: the messaging key files beside them are not opened (DEF-1802)."""
|
|
1704
2160
|
import agent_state as AS # libexec; agent_state imports nothing of lanes_lib
|
|
2161
|
+
refusal = names_refusal(lane, info) # H1: no write transport, a guest, a tmux_probe-only route: never an exit 0
|
|
2162
|
+
if refusal:
|
|
2163
|
+
return 'failed', refusal
|
|
1705
2164
|
if not info.get('pid'):
|
|
1706
2165
|
return 'failed', 'container not running: not typed'
|
|
1707
2166
|
tmux = lane.get('tmux') or {}
|
|
@@ -1956,6 +2415,7 @@ def build_registry(previous=None, strict=True):
|
|
|
1956
2415
|
for repo in manifest.get('repositories') or []:
|
|
1957
2416
|
container_names.add(repo.get('host'))
|
|
1958
2417
|
containers = refresh_containers(name for name in container_names if name)
|
|
2418
|
+
transports = catalog_transports(site, manifests) # H1: a bad or guest board transport is that board's error
|
|
1959
2419
|
previous_by_id = {w['id']: w for w in (previous or {}).get('workspaces', [])}
|
|
1960
2420
|
workspaces = []
|
|
1961
2421
|
used_ids = set()
|
|
@@ -1965,6 +2425,9 @@ def build_registry(previous=None, strict=True):
|
|
|
1965
2425
|
'cwd': _workspace_cwd(manifest), 'errors': []}
|
|
1966
2426
|
coordinator = None
|
|
1967
2427
|
try:
|
|
2428
|
+
refusal = board_refusal(workspace, transports)
|
|
2429
|
+
if refusal:
|
|
2430
|
+
raise LanesError(refusal)
|
|
1968
2431
|
lanes = _workspace_lanes(manifest, containers)
|
|
1969
2432
|
# W15 L2/L2b: the board's address overrides and coordinator, checked against its terminals. A bad one is
|
|
1970
2433
|
# a board error like a bad displayNames override: this board keeps its previous lanes and settings.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Lanes 2.0 native binaries: the shell readers' half of libexec/native_bin.py resolve() (lanes2 Round 1 H2; AR 7.3,
|
|
2
|
+
# 9.3, D9). Sourced (`. "$tree/libexec/native.sh"`), never executed. POSIX sh, no fork, no site.conf parse.
|
|
3
|
+
#
|
|
4
|
+
# lanes_native COMPONENT TREE
|
|
5
|
+
#
|
|
6
|
+
# sets $lanes_native to the native binary COMPONENT (relay, sidebar, key or signal) runs from TREE, or to the empty
|
|
7
|
+
# string for its Python path. Native only while `lanes rs apply` admitted the flag, i.e. while
|
|
8
|
+
# $LANES_STATE/flags/native.<component> exists ([ -e ]; `shadow` never selects a binary), and then only the FIRST
|
|
9
|
+
# candidate that exists, in resolve()'s order:
|
|
10
|
+
# 1. $LANES_SHARE/bin-rs/<binary>, the link `lanes rs install` made: used when it is a link to an executable file;
|
|
11
|
+
# 2. TREE/bin-rs/x86_64-unknown-linux-musl/<binary>: used when it is an executable file, not a link.
|
|
12
|
+
# A candidate that exists but fails its test keeps the Python path: it is never passed over for the next one, because
|
|
13
|
+
# only the first was checked (resolve: what runs is what was checked). test_flags.ShReader pins this against resolve()
|
|
14
|
+
# case by case. The binary names repeat native_bin.COMPONENT_BINARY (test_flags pins that too). Nothing sources this in
|
|
15
|
+
# Round 1: the reader hooks in view.sh (the relay, holders/ssh.sh included) and the sidebar wrapper are lane C7's.
|
|
16
|
+
lanes_native() {
|
|
17
|
+
lanes_native=
|
|
18
|
+
case $1 in
|
|
19
|
+
relay|sidebar|key) lanes_native_binary=lanes-terminal ;;
|
|
20
|
+
signal) lanes_native_binary=lanes-hook ;;
|
|
21
|
+
*) return 0 ;;
|
|
22
|
+
esac
|
|
23
|
+
[ -e "${LANES_STATE:-$HOME/.local/state/lanes}/flags/native.$1" ] || return 0
|
|
24
|
+
lanes_native_candidate=${LANES_SHARE:-$HOME/.local/share/lanes}/bin-rs/$lanes_native_binary
|
|
25
|
+
if [ -e "$lanes_native_candidate" ] || [ -L "$lanes_native_candidate" ]; then
|
|
26
|
+
if [ -L "$lanes_native_candidate" ] && [ -f "$lanes_native_candidate" ] && [ -x "$lanes_native_candidate" ]; then
|
|
27
|
+
lanes_native=$lanes_native_candidate
|
|
28
|
+
fi
|
|
29
|
+
return 0
|
|
30
|
+
fi
|
|
31
|
+
lanes_native_candidate=$2/bin-rs/x86_64-unknown-linux-musl/$lanes_native_binary
|
|
32
|
+
if [ -e "$lanes_native_candidate" ] || [ -L "$lanes_native_candidate" ]; then
|
|
33
|
+
if [ ! -L "$lanes_native_candidate" ] && [ -f "$lanes_native_candidate" ] && [ -x "$lanes_native_candidate" ]; then
|
|
34
|
+
lanes_native=$lanes_native_candidate
|
|
35
|
+
fi
|
|
36
|
+
fi
|
|
37
|
+
return 0
|
|
38
|
+
}
|