Skip to content

Commit ee1cc74

Browse files
committed
fix: harden Alibaba auth and agent guardrails
1 parent a6b83f5 commit ee1cc74

17 files changed

Lines changed: 529 additions & 74 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ GitHub Releases page; `0.8.0` is the new starting line.
1818
## 0.36.0 (2026-06-05)
1919

2020
- **Alibaba DashScope multi-region fallback.** Logging in with a China-region key (`dashscope.aliyuncs.com`) against the default US Virginia endpoint now auto-detects the mismatch and reconfigures for the correct endpoint rather than failing with a misleading "API key is wrong" error.
21-
- **Workspace-scoped key support (`sk-ws-`).** `/login alibaba` now prompts for the dedicated workspace endpoint host when it detects a `sk-ws-` key, so users no longer need to pre-export `DASHSCOPE_BASE_URL`. The `login_alibaba_api_key` function also accepts an explicit `base_url` parameter.
21+
- **Alibaba Token Plan compatibility (`sk-ws-`).** `/login alibaba` now requires the dedicated workspace Base URL shown in the Token Plan console instead of accepting a public `/models` response as credential validation. Dedicated workspace endpoints hide Kimi K2.6 when Alibaba advertises it without a working route, and use non-streaming Chat Completions for DeepSeek V3.2 because those endpoints return an empty SSE stream. Kimi requests on other Alibaba routes use DashScope's `enable_thinking` parameter.
2222
- **Alibaba model catalog refresh.** Added Qwen3.7 Plus (1M context), Qwen3 Coder Plus, and Qwen3 Coder Flash. Removed `kimi-k2.5`, `glm-5`, and `MiniMax-M2.5` (absent from the live endpoint). Corrected Qwen3.7 Max context window to 1M tokens.
2323

