Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 28 additions & 8 deletions .github/workflows/desktop-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,20 @@ jobs:
--jq '.assets[].name | select(. == "DESKTOP-SHA256SUMS" or (startswith("LoopX") and (endswith(".dmg") or endswith(".zip") or endswith(".exe") or endswith(".msi"))))'
)
for asset in "${assets[@]}"; do
gh release download "${RELEASE_TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "${asset}" \
--dir dist/previous-desktop
for attempt in 1 2 3 4; do
rm -f "dist/previous-desktop/${asset}"
if gh release download "${RELEASE_TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "${asset}" \
--dir dist/previous-desktop
then
break
fi
if [[ "${attempt}" -eq 4 ]]; then
exit 1
fi
sleep "$((1 << (attempt - 1)))"
done
done
{
echo "release_tag=${RELEASE_TAG}"
Expand Down Expand Up @@ -434,10 +444,20 @@ jobs:
"LoopX_${RELEASE_VERSION}_x64_en-US.msi" \
DESKTOP-SHA256SUMS
do
gh release download "${RELEASE_TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "${asset}" \
--dir dist/published-desktop
for attempt in 1 2 3 4; do
rm -f "dist/published-desktop/${asset}"
if gh release download "${RELEASE_TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "${asset}" \
--dir dist/published-desktop
then
break
fi
if [[ "${attempt}" -eq 4 ]]; then
exit 1
fi
sleep "$((1 << (attempt - 1)))"
done
done
python scripts/desktop_release_artifacts.py verify-checksums \
--dist-dir dist/published-desktop \
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/desktop-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,16 @@ jobs:
decision=advance
if grep -Fxq desktop-updater.json <<<"$pointer_assets"; then
mkdir -p dist/current-pointer
gh release download "$pointer" --pattern desktop-updater.json --dir dist/current-pointer
for attempt in 1 2 3 4; do
rm -f dist/current-pointer/desktop-updater.json
if gh release download "$pointer" --pattern desktop-updater.json --dir dist/current-pointer; then
break
fi
if [ "$attempt" -eq 4 ]; then
exit 1
fi
sleep "$((1 << (attempt - 1)))"
done
decision="$(python scripts/desktop_update_feed.py \
--channel-pointer-decision "$CHANNEL" \
--current-feed dist/current-pointer/desktop-updater.json \
Expand Down
9 changes: 7 additions & 2 deletions loopx/capabilities/configuration_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ def capability_configuration_editor(
"string_list",
description=(
"One authorized executor id per line. Required only for "
"flexible selection; include the primary executor."
"flexible selection; include the primary executor. "
"Optional per-endpoint model and reasoning effort overrides "
"(endpoint_models) are authored in JSON mode and preserved "
"by guided saves."
),
),
_field(
Expand All @@ -252,7 +255,9 @@ def capability_configuration_editor(
nullable=True,
description=(
"Optional model for the selected executor. Leave blank to keep "
"the executor's own default."
"the executor's own default. Configure per-endpoint overrides "
"(endpoint_models: {\"<endpoint>\": {\"model\": ..., "
"\"reasoning_effort\": ...}}) in JSON mode."
),
),
_field(
Expand Down
84 changes: 53 additions & 31 deletions loopx/capabilities/native_chat/antigravity_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,39 @@ def _matching_antigravity_model_config(rows: list[Any], model_id: str) -> list[d
]


def _extract_user_model_quota(
user: Any,
model_id: str,
*,
fallback_rows: list[Any] | None = None,
) -> tuple[str, float, str] | None:
"""Validate and extract `(account_ref, remaining_fraction, reset_time)` for one canonical model."""
if not isinstance(user, Mapping):
return None
account = user.get("email")
if not isinstance(account, str) or not account.strip():
return None
rows = (user.get("cascadeModelConfigData") or {}).get("clientModelConfigs")
if not isinstance(rows, list):
if fallback_rows is None:
return None
rows = fallback_rows
matching = _matching_antigravity_model_config(rows, model_id)
if len(matching) != 1:
return None
quota = matching[0]["quotaInfo"]
fraction, reset = quota.get("remainingFraction", 0), quota.get("resetTime")
if (type(fraction) not in (int, float) or not math.isfinite(fraction)
or not 0 <= fraction <= 1 or not isinstance(reset, str)
or datetime.fromisoformat(reset).tzinfo is None):
return None
return (
hashlib.sha256(account.strip().casefold().encode()).hexdigest(),
fraction,
reset,
)


def _native_user_input_text(step: dict[str, Any]) -> str | None:
"""Read the one native text item; any redundant response must agree."""
content = step.get("userInput")
Expand Down Expand Up @@ -683,6 +716,7 @@ def metadata_review_capacity(*, cascade_id: str, model_id: str) -> dict[str, Any
native failure alongside the exact model's quota epoch.
"""
try:
canonical_model_id, _ = resolve_antigravity_model_placeholder(model_id)
found = discover_antigravity_language_server()
if found is None:
return None
Expand Down Expand Up @@ -717,25 +751,15 @@ def read(method: str, payload: dict[str, Any]) -> dict[str, Any]:
if not normal and not exhausted:
return None # An unknown native failure is not capacity evidence.
status = read("GetUserStatus", {})
user = status["userStatus"]
account = user.get("email")
if not isinstance(account, str) or not account.strip():
return None
rows = user["cascadeModelConfigData"]["clientModelConfigs"]
matching = _matching_antigravity_model_config(rows, model_id)
if len(matching) != 1:
return None
quota = matching[0]["quotaInfo"]
fraction, reset = quota.get("remainingFraction", 0), quota.get("resetTime")
if (type(fraction) not in (int, float) or not math.isfinite(fraction)
or not 0 <= fraction <= 1 or not isinstance(reset, str)
or datetime.fromisoformat(reset).tzinfo is None):
extracted = _extract_user_model_quota(status.get("userStatus"), canonical_model_id)
if extracted is None:
return None
account_ref, fraction, reset = extracted
after = read("GetCascadeTrajectory", {"cascadeId": cascade_id})
if (after.get("status") != before["status"] or after.get("numTotalSteps") != total
or (after.get("trajectory") or {}).get("cascadeId") != cascade_id):
return None
return {"model_id": model_id, "account_ref": hashlib.sha256(account.strip().casefold().encode()).hexdigest(),
return {"model_id": canonical_model_id, "account_ref": account_ref,
"remaining_fraction": fraction, "reset_time": reset,
"execution_id": (latest[0].get("metadata") or {}).get("executionId"),
"observed_at": time.time(), "quota_exhausted": exhausted, "normal_completion": normal}
Expand All @@ -746,35 +770,33 @@ def read(method: str, payload: dict[str, Any]) -> dict[str, Any]:
def endpoint_model_capacity(
*,
model_id: str,
reasoning_effort: str | None = None,
env: Mapping[str, str] | None = None,
discovered: Mapping[str, Any] | None = None,
) -> dict[str, Any] | None:
"""Observe the live LS account's quota for one offered model without opening a cascade."""
try:
canonical_model_id, _ = resolve_antigravity_model_placeholder(
model_id,
reasoning_effort,
)
found = discovered or discover_antigravity_language_server(env=env, include_model_config=True)
if found is None:
return None
status = _rpc_post(str(found["url"]), str(found["csrf_token"]), "GetUserStatus", {}, timeout=5.0)
user = status["userStatus"]
account = user.get("email")
if not isinstance(account, str) or not account.strip():
return None
rows = (user.get("cascadeModelConfigData") or {}).get("clientModelConfigs")
if not isinstance(rows, list):
rows = (found.get("model_config_data") or {}).get("clientModelConfigs") or []
matching = _matching_antigravity_model_config(rows, model_id)
if len(matching) != 1:
return None
quota = matching[0]["quotaInfo"]
fraction, reset = quota.get("remainingFraction", 0), quota.get("resetTime")
if (type(fraction) not in (int, float) or not math.isfinite(fraction)
or not 0 <= fraction <= 1 or not isinstance(reset, str)
or datetime.fromisoformat(reset).tzinfo is None):
fallback_rows = (found.get("model_config_data") or {}).get("clientModelConfigs") or []
extracted = _extract_user_model_quota(
status.get("userStatus"),
canonical_model_id,
fallback_rows=fallback_rows if isinstance(fallback_rows, list) else [],
)
if extracted is None:
return None
account_ref, fraction, reset = extracted
exhausted = fraction <= 0
return {
"model_id": model_id,
"account_ref": hashlib.sha256(account.strip().casefold().encode()).hexdigest(),
"model_id": canonical_model_id,
"account_ref": account_ref,
"remaining_fraction": fraction,
"reset_time": reset,
"execution_id": f"endpoint-probe:{uuid.uuid4().hex}",
Expand Down
9 changes: 6 additions & 3 deletions loopx/chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,13 @@ def manager_session_quota_route(controller: Any, session: Mapping[str, Any]) ->
else:
route = accounts.steward_route(**route_inputs, primary_capacity=None, fallback_capacity=None)
if route.get("endpoint") is None:
target_ag_model = manager_model_resolution(
target_ag_config = manager_model_config(
clean_environment, endpoint="antigravity", machine_defaults=defaults,
)[0]
capacity = AntigravityAdapter.endpoint_model_capacity(model_id=target_ag_model)
)
capacity = AntigravityAdapter.endpoint_model_capacity(
model_id=target_ag_config["model"],
reasoning_effort=target_ag_config["reasoning_effort"],
)
if capacity is not None:
route = accounts.steward_route(
**route_inputs, primary_capacity=None, fallback_capacity=capacity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ function receiptEffectIds(payload: Record<string, unknown>): string[] {

function executablePlanArgs(
steps: readonly Record<string, unknown>[],
kind: 'durable_writeback' | 'quota_spend',
kind: 'durable_writeback',
replacements: Readonly<Record<string, string>> = {},
): string[] {
const command = String(
steps.find(step => step.kind === kind)?.command_template ?? '',
)
expect(command).not.toBe('')
const tokens = command.match(/'[^']*'|"[^"]*"|\S+/gu) ?? []
expect(tokens.shift()).toBe('loopx')
const args = tokens.map(token => replacements[token] ?? token.replace(/^(['"])(.*)\1$/u, '$2'))
Expand Down Expand Up @@ -522,6 +523,7 @@ describe('DSH admission-to-closeout integration', () => {
expect(heartbeatReceipt.turn_instance_id).toBe(turnInstanceId)
const cliChannel = record(record(guard.payload.interaction_contract).cli_channel)
const rawPlan = record(cliChannel.settlement_plan)
expect(rawPlan.schema_version).toBe('quota_settlement_plan_v2')
const identity = record(rawPlan.identity)
const replayChannel = record(record(guardReplay.payload.interaction_contract).cli_channel)
expect(record(record(replayChannel.settlement_plan).identity)).toEqual(identity)
Expand All @@ -530,16 +532,15 @@ describe('DSH admission-to-closeout integration', () => {
expect(identity.todo_id).toBe(todoId)
expect(JSON.stringify(rawPlan)).not.toContain('${LOOPX_TURN:?}')
const steps = array(rawPlan.ordered_steps).map(record)
const writebackTemplate = String(
steps.find(step => step.kind === 'durable_writeback')?.command_template,
)
const spendTemplate = String(
steps.find(step => step.kind === 'quota_spend')?.command_template,
)
for (const command of [writebackTemplate, spendTemplate]) {
expect(command).toContain(`--turn-instance-id ${turnInstanceId}`)
expect(command).toContain(`--todo-id ${todoId}`)
}
const writebackStep = steps.find(step => step.kind === 'durable_writeback')
const spendStep = steps.find(step => step.kind === 'quota_spend')
const writebackTemplate = String(writebackStep?.command_template)
expect(writebackStep?.owner).toBe('agent')
expect(writebackTemplate).toContain(`--turn-instance-id ${turnInstanceId}`)
expect(writebackTemplate).toContain(`--todo-id ${todoId}`)
expect(writebackTemplate).toContain('--settle-turn')
expect(spendStep?.owner).toBe('runtime')
expect(spendStep?.command_template).toBeUndefined()

const writeback = await runCli(testFixture, [
...executablePlanArgs(steps, 'durable_writeback', {
Expand All @@ -552,15 +553,25 @@ describe('DSH admission-to-closeout integration', () => {
])
expect(writeback.exitCode, JSON.stringify(writeback.payload)).toBe(0)
expect(new Set(receiptEffectIds(writeback.payload))).toEqual(new Set([effectId]))
expect(
array(record(writeback.payload.settlement_result).receipts)
.map(receipt => String(record(receipt).step_kind)),
).toEqual(['validation', 'durable_writeback', 'quota_spend'])

const spendArgs = executablePlanArgs(steps, 'quota_spend')
const spend = await runCli(testFixture, spendArgs)
const spendReplay = await runCli(testFixture, spendArgs)
expect(spend.exitCode).toBe(0)
expect(spendReplay.exitCode).toBe(0)
const spendReplay = await runCli(testFixture, [
'quota', 'spend-slot',
'--goal-id', goalId,
'--slots', '1',
'--source', 'heartbeat',
'--execute',
'--todo-id', todoId,
'--agent-id', agentId,
'--turn-instance-id', turnInstanceId,
])
expect(spendReplay.exitCode, JSON.stringify(spendReplay.payload)).toBe(0)
expect(spendReplay.payload.idempotent_replay).toBe(true)
expect(spendReplay.payload.appended).toBe(false)
expect(new Set(receiptEffectIds(spend.payload))).toEqual(new Set([effectId]))
expect(new Set(receiptEffectIds(spendReplay.payload))).toEqual(new Set([effectId]))

const closeout = await runCli(testFixture, [
'todo', 'complete',
Expand Down
Loading
Loading