fix(agent): bound structured close reasons - #3213
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gittensory-ui | 38a1c3b | Commit Preview URL Branch Preview URL |
Jul 04 2026, 11:26 PM |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-07-04 23:27:03 UTC
⏸️ Suggested Action - Manual Review Review summary Nits — 4 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3213 +/- ##
=======================================
Coverage 94.11% 94.11%
=======================================
Files 275 275
Lines 30120 30124 +4
Branches 10993 10995 +2
=======================================
+ Hits 28347 28351 +4
Misses 1127 1127
Partials 646 646
🚀 New features to boost your workflow:
|
…t path The executor's closeReasonsForAudit() pre-bounded the reason count before buildAgentActionAudit() ever saw it, so closeReasonsTruncated could never be set on a real close action -- only on a direct buildAgentActionAudit() call with an unbounded array. Count-bounding now happens exactly once, inside buildAgentActionAudit, so the persisted audit row's closeReasonCount/closeReasonsTruncated reflect the true original count regardless of caller. Also removes a resulting dead ?? fallback that TypeScript's own narrowing already made unreachable.
The prior fix restored truncation visibility but reintroduced the original cost problem: closeReasonsForAudit mapped every reason through boundAuditReason before any count cap ran, so an unbounded closeReasons array still cost O(N) string-length work on the hot executor path. Bound the count first (a cheap slice), map only the bounded subset, and carry the true original count to buildAgentActionAudit separately (as closeReasonCount) so the persisted audit row still correctly flags truncation.
Motivation
metadata_jsonorparams_jsonrows and exhaust storage or D1 limits.Description
STRUCTURED_CLOSE_REASONS_MAX_COUNTandboundStructuredCloseReasonsForPersistence()to cap the number of persisted structured close reasons to a safe, small constant.buildAgentActionAudit()copies a bounded slice and exposescloseReasonsTruncatedwhen the original count exceeded the cap, andcloseReasonsForAudit()andactionParams()also use the same bound before per-reason truncation.AUDIT_REASON_MAX_LENGTH = 280) while preventing an unbounded array from being serialized.buildAgentActionAudit()truncation behavior, and regenerate the self-host env reference updated by the edit.Testing
npm test -- --run test/unit/agent-execution.test.ts test/unit/agent-action-executor.test.ts, which passed.npm run typecheckwhich succeeded (no type errors).npm run test:ci, but the run could not be completed in this environment due to unrelated long-runningqueuetests/timeouts and was stopped; the functional unit coverage for the changed files was verified locally.npm audit --audit-level=moderatewas attempted but the registry audit endpoint returned403 Forbiddenin this environment so the dependency-audit step could not be completed here.Codex Task