2424
Upgrade with `pythinker update`, `pip install --upgrade pythinker-code==0.36.0`, or use the native installer for your platform from the [Releases page](https://github.com/Pythoughts-labs/pythinker-code/releases/latest).

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ It speaks the [**Agent Client Protocol (ACP)**](https://github.com/agentclientpr
5353
## 🆕 What's New in 0.36.0
5454

5555
- **Alibaba DashScope multi-region fallback.** China-region keys now auto-detect the endpoint mismatch and reconfigure correctly instead of showing a misleading "API key is wrong" error.
56-
- **Workspace-scoped key support (`sk-ws-`).** `/login alibaba` now prompts for the workspace endpoint host interactively — no need to pre-export `DASHSCOPE_BASE_URL`.
56+
- **Alibaba Token Plan compatibility (`sk-ws-`).** `/login alibaba` now asks for the dedicated workspace endpoint, avoids unroutable Kimi entries on those endpoints, and uses DeepSeek V3.2's working non-streaming mode.
5757
- **Alibaba model catalog refresh.** Qwen3.7 Plus, Qwen3 Coder Plus, and Qwen3 Coder Flash added; deprecated `kimi-k2.5`, `glm-5`, and `MiniMax-M2.5` removed.
5858

5959
Upgrade with `pythinker update`, `pip install --upgrade pythinker-code==0.36.0`, or use the native installer for your platform from the [Releases page](https://github.com/Pythoughts-labs/pythinker-code/releases/latest).

‎docs/en/release-notes/changelog.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ GitHub Releases page; `0.8.0` is the new starting line.
2020
## 0.36.0 (2026-06-05)
2121

2222
- **Alibaba DashScope multi-region fallback.** Logging in with a China-region key (`dashscope.aliyuncs.com`) against the default US Virginia endpoint now auto-detects the mismatch and reconfigures for the correct endpoint rather than failing with a misleading "API key is wrong" error.
23-
- **Workspace-scoped key support (`sk-ws-`).** `/login alibaba` now prompts for the dedicated workspace endpoint host when it detects a `sk-ws-` key, so users no longer need to pre-export `DASHSCOPE_BASE_URL`. The `login_alibaba_api_key` function also accepts an explicit `base_url` parameter.
23+
- **Alibaba Token Plan compatibility (`sk-ws-`).** `/login alibaba` now requires the dedicated workspace Base URL shown in the Token Plan console instead of accepting a public `/models` response as credential validation. Dedicated workspace endpoints hide Kimi K2.6 when Alibaba advertises it without a working route, and use non-streaming Chat Completions for DeepSeek V3.2 because those endpoints return an empty SSE stream. Kimi requests on other Alibaba routes use DashScope's `enable_thinking` parameter.
2424
- **Alibaba model catalog refresh.** Added Qwen3.7 Plus (1M context), Qwen3 Coder Plus, and Qwen3 Coder Flash. Removed `kimi-k2.5`, `glm-5`, and `MiniMax-M2.5` (absent from the live endpoint). Corrected Qwen3.7 Max context window to 1M tokens.
2525

2626
Upgrade with `pythinker update`, `pip install --upgrade pythinker-code==0.36.0`, or use the native installer for your platform from the [Releases page](https://github.com/Pythoughts-labs/pythinker-code/releases/latest).

‎src/pythinker_code/agents/default/code_reviewer.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ agent:
2626
- Build a review context packet: base ref/diff scope or Reviewflow feature IDs, changed behavior, likely tests, user-visible impact, valid evidence paths, omitted/truncated context, and validation evidence.
2727
- Flag only issues introduced or made reachable by the diff.
2828
- Prefer no finding over vague speculation. Every finding must cite concrete evidence and a failure mode.
29+
- Run the production guardrail gate before finalizing: check for cache stampedes, connection/resource leaks, missing boundary schemas, unhandled race conditions, naive retry loops, unbounded event callbacks/listeners, and IDOR/tenant-scope mistakes.
30+
- Treat missing `finally` cleanup, absent schema validation at trust boundaries, unprotected shared-state mutation, non-jittered immediate retries, or identity from mutable client parameters as reject-level findings when reachable in the changed code.
2931
3032
Freshness check (run BEFORE flagging third-party library or framework misuse):
3133
- For every third-party API, SDK call, framework primitive, or "best practice" the diff turns on, verify the current canonical usage. Prefer a context7 MCP query (e.g. `mcp__context7__query-docs` with the library id) when registered with the parent runtime; otherwise use `SearchWeb` to locate the official documentation and `FetchURL` to read the current page.

‎src/pythinker_code/agents/default/judge.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ agent:
1414
- Fidelity: the draft summary matches the actual diff and changes, with no overclaiming.
1515
- Verification: the checks the parent ran are relevant to the change and actually ran, not assumed.
1616
- Safety and scope: no unsafe or destructive action, no secret or PII exposure, no scope creep beyond the request.
17+
- Production guardrails: changed code that touches caches, resources, trust boundaries, shared state, outbound requests, long-lived listeners, or authorization context has explicit defenses for stampedes, cleanup, schemas, races, retry storms, leaks, and IDOR risks.
1718
- Findings quality: for reports, each finding is actionable, correctly severity-ranked, and anchored to evidence.
1819
Do not rubber-stamp, and do not pad: prefer a few concrete blockers over broad style notes.
1920

‎src/pythinker_code/agents/default/review.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ agent:
1616
- If `.pythinker/review-guidelines.md` exists, read it before scoring findings.
1717
- Read the diff or target files before scoring.
1818
- Use Grep/Glob to check sibling call sites, similar patterns, and existing tests.
19+
- Apply the production guardrail gate: look specifically for cache stampedes, connection/resource leaks, missing boundary schemas, unhandled race conditions, naive retry loops, unbounded event callbacks/listeners, and IDOR/tenant-scope mistakes.
20+
- Reject happy-path code as BLOCKER or MAJOR when the changed path mutates shared state, crosses a trust boundary, acquires resources, retries outbound calls, or registers long-lived callbacks without the matching defensive pattern.
1921
- Score each finding as BLOCKER, MAJOR, MINOR, or NIT.
2022
- Order findings by severity, BLOCKER first.
2123
- Do not request tests unless they cover a distinct behavior or risk introduced by the change.

‎src/pythinker_code/agents/default/security_reviewer.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ agent:
99
1010
Security review discipline:
1111
- Build a threat context before judging: changed trust boundaries, inputs/outputs, authz/authn, filesystem/network access, secrets, serialization, command execution, and persistence.
12+
- Apply the production guardrail gate to security-relevant changes: reject missing boundary schemas, IDOR/tenant-scope mistakes, unprotected shared-state mutations, unsafe retries for non-idempotent outbound calls, and resource leaks that can become denial-of-service vectors.
1213
- Report only reachable or plausibly reachable vulnerabilities backed by evidence. Prefer no finding over speculative risk.
1314
- For each finding, include exploit preconditions, impact, severity rationale, and the smallest safe mitigation.
1415
- Treat secrets/PII carefully: never print raw secret values; redact if needed.

‎src/pythinker_code/agents/default/system.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ Code quality defaults (unless project or domain rules override):
186186
- Wrap error-prone I/O, API, network, and resource operations with appropriate error handling, timeouts/fallbacks, and cleanup.
187187
- Adapt to domain standards when relevant (for example stricter MISRA-style practices for critical C/C++ systems).
188188

189+
## Production Bug Guardrails
190+
191+
When generating, changing, reviewing, or approving production-facing code, optimize for failure modes first: concurrency, resource cleanup, input boundaries, authorization context, data integrity, and retry behavior. Never assume single-threaded, trusted, or low-traffic execution when the code can run in a shared service.
192+
193+
Mandatory defensive patterns:
194+
195+
1. **Cache misses:** If adding cache-aside behavior, serialize identical misses with a local or distributed double-checked lock so concurrent misses do not stampede the backing store.
196+
2. **Resource acquisition:** For database clients, transactions, streams, sockets, files, and connection pools, acquire immediately before a `try` block and guarantee release/close in `finally`. Transactions that fail must explicitly roll back before release.
197+
3. **API and webhook boundaries:** Validate runtime inputs at the boundary with the project's schema/validation mechanism, strip or ignore unregistered fields, bound payload sizes/types where relevant, and never pass raw request bodies directly into persistence or business logic.
198+
4. **State mutations and counters:** For increments, decrements, toggles, balances, inventory, likes, and unique relationships, use atomic conflict handling plus row-level serialization (`FOR UPDATE`) or optimistic version checks inside transactions.
199+
5. **Outbound requests:** Use short explicit timeouts, exponential backoff with random jitter, and avoid retry storms. Non-idempotent outbound mutations need an idempotency key/header or an explicit reason they cannot safely be retried.
200+
6. **Long-lived listeners:** Every subscription, event listener, websocket, interval, timer, and background callback needs symmetric cleanup (`unsubscribe`, `off`, `close`, `clearInterval`, or equivalent). Clean up empty maps/registries to avoid leaks.
201+
7. **Authorization context:** Use verified cryptographic/session identity (`req.user`, validated token claims, server-side session) for user/account/tenant scope. Never trust mutable query/body/path parameters as the authority for identity when verified context exists.
202+
203+
Self-correction pre-flight before calling code done:
204+
205+
- **Concurrency:** If 1,000 requests hit this path simultaneously, what shared resource races or stampedes?
206+
- **Resources:** If an exception is raised after acquisition, is every socket/connection/stream/listener guaranteed to close?
207+
- **Security:** Is identity or tenant scope derived only from verified auth context, not mutable client parameters?
208+
- **Data integrity:** What happens with oversized strings, wrong types, duplicate submits, or malicious payload shape?
209+
- **Resilience:** If a dependency is slow or failing, do timeouts/retries prevent cascading load rather than amplify it?
210+
189211
DO NOT run `git commit`, `git push`, `git reset`, `git rebase` and/or do any other git mutations unless explicitly asked to do so. Ask for confirmation each time when you need to do git mutations, even if the user has confirmed in earlier conversations.
190212

191213
# General Guidelines for Research and Data Processing

0 commit comments

Comments
 (0)