Close the native P1 gaps the audit listed for this batch
Why: token budget let the current tool batch run, compaction could split a tool pair or race an append, writes were not crash-atomic, and several MCP and session edges only existed as comments. Evidence: GOWORK=off go test -count=1 -race ./runtime/ ./runtime/llm/ ./runtime/session/ ./runtime/tools/ ./runtime/mcp/ ./adapters/native/ ./adapters/intentgate/ passed, including the TestR2* cases for budget, replacement, cancel, compaction, SSE, UTF-8, schema, MCP retry, session terminate, poison reload, and registry reload. Impact: over-budget tool calls are skipped and paired; Stop.Replacement is appended to the session; the intent gate can follow Registry.Reload. Refs: N5, N6, N7, N8, N9, N11, N12, N15, N16, N17, N18, N19, N21, I9 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -276,9 +276,7 @@ func (b *Backend) Execute(ctx context.Context, req exec.Request) (*exec.Result,
|
||||
|
||||
if runRes.Err != nil {
|
||||
reason := runRes.Err.Error()
|
||||
b.mu.Lock()
|
||||
b.lastFailure[workDir] = reason
|
||||
b.mu.Unlock()
|
||||
b.noteFailure(workDir, reason)
|
||||
assessment := exec.AssessStepFailure(exec.StepFailureSignals{
|
||||
Err: runRes.Err,
|
||||
WorkDir: workDir,
|
||||
@@ -293,9 +291,7 @@ func (b *Backend) Execute(ctx context.Context, req exec.Request) (*exec.Result,
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
b.mu.Lock()
|
||||
delete(b.lastFailure, workDir)
|
||||
b.mu.Unlock()
|
||||
b.clearFailure(workDir)
|
||||
|
||||
patches, matErr := exec.MaterializeTargets(workDir, req.Targets, nil)
|
||||
if matErr != nil {
|
||||
@@ -433,9 +429,7 @@ var resumeUnsafeMarkers = []string{
|
||||
|
||||
// rotateIfPoisoned 上次失败属 resume-unsafe 且存在旧会话时归档旧会话。
|
||||
func (b *Backend) rotateIfPoisoned(workDir string) {
|
||||
b.mu.Lock()
|
||||
reason := strings.ToLower(b.lastFailure[workDir])
|
||||
b.mu.Unlock()
|
||||
reason := strings.ToLower(b.failureReason(workDir))
|
||||
if reason == "" {
|
||||
return
|
||||
}
|
||||
@@ -469,6 +463,36 @@ func (b *Backend) logger() *logsys.Logger {
|
||||
return log.With("execution_id", b.opts.ExecutionID)
|
||||
}
|
||||
|
||||
const lastFailureFile = ".native-last-failure"
|
||||
|
||||
func (b *Backend) noteFailure(workDir, reason string) {
|
||||
b.mu.Lock()
|
||||
b.lastFailure[workDir] = reason
|
||||
b.mu.Unlock()
|
||||
_ = os.WriteFile(filepath.Join(workDir, lastFailureFile), []byte(reason), 0o644)
|
||||
}
|
||||
|
||||
func (b *Backend) clearFailure(workDir string) {
|
||||
b.mu.Lock()
|
||||
delete(b.lastFailure, workDir)
|
||||
b.mu.Unlock()
|
||||
_ = os.Remove(filepath.Join(workDir, lastFailureFile))
|
||||
}
|
||||
|
||||
func (b *Backend) failureReason(workDir string) string {
|
||||
b.mu.Lock()
|
||||
reason := b.lastFailure[workDir]
|
||||
b.mu.Unlock()
|
||||
if reason != "" {
|
||||
return reason
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(workDir, lastFailureFile))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(raw)
|
||||
}
|
||||
|
||||
// systemPrompt 经 promptx 组装:角色指令 + 环境事实 + 技能索引 + 交付物约束。
|
||||
func (b *Backend) systemPrompt(req exec.Request, model, profile, workDir string, skillIndex []skills.Skill) string {
|
||||
var index []promptx.IndexEntry
|
||||
|
||||
Reference in New Issue
Block a user