Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
d8e688b
Test: 使用率のキャッシュ・外した間・上限の観測と status line の記録の失敗するテストを足す(#3604 #3864)
takemi-ohama Nov 21, 2026
eb3750c
Add: 使用率のキャッシュ・外した間・上限の観測と status line の記録を足す(#3604 #3864)
takemi-ohama Nov 21, 2026
8b05375
Docs: 要求仕様の影響の表の使用率のキャッシュの 2 行を設計で決めた形へ直す(#3604 #3864)
takemi-ohama Nov 21, 2026
94e9cb6
Fix: 使用率のキャッシュの世代・パス・錠・後始末と status line の書き方を直す(#3604 #3864 PR 4028 の…
takemi-ohama Nov 21, 2026
d1b8d70
Fix: flock の無い環境の status line の錠・旧い登録の世代・削除の確かめを直す(#3604 #3864 PR 402…
takemi-ohama Nov 21, 2026
ff15aca
Fix: 旧い登録の世代の決め方を設計に書き、出していない形式の錠の削除を外し、登録の削除を外す操作と残りの削除に分ける(#3604 #3…
takemi-ohama Nov 22, 2026
29d1361
Fix: 削除の打ち直しは残りだけを消し、今の登録に触れない(#3604 #3864 PR 4028 の cross-review の 5…
takemi-ohama Nov 22, 2026
b74acce
Fix: 登録の削除を登録と同じ排他の中で行い、打ち直しは残りを先に消して今の登録に触れない(#3604 #3864 PR 4028 の …
takemi-ohama Nov 22, 2026
7db2b44
fix(relay): 残りの後始末の打ち直しが排他待ちの間に残りが消えても今の登録を外さない (#4028 r7-1)
takemi-ohama Nov 22, 2026
612bba0
Fix: 登録の削除の 2 行に境界の種類を書き、ndf check の NDF501・NDF402 を通す(#3604 #3864)
takemi-ohama Nov 22, 2026
eadfc31
Fix: 外した間と上限の観測のファイルの行に keys を置く(名前を頭に持つ形なので空)(#3604 #3864)
takemi-ohama Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions issues/issue-3604-3864-design-detail.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions issues/issue-3864-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ NDF `main` の d16aa39d0(11.0.8 の後)・d14325d76(11.0.13 の後)、Li

| 対象 | 影響 |
| --- | --- |
| 公開インタフェース | 変わる。使用率のキャッシュ(`usage.json`)の行にリセットの時刻が足される(今は書き手が無いので互換の問題は無い)。status line が使用率を記録する。コマンドの引数と結果の形は変わらない |
| 公開インタフェース | 変わる。使用率のキャッシュは、アカウントごと・登録の世代ごとのファイル `usage/<名前>/<世代>.json`(`<状態の保存先>/relay/accounts/` の下。書き手は NDF の status line)になり、使用率の API の取得の記録を `.usage-fetch/<名前>/<世代>.json`(`<アカウントの登録簿>/` の下。書き手は使用率の API の取得)に置く。どちらも窓ごとにリセットの時刻を持つ(今の `usage.json` は書き手が無いので互換の問題は無い)。status line が使用率を記録する。コマンドの引数と結果の形は変わらない |
| 重さ | 中継のアカウントの切り替えが一度も働かない。2 つ以上のアカウントを登録した利用者のレーンが上限で止まる。回避は、`/exit` して手で別のアカウントで起動し直すこと |
| データ | `usage.json`(`<状態の保存先>/relay/accounts/`)に行のキーが増える。認証の失敗で外したアカウントの記録が状態の保存先に増える |
| データ | 使用率のキャッシュ `usage/<名前>/<世代>.json`(`<状態の保存先>/relay/accounts/` の下)と、取得の記録 `.usage-fetch/<名前>/<世代>.json`(`<アカウントの登録簿>/` の下)が増える。認証の失敗で外したアカウントの記録が状態の保存先に増える |
| 既存の振る舞い | 上限・401・カットポイントでの切り替え、指定の効く時点、従量の接続への退避が変わる。手順書の大半の節が書き直しになる |

## 用語
Expand Down
4 changes: 3 additions & 1 deletion plugins/ndf/contracts/domains/ndf-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
{"id": "relay-next", "location": "relay-wrappers", "path": "<名前>/next.json", "kind": "exchange", "tracked": false, "writer": "Stop の hook(M3a)", "ends": "run"},
{"id": "relay-question", "location": "relay-wrappers", "path": "<名前>/question.json", "kind": "exchange", "tracked": false, "writer": "PreToolUse の hook(M3a)", "ends": "run"},
{"id": "relay-stop", "location": "relay-wrappers", "path": "<名前>/stop", "kind": "exchange", "tracked": false, "writer": "ndf relay stop(M3b)と人(touch)", "ends": "run"},
{"id": "relay-usage", "location": "relay-accounts", "path": "usage.json", "kind": "measured", "tracked": false, "writer": "使用率のセンサー(M3a)", "ends": "replaced", "keys": ["accounts"]},
{"id": "relay-usage", "location": "relay-accounts", "path": "usage/<名前>/<世代>.json", "kind": "measured", "tracked": false, "writer": "NDF の status line(statusline.sh)", "ends": "replaced", "keys": ["windows", "recorded_at"]},
{"id": "relay-auth-held", "location": "relay-accounts", "path": "held.json", "kind": "measured", "tracked": false, "writer": "中継のラッパー(M3b)", "ends": "replaced", "keys": []},
{"id": "relay-limit-seen", "location": "relay-accounts", "path": "limited.json", "kind": "measured", "tracked": false, "writer": "中継のラッパー(M3b)", "ends": "replaced", "keys": []},
{"id": "gws-install-material", "location": "google-workspace", "path": "install.md", "kind": "document", "tracked": false, "writer": "gws の確認(S1d)", "ends": "replaced"},
{"id": "relay-pinned-account", "location": "relay-accounts", "path": "pinned.json", "kind": "ndf_settings", "tracked": false, "writer": "人(ndf relay account use)", "ends": "replaced"},
{"id": "relay-marker", "location": "relay-markers", "path": "<id>.json", "kind": "exchange", "tracked": false, "writer": "中継のラッパー(M3b)", "ends": "run"},
Expand Down
2 changes: 2 additions & 0 deletions plugins/ndf/contracts/limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
"relay.registry-lock": {"summary": "リレーハブの登録簿の排他を待つ上限", "seconds": 5},
"relay.child-exit": {"summary": "ラッパーが子を強制終了した後、子の終わりを確かめるまで待つ上限。終わらなければ次の子を起動せずに止める(#3814)", "seconds": 5},
"relay.signal-lock": {"summary": "シグナルファイル(次のセグメントのマーカー・質問)の排他を待つ上限。hook の締め切りの中に収める", "seconds": 0.3},
"relay.auth-hold": {"summary": "認証の失敗で、そのアカウントを替え先と指定の候補から外す秒(#3864)", "seconds": 3600},
"relay.limit-unknown": {"summary": "上限の行を見たアカウントの使用率の記録に有効な窓が無いとき、上限として扱う秒(5 時間の窓の長さ)", "seconds": 18000},
"relay.usage-guard": {"summary": "利用上限の前にカットポイントでアカウントを替える使用率(百分率。#3336)", "count": 90},
"relay.transcript-tail": {"summary": "ラッパーが文脈の量を読む会話の記録の末尾の大きさ(バイト)", "count": 262144},
"relay.context": {"summary": "中継の下のセッションを次のセグメントへ切り替える文脈の量(token。#2595)", "count": 800000},
Expand Down
4 changes: 3 additions & 1 deletion plugins/ndf/docs/contracts/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ NDF の工程が書くファイル(設定・計測値・実行の記録・文
| `project` | `ndf` repo:.ndf | `project.json` | ndf_settings | 追跡 | 人と解析(M7) | kept | 内部(予告なく変えてよい) |
| `project-measured` | `measured` state:measured | `<repo>/project.json` | measured | — | 解析とテストの実行(M7) | replaced | 内部(予告なく変えてよい) |
| `projects` | `ndf` repo:.ndf | `projects.json` | ndf_settings | 追跡 | 人 | kept | 内部(予告なく変えてよい) |
| `relay-auth-held` | `relay-accounts` state:relay/accounts | `held.json` | measured | — | 中継のラッパー(M3b) | replaced | 内部(予告なく変えてよい) |
| `relay-copy-launcher` | `relay-copy` config:ndf | `relay.py` | exchange | — | 人(ndf relay install) | replaced | 内部(予告なく変えてよい) |
| `relay-copy-root` | `relay-copy` config:ndf | `relay.root` | exchange | — | 中継(M3b)・SessionStart hook(更新後の向け直し) | replaced | 内部(予告なく変えてよい) |
| `relay-hub-log` | `relay-hub` state:relay/hub | `hub-log.jsonl` | record | — | 中継のリレーハブ(M3) | cleanup | 内部(予告なく変えてよい) |
| `relay-hub-registry` | `relay-hub` state:relay/hub | `registry.json` | exchange | — | 中継(M3) | replaced | 内部(予告なく変えてよい) |
| `relay-hub-request` | `relay-hub` state:relay/hub | `requests-v2/<id>.json` | exchange | — | 中継の頼む側(M3) | run | 内部(予告なく変えてよい) |
| `relay-hub-result` | `relay-hub` state:relay/hub | `results/<id>.json` | exchange | — | 中継のリレーハブ(M3) | run | 内部(予告なく変えてよい) |
| `relay-hub-state` | `relay-hub` state:relay/hub | `hub.json` | exchange | — | 中継(M3) | replaced | 内部(予告なく変えてよい) |
| `relay-limit-seen` | `relay-accounts` state:relay/accounts | `limited.json` | measured | — | 中継のラッパー(M3b) | replaced | 内部(予告なく変えてよい) |
| `relay-marker` | `relay-markers` state:relay/markers | `<id>.json` | exchange | — | 中継のラッパー(M3b) | run | 内部(予告なく変えてよい) |
| `relay-next` | `relay-wrappers` state:relay/wrappers | `<名前>/next.json` | exchange | — | Stop の hook(M3a) | run | 内部(予告なく変えてよい) |
| `relay-pinned-account` | `relay-accounts` state:relay/accounts | `pinned.json` | ndf_settings | — | 人(ndf relay account use) | replaced | 内部(予告なく変えてよい) |
| `relay-question` | `relay-wrappers` state:relay/wrappers | `<名前>/question.json` | exchange | — | PreToolUse の hook(M3a) | run | 内部(予告なく変えてよい) |
| `relay-stop` | `relay-wrappers` state:relay/wrappers | `<名前>/stop` | exchange | — | ndf relay stop(M3b)と人(touch) | run | 内部(予告なく変えてよい) |
| `relay-usage` | `relay-accounts` state:relay/accounts | `usage.json` | measured | — | 使用率のセンサー(M3a) | replaced | 内部(予告なく変えてよい) |
| `relay-usage` | `relay-accounts` state:relay/accounts | `usage/<名前>/<世代>.json` | measured | — | NDF の status line(statusline.sh) | replaced | 内部(予告なく変えてよい) |
| `relay-wrapper` | `relay-wrappers` state:relay/wrappers | `<名前>/wrapper.json` | exchange | — | 中継のラッパー(M3b) | replaced | 内部(予告なく変えてよい) |
| `relay-wrapper-lock` | `relay-wrappers` state:relay/wrappers | `<名前>/relay.lock` | exchange | — | 中継のラッパー(M3b) | replaced | 内部(予告なく変えてよい) |
| `relay-wrapper-log` | `relay-wrappers` state:relay/wrappers | `<名前>/log.jsonl` | record | — | 中継のラッパー(M3b) | cleanup | 内部(予告なく変えてよい) |
Expand Down
2 changes: 1 addition & 1 deletion plugins/ndf/docs/contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NDF を外から呼ぶ面(設定・サブコマンド・環境変数・受け
| [サブコマンドの引数と結果](commands.md) | 公開 0・内部 28 |
| [終了コードと停止理由](exit-codes.md) | 終了コード 11・停止理由 33 |
| [環境変数](env.md) | 公開 10・内部 69 |
| [受け渡しのファイル](files.md) | 公開 12・内部 56 |
| [受け渡しのファイル](files.md) | 公開 12・内部 58 |
| [hook の入出力](hooks.md) | 公開 6・内部 11 |
| [Skill と起動スクリプト](skills.md) | 公開 1・内部 48 |

Expand Down
25 changes: 17 additions & 8 deletions plugins/ndf/src/ndf/domains/relay/account_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,22 @@ def _wait_exit(p: dict[str, Any]) -> bool:
return _wait_until(lambda: not _alive(p), limits.seconds("relay.login-exit"))


def _register(store: Path, claude: str, name: str, config_dir: Path, environ: Mapping[str, str], now: float) -> Added:
ident = _identity(claude, config_dir, environ)
# 登録の後始末(`reg.register` の `settle`。前の世代・新しい世代を受け、登録の排他の中で呼ばれる)
Settle = Optional[Callable[[Optional[str], str], None]]


def _register(store: Path, name: str, config_dir: Path, environ: Mapping[str, str], now: float, settle: Settle = None) -> Added:
ident = _identity(_claude(), config_dir, environ)
if ident is None or not (config_dir / reg.CRED_FILE).is_file():
raise LoginError("refused", "ログインが通らなかった。登録しない")
owner = owner_of(store, ident.email, ident.org_id, other_than=name)
if owner:
raise LoginError("refused", f"同じメールアドレスと組織で登録済み: {owner}")
reg.register(store, name, config_dir, ident, now)
reg.register(store, name, config_dir, ident, now, settle)
return Added(name, needs_code=False, email=ident.email, org_name=ident.org_name or None) # noqa: NDF501 外部コマンド: 組織名の無い本人は null


def _finish(store: Path, name: str, code: str, environ: Mapping[str, str], now: float) -> Added:
def _finish(store: Path, name: str, code: str, environ: Mapping[str, str], now: float, settle: Settle = None) -> Added:
p = _read_pending(store, name)
try:
if p is None:
Expand All @@ -293,19 +297,24 @@ def _finish(store: Path, name: str, code: str, environ: Mapping[str, str], now:
os.close(fd)
if not _wait_exit(p):
raise LoginError("refused", "claude auth login が終わらなかった。登録しない")
return _register(store, _claude(), name, pending_dir(store, name) / PENDING_CONFIG, environ, now)
return _register(store, name, pending_dir(store, name) / PENDING_CONFIG, environ, now, settle)
finally:
discard_pending(store, name)


def add(store: Path, name: str, code: Optional[str], environ: Mapping[str, str], now: Optional[float] = None) -> Added:
"""`code` が無ければ待機中のログインを起動して認可コードを求め、あれば渡して登録する。"""
def add(
store: Path, name: str, code: Optional[str], environ: Mapping[str, str], now: Optional[float] = None, settle: Settle = None
) -> Added:
"""`code` が無ければ待機中のログインを起動して認可コードを求め、あれば渡して登録する。

`settle` は登録の排他の中で前の世代の記録を片付ける呼び出し(`reg.register` の `settle`)。
"""
now = time.time() if now is None else now
sweep_pending(store, now)
check_name(store, name)
if code is None:
return _start(store, name, environ, now)
return _finish(store, name, code, environ, now)
return _finish(store, name, code, environ, now, settle)


def logout(store: Path, name: str, environ: Mapping[str, str]) -> bool:
Expand Down
Loading